gpt4 book ai didi

linux - SO_TIMESTAMP 和 SO_TIMESTAMPING 软件时间戳的区别

转载 作者:行者123 更新时间:2023-12-03 09:47:17 25 4
gpt4 key购买 nike

Linux 内核提供了两个套接字选项来检索传入网络数据包的软件时间戳:SO_TIMESTAMPSO_TIMESTAMPINGSOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE标志。 documentation将它们描述如下:

  • SO_TIMESTAMP

  • Generates a timestamp for each incoming packet in (not necessarilymonotonic) system time.


  • SO_TIMESTAMPING

  • Request rx timestamps when data enters the kernel. These timestampsare generated just after a device driver hands a packet to thekernel receive stack.


    据我所知,它们不一样,因为文档说:

    Note that if the SO_TIMESTAMP or SO_TIMESTAMPNS option is enabledtogether with SO_TIMESTAMPING using SOF_TIMESTAMPING_SOFTWARE, a falsesoftware timestamp will be generated in the recvmsg() call and passedin ts[0] when a real software timestamp is missing.


    我的问题是,这两种时间戳类型真的不同吗?如果是这样,有什么区别?
    另外我想知道系统时间在这里意味着什么?这是与 clock_gettime 相同的时间源吗?与 CLOCK_REALTIME提供?

    最佳答案

    你的猜测是正确的,它们不一样,它们之间的主要区别在于它们的工作方式或它们提供的结果,我发现自己在一些 drivers 的实现过程中处理了这个问题。 :SO_TIMESTAMP:

    This enables timestamps of datagrams on the reception path, if exist any destination socket is unknown beforehand which means that the same options are true for all the packets, this also generates timestamps per each packet received, and the result is a struct timeval.

    SO_TIMESTAMPNS:

    Same that SO_TIMESTAMP but returns the timestamp as struct timespec.

    SO_TIMESTAMPING:

    This option supports multiple types of timestamps requests and as a result, thissocket option takes a bitmap of flags, not a boolean. Also, this option generates timestamps on reception, transmission, or both at the same time and of course, supports different timestamp resources.

    struct timespec represents a simple calendar time, or an elapsed time, with sub-second resolution (nsec resolution). struct timeval. struct timeval is an older type for representing a simple calendar time, or an elapsed time, with sub-second resolution. It is almost the same as struct timespec, but provides only microsecond resolution.系统时间代表计算机系统的时间流逝概念。根据上下文,可能是 CPU 完成一项操作所用的时间或挂钟时间,我们通常称之为 real-time .在这种情况下不一定是相同的 asnwer将帮助您了解 monotonic 之间的区别和 system-time .
    希望以上内容有助于澄清( this might be helpful too)! 👍

    关于linux - SO_TIMESTAMP 和 SO_TIMESTAMPING 软件时间戳的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65363515/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com