Commit Graph

1249 Commits (226c285ec42241d2133877346563353f9849274f)

Author SHA1 Message Date
Jacob Keller 226c285ec4 phc_ctl: display all capability information
The capability command for phc_ctl does not display the number of pins
or the cross timestamping support. Add this as output so that the user
can see the complete device capabilities.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2020-08-05 18:48:33 -07:00
Richard Cochran 3da961bb11 Version 3.0
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-07-22 16:14:39 -07:00
Richard Cochran 1335db3bde ts2phc: Ignore pulses with invalid time stamps.
The API to obtain the time stamp of a PPS source indicates the validity of
the returned value.  However, the current code does not ever test the
validity information in any way.  This patch lets the clients ignore PPS
values that lack a valid time stamp.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-07-22 14:56:36 -07:00
Richard Cochran 70c32043a5 ts2phc: Fix memory leak.
Each slave creates an instance of a servo.  However, when cleaning up, the
code neglected to free the servo, resulting in a memory leak.  This patch
fixes the issue by calling the appropriate method to destroy the servo.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-07-22 14:52:48 -07:00
Richard Cochran 278d9f45ab ts2phc: Use proper close method on the error path.
When creating a ts2phc slave, a clock is obtained by invoking the
posix_clock_open() method.  However, in case of an error, the same clock
is closed again by calling close(2) on the associated file descriptor
directly.  While not incorrect, still the code should instead use the
close function that matches the open method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-07-22 14:49:05 -07:00
Vladimir Oltean 61c6a70898 phc2sys: provide missing kernel headers for sysoff functionality
Currently it is very finicky to deploy linuxptp in an automated build
system and make KBUILD_OUTPUT pick up the output of "make
headers_install" in order for the application to make full use of the
features exposed by the runtime kernel. And the toolchain/libc will
almost certainly never contain recent enough kernel headers to be of any
use here. And there's no good reason for that: the application can probe
at runtime for the sysoff methods supported by the kernel anyway.

So let's provide the kernel definitions for sysoff, sysoff_precise and
sysoff_extended, such that SYSOFF_COMPILE_TIME_MISSING is not something
that will bother us any longer.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-06-24 16:09:47 -07:00
Richard Cochran cb3fbc1010 Catch unexpected socket polling errors.
The poll(2) system call may set POLLERR in the returned events.  Normally
no errors are returned unless specifically requested by setting an
appropriate socket option.  Nevertheless, the poll(2) API is quite generic,
and there is no guarantee that the kernel networking stack might push an
error event one day.  This patch adds defensive code in order to catch any
unexpected error condition.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-06-24 11:02:02 -07:00
Georg Sauthoff b6fa222201 Eliminate isort
This saves a few bytes of static storage and less instructions are
executed when looking for the best offset.

Signed-off-by: Georg Sauthoff <mail@gms.tf>
2020-06-24 10:09:13 -07:00
Vladimir Oltean bf0a644b99 port: print sync/follow-up mismatch events
ptp4l is too silent when receiving, for whatever reason, out of order
messages. If the reordering is persistent (which is either a broken
network, or a broken kernel), the behavior looks like a complete
synchronization stall, since the application is designed to never
attempt to recover from such a condition.

At least save some people some debugging hours and print when the
application reaches this code path. Since it's a debugging tool, we
don't want to create false alarms when the occasional packet gets
reordered in a production system, but have this information readily
available when the program's log level is set to debug, instead of
having users fish for it with code instrumentation.

[ RC - corrected printf format for sequence id. ]

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-06-24 10:09:13 -07:00
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
Werner Macho 7c49882e34 fix small typo
Signed-off-by: Werner Macho <werner.macho@gmail.com>
2020-06-15 11:59:47 -07:00
Christian Eggers 7de73fefc3 Fix printf if time_t is long long
On some platforms, time_t has recently switched from "long" to "long
long" [1]. For these platforms it is necessary to use "%lld" as printf
format specifier because the ABI differs between "long" and "long long".

I found no way for creating something similar to PRId64 for time_t. No
idea how to determine whether it's "long" or "long long". So I cast
everything to "long long" instead.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=38143339646a4ccce8afe298c34467767c899f51

