Commit Graph

867 Commits (73318c5b99571c8da01474ad665e2e2e06ab12bb)

Author SHA1 Message Date
Richard Cochran 73318c5b99 clock: Force a BMC election when a port link goes down.
Having one fewer port may affect the result of the BMCA.  This patch
changes the main loop so that a link down event also causes a state
decision event.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
2017-02-05 18:31:27 +01:00
Richard Cochran 6b471d45ed port: Change port_dispatch() into a void function.
This global function used to return an error code, but now it always
returns zero.  This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-02-05 18:25:18 +01:00
Miroslav Lichvar 117ed5c2d0 timemaster: check support for SW time stamping.
When an interface doesn't support HW time stamping, before falling back
to SW time stamping, check if it's actually supported and exit with an
error message if not.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar e54158195b timemaster: tag ptp4l and phc2sys messages.
Use the new options of ptp4l and phc2sys to tag their log messages with
the PTP domain number and name(s) of interface(s) in the domain.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar 0f6c6972c7 Add options to tag ptp4l and phc2sys log messages.
When running multiple instances of ptp4l or phc2sys, it's difficult to
tell which log message belongs to which instance. Add new options to
ptp4l and phc2sys which can specify a tag for all messages printed to
the standard output or system log, so messages from different instances
can have different tags.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Viliam Lejcik 33e62f9925 ptp4l: Make UTC offset configurable.
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.

Signed-off-by: Viliam Lejcik <viliam.lejcik@kistler.com>
2017-02-05 16:41:58 +01:00
Richard Cochran b738afb604 fsm: Make the transition out of INITIALIZING part of the FSM code.
The state machines in 1588 do not specify an event that causes a transition
out of the initializing state.  This was left as a local issue.  For this
transition, the current code assigns the next state outside of the FSM.  But
doing so prevents an alternative FSM to handle this transition differently.

By introducing a new event, this patch places this transition where it
belongs, namely under the control of the FSM code,

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:54 +01:00
Richard Cochran 01ee947457 Disentangle initialization from fault clearing.
Although leaving the INITIALIZING state and clearing the FAULTY state
ASAP both result in a port entering the LISTENING state, still there
is no benefit from conflating the two.  In the FAULTY case, the
current code actually skips the INITIALIZING state altogether.

This patch separates the two cases resulting in two benefits.  First,
the check for ASAP fault status is only made when a fault is actually
present, unlike the present unconditional check.  Second, this change
will allow us to cleanly support alternative state machines later on.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 1f66948d38 Make the fault handling code more readable.
The code that decides whether a fault qualifies for ASAP treatment is
a tangle of logical operators.  This patch replaces the open coded
logic with a helper function whose name makes the intent clear.  This
is a cosmetic change only.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 80a28a9dc3 Change a misleading fault handling function signature.
Looking at the fault logic in port_dispatch(), you might think that
the function, fault_interval(), checks whether a fault is active, but
you would be wrong, since that function always returns zero.

This patch removes the superfluous input error checking inside of
fault_interval() and changes the return type to void, making the
actual behavior explicit.  Dropping the input check is safe because
that function has exactly two callers, both of whom always provide
valid inputs.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 10d4e7f8b0 port: Make the finite state machine into a function variable.
This allows adding new FSM flavors in the future.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Miroslav Lichvar 0309a880fb Update TAI-UTC offset
A leap second was applied to UTC on 2016-12-31 and the offset between
TAI and UTC is now 37 seconds.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-01-08 21:28:40 +01:00
Richard Cochran 4e966536c6 ptp4l: Document the "long" command line options in the man page.
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
2016-12-13 20:52:45 +01:00
Richard Cochran e658982624 config: Fix bitwise copy-and-pasto for command line items.
The recent change allowing every configuration option to appear on the
command line wrongly used bitwise AND to set a flag.  This patch fixes
the bug by using the proper bitwise OR idiom.

Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 4e8dbd8 ("ptp4l: Accept any configuration option as a command line argument.")
2016-12-13 19:57:07 +01:00
Richard Cochran 81d97657bf Add an acknowledgment in the readme for Exablaze.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-12-09 19:41:08 +01: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 4e8dbd8492 ptp4l: Accept any configuration option as a command line argument.
This patch provides a way to use the entire table of configuration options
as "long" command line switches.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-12-06 19:40:36 +01:00
Richard Cochran 891d56e429 Version 1.8
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-11-04 19:38:56 +01:00
Richard Cochran 3b82f227ce clock: Monitor the link status using a RT netlink socket.
Poll for link up/down events.  When a link goes down, the port becomes
faulty until the link goes up again.  We keep the fault timer from the
existing fault detection, but a downed link prevents clear the fault.

