In preparation of moving these functions to pmc_common.c, break the
lines to a maximum of 80 characters, otherwise checkpatch will complain.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
We will be reusing some PMC code between phc2sys and ts2phc. In
preparation of that, we would like to extract the PMC related properties
of the current private program data structure of phc2sys, "struct node",
into something smaller that can be shared properly.
The "struct node" name is nice enough, so use that to denote the smaller
data structure for PMC from now on. Rename the bigger data structure to
phc2sys_private.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
The one user of the function, posix_clock_open(), simply open codes
the closing call to phc_close(). This patch provides a method to
balance closing and opening of a posix clock. In addition, the
phc_ctl program never explicitly closed the opened clock, and so this
patch adds the missing call.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This novel use of the STA_UNSYNC flag breaks with the established,
traditional meaning of that flag, which is:
The clock has is believed to have an error larger than 16 seconds.
This reverts commit 944f5f7ac6.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
In case there is no connection to the server, notify the kernel
that the clock is currently unsynchronized.
Signed-off-by: Ville Heikkinen <ville.heikkinen@nokia.com>
The two programs, phc2sys and phc_ctl, use nearly identical subroutines to
open an instance of a dynamic posix clock. In anticipation of yet a third
program with similar needs, this patch refactors the common code into the
utilities.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This commit adds functionality to increase the sync and pdelay request
intervals once gptp synchronization has been achieved. This is useful
while running Automotive Profile where the network is usually static.
Here, we are assuming that the gPTP synchronization is achieved whenever
the last 'n' offsets calculated using the Sync messages are below a
certain threshold. Both, the number of offsets to consider and the offset
threshold are configurable.
In order to support the interval update, a new clock servo state
CLOCK_SERVO_STABLE has been added. The clock will transition to this
state whenever the above condition is satisfied. When this transition
occurs, the slave will send an "interval request" signaling message
asking the master to change the sync interval. It will also update the
pdelay request interval locally.
Four new config options have been added to provide this functionality:
- servo_offset_threshold: All the offset values being considered should
be below this value.
- servo_num_offset_values: number of previously received offset values
to consider.
- operLogSyncInterval: slave will ask the master to switch to this
interval for sending sync messages when the offset stabilizes.
- operLogPdelayReqInterval: the slave will set this interval for pdelay
request messages when the offset stabilizes.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
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>