Commit Graph

240 Commits (8feaa8ada8a479c8a0c2900f0b34bd5505a32b5b)

Author SHA1 Message Date
Richard Cochran 0c30ab463f telecom: Add a configuration option to use the alternate BMCA.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:50:03 -07:00
Richard Cochran c7fb525721 telecom: Add a configuration option for G.8275.defaultDS.localPriority.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:13 -07:00
Richard Cochran a8d0eb92c6 telecom: Introduce the local priority attribute into the data set.
The Telecom Profiles G.8275.1 and G.8275.2 have invented a new
per-port and per-clock attribute, not in 1588, called "localPriority".
The use of this attribute is a distinguishing feature of the telecom
data set comparison algorithm.

This patch adds the attribute, hard coded to its default value.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:13 -07:00
Richard Cochran 6f96ebb7b8 Refactor the data set comparison function variable.
There is no need to keep two copies of the data set comparison
function.  This patch adds a method that allows the port code to
obtain the function from the clock code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:10 -07:00
Miroslav Lichvar 742f878821 rtnl: remove dependency on config.h.
Change the rtnl_get_ts_label() function to accept the name of the master
interface and the buffer for the slave interface directly instead of the
struct interface from config.h.

Also, rename the function to rtnl_get_ts_device().

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-04-19 07:41:11 -07:00
Richard Cochran f26ca92f1c clock: Maintain the master/local rate ratio when free running.
When using long chains of transparent clocks, the recommended practice is
to measure the rate ratio without adjusting the local clock.  Then the
residence times should be corrected to reflect the master's frequency.

This patch expands the clock_rate_ratio() method to provide the estimated
ratio when the clock is free running.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:37:26 -07:00
Richard Cochran eb8507a45a clock: Calculate frequency offset even without any delay estimation.
If the "free_running" option is set, the "no adjust" calculates and
prints an estimation of the phase and frequency offsets to the remote
master.  Because the phase estimate requires a delay measurement, this
calculation is not performed without having the delay estimate first.
However, a typical transparent clock application will want to use the
frequency offset to correct the residence times to match the master's
frequency.

This patch adds a call to the "no adjust" routine even if no valid
delay measurement has been made.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:37:26 -07:00
Richard Cochran a1c5e3f2ed transport: Fix callers to pass a proper enumeration value.
The majority of the callers of transport_send() use hard coded magic
numbers.  This patch fixes them to use the corresponding enumerated
values instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:29:05 -07:00
Anders Selhammer da7bc1db1e clock: Fix coding style
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-04-12 19:47:51 -07:00
Richard Cochran 1b3ef0d195 bmc: Allow alternative data set comparison algorithms.
Instead of using a hard coded algorithm, let the caller provide the
function that performs the comparison.  This will allow implementing
alternative algorithms from PTP profiles.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran b05991dbb8 clock: Make the data set comparison algorithm into a function variable.
This will allow adding alternative algorithms as defined in PTP profiles.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran 992e292055 Make the LIST_FOREACH_SAFE publicly visible.
We will want to use this macro in more than one source file.  This patch
moves the macro into the common header for possibly undefined code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-31 11:05:57 -07:00
Richard Cochran 8857ad9834 Expand and rationalize time stamping options.
Up until now, one step operation was controlled by a combination of
options, namely time_stamping=hardware with twoStepFlag=0.  The
introduction of peer to peer one step makes the situation a bit more
complicated.

This patch adds support for setting the one step options directly by
using the "time_stamping" option.  The "twoStepFlag" is adjusted
automatically if needed.  The legacy behavior for Sync message one
step is preserved.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Richard Cochran 4842d2c7ec Introduce peer to peer one step.
The 1588 standard defines one step operation for both Sync and
PDelay_Resp messages.  Up until now, hardware with P2P one step has
been rare, and kernel support was lacking.  This patch adds support of
the mode in anticipation of new kernel and hardware developments.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Jacob Keller 862724fda5 differ message printed when local clock is best master
Make the log output a bit more clear by changing how we inform the user
when the local clock is the best master clock. This allows easier
parsing of the log and identifying when the local clock is being
selected as the best clock.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2018-03-27 18:22:22 -07:00
Michael Brown c9f3fad780 clock: Remove open-coded conversion of struct timespec
The function clock_check_ts() performs open-coded manipulation of a
struct timespec instead of using the tmv_t abstractions.

Use the existing tmv_t abstractions to convert from struct timespec to
nanoseconds, and modify the prototype of clock_check_ts() to match
that of the underlying clockcheck_sample().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Richard Cochran 36550e415c clock: Introduce a method to obtain the last synchronization time.
The NetSync Monitor protocol will require us to report the time stamp of
the last synchronization.  This patch adds new the method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Richard Cochran fb2c979182 clock: Introduce a method to get the current dataset.
As part of the NetSync Monitor protocol, the port will need to have
access to the current data set.  This patch adds the appropriate
function.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Richard Cochran 7fe69e7ba0 msg: Populate the TLV list on receive.
This patch changes the receive message parsing code to place each TLV
into the list.  A method is introduced that allows attaching TLVs to
the end of the list.

