Five Minute Facts About Packet Timing
By Doug Arnold
Why is IEEE 1588 so accurate? Two words: Hardware timestamping. That’s it, really! Let me explain. The Precision Time Protocol, PTP, defined by IEEE 1588-2008 works by exchanging messages between master clocks and slave clocks.
Figure 1. Sequence diagram showing the exchange of messages between a PTP master clock and a PTP save clock. The departure and arrival times of the Sync and Delay_Request messages are saved as the four timestamps t1-t4. The Follow_Up and Delay_Response messages are used to transport the timestamps recorded at the master clock to the slave clock, so that it has the information needed to adjust its time.
At the end of these exchanges the slave clock has all four timestamps. So it can calculate the offset of it’s clock with respect to the master as
offset = (t2 + t3 – t1 – t4) /2
However, there is a catch. Isn’t there always? The equation assumes that the time it takes for messages to go from the master to the slave, the forward delay, is the same as the time it takes for messages to go from the slave to the master, the reverse delay. There is no problem if these delays are large, just so long as they are the same. Any difference in the forward and reverse delay results in an error in determining the difference between the master clock and the slave clock.
Why would the forward and reverse delays be different? Its mainly due to all of those pesky queues. There are queues in the routers, there are queues in the switches, there are even queues in the network stacks at the end devices. Usually messages spend minimal time in the queues, but sometimes they are waiting for a switch to finish up with other messages on the same port, or for an operating system to complete what it was doing so it can fetch a timestamp. In some cases the delay can be quite long, many microseconds, or even milliseconds. So obviously if this happens in the one direction, but not the other, then BAM! you’ve got a big time transfer error.
Since I already gave away the ending in the opening sentence, you know that this is solved with hardware timestamping. How this works is shown in the diagram below. When messages depart from or arrive at a network port, special hardware generates a timestamp from the local clock, usually in the media independent interface between the data link layer (MAC) and the physical layer (PHY). That removes the unpredictably slow response of the operating system and other software. Switches and routers which are PTP aware also timestamp PTP messages. One type of such devices, shown below, called a transparent clock works by updating PTP messages to correct for time spent in the device. Another type, called a boundary clock uses the PTP messages to set its own clock, then sends its time to PTP slaves which need it.
Figure 2. Diagram of hardware timestamping during the transport of a Sync messages. The Sync message triggers a timestamp at the local clocks of the PTP devices when it passes through the MII between the PHY and the MAC.
This delay measurement mechanism is know as the End-to-End delay measurement mechanism. As it turns out PTP has an alternative delay measurement mechanism known as the Peer-to-Peer mechanism. For a description of this approach to delay measurement see End-to-End Versus Peer-to-Peer.
- 1588 how to
- how does accuracy work towards hardware