Search code examples
network-programmingtimestampunix-timestampnictimestamping

Where exactly a timestamp is set?


I need to know at what exact point the timestamp for receiving or sent frames on a NIC is set. I have already searched a lot, but i can't find anything, which really helped me. For the sending-case it could be for example:

  • when the first Bit left the network cable
  • when the last Bit left the network cable
  • when the frame data was written into buffer

I am using a Intel 82541PI-Network Card.


Solution

  • I have done some research into this recently, but e.g. Linux driver writers may add more details or correct me if I am wrong. Short summary: When timestamp is taken is device dependent.

    For example on the Intel I210 NIC when using PTP one-step timestamping (i.e. the not-yet common PTP mode of specifying an offset into the UDP payload where a sender PTP timestamp is written by NIC hw), then the hw timestamp is taken right before frame is sent from MAC to PHY. At 1 Gbit speed, it then takes approx 178 ns until first bit after Ethernet preamble is put on the wire by the PHY. Look in NIC datasheet for your NIC for more info, or check the Linux driver source code. For I210, the datasheet is publicly downloadable, name 'Intel® Ethernet Controller I210 Datasheet'. Also note that it is not clear if I210 Linux driver (igb) supports one-step timestamping yet. The 'classic' way of doing it is to send a packet, receive hw timestamp on socket error queue, and then send the hw timestamp in a subsequent packet, this is called 2-step hw tx timestamping and is supported by many more NICs. Note also that the driver compensates for the 178 ns MAC-to-PHY latency.