English Ukrainian
Configuring PTP Using ptp4l
Introduction to PTP
The _Precision Time Protocol_ (*PTP*) is a protocol used to synchronize clocks in a network. When used in conjunction with hardware support, `PTP` is capable of sub-microsecond accuracy, which is far better than is normally obtainable with `NTP`. `PTP` support is divided between the kernel and user space. The kernel in Fedora includes support for `PTP` clocks, which are provided by network drivers. The actual implementation of the protocol is known as [application]*linuxptp*, a `PTPv2` implementation according to the IEEE standard 1588 for Linux.
The [package]*linuxptp* package includes the [application]*ptp4l* and [application]*phc2sys* programs for clock synchronization. The [application]*ptp4l* program implements the `PTP` boundary clock and ordinary clock. With hardware time stamping, it is used to synchronize the `PTP` hardware clock to the master clock, and with software time stamping it synchronizes the system clock to the master clock. The [application]*phc2sys* program is needed only with hardware time stamping, for synchronizing the system clock to the `PTP` hardware clock on the _network interface card_ (*NIC*).
Understanding PTP
The clocks synchronized by `PTP` are organized in a master-slave hierarchy. The slaves are synchronized to their masters which may be slaves to their own masters. The hierarchy is created and updated automatically by the _best master clock_ (*BMC*) algorithm, which runs on every clock. When a clock has only one port, it can be _master_ or _slave_, such a clock is called an _ordinary clock_ (*OC*). A clock with multiple ports can be master on one port and slave on another, such a clock is called a _boundary_ clock (*BC*). The top-level master is called the _grandmaster clock_, which can be synchronized by using a _Global Positioning System_ (*GPS*) time source. By using a GPS-based time source, disparate networks can be synchronized with a high-degree of accuracy.
PTP grandmaster, boundary, and slave Clocks
An illustration showing PTP grandmaster
Advantages of PTP
One of the main advantages that `PTP` has over the _Network Time Protocol_ (*NTP*) is hardware support present in various _network interface controllers_ (*NIC*) and network switches. This specialized hardware allows `PTP` to account for delays in message transfer, and greatly improves the accuracy of time synchronization. While it is possible to use non-PTP enabled hardware components within the network, this will often cause an increase in jitter or introduce an asymmetry in the delay resulting in synchronization inaccuracies, which add up with multiple non-PTP aware components used in the communication path. To achieve the best possible accuracy, it is recommended that all networking components between `PTP` clocks are `PTP` hardware enabled. Time synchronization in larger networks where not all of the networking hardware supports `PTP` might be better suited for `NTP`.
With hardware `PTP` support, the NIC has its own on-board clock, which is used to time stamp the received and transmitted `PTP` messages. It is this on-board clock that is synchronized to the `PTP` master, and the computer's system clock is synchronized to the `PTP` hardware clock on the NIC. With software `PTP` support, the system clock is used to time stamp the `PTP` messages and it is synchronized to the `PTP` master directly. Hardware `PTP` support provides better accuracy since the NIC can time stamp the `PTP` packets at the exact moment they are sent and received while software `PTP` support requires additional processing of the `PTP` packets by the operating system.
Using PTP
In order to use `PTP`, the kernel network driver for the intended interface has to support either software or hardware time stamping capabilities.
Checking for Driver and Hardware Support
In addition to hardware time stamping support being present in the driver, the NIC must also be capable of supporting this functionality in the physical hardware. The best way to verify the time stamping capabilities of a particular driver and NIC is to use the [application]*ethtool* utility to query the interface as follows:
~]#{nbsp}ethtool -T em3
Time stamping parameters for em3:
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
Hardware Receive Filter Modes:
Where _em3_ is the interface you want to check.
For software time stamping support, the parameters list should include: