Go to file
Cliff Spradlin via Linuxptp-devel 4c5d180ab3 phc2sys: don't over-control a destination clock
If ptp4l is running as a boundary clock, and multiple master ports
share a hardware clock that is different than the slave port's
hardware clock, then phc2sys in autocfg mode will synchronize that
clock multiple times per sync loop, once per-port.

Example output when this happens:
CLOCK_REALTIME phc offset        -9 s2 freq    -355 delay   3635
eth9 phc offset         9 s2 freq   +1762 delay   7488
eth8 phc offset        41 s2 freq   +1985 delay   7424
eth7 phc offset        15 s2 freq   +1952 delay   7440
eth6 phc offset        20 s2 freq   +1059 delay   7440
eth1 phc offset        22 s2 freq   +1783 delay   7424
eth12.400 phc offset        15 s2 freq -4207943 delay   7551
eth12.300 phc offset       388 s2 freq +2336645 delay   7536
eth12.200 phc offset       451 s2 freq +2516553 delay   7438
eth12.100 phc offset       268 s2 freq  +64274 delay   7405

This is easily reproducible by adding VLANs to a single network
interface and configuring ptp4l to use those VLAN interfaces as PTP
ports.

This patch prevents this problem by introducing a new deduplicated
destination clock list to phc2sys. Each time phc2sys reconfigures,
the destination clock list is re-populated. In the synchronization
loop, phc2sys will only use the clocks in this list.

Example output of reconfiguration with this patch:
reconfiguring after port state change
selecting eth9 for synchronization
selecting eth8 for synchronization
selecting eth7 for synchronization
selecting eth6 for synchronization
selecting eth1 for synchronization
selecting eth13.400 for synchronization
skipping eth13.300: eth13.400 has the same clock and is already selected
skipping eth13.200: eth13.400 has the same clock and is already selected
skipping eth13.100: eth13.400 has the same clock and is already selected
selecting eth12.400 for synchronization
skipping eth12.300: eth12.400 has the same clock and is already selected
skipping eth12.200: eth12.400 has the same clock and is already selected
skipping eth12.100: eth12.400 has the same clock and is already selected
skipping eth13.500: eth13.400 has the same clock and is already selected

This patch was tested with autocfg mode and also when specifying source
and destination manually via commandline.

