Commit Graph

205 Commits (17aa750a49ebaecfc7b063c770aa8d36f5078b2c)

Author SHA1 Message Date
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
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 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 2201345058 uds: restore delay mechanism to zero value.
The new configuration code inadvertently causes the UDS port to use P2P
messaging when P2P is set as a global option.  This results in a never
ending series of "missing timestamp" error messages from the UDS port as
it vainly tries to send peer delay requests.

This patch fixes the bug by changing the UDS delay mechanism back to zero
as it was before.  This is the appropriate setting for the UDS port,
because it never leaves the listening state and thus never sends an E2E
delay request.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-09-05 21:27:04 +02:00
Richard Cochran e27b036d09 config: convert 'uds_address' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Richard Cochran 8836f3cc67 config: convert 'clock_servo' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Richard Cochran ed566513e0 config: convert 'time_stamping' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Richard Cochran b6a91303a9 config: convert 'delay_filter' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Richard Cochran a8b550887d config: convert 'tsproc_mode' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 3d1d93bcb2 config: convert 'network_transport' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 76f8d5eb48 config: convert 'timeSource' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 5277396b3a config: convert 'sanity_freq_limit' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 0aff268a4e config: convert 'kernel_leap' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran f2da3cc484 config: convert 'summary_interval' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 2816133b5e config: convert 'gmCapable' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran 5eeea13652 config: convert 'free_running' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran eaa70f165f config: port: convert 'delay_filter_length' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran ffa7d49df6 config: clock, port: convert 'freq_est_interval' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran bde8ef4360 servo: store the configuration in the servo data structure.
This will allow removing the code that passes configuration options via
global variables.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +02:00
Richard Cochran b297f22a82 clock: add a method to obtain the configuration.
This function allows the ports to read configuration variables without
changing the port method signatures.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-16 11:20:23 +02:00
Richard Cochran 1579b7893b clock: store the configuration in the clock data structure.
This will help us to simplify the passing of parameters between the main
program. clock, and ports.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-16 11:20:23 +02:00
Richard Cochran 2318432b94 clock: support management SET of the priority attributes.
This patch adds support for changing the priority1 and priority2
elements of the "default data set" at run time.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-07-24 21:59:43 +02:00
Miroslav Lichvar f0b0c1116a servo: add support for weighted samples.
Add weight parameter to the sample function. Samples with smaller weight
are less reliable, they can be ignored by the servo or the adjustments
of the clock can be smaller.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-03-27 10:58:04 +01:00
Miroslav Lichvar 06fcfe123c tsproc: add raw and weighting modes.
Add new time stamp processing modes to return raw delay and offset based
on the raw delay instead of the long-term filtered delay, and to return
also a weight of the sample. The weight is set to the ratio between the
two delays. This gives smaller weight to samples where the sync and/or
delay messages were delayed significantly in the network and possibly
include a large error.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-03-27 10:58:04 +01: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 6813fd7c3d Convert and correct time stamps early.
Convert time stamps to tmv_t and apply all corrections before passing
them to clock/port functions to reduce the number of parameters.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-03-27 10:58:04 +01:00
Richard Cochran a96797a7fc clock: Introduce a function to switch the PTP Hardware Clock.
When switching clock devices in JBOD mode, we need to be able to reset the
servo. The existing servo_reset() function will not serve us well, because
in this case we also need to seed the existing frequency offset and limit.
This patch adds a new method that simply starts the servo from scratch.

In the unlikely event of a resource allocation failure, the method will
simply continue to use the previous device, which is better than nothing
and certainly preferable to bailing out the program.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-17 16:15:25 +01:00
Richard Cochran a4264b3e6e trivial: do not assign a FP constant to an integer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-11-07 19:47:36 +01:00
Miroslav Lichvar 50d5c63e16 clock: keep ports in specified order.
When adding a new port, put it at the end of the list instead of head.
This restores the order of received management messages as was before
commit 08575133.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-11-07 18:57:40 +01:00
Jiri Benc 5e0196d647 Dynamic allocation of interface config entries
Remove the limit of MAX_PORTS ports also when parsing command line
arguments.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00
Jiri Benc c017adc8d1 Remember last used port number
For the ports to be truly created and removed dynamically, the last used
port number has to be remembered by the clock and used for port creation.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00
Jiri Benc 83f637fb8e Lazy regeneration of pollfd
There's no need to regenerate pollfd multiple times during batches of port
operations (like creating of the clock). Just be lazy and regenerate it only
once it's needed.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00
Jiri Benc 08575133b3 Dynamic port allocation
Remove the limit of MAX_PORTS ports (default 8) and keep the ports in
a linked list. This allows ptp4l to be used on large machines and in the
future, it will allow dynamic adding and removing of ports while ptp4l is
running.

For this to work, pollfd needs to be dynamically allocated. Changed pollfd
handling from clock_install_fda/clock_remove_fda to notification
(clock_fda_changed), where the clock will rebuild pollfd by querying all its
ports.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00
Jiri Benc 48a8425ff7 Make uds port a separate field in struct clock
The uds port is handled specially in almost all cases, it doesn't behave
like the rest of ports in the port array. Make it a standalone member of
struct clock.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00