world leader in high performance signal processing
Trace: » ptp

Precision Time Protocol (PTP)

The Precision Time Protocol (PTP) is a high precision time synchronization protocol for networked measurement and control systems. It is defined in the IEEE 1588 standard, which is designed for local systems requiring very high accuracies beyond those attainable using NTP.

The IEEE 1588 engine module (PTP_TSYNC) provides hardware assistance for the implementation of the IEEE 1588 standard on Blackfin processors. BF518 and BF609 processors include this module.

Old tools

There are 2 versions of IEEE1588 protocols. PTPd open source project at http://ptpd.sourceforge.net/ implements both of them in v1.0 and v2.0 releases. It doesn't support the Linux hardware timestamp API introduced since 2.6.30. Other projects branched from PTPd have hardware timestamp enabled.

PTPd from git://github.com/pohly/ptpd.git supports IEEE1588 v1 as well as the hardware timestamp API.

PTPd from https://github.com/richardcochran/ptpd-phc.git supports IEEE1588 v2 as well as the hardware timestamp API. This project is only included in buildroot distribution for bf60x.

New tools

After 2012R1 release, Linuxptp from linuxptp.sourceforge.net should be used to replace PTPd. It also supports IEEE1588 v2 as the hardware timestamp API and is already included in buildroot distribution.

Be sure all machines which run PTPd/linuxptp have different MAC address, otherwise PTP can't work correctly!

Kernel Config

Old Config

To enable hardware timestamp support in bf51x kernel config:

Device Drivers  -->
   [*] Network device support  --->
       [*] Ethernet (10 or 100Mbit) --->
           [*] Blackfin on-chip MAC support
           [*] Use IEEE 1588 hwstamp

To enable hardware timestamp support in bf60x kernel config:

Device Drivers  -->
   [*] Network device support  --->
       [*] Ethernet (10 or 100Mbit) --->  
           [*] STMicroelectronics devices
           [*] STMicroelectronics 10/100/1000 Ethernet driver
               [*] STMMAC platform bus support
               [*] STMMAC ieee1588 hw timestamp support

New Config

Common parts

General setup  --->
    [*] Enable eventpoll support
    
[*] Networking support  ---> 
    Networking options  ---> 
    [*] Timestamping in PHY devices
    
Device Drivers  --->
    PPS support  ---> 
      <*> PPS support
    PTP clock support  --->
      <*> PTP clock support   

To enable hardware timestamp support in bf51x

kernel config:

Device Drivers  -->
   [*] Network device support  --->
       [*] Ethernet (10 or 100Mbit) --->
           [*] Blackfin on-chip MAC support
           [*] Use IEEE 1588 hwstamp

To enable hardware timestamp support in bf60x

kernel config:

Device Drivers  -->
   [*] Network device support  --->
       [*] Ethernet (10 or 100Mbit) --->  
           [*] STMicroelectronics devices
           [*] STMicroelectronics 10/100/1000 Ethernet driver
               [*] STMMAC platform bus support

kernel boot argument in u-boot:

bfin> set bootargs root=/dev/mtdblock0 rw stmmac.debug=14 console=ttyBF0,57600

Userspace Config

Old Config

ptpd is a daemon in blackfin Linux distribution. It can run as masters or slaves.

In uClinux-dist Linux distribution, ptpd can be found under uclinux-dist/user/ptpd/, which supports IEEE1588 v1.

Network Applications  --->
[*] ptpd 

In Buildroot Linux distribution, ptpd and ptpd2 can be found under buildroot/package/, which support IEEE1588 v1 and v2 respectively.

Package Selection for the target  --->
    Networking applications  --->
    [*] ptpd v1
    [*] ptpd v2

New Config

Package Selection for the target  --->
    Networking applications  --->
    [*] linuxptp

Example

Here you will find the time of all slaves will keep synchronizing with the master. For a master without hardware stamp support, you can run “ptpd” without any parameter, and for slaves, run “ptpd -g”, then the master and slaves will use software stamp to synchronize. As a result, the time difference between the master and slaves will increase.

PTPd v1

Master

root:/> date -s 2010.03.16-15:30
root:/> ptpd -z linux_hw -f log.master

Slave

root:/> date
Tue Jun  5 05:07:07 UTC 2035
root:/> ptpd -z linux_hw -g -f log.slave
root:/> date
Tue Mar 16 15:32:37 UTC 2010
root:/> cat log.slave
(ptpd debug) master-to-slave delay:            0s       44483ns
(ptpd debug) slave-to-master delay:            0s       56536ns
(ptpd debug) one-way delay:                    0s       39828ns
(ptpd debug) offset from master:               0s        4900ns

PTPd v2

Master

root:/> date -s 2010.03.16-15:30
root:/> ptpd2 -d -f log.master

Slave

