A clock that cannot be adjusted has no servo. Check if a servo is
present before updating the clock.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
If synchronizing a PHC to the system clock, use one of the
PTP_SYS_OFFSET ioctls (if supported) to measure the offset between the
two clocks. Negate the offset and switch the timestamp before passing
them to the servo.
This makes the synchronization between PHC and system clock symmetric.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The kernel supports different PTP_SYS_OFFSET* ioctls. Use the sysoff
enum to allow selecting between them in sysoff_measure().
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The field is redundant with the length tlv_list. Replace it with a
function msg_tlv_count() instead. This iterates over the tlv_list. The
computational overhead should be small, because the lists are very short
and the tlv_count is only used in management paths (yet).
Signed-off-by: Michael Walle <michael@walle.cc>
Consistenly use the pid_eq() and cid_eq() helper functions. Move the
functions into utils.h (making them inline functions) because they are
used in multiple source files.
Signed-off-by: Michael Walle <michael@walle.cc>
If ptp4l is running as a boundary clock, and multiple master ports
share a hardware clock that is different than the slave port's
hardware clock, then phc2sys in autocfg mode will synchronize that
clock multiple times per sync loop, once per-port.
Example output when this happens:
CLOCK_REALTIME phc offset -9 s2 freq -355 delay 3635
eth9 phc offset 9 s2 freq +1762 delay 7488
eth8 phc offset 41 s2 freq +1985 delay 7424
eth7 phc offset 15 s2 freq +1952 delay 7440
eth6 phc offset 20 s2 freq +1059 delay 7440
eth1 phc offset 22 s2 freq +1783 delay 7424
eth12.400 phc offset 15 s2 freq -4207943 delay 7551
eth12.300 phc offset 388 s2 freq +2336645 delay 7536
eth12.200 phc offset 451 s2 freq +2516553 delay 7438
eth12.100 phc offset 268 s2 freq +64274 delay 7405
This is easily reproducible by adding VLANs to a single network
interface and configuring ptp4l to use those VLAN interfaces as PTP
ports.
This patch prevents this problem by introducing a new deduplicated
destination clock list to phc2sys. Each time phc2sys reconfigures,
the destination clock list is re-populated. In the synchronization
loop, phc2sys will only use the clocks in this list.
Example output of reconfiguration with this patch:
reconfiguring after port state change
selecting eth9 for synchronization
selecting eth8 for synchronization
selecting eth7 for synchronization
selecting eth6 for synchronization
selecting eth1 for synchronization
selecting eth13.400 for synchronization
skipping eth13.300: eth13.400 has the same clock and is already selected
skipping eth13.200: eth13.400 has the same clock and is already selected
skipping eth13.100: eth13.400 has the same clock and is already selected
selecting eth12.400 for synchronization
skipping eth12.300: eth12.400 has the same clock and is already selected
skipping eth12.200: eth12.400 has the same clock and is already selected
skipping eth12.100: eth12.400 has the same clock and is already selected
skipping eth13.500: eth13.400 has the same clock and is already selected
This patch was tested with autocfg mode and also when specifying source
and destination manually via commandline.
Signed-off-by: Cliff Spradlin <cspradlin@google.com>
When using a PPS source with no source clock specified with the -s
option, avoid referencing a NULL pointer and using CLOCK_INVALID in
system calls.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Check if a signal was received when waiting for ptp4l in the automatic
mode to not get stuck in an infinite loop.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Use struct config item 'kernel_leap' for parameter handling. Copy this to
node.kernel_leap afterwards. Check for 'servo_type' == CLOCK_SERVO_NTPSHM.
Signed-off-by: Peter Schneider <peter@psch.de>
Replaced usage of variable 'use_syslog' with struct config item
'use_syslog'. Original variable removed.
Signed-off-by: Peter Schneider <peter@psch.de>
Replaced usage of variable 'message_tag' with struct config item
'message_tag'. Original variable removed.
Signed-off-by: Peter Schneider <peter@psch.de>
Replaced usage of variable 'print_level' with struct config item
'logging_level'. Original variable still used for range checking.
Signed-off-by: Peter Schneider <peter@psch.de>
Replaced usage of variable 'domain_number' with struct config item
'domainNumber'. Original variable still used for range checking. Removed
(now obsolete) third parameter of init_pmc().
Signed-off-by: Peter Schneider <peter@psch.de>
Valgrind complains about memory leaks, none of which are serious. This
patch frees the allocations on exit, so that any future *real* memory leaks
will be obvious in the valgrind report.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When the clock device or phc index changed, the new phc device may have
different maximum adjustment. So we need to create a new clkid and servo
in clock_reinit().
At the same time, we should not only do clock_reinit() when the new state
is PS_MASTER. We also need to reinit clock after a failover in slave mode(
the new state is PS_SLAVE). We can do clock_reinit() even in PS_FAULTY so
we can finish adjust offset before come back to PS_LISTENING. So I removed
the check and let's do clock_reinit() whenever there is a new state.
And for servo reset, as Miroslav suggested, we will do it in these cases:
- the system clock is the new destination (master state)
- a PHC is the new destination (master state)
- a PHC is switched (in any state)
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
When the master clock changed its state and then changed it back to the
original state before phc2sys could process the first change, e.g. SLAVE
-> UNCALIBRATED -> SLAVE after a clockcheck failure, the second change
was ignored because the new value was the same as the original state,
which wasn't updated for the first change yet. This caused phc2sys to be
stuck with a wrong state.
Fix phc2sys to check both the state and new_state variables of the clock.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When ptp4l is using multiple interfaces sharing the same clock, phc2sys
in the automatic mode should not try to synchronize them to each other.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reported-by: Stefan Lange <s.lange@gateware.de>
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>
Now that all of the legacy, open coded configuration fields are gone,
we can follow a normal create/destroy pattern for the configuration.
This patch add the new method and converts the programs to use it.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>
In the near future, the transports will need to consult the configuration
database in order to obtain various options. This patch also introduces
the idea of a configuration file into the phc2sys and pmc programs.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>
When no source is found in the automatic mode and a clock is selected as
the default source, set its state temporarily to slave to prevent the
clock from being synchronized to itself and drifting quickly away.
Also, don't use this mode with only one PTP clock and don't include the
system clock.
This fixes phc2sys with SHM servo (e.g. used by timemaster).
If we have clocks to synchronize but no source, just pick the last one in
the list, which is the first one from the ptp4l command line.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When running a "jbod" Boundary Clock, as long as we have one slaved port,
we always want the clocks on the other ports to be synchronized, regardless
of their port state.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jiri Benc <jbenc@redhat.com>
The reconfigure function is missing a check whether state for the given
clock actually changed or not. This caused state for all unchanged ports to
be zeroed.
Reported-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Instead of setting it to the PTP domain number, add a new option to
ptp4l and phc2sys to set it as needed. The default value is 0. This
allows multiple ptp4l/phc2sys instances running in the same domain.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
In pmc and phc2sys handle terminating signals and close the UDS
transport before exit to remove the sockets in /var/run.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Always disable the clock sanity check when the ntpshm servo is used,
because it doesn't know when or how is the clock adjusted. Disable also
the kernel leap option as the process controlling the clock is
responsible for setting the kernel flag.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>