Table of Contents

PTPd: Time synchronization for (realtime) Linux systems with Tux

Hey, my name is "Tux"! Did you ever wonder how you can configure PTPd services on your Linux system?

Hey, my name is "Tux" and this tutorial will show you how you can get PTPd up and running to have a reliable time synchronization between all involved ethernet hosts.



First thoughts

Alternatively to the time synchronization tool NTP, which is not useful in a realtime environment, PTP was designed. Unlike NTP, PTP is based on Multicast technology (Master/Slave) while NTP is based on Client-Server technology. PTP was designed for synchronizing system time between a PTP master and one or multiple PTP slaves as precise as possible. There do exists two different types of PTP applications: hard- or software driven applications or even both in a single application. Hardware driven PTP applications in general are a lot more reliable than software driven PTP applications, especially when used in realtime systems. The disadvantage of hardware driven PTP is the requirement for physical hardware that supports PTP (dedicated PTP clock chip onto master NIC and slaves NIC(s) and optional switches/routers in between). When there is no need for hardware driven PTP (for example in test environments) PTPd can be used.
PTPd is a software driven only PTP application and therefore it cannot get controlled by dedicated hardware.
Advantage: No financial issues but on cost of precision.
Beware: PTPd is very limited on realtime usability and therefore it should only be used after checking all requirements on the realtime system! For critical realtime applications hardware based PTP should always be the first choice.

Example of usage


Start of tutorial

Platform independent variants of installation

Ubuntu 14.04 with current version of PTPd from GitHub.com

Download source code files from here. Copy source code file into the following directory (replace the following placeholders <x> with corresponding version number according the downloaded file):

$ cp ptpd-<x>.<x>.<x>.tar.gz /opt

Navigate into folder /opt:

$ cd /opt

Extract the ptpd-<x>.<x>.<x>.tar.gz file here:

$ tar xvzf ptpd-<x>.<x>.<x>.tar.gz

Delete the ptpd-<x>.<x>.<x>.tar.gz file:

$ rm -rf ptpd-<x>.<x>.<x>.tar.gz

Rename the ptpd-<x>.<x>.<x> folder into ptpd:

$ mv "/opt/ptpd-<x>.<x>.<x>" /opt/ptpd

Navigate into folder /opt/ptpd:

$ cd /opt/ptpd

Now execute the following commands successively:

$ ./configure
$ make
$ make install

Next step is configuring autostart of PTPd service on operation system's start.
Create a file <myStartScript>.sh inside the /usr/local/bin/ folder…

$ vi /usr/local/bin/<myStartScript>.sh

…and add the following content (Beware: sleep is required because of autostart failure if the corresponding networkinterface's drivers are not being loaded fast enough on operating system's start.),…

sleep 30

Variant Master

$ sudo /opt/ptpd/src/ptpd2 -M -i <myNetworkInterface>

Variant Slave

$ sudo /opt/ptpd/src/ptpd2 -s -i <myNetworkInterface>

…save the file and quit the editor.
Now make the file executable:

$ chmod +x /usr/local/bin/<myStartScript>.sh

Now edit the file:

$ vi /etc/rc.local

Before the already existing entry exit 0 add the following content:

/usr/local/bin/<meinStartSkript>.sh
exit 0

Optional

If there are additional processes required being started via rc-.local file it is required to separate those processes by an &-symbol. Example:

/usr/local/bin/<myFirstStartScript>.sh &
/usr/local/bin/<mySecondStartScript>.sh
exit 0

Now save the file and quit the editor.
Reboot the system and check if ptpd2 service is running:

$ ps -A | grep ptpd2

Beware: When no message appears the service is not running!


Ubuntu 14.04 and 16.04 with PTPd from default repository

Installation

pdpdpackage installation via default repository:

$ apt-get install ptpd

Edit the following file…

$ vi /etc/default/ptpd

…and change the following default entries according to the following instructions (Beware: case sensitive!)
START_DAEMON = no → change to → START_DAEMON = yes

Variant Ubuntu 16.04 Master


PTPD_OPTS = "" → change to → PTPD_OPTS = "-M -i <myNetworkInterface>"

Variant Ubuntu 14.04 Master


PTPD_OPTS = "" → change to → PTPD_OPTS = "-G -h -b <myNetworkInterface>"

Variant Ubuntu 16.04 Slave


PTPD_OPTS = "" → change to → PTPD_OPTS = "-s -i <myNetworkInterface>"

Variant Ubuntu 14.04 Slave


PTPD_OPTS = "" → change to → PTPD_OPTS = "-g -h -b <myNetworkInterface>"


Save the file and quit the editor.
Next step is configuring autostart of PTPd service on operation system's start.
Create a file <myStartScript>.sh inside the /usr/local/bin/ folder…

$ vi /usr/local/bin/<myStartScript>.sh

…and add the following content (Beware: sleep is required because of autostart failure if the corresponding networkinterface's drivers are not being loaded fast enough on operating system's start.),…

sleep 30

Variant Ubuntu 16.04 Master

$ sudo ptpd -M -i <myNetworkInterface>

Variant Ubuntu 14.04 Master

$ sudo ptpd -G -h -b <myNetworkInterface>

Variant Ubuntu 16.04 Slave

$ sudo ptpd -s -i <myNetworkInterface>

Variant Ubuntu 14.04 Slave

$ sudo ptpd -g -h -b <myNetworkInterface>

…save the file and quit the editor.
Now make the file executable:

$ chmod +x /usr/local/bin/<myStartScript>.sh

Now edit the file:

$ vi /etc/rc.local

Before the already existing entry exit 0 add the following content:

/usr/local/bin/<myStartScript>.sh
exit 0

Optional

If there are additional processes required being started via rc-.local file it is required to separate processes by an &-symbol. Example:

/usr/local/bin/<myFirstStartScript>.sh &
/usr/local/bin/<mySecondStartScript>.sh
exit 0

Now save the file and quit the editor.
Reboot the system and check if ptpd service is running:

$ service ptpd status

Variant Ubuntu 16.04

As an output message there is a green «light» being generated (there may be a delay of about 10 seconds).

Variante Ubuntu 14.04

As an output message «ptpd is running» is showing up (there may be a delay of about 10 seconds).



Troubleshooting and additional information on PTP and PTPd


End of tutorial



Appreciate my work?
Buy me a coffee or PayPal

Source(s):
http://ptpd.sourceforge.net/doc.html
https://manpages.debian.org/stretch/ptpd/ptpd.8.en.html
https://www.youtube.com/watch?v=Forh3XfD_Ec
https://de.wikipedia.org/wiki/Precision_Time_Protocol
http://www.pdv.reutlingen-university.de/rte/White_paper_ieee1588_de_v1-2.pdf
http://manpages.ubuntu.com/manpages/trusty/man8/ptpd.8.html
https://gist.github.com/mhaberler/f4809ed2e465912d3534
https://www.endruntechnologies.com/pdf/PTP-1588.pdf
https://www.endruntechnologies.com/ptp-ieee-1588-faq.htm
https://www.endruntechnologies.com/ptp-slave.htm
http://www.en4tel.com/pdfs/NTPandPTP-A-Brief-Comparison.pdf
https://www.youtube.com/watch?v=-MK7DcGjjFE
https://networkengineering.stackexchange.com/questions/23369/how-to-check-if-a-nic-supports-hardware-timestamps
http://linuxptp-users.narkive.com/kYXafDxt/installation-of-linuxptp-on-ubuntu-pc
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/ch-configuring_ptp_using_ptp4l
https://www.reddit.com/r/openwrt/comments/515oea/finally_got_80211r_roaming_working/