Commit Graph

86 Commits (master)

Author SHA1 Message Date
Vladimir Oltean 314ff98903 ts2phc: instantiate a pmc node
This introduces the '-a' option in ts2phc, an option inspired from
phc2sys that puts the clocks in "automatic" mode. In this mode, ts2phc
listens, as a PMC, to port state change events from ptp4l, and detects
which port state machine, if any, has transitioned to PS_SLAVE. That
port's clock will become the synchronization master for the hierarchy
described by ts2phc.

The use case is a multi-switch DSA setup with boundary_clock_jbod, where
there is only one grandmaster, connected to one switch's port. The other
switches, connected together through a PPS signal, must adapt themselves
to this new source of time, while the switch connected to the GM must
not be synchronized by ts2phc because it is already synchronized by
ptp4l.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-08-30 02:56:48 +03:00
Richard Cochran d3a519e26d Introduce a module for slave event monitoring.
This patch adds a new module for slave event monitoring with its own
configuration option, a UDS address.  If the option is enabled, then
the monitor will send events to the configured address.  The default
setting produces an inactive monitor that does nothing.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 7486e6e4e1 ts2phc: Support using a GPS radio as the master clock.
Many GPS radios provide both a 1-PPS and time of day information via
NMEA sentences.  This patch introduces a ts2phc master that decodes
the "recommended minimum data" sentence, RMC, which provides UTC time
and a validity flag.  Together with the file based leap second table,
this sentence provides adequate time of day for determining the time
of the PPS edge.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 9c6e0f57b3 ts2phc: Support using a PHC as the master clock.
This patch introduces a new ts2phc source using a PHC device.  There
are multiple use cases for such a master.  By connecting pins of two
or more separate PHC devices together, one may act as the source, and
the others may be synchronized to it in hardware.  In this way, "just
a bunch of devices" together forms a Transparent Clock.  If the master
clock is synchronized to a global time source (like a PPS from a GPS),
then the system becomes a mutli-port Grand Master or a Boundary Clock
with GM capability.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 1bdc9143aa Introduce the ts2phc program.
Some PTP Hardware Clocks have input pins that can generate time stamps
on the edges of external signals.  This functionality can be used in
various ways.  For example, one can synchronize a PHC device to a
global time source by taking a Pulse Per Second signal from the source
into the PHC.  This patch adds support for synchronizing one or more
PHC slaves to a given master clock.

The implementation follows a modular design that allows adding
different kinds of master clocks in the future.  This patch starts off
with a single "generic" PPS master, meaning a PPS signal that lacks
and time or date information.  The generic master assumes that the
Linux system time is approximately correct (by NTP or RTC for example)
in order to calculate the time of the incoming PPS edges.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Balint Ferencz <fernya@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 01db4c8849 Remove the unfinished SNMP code.
Unfortunately the SNMP code still has issues like not passing the
valgrind test, and no one is able to finish this up right now.  This
patch removes the SNMP program so that the upcoming release does not
contain unfinished work, potentially misleading end users about the
scope and completeness of the features.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-21 04:35:51 -07:00
Richard Cochran 34945679fe Convert call sites to the proper method for getting interface names.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Richard Cochran 380ee349f6 interface: Introduce an access method for the name field.
Many of the users only require a read only reference to the interface name.
This patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Richard Cochran b8480ef908 Group related objects together within the makefile.
Any program that links to the servo interface must also link with the
implementations of that interface.  Similarly, the filter and network
transport interfaces each require their implementations.  This patch
re-factors the makefile to reflect this fact in order to simplify
adding new programs making use of these interfaces.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:25 -08:00
Richard Cochran d32758aa09 phc2sys, phc_ctl: Re-factor common code.
The two programs, phc2sys and phc_ctl, use nearly identical subroutines to
open an instance of a dynamic posix clock.  In anticipation of yet a third
program with similar needs, this patch refactors the common code into the
utilities.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-08-25 12:19:36 -07:00
Vedang Patel 83be05256b Add BMCA config option.
This adds config option to specify static roles for master and slave
in the Best Master Clock Algorithm. This is the case for Automotive
Profile where networks are mostly static and role for each device is
known in advance.