root:/> date
Tue Jun  5 05:07:07 UTC 2035
root:/> ptpd2 -d -g -f log.slave
root:/> date
Tue Mar 16 15:32:37 UTC 2010
root:/> cat log.slave
(ptpd debug)--Offset Correction-- 
(ptpd debug)Raw offset from master:           0s         323ns
(ptpd debug)--Offset and Delay filtered-- 
(ptpd debug)offset from master:               0s         402ns
(ptpd debug)observed drift:               13704
(ptpd debug)--Offset Correction-- 
(ptpd debug)Raw offset from master:           0s         340ns
(ptpd debug)--Offset and Delay filtered-- 
(ptpd debug)offset from master:               0s         331ns
(ptpd debug)observed drift:               13704
(ptpd debug)--Offset Correction-- 
(ptpd debug)Raw offset from master:           0s         516ns
(ptpd debug)--Offset and Delay filtered-- 
(ptpd debug)offset from master:               0s         428ns
(ptpd debug)observed drift:               13704

Turn on the debug print in ptpd source code to show above delay and offset information.

Linuxptp

Master

root:~> date -s 2010.03.16-15:30
root:~> date
Thu Dec 21 02:17:54 UTC 2010
root:~> testptp -g
clock time: 3030.230430976 or Thu Jan  1 00:50:30 1970
root:/> 
root:~> hwstamp_ctl -i eth0 -r 6 -t 1
root:/> 
root:/> testptp -s

root:/> testptp -g
clock time: 1166667484.236271664 or Thu Dec 21 02:18:04 2010
root:/> 
root:/> ptp4l -i eth0 &
ptp4l[3110.220]: selected /dev/ptp0 as PTP clock
ptp4l[3110.220]: m
ptp4l[3110.224]: driver rejected most general HWTSTAMP filter
ptp4l[3110.224]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3110.224]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3116.228]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES

Slave

root:~> hwstamp_ctl -i eth0 -r 6 -t 1
root:/> 
root:/> ptp4l -i eth0 -s &
ptp4l[3121.429]: selected /dev/ptp0 as PTP clock
ptp4l[3121.429]: m
ptp4l[3121.433]: driver rejected most general HWTSTAMP filter
ptp4l[3121.433]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3121.433]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3123.236]: port 1: new foreign master 00e022.fffe.fe8529-1
ptp4l[3127.244]: selected best master clock 00e022.fffe.fe8529
ptp4l[3127.244]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[3129.268]: master offset -1166664449861224856 s0 adj      +0 path delay      10008
ptp4l[3130.272]: master offset -1166664449861224728 s0 adj      +0 path delay      10008
ptp4l[3131.276]: master offset -1166664449861224372 s0 adj      +0 path delay      10052
ptp4l[3132.280]: master offset -1166664449861224048 s1 adj      +0 path delay      10048
ptp4l[3133.284]: master offset       -896 s2 adj    -896 path delay      10048
ptp4l[3133.284]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[3134.288]: master offset       5648 s2 adj   +5379 path delay      10048
ptp4l[3135.292]: master offset       6102 s2 adj   +7528 path delay      10026
ptp4l[3136.296]: master offset       3976 s2 adj   +7232 path delay      10216
ptp4l[3137.300]: master offset       2408 s2 adj   +6857 path delay      10216
ptp4l[3138.304]: master offset       1376 s2 adj   +6547 path delay      10240
ptp4l[3139.308]: master offset        432 s2 adj   +6016 path delay      10240
ptp4l[3140.312]: master offset        216 s2 adj   +5930 path delay      10216
ptp4l[3141.316]: master offset         16 s2 adj   +5795 path delay      10224
ptp4l[3142.320]: master offset       -100 s2 adj   +5683 path delay      10212
ptp4l[3143.324]: master offset       -246 s2 adj   +5507 path delay      10230
ptp4l[3144.328]: master offset        -55 s2 adj   +5625 path delay      10215
ptp4l[3145.332]: master offset         37 s2 adj   +5700 path delay      10219

Then start phc2sys

root:~> date
Thu Jan  1 00:51:23 UTC 1970

root:~> phc2sys -s /dev/ptp0 -O 0 &
phc   1557719 s1 1166667535.449552903 drift 0.00
phc   1580659 s2 1166667536.453552851 drift 0.00
phc   1577971 s3 1166667537.457552851 drift 0.00
phc   1588227 s4 1166667538.461552851 drift 10128.82
phc    -21552 s4 1166667539.463954496 drift 3663.22
phc      5511 s4 1166667540.467965879 drift 5316.52
phc      7037 s4 1166667541.471956749 drift 7427.62
phc      -104 s4 1166667542.475944360 drift 7396.42
phc      -982 s4 1166667543.479936986 drift 7101.82
phc     -8978 s4 1166667544.483930542 drift 4408.42
phc    -14327 s4 1166667545.487932393 drift 110.32
phc     22017 s4 1166667546.491942321 drift 6715.42
phc      7801 s4 1166667547.495920233 drift 9055.72
phc      1691 s4 1166667548.499905627 drift 9563.02

Check the system time, should be the same as master

root:~> date
Thu Dec 21 02:19:05 UTC 2010
root:~> date
Thu Dec 21 02:19:06 UTC 2010

More information