我目前正在深入研究像PTP (IEEE 1588)这样的主题,以及捕捉网络流量的精确时间戳。Internet上的许多资源将硬戳作为网卡的一个功能,允许它们在将数据包放入(通常是不确定的)队列到应用层之前向数据包添加时间戳。
这些时间戳是什么样的?它们是相对于操作系统发送的启动信号还是绝对时间戳来测量的呢?绝对邮票是否与操作系统时钟或NIC管理的时钟同步?
发布于 2015-10-22 09:39:11
时间戳发生在基于NIC中时钟的硬件中。根据您的NIC,有一个NIC寄存器,您的时间戳将被写入,或者某个卡(英特尔82580)可以将信息添加到数据包缓冲区。对于将时间戳写入寄存器的卡,您必须先读取寄存器,然后寄存器才能对下一个数据包进行时间戳,从而有效地限制了您的吞吐量,而82580可以对所有数据包进行时间戳。
在Linux中,您将在数据包本身之外的数据结构中接收时间戳。下面是内核文档上的一些内容:
These timestamps are returned in a control message with cmsg_level
SOL_SOCKET, cmsg_type SCM_TIMESTAMPING, and payload of type
struct scm_timestamping {
struct timespec ts[3];
};
The structure can return up to three timestamps. This is a legacy
feature. Only one field is non-zero at any time. Most timestamps
are 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/ptp/ptp.txt.
时间戳是基于NIC时间的。我相信您可以修改NIC时钟,但更常见的方法是让NIC时钟自由运行(保证单调时间),并在用户空间中进行任何调整。调整可以包括用系统时间计算偏移量,并将收到的所有时间戳调整为系统时间。内核可以/可以(我检查了很长一段时间)为您做这件事,但是我相信推荐的方法是在用户空间中自己做。在其他应用程序中,您根本不关心绝对时间,因为数据包之间的相对时间是唯一重要的因素。
我的两个同事基于此编写了一个SLA度量应用程序。您可以在GitHub上找到源代码。
还有MoonGen,它是一个基于DPDK的框架,具有用于数据包处理的Lua脚本能力。他们有一个包含时间戳信息的优质纸。
https://networkengineering.stackexchange.com/questions/23402
复制相似问题