English Korean
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*).
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.
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:
The kernel in Fedora includes support for `PTP`. User space support is provided by the tools in the [application]*linuxptp* package. To install [application]*linuxptp*, issue the following command as `root`:
~]#{nbsp}dnf install linuxptp
This will install [application]*ptp4l* and [application]*phc2sys*.
Do not run more than one service to set the system clock's time at the same time. If you intend to serve `PTP` time using `NTP`, see xref:Configuring_PTP_Using_ptp4l.adoc#sec-Serving_PTP_Time_with_NTP[Serving PTP Time with NTP].
Starting ptp4l
The [application]*ptp4l* program can be started from the command line or it can be started as a service. When running as a service, options are specified in the `/etc/sysconfig/ptp4l` file. Options required for use both by the service and on the command line should be specified in the `/etc/ptp4l.conf` file. The `/etc/sysconfig/ptp4l` file includes the [command]#-f /etc/ptp4l.conf# command line option, which causes the `ptp4l` program to read the `/etc/ptp4l.conf` file and process the options it contains. The use of the `/etc/ptp4l.conf` is explained in xref:Configuring_PTP_Using_ptp4l.adoc#sec-Specifying_a_Configuration_File[Specifying a Configuration File]. More information on the different [application]*ptp4l* options and the configuration file settings can be found in the `ptp4l(8)` man page.
The [application]*ptp4l* program tries to use hardware time stamping by default. To use [application]*ptp4l* with hardware time stamping capable drivers and NICs, you must provide the network interface to use with the [option]`-i` option. Enter the following command as `root`:
Where _em3_ is the interface you want to configure. Below is example output from [application]*ptp4l* when the `PTP` clock on the NIC is synchronized to a master:
The master offset value is the measured offset from the master in nanoseconds. The `s0`, `s1`, `s2` strings indicate the different clock servo states: `s0` is unlocked, `s1` is clock step and `s2` is locked. Once the servo is in the locked state (`s2`), the clock will not be stepped (only slowly adjusted) unless the [option]`pi_offset_const` option is set to a positive value in the configuration file (described in the `ptp4l(8)` man page). The `adj` value is the frequency adjustment of the clock in parts per billion (ppb). The path delay value is the estimated delay of the synchronization messages sent from the master in nanoseconds. Port 0 is a Unix domain socket used for local `PTP` management. Port 1 is the `em3` interface (based on the example above.) INITIALIZING, LISTENING, UNCALIBRATED and SLAVE are some of possible port states which change on the INITIALIZE, RS_SLAVE, MASTER_CLOCK_SELECTED events. In the last state change message, the port state changed from UNCALIBRATED to SLAVE indicating successful synchronization with a `PTP` master clock.
When running as a service, options are specified in the `/etc/sysconfig/ptp4l` file. More information on the different [application]*ptp4l* options and the configuration file settings can be found in the `ptp4l(8)` man page.
By default, messages are sent to `/var/log/messages`. However, specifying the [option]`-m` option enables logging to standard output which can be useful for debugging purposes.