The new state machine is depicted in this ascii art diagram:

          +--------+    Fault    +---------+
          |        |------------>|         |
          |   UP   |             |  FAULT  |
          |        |<------------|         |
          +--------+   Timeout   +---------+
             A  |                   /
             |  |                  /
   Link-Up   |  | Link-Down       /
             |  |                /
             |  V               /
          +--------+           /  Link-Down
          |        |          /
          |  DOWN  |<--------/
          |        |
          +--------+

If the fault timer occurs in the DOWN state, we simply ignore it.
After all, without the link the port is useless.

There is one case where the new code changes the existing behavior.
If the link quickly does down and then up again while another fault
(and its timer) are active, then we will enter the UP state without
waiting for the fault timer expiration.  However, this behavior is
acceptable because when a link goes up, you are starting with a clean
slate.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-19 21:48:07 +02:00
Richard Cochran 5e3156da15 port: Provide methods to set and get the link status.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran e995cf7f52 clock: Remember each port's interface index.
We use a hash table to remember the mapping.  Since our existing hash
table is a simply string hash, we convert the integer index into a decimal
string.  Although hashing integers in this way is sub-optimal, the table
will not be used in a performance critical path.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran 6b99df29e0 clock: Fix coding style within a helper function.
No functional changes.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran c8b525755b clock: Remove stray semicolon.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran 44a469597a sk: Add a method to obtain a socket for utility purposes.
The clock module will want to know the interface indexes, in order to
implement link monitoring.  However, the clock does not open any sockets
directly.  This helper function lets us keep the clock module free of
socket level code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02: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 1de59d6226 clock: Remove cruft from the creation method.
The time stamping setup code needlessly queries the configuration data
base over and over, rather than simply using the local variable
already assigned.  This patch replaces the extraneous config_get_int()
calls with the local variable.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:14:16 +02:00
Richard Cochran 86ed2432f0 Fix regression in one-step configuration.
We activate on-step mode based on the "time_stamping" and
"twoStepFlag" configuration options.  If twoStepFlag is false and HW
time stamping is enabled, we upgrade the time stamping mode variable
to one-step.

