Skip to main content

PTP Time Synchronization

1 Overview​

PTP (Precision Time Protocol) is a protocol used to synchronize clocks across an entire computer network. It can achieve very high clock accuracy on local area networks, making it suitable for various measurement and control systems. As a high-precision environmental perception sensor, LiDAR relies on time synchronization to ensure the accuracy and reliability of its data in real-world application scenarios, which plays a critical role.

This document introduces the general principles of common PTP time synchronization protocols such as 1588v2 and gPTP (802.1AS) in detail.

2 1588v2 Protocol​

2.1 Overview​

The 1588v2 protocol is designed to implement high-precision time synchronization in networks. Through precise transmission of timestamp information and dynamic compensation mechanisms in the network, each node can spontaneously adjust its local clock to achieve microsecond-level or even sub-microsecond-level time synchronization.

2.2 Synchronization Principle​

The 1588v2 protocol mainly calculates the time deviation between the local clock of each slave node and the master clock by exchanging PTP data packets between master and slave nodes in the network, and adjusts the local clock frequency to synchronize with the master clock. Specifically, the 1588v2 protocol defines two types of PTP packets and two types of time synchronization modes.

2.2.1 Packet Types​

1588v2 protocol packets are divided into two categories: Event Messages and General Messages.

  1. Event Messages - Time-related packets that trigger internal clock sampling when entering or leaving a device port, obtaining the timestamp of that moment. Event Messages mainly include the following types:
  • Sync packet: Sent by the master clock to transmit the master clock's time information to the slave clock.
  • Delay_Req packet: Sent by the slave clock, which records the local timestamp when sending this packet. It is used to request the master clock to measure the transmission delay from the slave clock to the master clock.
  • Delay_Resp packet: Sent by the master clock after receiving the Delay_Req packet, carrying the timestamp when the master clock received the Delay_Req packet. It is used to feed back the transmission delay information from the slave clock to the master clock to the slave clock.
  1. General Messages - Non-time-related packets that only carry information, and no timestamps are generated when they enter or leave the device. General Messages mainly include the following two types:
  • Announce packet: Periodically sent by potential master clock devices, containing key attributes such as time source ID, clock accuracy, priority, and time traceability.
  • Follow_Up packet: Sent after an Event Message, carrying the precise timestamp when the corresponding packet left the device. When the above Event Message itself cannot carry the precise timestamp, the Follow_Up packet is used to supplement this information.

2.2.2 Synchronization Modes​

The synchronization modes of the 1588v2 protocol can be divided into two categories: One-step and Two-step.

  1. One-step: The master and slave clocks only send Event Messages, which directly contain timestamp information. This mode reduces the number of packets, but has high hardware requirements and relatively higher cost.
  2. Two-step: The Event Messages sent by the master and slave clocks do not carry time information themselves, and an additional Follow_Up packet is required to transmit the precise timestamp information.

2.2.3 Synchronization Process​

Taking the Two-step synchronization mode as an example, the synchronization process of the 1588v2 protocol is as follows:

  1. Transmission of time information from the master clock to the slave clock
  • The master clock sends a Sync packet at time t1, and carries the t1 timestamp in the Follow_Up packet.
  • The slave clock receives the Sync packet at time t2, and records the reception time t2 locally.
  1. Measurement of transmission delay from the slave clock to the master clock
  • The slave clock sends a Delay_Req packet at time t3, and records the transmission time t3 locally.
  • The master clock receives the Delay_Req packet at time t4, carries the t4 timestamp in the Delay_Resp packet, and sends it to the slave clock.
Schematic diagram of 1588v2 protocol Two-step synchronization mode

2.2.4 Time Deviation and Transmission Delay Calculation​

  • Time Deviation (Offset): The time deviation of the slave clock relative to the master clock.
  • Transmission Delay (Delay): The time delay between the master clock and the slave clock caused by factors such as network link transmission; as shown in the figure above, the transmission delay from the master clock to the slave clock during synchronization is Tms, and the transmission delay from the slave clock to the master clock is Tsm.

Based on the above time synchronization process, we can get:

  • t2 - t1 = Tms + Offset
  • t4 - t3 = Tsm - Offset

Assuming network transmission is symmetric, i.e., Tms = Tsm, then:

Offset = [(t2βˆ’t1)βˆ’(t4βˆ’t3)]/2
Delay = (Tms+Tsm)/2 = [(t2βˆ’t1)+(t4βˆ’t3)]/2

