1. PTP functional description
PTP is Precision Time Protocol as described by IEEE standard 1588.
The purpose of this application is to allow to synchronize multiple clocks in the network. This software is based on the open source project linuxptp. On top of which were added patches to add support for Relay as described in 8021.AS 2020. The plan is to have these patches upstream to the linuxptp project. The application that is part of the BSP has these extra patches.
This project can be found here ptp4l
Ptp4l supports the following:
-
hardware and software timestamping: 1-step and 2-step
-
implements: ordinary, boundary, transparent clocks and AS bridge
-
transport over UDP/IPv4, UDP/IPv6, raw Ethernet
-
supports multiple servos: pi, linreq, ntpshm, nullf
There are multiple executable that are are used:
-
ptp4l
: this is the daemon that adjusted the PHC(Physical Hardware Clock) such offset from master is 0. -
pmc
: short live application to interact with ptp4l to inspect status and allow certain configurations attributes to be updated without restarting the daemon -
phc2sys
: this is a daemon which is used to synchronize two or more clocks in the system. Typically is used to synchronize the system clock with a PTP hardware clock which itself is synchronized using ptp4l daemon. -
ts2phc
: this is a daemon which is used to synchronize a PTP hardware clock to GPS and or 1PPS.
It is possible to pass the following arguments to ptp4l to the command line. The most important arguments are:
-
-l
: to set the log level -
-m
: to print message to standard output -
-i
: interface on which to run -
-f
: to set the configuration file -
-p
: specify directly the PHC device
When ptp4l is started, it has an option to read the configuration from a file. The most important configurations options are:
-
delay_mechanism
: which can be P2P, Auto or E2E. -
network_transport
: which can be L2, UDPv4 or UDPv6. -
time_stamping
: which can be: hardware, software or legacy. -
clock_type
: which can be OC, BC or Relay -
slaveOnly
: force the node to behave as a slave only -
domainNumber
: represents the PTP domain number. Default is 0. -
twoStepFlag
: a value of 1 uses 2-step timestamping, while a value of 0 uses 1-step timestamping
For more details about ptp4l run: man ptp4l
Ptp4l is works on the physical interfaces and not on the bridge interface, so before starting the daemon, make sure that the interface is up using the command:
ip link set dev eth0 up
1.1. PTP4L
1.1.1. Ordinary clock(OC)
To run ptp4l as ordinary clock, the following configuration is needed:
cat > /tmp/linux.cfg [global] clock_type OC delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 [eth0]
And start ptp4l as:
ptp4l -f /tmp/linux.cfg &
1.1.2. Boundary clock(BC)
For the boundary clock, it is required at least 2 network interfaces. Because it is required have 1 slave and at least 1 master. Therefore the configuration file can look like this:
cat > /tmp/linux.cfg [global] clock_type BC delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 [eth0] [eth1]
And start ptp4l as:
ptp4l -f /tmp/linux.cfg &
1.1.3. Transparent clock(TC)
For the transparent clock, it is required at least 2 network interfaces. The frames will be forward in SW by the ptp4l application but the timestamps will be do by the HW. The configuration file can look like this:
[global] priority1 254 free_running 1 freq_est_interval 3 tc_spanning_tree 1 summary_interval 1 clock_type P2P_TC network_transport L2 delay_mechanism P2P [eth0] [eth1]
And start ptp4l as:
ptp4l -f /tmp/linux.cfg &
1.1.4. AS Bridge(Relay)
The support for this feature is not part of the upstream project. Therefore the implementation and the configuration might changed based on the requests received when this feature will be upstream. |
The relay behaves similar to the transparent clock and to boundary clock. The ptp4l configuration for relay can be the following:
cat > /tmp/linux.cfg [global] priority1 254 priority2 254 clock_type RELAY network_transport L2 delay_mechanism P2P path_trace_enabled 1 transportSpecific 1 follow_up_info 1 ptp_dst_mac 01:80:C2:00:00:0E gmCapable 1 logAnnounceInterval 0 logSyncInterval -3 syncReceiptTimeout 3 free_running 1 summary_interval 1 [eth0] [eth1] [eth2]
And start ptp4l as:
ptp4l -f /tmp/linux.cfg &
1.1.5. Multiple PTP instances
It is possible to run multiple ptp4l instances and each of them to control a different PHC. For example, let’s say that we want to control PHC0 and PHC1 and they have the PTP domains 0 and 20.
cat > /tmp/ptp0.cfg [global] clock_type OC delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001
And start the first ptp4l using:
ptp4l -p /dev/ptp0 -f /tmp/ptp0.cfg &
And the second ptp4l will have the configuration:
cat > /tmp/ptp1.cfg [global] clock_type OC delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 domainNumber 20
And start the second ptp4l using:
ptp4l -p /dev/ptp1 -f /tmp/ptp0.cfg &
If multiple ptp4l instances need to access the same PHC then it is possible and
recommended to use the option -i
instead of -p
.
1.2. PMC
To be able to see the current status of the ptp4l daemon, it is possible to use the pmc application.
For example to read the offset from master:
pmc -u -b 0 'GET CURRENT_DATA_SET' sending: GET CURRENT_DATA_SET a0369f.fffe.67c4e6-0 seq 0 RESPONSE MANAGEMENT CURRENT_DATA_SET stepsRemoved 1 offsetFromMaster 10.0 meanPathDelay 252.0
For more details about pmc run: man pmc
1.3. PHC2SYS
To synchronize the system clock to one of the PHC, the following command can be used:
phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -O 0
Also it is possible to synchronize 2 PHC using the command:
phc2sys -s /dev/ptp0 -c /dev/ptp1 -O 0
Where:
-
-s
: represents the master clock -
-c
: represents the slave clock -
-O
: represents the offset between the slave and master times in seconds.
For more details about phc2sys run: man phc2sys
1.4. Default configurations
IEEE1588 over Ethernet boundary clock:
[global] delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 clock_type BC logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0] [eth1]
IEEE1588 over Ethernet ordinary clock:
[global] delay_mechanism E2E network_transport L2 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0]
IEEE1588 over IPv4 boundary clock:
[global] delay_mechanism E2E network_transport UDPv4 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 clock_type BC logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0] [eth1]
IEEE1588 over IPv4 ordinary clock:
[global] delay_mechanism E2E network_transport UDPv4 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0]
IEEE1588 over IPv6 boundary clock:
[global] delay_mechanism E2E network_transport UDPv6 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 clock_type BC logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0] [eth1]
IEEE1588 over IPv6 ordinary clock:
[global] delay_mechanism E2E network_transport UDPv6 time_stamping hardware first_step_threshold 0.000001 step_threshold 0.000001 logAnnounceInterval 0 logSyncInterval -4 logMinDelayReqInterval -2 [eth0]
IEEE802.1AS Relay
[global] priority1 254 priority2 254 clock_type RELAY network_transport L2 delay_mechanism P2P path_trace_enabled 1 transportSpecific 1 follow_up_info 1 ptp_dst_mac 01:80:C2:00:00:0E gmCapable 1 logAnnounceInterval 0 logSyncInterval -3 syncReceiptTimeout 3 free_running 1 summary_interval 1 tc_spanning_tree 1 [eth0] [eth1]
IEEE802.1AS End-node
[global] gmCapable 1 priority1 248 priority2 248 logAnnounceInterval 0 logSyncInterval -3 syncReceiptTimeout 3 neighborPropDelayThresh 800 min_neighbor_prop_delay -20000000 assume_two_step 1 path_trace_enabled 1 follow_up_info 1 transportSpecific 0x1 ptp_dst_mac 01:80:C2:00:00:0E network_transport L2 delay_mechanism P2P [eth0]