Signed-off-by: Cliff Spradlin <cspradlin@google.com>
2018-06-18 11:01:56 -07:00
configs Move the configuration files to their own directory. 2018-05-25 07:46:03 -07:00
.gitignore nsm: Implement the NetSync Monitor query. 2018-03-08 07:20:42 -08:00
CODING_STYLE.org Add a coding style document. 2013-02-06 14:42:12 +01:00
COPYING Add the license, a readme, and some header files. 2011-11-01 17:39:14 +01:00
README.org Add an acknowledgment in the readme for Meinberg. 2017-11-25 11:43:38 -08:00
address.h ptp4l: Add IPoIB interface support for ptp4l 2017-08-10 10:42:16 +02:00
bmc.c bmc: Make the second part of the data set comparison algorithm public. 2018-04-03 09:28:22 -07:00
bmc.h telecom: Add a configuration option to use the alternate BMCA. 2018-04-24 21:50:03 -07:00
clock.c e2e_tc: Implement an end to end transparent clock. 2018-05-01 07:46:43 -07:00
clock.h clock: Add a method to determine whether a clock is free running. 2018-05-01 07:01:57 -07:00
clockadj.c added workaround for ticks being returned as zero from 2.6.32 kernel. 2017-06-19 08:14:40 +02:00
clockadj.h Set TAI offset of system clock. 2014-06-22 09:23:55 +02:00
clockcheck.c Add clock sanity check. 2013-10-27 08:24:01 +01:00
clockcheck.h Add clock sanity check. 2013-10-27 08:24:01 +01:00
config.c config: Fix value range for tc_spanning_tree option 2018-05-17 10:41:59 -07:00
config.h Expand and rationalize time stamping options. 2018-03-27 22:26:32 -07:00
contain.h Fix a trivial spelling mistake in a comment. 2014-06-02 18:00:21 +02:00
ddt.h adds CLOCK_DESCRIPTION struct 2013-02-25 18:11:03 +01:00
dm.h Expose the peer delay flavors in their own header file. 2012-04-05 17:48:59 +02:00
ds.h telecom: Introduce the local priority attribute into the data set. 2018-04-24 21:39:13 -07:00
e2e_tc.c msg: Introduce a helper to test for unicast messages. 2018-05-25 15:28:35 -07:00
ether.h ptp4l: Add IPoIB interface support for ptp4l 2017-08-10 10:42:16 +02:00
fault.c port: allow running a boundary clock with multiple clock devices. 2014-12-18 11:38:00 +01:00
fault.h fault: protect header against multiple inclusion. 2016-04-03 14:45:41 +02:00
fd.h Fix crash in hybrid E2E mode. 2018-05-16 06:44:56 -07:00
filter.c Add median filter. 2013-10-30 21:54:07 +01:00
filter.h Add median filter. 2013-10-30 21:54:07 +01:00
filter_private.h Add modular filter interface. 2013-10-30 21:43:37 +01:00
foreign.h Implement the PTP clock. 2011-11-12 18:59:13 +01:00
fsm.c fsm: Make the transition out of INITIALIZING part of the FSM code. 2017-01-08 21:34:54 +01:00
fsm.h fsm: Make the transition out of INITIALIZING part of the FSM code. 2017-01-08 21:34:54 +01:00
hash.c Introduce a simple hash table implementation. 2015-08-16 11:20:23 +02:00
hash.h Introduce a simple hash table implementation. 2015-08-16 11:20:23 +02:00
hwstamp_ctl.8 Bump the date on the hwstamp_ctl man page. 2014-06-04 15:17:22 +02:00
hwstamp_ctl.c Fix copying of device name to ifreq. 2014-09-21 13:10:27 +02:00
incdefs.sh Introduce peer to peer one step. 2018-03-27 22:26:32 -07:00
linreg.c linreg: use sample weight. 2015-03-27 10:58:04 +01:00
linreg.h Add an adaptive servo based on linear regression. 2014-03-14 09:52:40 +01:00
makefile e2e_tc: Implement an end to end transparent clock. 2018-05-01 07:46:43 -07:00
mave.c tmv: Add missing uses of tmv_zero() 2018-03-07 07:55:51 -08:00
mave.h Add modular filter interface. 2013-10-30 21:43:37 +01:00
missing.h Make the LIST_FOREACH_SAFE publicly visible. 2018-03-31 11:05:57 -07:00
mmedian.c tmv: Generalise tmv_eq() to tmv_cmp() 2018-03-07 07:55:51 -08:00
mmedian.h Add median filter. 2013-10-30 21:54:07 +01:00
msg.c msg: Detect missing HW time stamps on duplicated messages. 2018-04-18 18:44:28 -07:00
msg.h msg: Introduce a helper to test for unicast messages. 2018-05-25 15:28:35 -07:00
notification.h Event notification: port state 2014-05-06 20:08:59 +02:00
nsm.c msg: Introduce a helper to test for unicast messages. 2018-05-25 15:28:35 -07:00
ntpshm.c config: convert 'ntpshm_segment' to the new scheme. 2015-08-23 21:09:45 +02:00
ntpshm.h config: convert 'ntpshm_segment' to the new scheme. 2015-08-23 21:09:45 +02:00
nullf.c Add a servo that inhibits all frequency adjustment 2015-07-24 22:17:09 +02:00
nullf.h Add a servo that inhibits all frequency adjustment 2015-07-24 22:17:09 +02:00
p2p_tc.c msg: Introduce a helper to test for unicast messages. 2018-05-25 15:28:35 -07:00
pdt.h Add the license, a readme, and some header files. 2011-11-01 17:39:14 +01:00
phc.c Don't return bogus clock id 2013-06-06 17:00:25 +02:00
phc.h phc2sys: enable PPS output from PHC 2013-04-19 17:52:25 +02:00
phc2sys.8 phc2sys: fix manpage documentation for -F 2018-05-15 06:14:19 -07:00
phc2sys.c phc2sys: don't over-control a destination clock 2018-06-18 11:01:56 -07:00
phc_ctl.8 linuxptp: add phc_ctl program to help debug PHC devices 2014-07-19 07:15:24 +02:00
phc_ctl.c phc_ctl: fix adj command to accept negative offset. 2017-10-14 05:51:43 -07:00
pi.c config: convert 'pi_integral_norm_max' to the new scheme. 2015-08-23 21:09:45 +02:00
pi.h config: convert 'pi_integral_norm_max' to the new scheme. 2015-08-23 21:09:45 +02:00
pmc.8 pmc: Documentation for long opts / cfg file 2018-03-24 21:15:17 -07:00
pmc.c pmc: Fix LOG_SYNC_INTERVAL 2018-04-18 14:51:57 -07:00
pmc_common.c nsm, pmc: Check for missing HW time stamps. 2018-04-18 18:44:28 -07:00
pmc_common.h pmc: require a configuration for creating a PMC instance. 2015-08-16 11:20:23 +02:00
port.c port: don't clockcheck timestamps from other domains 2018-06-13 21:15:19 -07:00
port.h tc: Add the transparent clock implementation. 2018-05-01 07:46:43 -07:00
port_private.h e2e_tc: Implement an end to end transparent clock. 2018-05-01 07:46:43 -07:00
print.c Add options to tag ptp4l and phc2sys log messages. 2017-02-05 16:44:48 +01:00
print.h Add options to tag ptp4l and phc2sys log messages. 2017-02-05 16:44:48 +01:00
ptp4l.8 config: Add a configuration option for preventing loops in TC mode. 2018-05-01 07:46:43 -07:00
ptp4l.c config: Add a configuration option for TC mode. 2018-05-01 07:46:43 -07:00
raw.c transport: Introduce transmit time stamp deferral. 2018-04-13 22:29:05 -07:00
raw.h config: convert 'p2p_dst_mac', letting it be a per-port option. 2015-08-23 21:09:46 +02:00
rtnl.c rtnl: remove dependency on config.h. 2018-04-19 07:41:11 -07:00
rtnl.h rtnl: remove dependency on config.h. 2018-04-19 07:41:11 -07:00
servo.c servo: NULL pointer check for servo constructors 2017-04-06 06:25:34 +02:00
servo.h config: convert the 'max_frequency' option to the new scheme. 2015-08-23 21:09:45 +02:00
servo_private.h servo: add support for weighted samples. 2015-03-27 10:58:04 +01:00
sk.c sk: Silence gcc warning about unused variable. 2018-04-06 18:41:15 -07:00
sk.h sk: Add a method to obtain a socket for utility purposes. 2016-10-16 12:42:56 +02:00
stats.c Add summary statistics. 2013-02-09 10:09:25 +01:00
stats.h Add summary statistics. 2013-02-09 10:09:25 +01:00
sysoff.c phc2sys: Print clock reading delay. 2013-02-08 18:41:34 +01:00
sysoff.h phc2sys: Print clock reading delay. 2013-02-08 18:41:34 +01:00
tc.c p2p_tc: Implement a peer to peer transparent clock. 2018-05-01 07:46:43 -07:00
tc.h tc: Add the transparent clock implementation. 2018-05-01 07:46:43 -07:00
telecom.c telecom: Add the data set comparison algorithm from the Telecom Profiles. 2018-04-24 21:39:13 -07:00
timemaster.8 timemaster: restart terminated processes. 2018-04-19 07:41:11 -07:00
timemaster.c timemaster: restart terminated processes. 2018-04-19 07:41:11 -07:00
tlv.c tlv: Introduce the NetSync Monitor TLVs. 2018-03-08 07:20:42 -08:00
tlv.h tlv: Introduce the NetSync Monitor TLVs. 2018-03-08 07:20:42 -08:00
tmv.h tmv: Add a method to convert to a struct Timestamp. 2018-03-08 07:20:42 -08:00
transport.c transport: Introduce method for fetching a deferred transmit time stamp. 2018-04-13 22:29:05 -07:00
transport.h transport: Introduce method for fetching a deferred transmit time stamp. 2018-04-13 22:29:05 -07:00
transport_private.h transport: Use the proper enumerated event code. 2018-04-13 22:27:03 -07:00
tsproc.c tmv: Add tmv_sign() 2018-03-07 07:55:51 -08:00
tsproc.h tsproc: add raw and weighting modes. 2015-03-27 10:58:04 +01:00
udp.c transport: Introduce transmit time stamp deferral. 2018-04-13 22:29:05 -07:00
udp.h Add missing release method to the UDPv4 transport. 2012-03-17 17:30:21 +01:00
udp6.c transport: Introduce transmit time stamp deferral. 2018-04-13 22:29:05 -07:00
udp6.h config: convert 'udp6_scope' to the new scheme. 2015-08-23 21:09:45 +02:00
uds.c transport: Use the proper enumerated event code. 2018-04-13 22:27:03 -07:00
uds.h config: convert 'uds_address' to the new scheme. 2015-08-23 21:09:46 +02:00
util.c util: Relocate utility functions from pmc.c. 2018-03-08 07:20:42 -08:00
util.h util: Relocate utility functions from pmc.c. 2018-03-08 07:20:42 -08:00
version.c Add utility functions to get the software version string. 2012-12-10 15:11:51 +01:00
version.h Add utility functions to get the software version string. 2012-12-10 15:11:51 +01:00
version.sh Version 1.9 2018-03-31 11:36:56 -07:00

