About PTP
Use PTP to synchronise system clocks on a LAN more accurately than than NTP. If network drivers support either hardware or software time stamping, a PTP clock can use the time stamps in PTP messages to resolve propagation delays across a network. With software time stamping, PTP synchronises systems to within a few tens of microseconds. With hardware time stamping, PTP can synchronise systems to within a few tenths of a microsecond. If you require high-precision time synchronization of systems, use hardware time stamping.
A typical PTP configuration on an enterprise local area network consists of:
-
One or more grandmaster clock systems.
A grandmaster clock is typically implemented as specialized hardware that can use high-accuracy GPS signals or lower-accuracy code division several access (CDMA) signals, radio clock signals, or NTP as a time reference source. If several grandmaster clocks are available, the best master clock (BMC) algorithm selects the grandmaster clock based on the settings of their
priority1
,clockClass
,clockAccuracy
,offsetScaledLogVariance
, andpriority2
parameters and their unique identifier, in that order. -
Several boundary clock systems.
Each boundary clock is backed up to a grandmaster clock on one subnetwork and relays PTP messages to one or more added subnetworks. A boundary clock is usually implemented as a function of a network switch.
-
Several secondary clock systems.
Each secondary clock on a subnetwork is backed up to a boundary clock, which acts as the master clock for that secondary clock.
For a basic configuration, set up a single grandmaster clock and several secondary clocks on the same network segment and thus eliminates any need for an intermediate layer of boundary clocks.
Grandmaster and secondary clock systems that use only one network interface for PTP are termed ordinary clocks.
Boundary clocks require at least two network interfaces for PTP: one interface acts a secondary to a grandmaster clock or a higher-level boundary clock; the other interfaces act as masters to secondary clocks or lower-level boundary clocks.
Synchronization of boundary and secondary clock systems is achieved by sending time stamps in PTP messages. By default, PTP messages are sent in UDPv4 datagrams. You can also configure PTP to use UDPv6 datagrams or Ethernet frames as its transport mechanism.
To use PTP on a system, the driver for at least one of the system's network interfaces must support either software or hardware time stamping. To find out whether the driver for a network interface supports time stamping, use the ethtool command:
sudo ethtool -T en1
Time stamping parameters for en1:
Capabilities:
hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)
...
The output in the example shows that the en1
interface supports both hardware and software time stamping
capabilities.
With software time stamping, ptp4l
synchronises
the system clock to an external grandmaster clock.
If hardware time stamping is available, ptp4l
can synchronise the PTP hardware clock to an external grandmaster
clock. In this case, you use the phc2sys
daemon
to synchronise the system clock with the PTP hardware clock.
Configuring the PTP Service
To configure the PTP service on a system:
-
Install the
linuxptp
package.sudo dnf install linuxptp
-
Edit
/etc/sysconfig/ptp4l
and define the start-up options for theptp4l
daemon.Grandmaster clocks and secondary clocks require that you define only one interface.
For example, to use hardware time stamping with interface
en1
on a secondary clock:OPTIONS="-f /etc/ptp4l.conf -i en1 -s"
To use software time stamping instead of hardware time stamping, specify the -S option:
OPTIONS="-f /etc/ptp4l.conf -i en1 -S -s"
Note:
The -s option specifies that the clock operates only as a secondary (
slaveOnly
mode). Don't specify this option for a grandmaster clock or a boundary clock.For a grandmaster clock, omit the -s option, for example:
OPTIONS="-f /etc/ptp4l.conf -i en1"
A boundary clock requires that you define at least two interfaces, for example:
OPTIONS="-f /etc/ptp4l.conf -i en1 -i en2"
You might need to edit the
/etc/ptp4l.conf
file to customizeptp4l
further, for example:-
For a grandmaster clock, set the value of the
priority1
parameter to a value between 0 and 127, where lesser values have greater priority when the BMC algorithm selects the grandmaster clock. For a configuration that has a single grandmaster clock, a value of 127 is suggested. -
If you set the value of
summary_interval
to an integer value N instead of 0,ptp4l
writes summary clock statistics to/var/log/messages
every 2N seconds instead of every second (20 = 1). For example, a value of 10 would correspond to an interval of 210 or 1024 seconds. -
The
logging_level
parameter controls the amount of logging information thatptp4l
records. The default value oflogging_level
is6
, which corresponds toLOG_INFO
. To turn off logging, set the value oflogging_level
to0
. Alternatively, specify the -q option toptp4l
.
See the
ptp4l(8)
manual page. -
-
Configure the system firewall to accept access by PTP event and general messages to UDP ports 319 and 320 in the appropriate zone, for example:
sudo firewall-cmd --zone=zone --add-port=319/udp --add-port=320/udp
sudo firewall-cmd --permanent --zone=zone --add-port=319/udp --add-port=320/udp
-
Start the
ptp4l
service and configure it to start following a system reboot.sudo systemctl start ptp4l
sudo systemctl enable ptp4l
-
To configure
phc2sys
on a clock system that uses hardware time stamping:-
Edit the
/etc/sysconfig/phc2sys
file and define the start-up options for thephc2sys
daemon.On a boundary clock or secondary clock, synchronise the system clock with the PTP hardware clock that's associated with the secondary network interface, for example:
OPTIONS="-c CLOCK_REALTIME -s en1 -w"
Note:
The secondary network interface on a boundary clock is the one that it uses to communicate with the grandmaster clock.
The -w option specifies that
phc2sys
waits untilptp4l
has synchronised the PTP hardware clock before synchronising the system clock.On a grandmaster clock, which derives its system time from a reference time source such as GPS, CDMA, NTP, or a radio time signal, synchronise the network interface's PTP hardware clock from the system clock, for example:
OPTIONS="-c en1 -s CLOCK_REALTIME -w"
See the
phc2sys(8)
manual page. -
Start the
phc2sys
service and configure it to start following a system reboot.sudo systemctl start phc2sys
sudo systemctl enable phc2sys
-
You can use the pmc command to query the status of
ptp4l
operation. The following example shows the results of running
pmc on a slave clock system that's directly connected to the
grandmaster clock system without any intermediate boundary clocks:
sudo pmc -u -b 0 'GET TIME_STATUS_NP'
sending: GET TIME_STATUS_NP
080027.fffe.7f327b-0 seq 0 RESPONSE MANAGEMENT TIME_STATUS_NP
master_offset -98434
ingress_time 1412169090025854874
cumulativeScaledRateOffset +1.000000000
scaledLastGmPhaseChange 0
gmTimeBaseIndicator 0
lastGmPhaseChange 0x0000'0000000000000000.0000
gmPresent true
gmIdentity 080027.fffe.d9e453
sudo pmc -u -b 0 'GET CURRENT_DATA_SET'
sending: GET CURRENT_DATA_SET
080027.fffe.7f327b-0 seq 0 RESPONSE MANAGEMENT CURRENT_DATA_SET
stepsRemoved 1
offsetFromMaster 42787.0
meanPathDelay 289207.0
This output examples include the following useful information:
-
gmIdentity
-
The unique identifier of the grandmaster clock, which is based on the MAC address of its network interface.
-
gmPresent
-
Whether an external grandmaster clock is available. This value is displayed as
false
on the grandmaster clock itself. -
meanPathDelay
-
An estimate of how many nanoseconds by which synchronization messages are delayed.
-
offsetFromMaster
-
The most recent measurement of the time difference in nanoseconds relative to the grandmaster clock.
-
stepsRemoved
-
The number of network steps between this system and the grandmaster clock.
For more information, see the phc2sys(8)
,
pmc(8)
, and ptp4l(8)
manual pages, and
IEEE
1588.
Using PTP as a Time Source for NTP
To make the PTP-adjusted system time on an NTP server available
to NTP clients, include the following entries in the
/etc/chrony.conf
file on the NTP server:
server 127.127.1.0
fudge 127.127.1.0 stratum 0
These entries define the local system clock as the time reference.
Note:
Don't configure any added server
lines in the file.