- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试测量数据包进入 Rx 缓冲区并复制到应用程序内存时的延迟。我正在用这段代码测量它:
struct timespec start, end;
clock_gettime(CLOCK_REALTIME, &start);
recvfrom(sock, msg, msg_len, 0, &client, &client_addrlen);
clock_gettime(CLOCK_REALTIME, &end);
我知道这不能精确测量延迟。但是,我可以通过接收许多数据包、测量每个数据包并计算它们来计算平均延迟。有什么方法可以更精确地测量延迟吗? (例如,latency =(recvfrom() 完成的时间)-(NIC 从中接收数据包的时间)
)
对于设备和设备驱动程序,我使用的是 Mellanox connectx-3 和 mlx4_en。
最佳答案
我能够通过 recvmsg()
获得几乎精确的数字。
我正在重现第一个链接中的代码。此代码不是准备运行的,而只是工作代码中的一个片段。
static struct timespec handle_time(struct msghdr *msg) {
struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg);
struct scm_timestamping *ts = (struct scm_timestamping *)CMSG_DATA(cmsg);
return ts->ts[0];
}
...
char ctrl[64];
char *msg = malloc(64);
int val = SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_RX_SOFTWARE
| SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RAW_HARDWARE;
setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMPING, &val, sizeof(val));
// user buffer
struct iovec iov = {
.iov_base = msg,
.iov_len = msg_len,
};
// ancillary message header
struct msghdr m = {
.msg_name = &client_addr, // struct sockaddr_in
.msg_namelen = client_addrlen, // socklen_t
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = &ctrl,
.msg_controllen = sizeof(ctrl),
};
while (1) {
memset(msg, 0, msg_len);
num_received = recvmsg(sock_fd, &m, 0);
start = handle_time(&m);
clock_gettime(CLOCK_REALTIME, &end);
if (verbose) {
double elapsed_time = time_diff(start, end) / 1000;
total_elapsed += elapsed_time;
count++;
printf("%f us %f us\n", elapsed_time, total_elapsed / count);
}
if (sendto(sock_fd, msg, msg_len, 0, (struct sockaddr *) &client_addr, client_addrlen) < 0) {
perror("\nMessage Send Failed\n");
fprintf(stderr, "Value of errno: %d\n", errno);
}
}
关键点是使用setsockopt()
和recvmsg()
。关键机制是当你为某个套接字FD设置一个选项时,内核会根据时间戳标志设置一个时间戳。在你设置它们之后,如果你收到一个带有 struct msghdr
的消息,内核将以 SW 或 HW 的方式审计时间戳。当您查看数据时,您将能够获得 3 个时间戳。这些信息可以解释如下:
The structure can return up to three timestamps. This is a legacyfeature. At least one field is non-zero at any time. Most timestampsare passed in ts[0]. Hardware timestamps are passed in ts[2]. ts[1] used to hold hardware timestamps converted to system time. Instead, expose the hardware clock device on the NIC directly as a HW PTP clock source, to allow time conversion in userspace and optionally synchronize system time with a userspace PTP stack such as linuxptp. For the PTP clock API, see Documentation/driver-api/ptp.rst.
有关详细信息,请参阅 Documentation/networking/timestamping.txt
中的 2.1。
如果你想看到硬件时间戳,那么你需要有一个特定的硬件(引用 this comment )并用 ioctl()
改变它的特性。但是,有一个名为 linuxptp
的便捷工具可以完成这项工作。
关于c - 如何精确或近似地测量接收数据包的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69888516/
感觉我在这里遗漏了一些明显的东西,所以提前道歉。无论如何,这是我尝试转换的一些数据a: acct_num year_prem prem exc 001 20
我正在尝试将表中的模式与用户话语 匹配。 string userUtterance = "I want identification number for number of customers";
当尝试在 Precise 上链接 gccgo 时,出现此链接错误: matt@matt-1005P:~/src/gopath/src/meme$ gccgo cmd/meme/main.go -o m
假设我有以下数据和命令: clc;clear; t = [0:0.1:1]; t_new = [0:0.01:1]; y = [1,2,1,3,2,2,4,5,6,1,0]; p = interp1(
假设我有以下数据和命令: clc;clear; t = [0:0.1:1]; t_new = [0:0.01:1]; y = [1,2,1,3,2,2,4,5,6,1,0]; p = interp1(
我总是想给精确匹配比只匹配前缀的分数更高的分数(例如,“ball”在与“ball*”匹配时应该比“ballistic”得到更高的分数)。 我当前(详细)的方法是在创建 PrefixQuery 时始终执
有什么解决方法可以让我在 Android 中使用 long 或 double 来寻找音频文件中的位置吗?目前 seekTo 只接受 ints 参数。我想更精确(比如在十分之一秒内) int resID
我的 replacingOccurrences 函数有问题。我有一个这样的字符串: let x = "john, johnny, johnney" 我需要做的只是删除“john” 所以我有这段代码:
我正在使用 BeautifulSoup 进行网页抓取。我有这段代码来提取 a 标签的值,但它似乎不起作用。显示错误: AttributeError: 'int' object has no attri
我要在带有标记顶点和标记有向边的图上寻找一种不精确的图匹配算法。我的任务是检测两个图表的变化以将它们显示给开发人员(想想颠覆差异)。我已经实现了基于禁忌搜索 ( this ) 的优化算法,但我无法让该
我有两个网站: example.com 和 yyy.com 他们都有类似的网络应用程序,但在不同的服务器上。我想让 Apache 将所有路径请求重定向到 example.com 与 完全相同的方式yy
因此,我尝试合并两个公司信息数据库(从现在起表 A 和表 B),其中最常见(且可靠)的单一引用点是网站 URL。表 A 已更新,表 B 待更新。 我已经从表 A 中提取了 URL,并使用 PHP 清理
我正在 http://classicorthodoxbible.com/new.html 上制作效果主要描述中的 Angular 色,包裹在自己的跨度中,从他们通常的休息地点移动到随机位置,然后通过指
我目前正在使用我的 Raspberry Pi 及其内置 UART 输入编写 MIDI 合成器。 在某个时间点,为了启用 MIDI 输入的实时回放,我必须设置一种环形缓冲区以与 OpenAL 一起使用,
在 C 中,当设置了一个 float 时, int main(int argc, char *argv[]) { float temp = 98.6f; printf("%f\n",
实现 MP3 无间隙循环的最佳可能性是什么?目前我正在使用 AVAudioPlayer 并将 .numberOfLoops() 属性设置为 -1 但可以听到,轨道重新启动。情况并非如此,例如使用 Tr
我想创建不一定是“正确”矩阵的“类矩阵”对象。但是,确切地说,“类矩阵”是什么意思? 示例 1 > image(1:9) Error in image.default(1:9) : argument
给定一个像这样的 XML 文档: john &title; 我想解析上面的 XML 文档并生成其所有实体已解析的副本。因此,给定上述 XMl 文档,解析器应输出: john
需要说明的是,这种方法不是我要找的: 事实上,此方法会调整 ImageField 的大小。我想将 Image 对象的大小调整为特定且精确的无比例分辨率。有什么办法吗? --编辑-- 对我来说,Ima
我正在尝试使用 TF2.0 eager 模式执行精确的 GP 回归,基于来自 https://colab.research.google.com/github/tensorflow/probabili
我是一名优秀的程序员,十分优秀!