README.org

Introduction

This software is an implementation of the Precision Time Protocol (PTP) according to IEEE standard 1588 for Linux. The dual design goals are to provide a robust implementation of the standard and to use the most relevant and modern Application Programming Interfaces (API) offered by the Linux kernel. Supporting legacy APIs and other platforms is not a goal.

License

The software is copyrighted by the authors and is licensed under the GNU General Public License. See the file, COPYING, for details of the license terms.

Features

  • Supports hardware and software time stamping via the Linux SO_TIMESTAMPING socket option.
  • Supports the Linux PTP Hardware Clock (PHC) subsystem by using the clock_gettime family of calls, including the new clock_adjtimex system call.
  • Implements Boundary Clock (BC) and Ordinary Clock (OC).
  • Transport over UDP/IPv4, UDP/IPv6, and raw Ethernet (Layer 2).
  • Supports IEEE 802.1AS-2011 in the role of end station.
  • Modular design allowing painless addition of new transports and clock servos.

Getting the Code

You can download the latest released version at Source Forge.

http://sourceforge.net/projects/linuxptp/files/latest/download

The source code is managed using the git version control system. To get your own copy of the project sources, use the following command.

  git clone git://git.code.sf.net/p/linuxptp/code linuxptp

If the git protocol is blocked by your local area network, then you can use the alternative HTTP protocol instead.

  git clone http://git.code.sf.net/p/linuxptp/code linuxptp