The code that tests the options and sets the one-step mode moved from
ptp4l.c into clock.c in commit 9b27664c ("clock: simplify the create
method.").  However, that commit inadvertently moved the test after
the place where the time stamping mode is latched in a local variable.
As a result, one-step mode is not activated when configured.

This patch fixes the issue by keeping the local time stamping mode
variable up to date during the one-step test.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 11:55:14 +02:00
Richard Cochran 5e5c98b3da port: Fix input to the BMC for forming the spanning tree.
If a non-slave port on a boundary clock see an announce message, then it
must decide whether it should take on the MASTER or the PASSIVE role.  When
the GM fields from the local clock are identical to those in the announce,
then the sender/receiver ports are used as a tie breaker.

Following a typographical error in 1588, the code wrongly uses the port
identity of the upstream parent as the "receiver" id.  As a result, a port
that should be PASSIVE may choose MASTER instead. This patch fixes the
code to use local port id.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-08-03 14:00:04 +02:00
Richard Cochran 159f4a265d Version 1.7
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-07-21 16:49:14 +02:00
Miroslav Lichvar 914ca86b37 timemaster: ignore failures of non-essential processes.
Assume only the chronyd or ntpd process is essential for synchronization
of the system clock and ignore SIGCHLD from other processes. This should
provide resiliency against possible bugs in ptp4l or phc2sys that can
terminate the processes.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2016-07-16 21:03:59 +02:00
Miroslav Lichvar 395544d117 timemaster: add option to specify first SHM segment.
This allows using a sequence of SHM segments that starts with a number
larger than zero, which can be useful to avoid conflicts with time
sources that are not started by timemaster, e.g. gpsd using segments
number 0 and 1.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2016-07-16 21:03:59 +02:00
Miroslav Lichvar ac77099493 timemaster: allow arbitrary options in server/refclock directives.
Instead of trying to support all options of the server and refclock
directives in both NTP implementations, add an "ntp_options" option
which specifies a string that is added directly to the lines in the
chronyd/ntpd configuration file.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2016-07-16 21:03:59 +02:00
Jesuiter, Henry (ALC NetworX GmbH) 1e667ff7fb Introduce options to set DSCP values in PTP messages.
In the last years there are several media streaming standards
evolving that are relying on PTP. These standards make requirements
about the DSCP priority of PTP messages. This patch introduces two
new configuration options 'dscp_event' and 'dscp_general' to address
that issue and to be able to set the DSCP priority separately for
PTP event messages and PTP general messages.

Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-07-12 15:11:56 +02:00
Jesuiter, Henry (ALC NetworX GmbH) dc09312ce7 Fix data type for return value of vasprintf()
Since size_t is an unsigned data type, it won't evaluate correctly on errors
of vasprintf(). This patch makes 'len2' a signed integer, as expected by
vasprintf().

'len2' is of type 'size_t' in util.c:451, but vasprintf in line
457 returns '-1' on error which is checked in line 460. Currently
this check will always fail (regardless of the return value of
vasprintf()), according to its declaration as unsigned int.

[ RC: Added more explanation taken from another list message. ]

Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
2016-07-12 14:55:46 +02:00
Richard Cochran 3938cbc101 uds: Prevent unintentional announce message timeouts.
During the configuration rework, the announce span was wrongly converted
into a hard coded macro.  In addition, the announceReceiptTimeout option
inadvertently became non-zero for the UDS port.  As a result, the UDS port
sets a useless announce message timer, causing the code to close and reopen
the UDS port every few seconds.

This bug has an interesting history.  It was first reported and fixed in
commit f36af8e0 ("uds: disable the accidentally enabled announce timer.").

That very fix was wrongly removed in commit 54f45063 ("port: change
'announce_span' into a macro.").  Because of various code changes, this
bad commit cannot be simply reverted now.

This patch re-introduces the 'announce_span' variable and clears both it
and 'announceReceiptTimeout' for the UDS port, effectively disabling the
announce message timer.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-07-07 18:41:57 +02:00
Richard Cochran 0d61027fd3 Fix the man page regarding the '-p' option.
The -p option for ptp4l, which specifies the PHC device, was added
before the ethtool get_ts_info ioctl had been invented.  Today it does
not "force" the given device as the man page says.  Instead this is a
legacy option only useful when running on older kernels.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-07-03 20:45:41 +02:00
Richard Cochran d825b1d549 Let the clock code figure the PHC index.
The code that determines the index of the PHC device is useful to all
kinds of clock devices.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 9c8fe6a94e clock: specify type at creation time.
Store the type in the clock object explicitly.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 63e530e297 config: count the interfaces as they are added.
This information is useful to the various clock types.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 8f7fb11fbc Perform the time stamping mode check in the clock module.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran adf36154f5 clock: offer a method to get the first port in the list.
This function will allow the TC code to iterate over the ports without
calling into the clock logic.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 948d511550 clock: offer a method to get the type rather than the number of ports.
The port code is not interested in the number of ports but rather the
clock type.  Since the polymorphic clock object will be able to report
its own type, this patch changes the clock interface accordingly.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran fd2eb9411f Move the clock type enumeration into the clock header.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran bbe55fbea4 clock: remove redundant parameter from the create method.
There is no need for the 'ifaces' parameter since the list of network
interfaces is already present in the configuration.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 9b27664cfc clock: simplify the create method.
With the new configuration API, there is no need to pass the default data
set.  Instead, the clock code can read the configuration directly.  This
patch simplifies the clock create method by removing the 'dds' parameter
and moving the code that initialized the data set into the clock module.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 2fc2af97d8 config: get the time stamp information early.
There is no need to have a function to get this information as
we can easily obtain it when the interface is first created.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 1b7088dea8 print: add missing include directive.
This patch adds a #include needed for the declaration of the function,
rate_limited.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 62ce44a08a fault: protect header against multiple inclusion.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 01dcf7e9ac Properly initialize the message lists.
The message lists are implemented using a TAILQ from queue(3).  The heads
of the list must be initialized using the provided macros, since the field
called 'tqh_last' is non-zero in the initial state.  This patch fixes a
potential null pointer dereference by properly initializing the queues.

Note that there is no actual bug in the current code, because it uses the
lists in such a way as to initialize 'tqh_last' before any dereference.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 3f2ef92052 tsproc: Fix time stamp handling with P2P one shot mode.
When the P2P link partner is using one shot mode, the residence time
in the peer (t3 - t2) is reflected in the correction field of the
peer delay response message, and t2 and t3 are both zero.

The function port_peer_delay() calls clock_peer_delay(), passing in
the zero valued 't2' to the 'rx' argument.  The latter function then
stores the zero value in the 't4' field of the clock's tsproc
instance.

As a result, tsproc_update_offset() returns an error to
clock_synchronize(), and so a slave clock will never leave the
"uncalibrated" state.

This patch fixes the issue by removing the test for a non-zero 't4'
field within the tsproc.

Acked-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 13:33:10 +02:00