masterOnly and slaveOnly will be used to determine the roles for the
devices. Since masterOnly is a per-port config and slaveOnly is a global
config option, role assignment will be slightly odd in case of bridges.
If slaveOnly is set to 1, all the ports will be in slave roles except
for the ones where masterOnly is set to 1. These ports will assume the
master role.

Two new FSMs which will be used for master and slave roles for this
config option have also been added.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Anders Selhammer 68dcd10673 snmp4lptp: Added communication to ptp4l via the UDS port.
UDS transport is configured using pmc_common functions.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-09-07 09:44:52 -07:00
Anders Selhammer b2f2c9e02d snmp4lptp: Add snmp sub agent for linuxptp
The sub agent use net-snmp library and AgentX protocol for the
communication towards the snmp master agent.
snmpd.c should only include general setup needed for handling snmp.
Supported MIBs should be implemented in separate files.
Makefile will include snmpd if libsnmp is available during compilation.
configs/snmpd.conf should be placed in /etc/snmp/

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-09-07 09:44:52 -07:00
Richard Cochran 63598688b7 Introduce unicast service.
This patch adds new code that handles unicast service contracts,
sending messages according the negotiated schedule.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:07 -07:00
Richard Cochran a076fd1ce9 Introduce a priority queue implementation.
This will be needed to keep track of multiple different deadlines
using a single timer.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran faf0e0a025 Introduce unicast client logic.
This patch adds new code that runs the state machine and handles the
TLVs for requesting unicast service from a remote master.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran 1ccc55ef07 port: Add a method for constructing signaling messages.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran 0fffa6c4b5 Introduce the unicast client finite state machine.
In order to implement client side unicast negotiation, state is needed
per port and master.  This patch adds the needed state machines.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran 96716060b1 e2e_tc: Implement an end to end transparent clock.
The E2E TC forwards Announce, Delay_Req, Delay_Resp, Management,
Signaling, and Sync messages, and drops P2P Delay messages.

This implementation tracks the GM using the BMCA in order
to syntonize (or possibly even synchronize) with it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran 6a928ae867 p2p_tc: Implement a peer to peer transparent clock.
The P2P TC forwards Announce, Management, Signaling, and Sync
messages, consumes P2P Delay messages, and drops E2E Delay messages.

This implementation tracks the GM using the BMCA in order
to syntonize (or possibly even synchronize) with it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran a13212fcbb tc: Add the transparent clock implementation.
This patch adds code that sends an event messages received on one port out
all the other ports and calculates the residence time.  The correction,
ingress port, and the original message are remembered in a TC transmit
descriptor.  These descriptors are recycled in a memory pool in a similar
way to the message buffers.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran f848a30a3e telecom: Add the data set comparison algorithm from the Telecom Profiles.
The first half of the telecom algorithm from G.8275.1 and G.8275.2
differs from the one in 1588, making use of profile specific
"localPriority" attributes.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:13 -07:00
Miroslav Lichvar e5ba2dae5f timemaster: add support for bonded interfaces.
Use the rtnl_get_ts_device() function to get the name of the slave
interface which will be timestamping PTP packets and use it instead of
the master interface to check the timestamping capabilities and PHC.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-04-19 07:41:11 -07:00
Richard Cochran 74cdaafd5b Correct the make install target.
The make install target tries to install a man page that does not
exist.  This patch fixes the makefile to install the existing man
pages only.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-06 18:41:05 -07:00
Richard Cochran ab8dc20cf7 nsm: Implement the NetSync Monitor query.
This patch adds a new "NSM" program.  The new code handles only one
outstanding NSM command at a time.  If and when all four event time
stamps have arrived, the code prints the instantaneous estimated
offset without any averaging or smoothing.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Richard Cochran 356eb81d4d makefile: Make the 'clean' target conform to standard practice.
This patch makes the build system less surprising by removing the
executable binaries in the 'clean' target.  This behavior is more in
line with the GNU makefile guidelines.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Suggested-by: Manuel Traut <manut@linutronix.de>
2016-12-06 19:48:39 +01:00
Richard Cochran 0b3c045a42 rtnl: Introduce RT netlink sockets.
This patch adds a source module that implements RT netlink sockets
for the purpose of link monitoring.  Unfortunately the netlink API
offers no possibility for per-port notification.  Instead it
forces us to use a de-multiplexing pattern.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran e7dbc068f6 config: introduce a new API for reading configuration settings.
This patch introduces generic code for adding and parsing new options.
The public 'get' methods return option values directly.  Although the
API is easy to use, it does not provide error checking in case the
option does not exist or if there is a type mismatch.

