ConfiguringChronytoSet SystemClockUsingPTP
AnupstreamPTPgrandmasterclock(e.g.,aGPSdisciplinedPTPclock)canbeusedtosetthesystem
time if preciseabsolute time is needed for sensor data. Chrony isa Linux time service that can read
from NTP and PTP and set the Linux system time using the most accurate source available. With a
properfunctioningPTPgrandmasterthePTPtimesourcewillbeselectedandtheerrorfromthepublic
timeserverscan bereviewed.
The following phc2shm service will synchronize the time fromeno1 (where the external grandmaster
isattached) tothe systemclock.
Createa filenamed/etc/systemd/system/phc2shm.service withthefollowingcontents:
# /etc/systemd/system/phc2shm.service
[Unit]
Description=Synchronize PTP hardware clock (PHC) to NTP SHM
Documentation=man:phc2sys
After=ntpdate.service
Requires=ptp4l.service
After=ptp4l.service
[Service]
Type=simple
ExecStart=/usr/sbin/phc2sys -s eno1 -E ntpshm -w
[Install]
WantedBy=multi-user.target
Thenstartthe newlycreatedservice andcheckthat itstarted.
$ sudo systemctl start phc2shm
$ sudo systemctl status phc2shm
AddthePTPtimesourcetothe chronyconfigurationwhichwillreadthe sharedmemoryregionman-
agedby thephc2shm servicecreatedabove.
Appendthe following tothe /etc/chrony/chrony.conf file:
refclock SHM 0 poll 1 refid ptp
Restartchronyso theupdated configurationfile takes effect:
$ sudo systemctl restart chrony
Afterwaitinga minuteforthe clockto synchronize,reviewthe chronyclient timingaccuracy:
$ chronyc tracking
Reference ID : 70747000 (ptp)
Stratum : 1
Ref time (UTC) : Thu Mar 14 02:22:58 2019
System time : 0.000000298 seconds slow of NTP time
Last offset : -0.000000579 seconds
RMS offset : 0.001319735 seconds
(continuesonnext page)
95