Go to file
Vladimir Oltean 5cca24bc07 ptp4l: call recvmsg() with the MSG_DONTWAIT flag
The application's main event loop (clock_poll) is woken up by poll() and
dispatches the socket receive queue events to the corresponding ports as
needed.

So it is a bug if poll() wakes up the process for data availability on a
socket's receive queue, and then recvmsg(), called immediately
afterwards, goes to sleep trying to retrieve it. This patch will
generate an error that will be propagated to the user if this condition
happens.

Can it happen?

As of this patch, ptp4l uses the SO_SELECT_ERR_QUEUE socket option,
which means that poll() will wake the process up, with revents ==
(POLLIN | POLLERR), if data is available in the error queue. But
clock_poll() does not check POLLERR, just POLLIN, and draws the wrong
conclusion that there is data available in the receive queue (when it is
in fact available in the error queue).

When the above condition happens, recvmsg() will sleep typically for a
whole sync interval waiting for data on the event socket, and will be
woken up when the new real frame arrives. It will not dequeue follow-up
messages during this time (which are sent to the general message socket)
and when it does, it will already be late for them (their seqid will be
out of order). So it will drop them and everything that comes after. The
synchronization process will fail.

The above condition shouldn't typically happen, but exceptional kernel
events will trigger it. It helps to be strict in ptp4l in order for
those events to not blow up in even stranger symptoms unrelated to the
root cause of the problem.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-06-24 10:09:13 -07:00
configs Add support for write phase mode. 2020-05-24 11:43:51 -07:00
.gitignore Introduce the ts2phc program. 2020-05-07 14:57:47 -07: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 Simplify the systems requirements section of the readme file. 2019-02-24 19:26:36 -08:00
address.h ptp4l: Add IPoIB interface support for ptp4l 2017-08-10 10:42:16 +02:00
as_capable.h port: Add configurable option to set asCapable. 2018-10-04 19:38:19 -07:00
bmc.c Add BMCA config option. 2018-10-04 19:38:19 -07:00
bmc.h telecom: Add a configuration option to use the alternate BMCA. 2018-04-24 21:50:03 -07:00
clock.c clock: Create a slave event monitor. 2020-05-24 19:46:31 -07:00
clock.h clock: Create a slave event monitor. 2020-05-24 19:46:31 -07:00
clockadj.c Add support for write phase mode. 2020-05-24 11:43:51 -07:00
clockadj.h Add support for write phase mode. 2020-05-24 11:43:51 -07: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 Introduce a module for slave event monitoring. 2020-05-24 19:46:31 -07:00
config.h Move the network interface into its own header file. 2020-03-04 09:44:57 -08:00
contain.h Fix a trivial spelling mistake in a comment. 2014-06-02 18:00:21 +02:00
ddt.h port: Introduce per-port stats for received and transmitted messages 2019-09-10 20:56:30 -07:00
designated_fsm.c Add BMCA config option. 2018-10-04 19:38:19 -07:00
designated_fsm.h Include missing headers. 2018-11-01 20:17:50 -07: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 fd: Introduce a unicast service timer. 2018-07-01 22:10:06 -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 fd: Introduce a unicast service timer. 2018-07-01 22:10:06 -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 Add BMCA config option. 2018-10-04 19:38:19 -07: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
interface.c interface: Remove obsolete method. 2020-03-04 09:46:41 -08:00
interface.h interface: Remove obsolete method. 2020-03-04 09:46:41 -08: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
lstab.c Introduce a leap second table. 2020-05-07 14:57:47 -07:00
lstab.h Introduce a leap second table. 2020-05-07 14:57:47 -07:00
makefile Introduce a module for slave event monitoring. 2020-05-24 19:46:31 -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 Add support for write phase mode. 2020-05-24 11:43:51 -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
monitor.c monitor: Add support for slave delay timing data TLV. 2020-05-24 19:46:31 -07:00
monitor.h monitor: Add support for slave delay timing data TLV. 2020-05-24 19:46:31 -07:00
msg.c msg: inline net2host64() and host2net64() 2018-07-21 16:28:07 -07:00
msg.h Implement the synchronization uncertain flag. 2020-05-24 12:02:49 -07:00
mtab.h Introduce the unicast client finite state machine. 2018-07-01 06:27:48 -07:00
nmea.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
nmea.h ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
notification.h Event notification: port state 2014-05-06 20:08:59 +02:00
nsm.8 nsm: Add man page. 2019-07-05 20:41:11 -07:00
nsm.c interface: Hide the implementation details. 2020-03-04 09:46:41 -08: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 Use llabs() instead of fabs() for integers. 2018-11-01 20:17:50 -07:00
nullf.h Add a servo that inhibits all frequency adjustment 2015-07-24 22:17:09 +02:00
p2p_tc.c fd: Introduce a unicast service timer. 2018-07-01 22:10:06 -07:00
pdt.h pdt: Added check if already defined 2018-07-05 23:54:26 -07:00
phc.c Add support for write phase mode. 2020-05-24 11:43:51 -07:00
phc.h Add support for write phase mode. 2020-05-24 11:43:51 -07:00
phc2sys.8 rtnl: add team activebackup support 2019-07-05 20:08:41 -07:00
phc2sys.c Balance the posix clock open function with a close method. 2020-03-21 04:36:10 -07:00
phc_ctl.8 fix small typo 2020-06-15 11:59:47 -07:00
phc_ctl.c Fix printf if time_t is long long 2020-06-02 07:36:21 -07:00
pi.c Use llabs() instead of fabs() for integers. 2018-11-01 20:17:50 -07:00
pi.h config: convert 'pi_integral_norm_max' to the new scheme. 2015-08-23 21:09:45 +02:00
pmc.8 pmc: Support querying TLV_PORT_PROPERTIES_NP 2019-10-12 19:42:42 -07:00
pmc.c pmc: Show slave delay timing data TLVs attached to signaling messages. 2020-05-24 19:46:31 -07:00
pmc_common.c pmc: Support getting and setting the local synchronization uncertain flag. 2020-05-24 12:02:49 -07:00
pmc_common.h pmc: Move private macros back into their source files. 2020-03-31 15:03:41 -07:00
port.c port: Support slave event monitoring of delay timing data. 2020-05-24 19:46:31 -07:00
port.h port: Publish the method for creating signaling messages. 2020-05-24 12:19:58 -07:00
port_private.h port: Support slave event monitoring of Sync timing data. 2020-05-24 19:46:31 -07:00
port_signaling.c port: Publish the method for creating signaling messages. 2020-05-24 12:19:58 -07:00
pqueue.c Introduce a priority queue implementation. 2018-07-01 22:10:06 -07:00
pqueue.h Introduce a priority queue implementation. 2018-07-01 22:10:06 -07:00
print.c Fix printf if time_t is long long 2020-06-02 07:36:21 -07:00
print.h Add options to tag ptp4l and phc2sys log messages. 2017-02-05 16:44:48 +01:00
ptp4l.8 Introduce a module for slave event monitoring. 2020-05-24 19:46:31 -07:00
ptp4l.c ptp4l: Remove bogus command line option. 2019-03-25 06:04:40 -07:00
raw.c ptp4l: call recvmsg() with the MSG_DONTWAIT flag 2020-06-24 10:09:13 -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 Convert call sites to the proper method for setting the time stamping label. 2020-03-04 09:46:00 -08:00
rtnl.h Convert call sites to the proper method for setting the time stamping label. 2020-03-04 09:46:00 -08:00
serial.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
serial.h ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
servo.c port: Add interval update mechanism. 2019-05-08 21:29:48 -07:00
servo.h port: Add interval update mechanism. 2019-05-08 21:29:48 -07:00
servo_private.h port: Add interval update mechanism. 2019-05-08 21:29:48 -07:00
sk.c sk: Convey transmit path errors to the caller. 2020-05-24 12:19:58 -07:00
sk.h sk: Added address family as inargument in sk_set_priority 2018-11-01 20:17:50 -07:00
sock.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
sock.h ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07: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 Correct the signature of the legacy system offset measurement method. 2019-12-25 10:25:59 -08:00
sysoff.h sysoff: Add support for PTP_SYS_OFFSET_EXTENDED ioctl. 2019-01-06 20:50:40 -08:00
tc.c transport_txts(): transport argument is unused 2018-06-25 07:24:17 -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: Allow ptp4l-specific sections in [ptp4l.conf]. 2018-09-30 18:54:31 -07:00
timemaster.c Fix building with new kernel headers. 2019-01-06 19:56:25 -08:00
tlv.c tlv: Encode and decode SLAVE_DELAY_TIMING_DATA_NP TLVs. 2020-05-24 19:46:31 -07:00
tlv.h tlv: Encode and decode SLAVE_DELAY_TIMING_DATA_NP TLVs. 2020-05-24 19:46:31 -07:00
tmv.h Provide a method to convert a tmv_t into a timespec. 2020-03-21 04:48:16 -07:00
transport.c transport_txts(): transport argument is unused 2018-06-25 07:24:17 -07:00
transport.h transport: Correct grammar in the doxygen comments. 2020-05-24 12:19:58 -07:00
transport_private.h transport: Use the proper enumerated event code. 2018-04-13 22:27:03 -07:00
ts2phc.8 Add documentation for the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_generic_master.c Introduce the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc_generic_master.h Introduce the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc_master.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_master.h Introduce the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc_master_private.h Introduce the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc_nmea_master.c ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_nmea_master.h ts2phc: Support using a GPS radio as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_phc_master.c ts2phc: Support using a PHC as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_phc_master.h ts2phc: Support using a PHC as the master clock. 2020-05-07 14:57:47 -07:00
ts2phc_slave.c Introduce the ts2phc program. 2020-05-07 14:57:47 -07:00
ts2phc_slave.h Introduce the ts2phc program. 2020-05-07 14:57:47 -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 ptp4l: call recvmsg() with the MSG_DONTWAIT flag 2020-06-24 10:09:13 -07:00
udp.h Add missing release method to the UDPv4 transport. 2012-03-17 17:30:21 +01:00
udp6.c ptp4l: call recvmsg() with the MSG_DONTWAIT flag 2020-06-24 10:09:13 -07:00
udp6.h config: convert 'udp6_scope' to the new scheme. 2015-08-23 21:09:45 +02:00
uds.c uds: Convey transmit path errors to the caller. 2020-05-24 12:19:58 -07:00
uds.h config: convert 'uds_address' to the new scheme. 2015-08-23 21:09:46 +02:00
unicast_client.c Fix printf if time_t is long long 2020-06-02 07:36:21 -07:00
unicast_client.h unicast: Enable sharing master tables between ports. 2020-02-09 04:20:08 -08:00
unicast_fsm.c Introduce the unicast client finite state machine. 2018-07-01 06:27:48 -07:00
unicast_fsm.h Introduce the unicast client finite state machine. 2018-07-01 06:27:48 -07:00
unicast_service.c Fix printf if time_t is long long 2020-06-02 07:36:21 -07:00
unicast_service.h Introduce unicast service. 2018-07-01 22:10:07 -07:00
util.c Balance the posix clock open function with a close method. 2020-03-21 04:36:10 -07:00
util.h util: Mark port identity comparisons as const. 2020-05-24 12:19:58 -07: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 2.0 2018-08-12 14:08:43 -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 clock_adjtimex system call.
  • Implements Boundary Clock (BC), Ordinary Clock (OC) and Transparent Clock (TC).
  • 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.
  • Implements unicast operation.
  • Supports a number of profiles, including:

    • The automotive profile
    • The default 1588 profile.
    • The enterprise profile.
    • The telecom profiles G.8265.1, G.8275.1, and G.8275.2.
  • Supports the NetSync Monitor protocol.
  • Implements Peer to peer one-step.
  • Supports bonded, IPoIB, and vlan interfaces.

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. Check whether your network interface supports PTP with the following command.

  ethtool -T eth0

This command shows whether a MAC supports hardware or software time stamping. The following example output indicates support for hardware time stamping.

Time stamping parameters for eth6:
Capabilities:
        hardware-transmit     (SOF_TIMESTAMPING_TX_HARDWARE)
        software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
        hardware-receive      (SOF_TIMESTAMPING_RX_HARDWARE)
        software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
        software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
        hardware-raw-clock    (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 1
Hardware Transmit Timestamp Modes:
        off                   (HWTSTAMP_TX_OFF)
        on                    (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
        none                  (HWTSTAMP_FILTER_NONE)
        all                   (HWTSTAMP_FILTER_ALL)

The next example shows the case where the MAC only supports software time stamping. The ptp4l program requires either the -S command line argument or the time_stamping software configuration option when using such interfaces.

Time stamping parameters for enp6s0:
Capabilities:
        software-transmit     (SOF_TIMESTAMPING_TX_SOFTWARE)
        software-receive      (SOF_TIMESTAMPING_RX_SOFTWARE)
        software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none

Note the software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE) capability. If this is lacking, then the MAC cannot be used at all. However, adding this capability entails adding a single line of code to the device driver.

Installation

  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.

Thanks to Moser Baer for sponsoring the Telecom Profiles and unicast support.

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