Therefore the code performs a BIST to ensure that the options are
properly populated.  In addition, the code terminates the program in
case of missing options or type mismatches.  This heavy handed
approach is meant to catch errors during development and should never
trigger during normal usage.

As a first element, we include an option for specifying the UDP TTL.

Users are required to call 'config_init', and so this patch add that into
all three programs, ptp4l, phc2sys and pmc.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:19 +02:00
Richard Cochran 8601aa31a3 Introduce a simple hash table implementation.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-16 11:20:23 +02:00
Richard Cochran fa79141211 Add a servo that inhibits all frequency adjustment
When running with Synchronous Ethernet (SyncE), the correct clock
frequency is provided by the link partner.  In this case, only the
offset needs correcting.

This patch provides SyncE nodes with an way to keep the frequency
correction dialed to zero.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-07-24 22:17:09 +02:00
IOhannes m zmölnig 572438b85e install into DESTDIR
and use 'install' throughout (rather than 'mkdir')

Signed-off-by: IOhannes m zmölnig <zmoelnig@umlaeute.mur.at>
2015-06-08 14:46:37 +02:00
Miroslav Lichvar c452e862dd Refactor time stamp processing.
Introduce a time stamp processor for offset/delay calculations and use
it in the clock and port modules.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-03-27 10:58:04 +01:00
Miroslav Lichvar 82f13c594a Add timemaster.
timemaster is a program that uses ptp4l and phc2sys in combination with
chronyd or ntpd to synchronize the system clock to NTP and PTP time
sources. The PTP time is provided by phc2sys and ptp4l via SHM reference
clocks to chronyd/ntpd, which can compare all time sources and use the
best sources to synchronize the system clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Jacob Keller bdb6a35883 linuxptp: add phc_ctl program to help debug PHC devices
This is an updated version of a script I wrote a couple years ago for
debugging the PHC when writing a new driver. I figured that it might be
handy for the LinuxPTP project to include, as it can give some insight
into the PHC directly. I have updated it to make use of the shared code
here, in order to reduce duplication. Hopefully this is of some use to
everyone.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2014-07-19 07:15:24 +02:00
Miroslav Lichvar 9710fb1a22 Add new servo for NTP SHM reference clock.
This is a simple servo that provides the NTP SHM reference clock. It
doesn't make any clock adjustments and it always returns with the
unlocked state. It writes all samples to the SHM segment and another
process (e.g. chronyd or ntpd) is needed to read the samples and
actually synchronize the clock. The SHM segment number is set to the PTP
domain number to allow multiple SHM reference clocks running at the same
time.

This is mainly useful when other time sources are available on the
system (e.g. NTP, hardware reference clocks, or other PTP domains)
and a fallback to/from PTP is needed.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-06-14 10:49:04 +02:00
Miroslav Lichvar a5890cbe98 Add an adaptive servo based on linear regression.
This servo uses linear regression to estimate current time and
frequency error. The number of points used in the regression is
variable (from 4 to 64 in powers of 2) and is selected by a long-term
statistic of the prediction error.

Future improvements could include tracking of sudden frequency changes
(e.g. due to temperature variations), better stability of the error
statistic when a large offset is corrected, options to set the speed of
the adaptation, minimum and maximum number of points, or an option to
prefer frequency accuracy over time accuracy.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-14 09:52:40 +01:00
Richard Cochran e2586af94a Merge Miroslav's random PTP timeout branch.
Conflicts:
	makefile