System Requirements

In order to run this software, you need Linux kernel version 3.0 or newer, and the kernel header files must available at compile time.

In addition, you will also need to have either:

  1. A supported Ethernet MAC device.
  2. A supported PHY device paired with a MAC that allows time stamping in the PHY (indicated by PHY=Y in the table below).

Linux Kernel Support

In order to support PTP, the operating system needs to provide two services: network packet time stamping and clock control. In 2009, Patrick Ohly added a new socket option called SO_TIMESTAMPING for packet time stamping, especially for PTP. This work appeared in Linux version 2.6.30.

In July of 2011, the PTP Hardware Clock (PHC) subsystem was merged into Linux version 3.0. The PHC code provides a driver framework and the user space API for clock control.

Ethtool Support

Starting with version 3.5 of the Linux kernel, you can query the time stamping capabilities of a network interface using the ETHTOOL_GET_TS_INFO ioctl. Using ethtool version 3.4 or later, you can check your system's time stamping support as shown in the following example.

  ethtool -T eth0

If the ethtool ioctl is available, then the ptp4l program will use it in order to discover the proper PHC device.

Driver Support Matrix

The following two tables list the drivers that support the PHC subsystem and the Linux kernel version when they first appeared. These drivers will create a PHC device for controlling the hardware clock.

Hardware Timestamping - PHY

Driver Hardware Version
dp83640 National Semiconductor PHYTER 3.0

Hardware Timestamping - MAC

Driver Hardware Version
amd-xgbe AMD 10GbE Ethernet Soc 3.17
bfin_mac Analog Blackfin 3.8
bnx2x Broadcom NetXtremeII 10G 3.18
cpts Texas Instruments am335x 3.8
e1000e Intel 82574, 82583 3.9
fm10k Intel FM10000 3.18
fec Freescale i.mx6 3.8
gianfar Freescale eTSEC PowerPC 3.0
i40e Intel XL710 Family 3.14
igb Intel 82576, 82580 3.5
ixgbe Intel 82599 3.5
mlx4 Mellanox 40G PCI 3.14
ptp_ixp46x Intel IXP465 3.0
ptp_phc Lapis EG20T PCH 3.5
sfc Solarflare SFC9000 3.7
stmmac STM Synopsys IP Core 3.10
tg3 Broadcom Tigon3 PCI 3.8
tilegx Tilera GBE/XGBE 3.12

Software Timestamping

The table below shows the Linux drivers that support software time stamping. In addition, the 'PHY' column indicates whether the Ethernet MAC driver can support a PTP Hardware Clock in an external PHY. The letter 'Y' in this column means that if you design a mother board that combines such a MAC with a PTP capable PHY, then it will work with the Linux PHC subsystem.