The slave clock adjusts its local clock according to the calculated Offset and Delay values to achieve time synchronization with the master clock.

3 gPTP (802.1AS) Protocol​

3.1 Overview​

gPTP, the IEEE 802.1AS protocol, is a more targeted time synchronization mechanism developed by IEEE after a series of optimizations based on the PTP 1588v2 protocol. It can achieve higher-precision time synchronization (up to nanosecond level) in local area networks. The 802.1AS protocol defines multiple device types (such as time-aware end stations and time-aware bridges) and packet types to achieve precise master-slave time synchronization.

3.2 Synchronization Principle​

Compared with the 1588v2 protocol, the gPTP protocol introduces the following changes in the principle of implementing time synchronization:

  1. Network Transmission Layer

The 1588v2 protocol allows PTP packets to be transmitted at layers L2-L4 (corresponding to MAC, IP, and UDP protocols respectively) in the network. However, the buffering of the UDP/IP protocol stack may introduce random delays, which will have an additional impact on time synchronization accuracy. To eliminate the uncertainty caused by the software protocol stack, the time collection point should be placed closest to the transmission medium, that is, the MAC layer (L2). Therefore, the gPTP protocol stipulates that all time synchronization packets are only allowed to be transmitted within the L2 layer, and the timestamps when the packets leave the MAC (sender) or arrive at the MAC (receiver) are recorded, so as to achieve higher-precision time synchronization.

Comparison of gPTP L2 layer and 1588v2 L4 layer packets

Difference between gPTP L2 layer (left) and 1588v2 L4 layer (right) in PTP packets

In addition, the MAC layer also supports obtaining more precise timestamps through hardware (eliminating the uncertainty caused by operating system scheduling), which can further improve time synchronization accuracy.

  1. Delay Measurement Mechanism

In the PTP protocol, link delay measurement mechanisms are divided into two categories:

  • End-to-End (E2E): This mechanism is used to measure the delay between two PTP endpoints (i.e., master clock and slave clock) in the current time synchronization network. These two endpoints may be directly connected, or there may be other devices bridged in between, such as ordinary switches, time-sensitive boundary clocks (BC, which have multiple ports and can synchronize time with other nodes in the network) or transparent clocks (TC, which only transparently transmit PTP packets and do not synchronize time with other nodes); from the perspective of the communicating parties, the packet information is transmitted between the master clock node and the slave clock node, so the final transmission delay measured by the slave clock is the end-to-end delay between the master and slave clocks.
  • Peer-to-Peer (P2P): This mechanism emphasizes packet communication between adjacent nodes, so the final measurement is only the point-to-point transmission delay between the ports of adjacent nodes, and requires that all other bridged devices (such as switches) in the time synchronization network must support the P2P mechanism.
Comparison of E2E and P2P mechanisms

Comparison of PTP packet transmission methods between E2E and P2P mechanisms (transparent clock)

The 1588v2 protocol supports both of the above delay mechanisms, and usually uses the E2E method by default (Hesai LiDAR products only support the E2E method when using 1588v2 protocol for time synchronization); gPTP mandatorily requires the use of the P2P mechanism, and uses the following different types of packets to measure link transmission delay:

  • Pdelay_Req packet: Sent by a device at one end to request the peer end to measure the transmission delay.
  • Pdelay_Resp packet: Sent by the peer end after receiving the Pdelay_Req packet, carrying the timestamp of receiving the Pdelay_Req packet, used to calculate the transmission delay.
  • Pdelay_Resp_Follow_Up packet: Provides the precise timestamp when the Pdelay_Resp packet leaves the MAC layer of the sender.

That is, the gPTP protocol mandatorily uses the Two-step synchronization mode including Follow_Up packets, because this mode has relatively low hardware requirements, is convenient for subsequent expansion, and is therefore easier to popularize in existing network environments.

3.2.1 Synchronization Process​