2013-12-19 19:20:58 +01:00
Miroslav Lichvar ed9e0fa975 Add median filter.
Median filter has an advantage over moving average that it is much less
sensitive to outliers.

For instance, it allows much faster recovery from an external clock
time step which happened between receiving sync message and sending
delay_req message. The measured delay includes a large error, but the
median is still a good estimate of the delay and the first step
correction applied by the servo is right.

In this implementation the median update has linear time complexity.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-30 21:54:07 +01:00
Miroslav Lichvar 2c9718f3c2 Add modular filter interface.
Similarly to the servo interface, allow multiple filters to be
used for delay filtering. Convert mave to the new interface.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-30 21:43:37 +01:00
Miroslav Lichvar 23d31d090e Drop tmtab module.
Instead of maintaining a table of precalculated values, use the
newly added set_tmo_random() function to set the delay request timeout.
It saves some memory and improves the timeout granularity, but has a
higher computational cost. It follows the requirements from section
9.5.11.2 of the spec.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-27 14:03:05 +01:00
Miroslav Lichvar ed379b4028 Add clock sanity check.
Check the sanity of the synchronized clock by comparing its uncorrected
frequency with the system monotonic clock. When the measured frequency
offset is larger than the value of the sanity_freq_limit option (20% by
default), a warning message will be printed and the servo will be reset.
Setting the option to zero disables the check.

This is useful to detect when the clock is broken or adjusted by another
program.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-27 08:24:01 +01:00
Richard Cochran ba12da671f Make the CFLAGS more robust.
This patch introduces a shell script to figure out the proper definitions
for the HAVE_CLOCK_ADJTIME and HAVE_ONESTEP_SYNC macros, as well as the
include path. The intent is to "do the right thing" for three different
user scenarios, namely cross compiling, compiling against a custom kernel,
and using a plain old disto kernel.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-09-29 20:16:16 +02:00
Jacob Keller 5bf265e860 missing: add onestep sync to missing.h
this patch uses grep to test whether the net_tstamp.h header has
HWTSTAMP_TX_ONESTEP_SYNC flag defined. If it doesn't then we can simply define
it with the correct value. This works because proper drivers should just report
that the value is not allowed if they don't support onestep mode. This is the
cleanest way to ensure that linuxptp will still work on kernels which have not
defined the one step flag, and also works for any distributions which backport
the feature.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2013-09-04 18:05:43 +02:00
Richard Cochran c14a243b46 Silence grep error during build.
Ever since upgrading to Debian 7.0, building linuxptp results in an
annoying error message. This is due to the fact that the directory
/usr/include/bits is no longer present, but our makefile expects it
to exist. This patch fixes the issue by telling grep not to complain
about missing files.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-06-14 12:04:52 +02:00
Miroslav Lichvar e3f57d1579 phc2sys: Read maximum frequency adjustment.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Richard Cochran bd28acffb3 Merge branch 'mlichvar_leap'
Fixed up trivial conflict in the makefile.

Conflicts:
	makefile
2013-03-20 19:51:46 +01:00
Miroslav Lichvar a29b1a4105 Move clock_adjtime wrapping to clockadj.c.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:39 +01:00
Delio Brignoli b936d35b6d Add support for multiple fault types
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-20 19:10:22 +01:00
Miroslav Lichvar 3136e3e46c Add summary statistics.
Add new options to ptp4l and phc2sys to print summary statistics of the
clock instead of the individual samples.

[ RC - Fix () function prototype with (void).
     - Use unsigned for sample counter.
     - Fix over-zealous line breaks. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-09 10:09:25 +01:00
Miroslav Lichvar 74692bb1b0 phc2sys: include PTP management client.
Add a new option to wait for ptp4l to be in a synchronized state.
Periodically check PORT_DATA_SET and wait until there is a port in
SLAVE, MASTER or GRAND_MASTER state. Also, set the default
synchronization offset according to the currentUtcOffset value from
TIME_PROPERTIES_DATA_SET and the direction of the clock synchronization.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-03 19:08:34 +01:00