5

Linux kernel provides two socket options for retrieving software timestamps of incoming network packets: SO_TIMESTAMP and SO_TIMESTAMPING with SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE flags. The documentation describes them as follows:

  • SO_TIMESTAMP

Generates a timestamp for each incoming packet in (not necessarily monotonic) system time.

  • SO_TIMESTAMPING

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

As far as I understood they are not the same, because the documentation says:

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

My question is, are these two timestamp types really different? If so, what's the difference?

Also I'm wondering what system time means here? Is this the same time source as clock_gettime with CLOCK_REALTIME provides?

dzhioev
  • 96
  • 1
  • 6
  • 18

1 Answers1

5

Your guess is correct they are not the same, the main difference between them is in the way they work or the result they provide, I found myself dealing with this during the implementations of some 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, this socket 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.

System time represents a computer system's notion of the passage of time. Depending on the context might be the time that took the CPU to finish an operation or the wall clock time the one that we usually called real-time. In this case is not necessarily the same this asnwer will help you to understand the difference between monotonic and system-time.

Hope the above helps to clarify (this might be helpful too)!

r4cc00n
  • 1,927
  • 1
  • 8
  • 24