Signed-off-by: Christian Eggers <ceggers@arri.de>
2020-06-02 07:36:21 -07:00
Richard Cochran 6eb9898f61 pmc: Show slave delay timing data TLVs attached to signaling messages.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 271a6d53f6 port: Support slave event monitoring of delay timing data.
After a successful message exchange, the delay measurement values are
processed by the port code.  This patch makes the values available to a
monitor by calling the appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 4466d7b8ab monitor: Add support for slave delay timing data TLV.
The slave delay timing data TLV provides the delay time stamps along with
the associated correction field.  This patch introduces a method to allow
publication of these values to a remote monitor.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran ef9d51a47d tlv: Encode and decode SLAVE_DELAY_TIMING_DATA_NP TLVs.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 2d2637989c pmc: Show slave receive timing data TLVs attached to signaling messages.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 18bd3054ff port: Support slave event monitoring of Sync timing data.
The monitoring module accepts Sync timing events.  This patch hooks up the
port receive path to call into the monitor.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 6f95c2e92c clock: Create a slave event monitor.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07: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 d0aa29b932 tlv: Encode and decode SLAVE_RX_SYNC_TIMING_DATA TLVs.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 18:46:25 -07:00
Richard Cochran b4d3b4126f tlv: Update macro definitions.
The 2019 version of 1588 known as v2.1 introduces new TLV type and
management IDs.  This patch adds the new definitions.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 18:46:25 -07:00
Richard Cochran faea24aa32 Reject path trace TLVs with excessive elements.
The current code truncates the size of path trace TLVs which exceed the
expected maximum based on the largest possible message size.  However if
another TLV follows, then a gap would appear, that is, an area in the
message buffer not pointed to by any TLV descriptor.  In order to avoid
forwarding such malformed messages, this patch changes the logic to reject
them.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 8f523e4d62 port: Publish the method for creating signaling messages.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 0695d48332 port: Export the value of the wildcard port identity.
Code in other modules will need this special port ID value.  This patch
makes it available through the port header file.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 44c06f5d44 util: Mark port identity comparisons as const.
The utility function to compare port IDs takes pointers, but it only needs
to read the referenced data.  This patch marks the parameters as const,
allowing passing constants in the future.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 5aa19dd3f4 port: Convey targeted forwarding errors to the caller.
The port_forward_to() method clobbers the specific error code returned
by the transport layer with -1.  This patch lets the code preserve the
specific error in question.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran a6e0b83bd5 sk: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the sk module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran d95fbcb566 raw: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the raw module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.  In addition, it removes the gratuitous printing
of the error message, leaving that task up to caller, just like the other
transport modules.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 0d82c41ac1 uds: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the uds module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.  In addition, it removes the gratuitous printing
of the error message, leaving that task up to caller, just like the other
transport modules.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran b2bf55aebd udp6: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the udp6 module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran d4fbb0701d udp: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the udp module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 306ac67460 transport: Correct grammar in the doxygen comments.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran f8078f00f7 Let the free running port state reflect the synchronization uncertain flag.
When using the "free running" option, a slaved port remains in the
UNCALIBRATED state.  If the actual servo resides in and external program,
for example when following the 802.1AS recommendations, that program can
signal the synchronization state using the "synchronization uncertain"
management message. This patch lets the port state transitions from
UNCALIBRATED to SLAVE based on that message.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran 6c5b61a64c pmc: Support getting and setting the local synchronization uncertain flag.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran b8194a177a Implement the synchronization uncertain flag.
IEEE 1588 v2.1 and ITU G.8275.1/2 call for an optional "synchronization
uncertain" flag passed in Announce messages along with the other flags
from the time properties data set.  The value of the flag depends is a
logical OR function of the inputs from the remote master and the local
process.  This patch adds background support for handling the flag.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran 7df88afab9 Add support for write phase mode.
Recently the Linux kernel's PTP Hardware Clock interface was expanded
to include a "write phase" mode where the clock servo in implemented
in hardware.  This mode hearkens back to the tradition ntp_adjtime
interface, passing a measured offset into the kernel's servo.

This patch adds a new configuration option and logic to support the
write phase mode.