In addition, msg.last_tlv is converted into a pointer to the last item
in the list.  Because of this change, the transmit code that uses this
field now allocates a TLV before using it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Michael Brown 1b7ff890be tmv: Generalise tmv_eq() to tmv_cmp()
Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Michael Brown ea82ae6c28 tmv: Add missing uses of tmv_to_nanoseconds()
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Michael Brown 5df2779ef0 tmv: Add missing uses of tmv_is_zero()
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Michael Brown 759f3f4019 clock: Pass floating point values to stats_add_value()
Use tmv_dbl() to obtain the floating point value passed to
stats_add_value() rather than relying on the existing implicit cast
from the result of tmv_to_nanoseconds().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Richard Cochran 3870bc1c5b clock: Fix coding style. 2018-03-06 06:37:54 -08:00
Richard Cochran 4a39103c74 clock: Simplify management response logic.
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-06 06:37:54 -08:00
Miroslav Lichvar 4b957cf566 clock: add option to specify initial path delay.
This option allows the clock to be updated before the path delay is
measured in order to speed up the initial correction of the clock, e.g.
in domains using a very long logMinDelayReqInterval.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-02-19 09:47:13 -08:00
Miroslav Lichvar 303b08cbf5 clock: Don't forward management requests to UDS port.
The UDS port is not expected to be used by PTP clocks and forwarding of
management messages to the port can be limited to responses.

This prevents ptp4l from printing error messages when a management
request is received from a non-UDS port and the last client which used
the UDS port is no longer listening.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-01-01 20:11:42 -08:00
Hangbin Liu 536a71031d ptp4l: use ts label to get ts info
Now the ts label will be either the bond active slave or the interface
name, which is the exactly interface we need to get ts info.

When the link down/up or there is a fail over and ts_label changed, the
phc index may also changed. So we need to check get new ts info and check
clock_required_modes. We will set the link to LINK_DOWN by force if
the new ts_label's timestamp do not support required mode.

If all good, then we set phc index to new one. Also sync clock interval
after switch phc.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 1440f09384 clock: add clock_required_modes to obtain the required time stamping mode
Separate required_modes setting from clock_create so we can obtain the
required time stamping flags from other place.

Add enum timestamping in struct clock to store the time stamping mode.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Richard Cochran 14a97dc5da Remove redundant test on the UTC flags.
Now that we test the UTC flags in clock_update_slave(), the similar
code in clock_utc_correct() is redundant.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Richard Cochran fa575b60f6 Latch the UTC offset.
When acting as a slave, we accept the foreign master's advertised
TAI-UTC offset for as long as that master is present.  However, when
the master disappears, we fall back to the initial offset value.  As a
result of this behavior, when starting with an out of date initial
offset, losing a foreign master causes a sudden UTC offset error (in
phc2sys for example) in the range of whole seconds.

This patch fixes the issue by remembering the UTC offset when assuming
the slave role.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Richard Cochran 97e4242361 Simplify UTC tracking.
The clock code uses two different variables to store the TAI-UTC
offset.  One variable represents the compile time, configuration file,
or command line initial UTC offset, while the other is used when
taking on the GM role and is settable at run time.  However, making
this distinction makes no sense.  This patch simplifies and clarifies
the code by using a single variable for the offset.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Hangbin Liu 7c3f9579f0 clock: remove hash table index2port
Remove index2port since we don't need it now.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu 25ec8a3b4e clock: remove rtnl fd on clock
Remove rtnl fd on clock since we track the link status per port now.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu c149a3dbc1 port: add FD_RTNL event to track per-port status
With rtnl socket we can track link status per port(except UDS port).

We can make sure we get the correct interface and latest status with function
port_link_status().

At the same time we need to set clock sde after link down. But we return
EV_FAULT_DETECTED in port_event(), which will not set clock sde. So we need
to set it in port_link_status().

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Richard Cochran 78d2a32a94 clock: Fix poor snprintf() handling.
The calls to snprintf() to format /dev/phc%d use the wrong pattern.
That function always properly terminates the string with null.
However, the code passes a hard coded length of 31 to static arrays of
length 32.  While this is not a bug, there are two issues here.

First, any (improbable) future increase in the array lengths would
have to also remember to fix up the snprintf() call site as well.
Secondly, the pattern of using buf[N] and then length=N-1 is
appropriate for strncpy(), but is useless for snprintf().

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
2017-05-21 21:17:03 +02:00
Miroslav Lichvar 8deb52a849 Fix leaks of sockets on errors.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-14 09:05:04 +01:00
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
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 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 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 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 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 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 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