Driver Hardware Version PHY
3c59x 3Com EtherLink PCI 3.14 N
altera_tse Altera Triple-Speed MAC 3.15 Y
bna Brocade 1010/1020 10Gb 3.14 N
bnx2x Broadcom Everest 3.5 N
davinci_emac TI DaVinci, Sitara 3.1 Y
dnet Dave Ethernet MAC 3.1 Y
e100 Intel PRO/100 3.5 N
e1000 Intel PRO/1000 PCI/PCI-X 3.5 N
e1000e Intel PRO/1000 PCIe 3.5 N
emaclite Xilinx Ethernet Lite 3.1 Y
ethoc OpenCores 10/100 MAC 3.1 Y
fec Freescale Coldfire 3.1 Y
fec_mpc52xx Freescale MPC5200 3.1 Y
forcedeth NVIDIA nForce 3.5 N
fs_enet Freescale MPC512x 3.1 Y
genet Broadcom GENET 3.15 Y
ixp4xx_eth Intel IXP4xx 3.0 Y
lib8390 Asix AX88796 3.1 Y
lib8390 Various 8390 based HW 3.1 N
ll_temac Xilinx LL TEMAC 3.1 Y
macb Atmel AT32, AT91 3.1 Y
mv643xx_eth Marvell Discovery, Orion 3.1 Y
pxa168_eth Marvell pxa168 3.1 Y
r6040 RDC Ethernet MAC 3.1 Y
r8169 Realtek 8169/8168/8101 3.4 N
samsun-sxgbe Samsung SXGBE 10G 3.15 Y
smsc911x SMSC LAN911x, LAN921x 3.1 Y
smsc9420 SMSC LAN9420 PCI 3.1 Y
stmmac STM Synopsys IP Core 3.1 Y
tg3 Broadcom Tigon3 PCI 3.1 Y
ucc_geth Freescale QE Gigabit 3.1 Y
usbnet USB network devices 3.2 Y/N
xgene-enet APM X-Gene SoC 3.17 Y

Installation

Linux kernel

There are many ways of getting a precompiled Linux kernel or compiling your own, so this section is only meant as an example. It is important to have the kernel headers available when compiling the Linux PTP stack.

   export ARCH=x86
   export CROSS_COMPILE=
   export KBUILD_OUTPUT=/home/richard/kernel/ptp_debian
   mkdir -p $KBUILD_OUTPUT
   cp /boot/config-2.6.38-bpo.2-686 $KBUILD_OUTPUT/.config
   make oldnoconfig
   make menuconfig
   time make -j4
   make headers_install

Here is a table of kernel configuration options needed for PTP support. In addtion to these, you should enable the specific Ethernet MAC and PHY drivers for your hardware.

Option Description
CONFIG_PPS Required
CONFIG_NETWORK_PHY_TIMESTAMPING Timestamping in PHY devices
PTP_1588_CLOCK PTP clock support

PTP stack

  1. Just type 'make'
  2. If you compiled your own kernel (and the headers are not installed into the system path), then you should set the KBUILD_OUTPUT environment variable as in the example, above.
  3. In order to install the programs and man pages into /usr/local, run the 'make install' target. You can change the installation directories by setttings the variables prefix, sbindir, mandir, and man8dir on the make command line.

Getting Involved

The software development is hosted at Source Forge.

https://sourceforge.net/projects/linuxptp/

Reporting Bugs

Please report any bugs or other issues with the software to the linuxptp-users mailing list.

https://lists.sourceforge.net/lists/listinfo/linuxptp-users

Development

If you would like to get involved in improving the software, please join the linuxptp-devel mailing list.

https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Submitting Patches

  1. Before submitting patches, please make sure that you are starting your work on the current HEAD of the git repository.
  2. Please checkout the CODING_STYLE.org file for guidelines on how to properly format your code.
  3. Describe your changes. Each patch will be reviewed, and the reviewers need to understand why you did what you did.
  4. Sign-Off each commit, so the changes can be properly attributed to you and you explicitely give your agreement for distribution under linuxptp's license. Signing-off is as simple as:

    git commit -s
    

    or by adding the following line (replace your real name and email) to your patch:

    Signed-off-by: Random J Developer <random@developer.example.org>
    
  5. Finally, send your patches via email to the linuxptp-devel mailing list, where they will be reviewed, and eventually be included in the official code base.

    git send-email --to linuxptp-devel@lists.sourceforge.net origin/master
    

Thanks

Thanks to AudioScience Inc for sponsoring the 8021.AS support.

Thanks to Exablaze for donating an ExaNIC X10

Thanks to Intel Corporation for donating four NICs, the 82574, 82580, 82599, and the i210.

Thanks to Meinberg Funkuhren for donating a LANTIME M1000.

For testing I use an OTMC 100 grandmaster clock donated by OMICRON Lab.