Because the hardware's adjustment bandwidth may be limited, this mode
is only activated when the servo reaches SERVO_LOCKED_STABLE state, in
order to achieve reasonably fast locking times.  Users may control the
SERVO_LOCKED_STABLE state by configuring 'servo_offset_threshold' and
'servo_num_offset_values' accordingly.

Example configuration file highlights:

  unicast_listen          1
  logSyncInterval         0
  logMinDelayReqInterval  0
  first_step_threshold    0.001000000
  step_threshold          0
  clock_servo             pi

  write_phase_mode        1
  servo_offset_threshold  50
  servo_num_offset_values 10
  tsproc_mode             raw

Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 11:43:51 -07:00
Vincent Cheng d4b97f497c Decouple servo state from automotive profile.
The logic for the Automotive Profile added a message interval update
mechanism that triggers whenever the servo enters the "stable locked"
state.  This SERVO_LOCKED_STABLE state is active when the
configuration option servo_offset_threshold is non-zero and
servo_offset_threshold criteria is satisfied.

However, in general, the state of the servo can and should be
independent of any profile specific optional behavior.  In particular,
the "stable locked" state will be used in the future to trigger other
kinds useful logic.  For example, an upcoming write phase mode feature
would like to take advantage of the SERVO_LOCKED_STABLE state to
trigger its activation.

This patch introduces a proper configuration option to enable
transmission of the message interval request that is specific to the
Automotive Profile.

Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 11:42:49 -07:00
Richard Cochran acd1429645 Add documentation for the ts2phc program.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -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 43c51cf144 Introduce a leap second table.
There are several issues surrounding leap seconds that emerge when a clock
takes on the Grand Master role.  One of them is the fact that GPS radios
provide time of day in the UTC time scale and not in TAI, and they do not,
in general, provide any conversion information.  Another issue is the
expectation that the GM provide correct leap second status flags to the
network.  Although both NTP and GPS do, in theory, provide on-line leap
second status, in practice the information is not reliable due to poor
implementations.

In order to provide correct leap second status and TAI - UTC offsets,
this patch introduces a leap second table based on the information
published by the IETF and NIST.  The hard coded default table can be
updated at run time by reading the standard leap seconds file from the
commonly used tzdata package.

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 2f0bfb2837 pmc: Allow multiple local subscribers.
If more than one local UDS client subscribes to push notifications,
only the last one receives data from the ptp4l service.  This happens
because ptp4l uses the PortIdentity as a unique key to track client
subscriptions.  As a result, it is not possible for both phc2sys and
pmc to receive push notifications at the same time, for example.

This patch sets the PortIdentity.portNumber attribute of UDS clients
to the local process ID, making each such client subscription unique.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-04-03 07:11:42 -07:00
Richard Cochran 1044268e85 pmc: Subscribe to port state push notification events when requested.
Allow interactive input like

    set SUBSCRIBE_EVENTS_NP duration 60 NOTIFY_PORT_STATE on

to request push notifications from the ptp4l service.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-04-03 07:04:31 -07:00
Richard Cochran e6d52c54e9 pmc: Allow printing of the SUBSCRIBE_EVENTS_NP tlv.
While we are at it, reformat the pmc_show() function into reverse
Christmas tree order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran aed79c38d4 pmc: Move private macros back into their source files.
The header file, pmc_common.h, makes some private macros public.  The
intent was to use those macros in SNMP code, but that development never
materialized into production code.  This patch removes the private macros
from public view.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran 467552d1cb clock: Reply with correct payload length for SUBSCRIBE_EVENTS_NP queries.
The clock layer indeed replies to management GET actions for this item,
but it sends an empty management message by mistake.  This patch fixes the
issue by replying with a payload of the correct length.

While we are at it, correct overly zealous line breaking according to our
coding style.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran b829580a33 Provide a method to convert a tmv_t into a timespec.
Currently there is a method to convert a timespec into a tmv_t, but
not the other way round.  This patch adds the missing function in
anticipation of a new feature that will need this conversion.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:48:16 -07:00
Richard Cochran 43d49a21d0 Add PHC methods for querying and configuring the pin functionality.
In anticipation of support for external time stamping in PHC devices, this
patch adds wrapper functions around the pin functionality.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:48:16 -07:00