The time synchronization process of the gPTP protocol mainly includes the following steps:

  1. GrandMaster clock selection: Before enabling time synchronization, the master clock in the network needs to be determined first, which can usually be completed through manual configuration or by executing the BMCA (Best Master Clock Algorithm).
  2. Clock synchronization initialization:
    • The master clock periodically sends Sync packets, and attaches the precise timestamp when the Sync packet was sent in the subsequent Follow_Up packet.
    • After receiving the Sync packet, the slave clock records the reception timestamp, and calculates the time deviation from the master clock in combination with the timestamp information in the Follow_Up packet.
  3. Link transmission delay measurement (as shown in the figure below):
    • Node A sends a Pdelay_Req packet and records the transmission timestamp t1.
    • After receiving the Pdelay_Req packet, Node B records the reception timestamp t2, and sends a Pdelay_Resp packet, which contains the t2 information.
    • Node B then sends a Pdelay_Resp_Follow_Up packet, which contains the transmission timestamp t3 of the Pdelay_Resp packet.
    • After receiving the Pdelay_Resp packet from the peer end, Node A records the reception timestamp t4.
Schematic diagram of gPTP link delay measurement

Similar to the delay calculation method of the 1588v2 protocol, the calculation formula for gPTP link transmission delay based on the above process is:

Delay = [(t2βˆ’t1)+(t4βˆ’t3)]/2 
  1. Time synchronization correction: Combined with the link delay information obtained in the previous step, the gPTP protocol implements clock correction by cumulatively calculating the ratio of the clock frequencies of adjacent nodes (NeighborRateRatio); this process also corrects the residence time of each packet (Residence Time, i.e., the time the packet stays inside the bridged device) at the same time, further ensuring the end-to-end time synchronization accuracy.

3.3 Special gPTP Protocols​

While supporting the standard 802.1AS PTP protocol, Hesai LiDAR products also support the following two special gPTP protocols, which are suitable for time synchronization applications in in-vehicle network environments.

3.3.1 802.1AS Automotive Protocol​

The 802.1AS Automotive protocol is a set of customized gPTP protocols formed by the Avnu Alliance after optimizing and extending the standard 802.1AS protocol for specific application scenarios such as in-vehicle networks. While maintaining the basic time synchronization mechanism, this protocol adds support for in-vehicle network characteristics, such as low latency, high reliability, and high bandwidth utilization.

Compared with the standard 802.1AS protocol, the differences of the 802.1AS Automotive protocol are mainly reflected in the following points:

  • Does not support BMCA algorithm

The BMCA algorithm is used to select the best master clock among multiple clock devices. In in-vehicle networks, there is usually a pre-determined master clock device, so the 802.1AS Automotive protocol does not need to support the BMCA algorithm additionally. This simplifies the implementation of the protocol and reduces unnecessary computation and network overhead.

  • Cancels Announce packets in the network

In the standard 802.1AS protocol, Announce packets are used for clock discovery and the operation of the Best Master Clock Algorithm (BMCA). Since the topology of in-vehicle networks is relatively fixed, there is no need for frequent clock discovery and master clock election, so canceling Announce packets can reduce packet traffic in the network and lower network load.

  • The master clock does not send PDelay_Req packets

In the standard 802.1AS protocol, both the master clock and the slave clock can send PDelay_Req packets to measure transmission delay. Since the roles of the master clock and the slave clock in in-vehicle networks are relatively fixed, the slave clock can measure the transmission delay with the master clock by sending Delay_Req packets, while the master clock does not need to actively measure the transmission delay with the slave clock. This reduces the burden on the master clock and improves the stability and reliability of the master clock.

3.3.2 802.1AS AUTOSAR Protocol​

The 802.1AS AUTOSAR protocol is a customized implementation of the standard 802.1AS protocol in the automotive field based on the AUTOSAR architecture, which is mainly used in Time-Sensitive Networks (TSN) of in-vehicle Ethernet to achieve high-precision time synchronization.

Due to similar application scenarios, the 802.1AS AUTOSAR protocol has many similarities with the 802.1AS Automotive protocol. In addition to the several characteristics of the Automotive protocol mentioned above, the AUTOSAR protocol also has the following special features:

  • Pdelay_Req is not a precondition for enabling the sending of Sync packets, which reduces the overhead of the protocol stack and is more suitable for resource-constrained in-vehicle ECUs.
  • The calculation of frequency difference does not depend on the P2P mechanism. That is, NeighborRateRatio is not calculated during the Path Delay measurement process, and the entire protocol only calculates the frequency difference with the master clock.
  • Supports unified control of packet format through the parameter MessageCompliance. If this parameter is TRUE, the packet format under the IEEE 802.1AS specification must be used; if this parameter is FALSE, some fields of the Follow_up packet can be customized and extended, and CRC check becomes optional, which improves the flexibility of the protocol.
  • Allows gPTP packets to carry VLAN Tags.