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>
Introduce a new function to inform the servo about upcoming leap second.
This is used when the kernel leap is disabled to allow the servo to
handle better the sudden 1 second step in the offset when the leap
second is inserted or deleted.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
After moving the leap second check away from update_pmc(), the time
stamp is used only to control the pmc update interval. Switch to
CLOCK_MONOTONIC to keep the interval stable when CLOCK_REALTIME is
stepped.
When synchronizing the system clock and the PTP UTC offset is valid and
traceable, set the TAI offset of the clock to have correct CLOCK_TAI
(which is implemented in the kernel as CLOCK_REALTIME + TAI offset).
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This simplifies passing of pending leap seconds to the clocks and it
will also allow to apply leap second to other clocks than system clock
if needed in future.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This is a simple servo that provides the NTP SHM reference clock. It
doesn't make any clock adjustments and it always returns with the
unlocked state. It writes all samples to the SHM segment and another
process (e.g. chronyd or ntpd) is needed to read the samples and
actually synchronize the clock. The SHM segment number is set to the PTP
domain number to allow multiple SHM reference clocks running at the same
time.
This is mainly useful when other time sources are available on the
system (e.g. NTP, hardware reference clocks, or other PTP domains)
and a fallback to/from PTP is needed.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When grandmaster does not use PTP timescale but the previous one did, we
need to reset sync offset and leap flag.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
By default, do not synchronize CLOCK_REALTIME. To do it, -r option is
needed. That will only consider CLOCK_REALTIME as the destination. To
consider it also as a possible time source, use -rr.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Recognize errors returned in MANAGEMENT_ERROR_STATUS TLV and return
a distinct value from run_pmc in case such error is received.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Add support for subscribing to events (run_pmc_subscribe) and receiving and
handling of received events (run_pmc_events).
Add initial support for port status changes.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Do not call clock_open to open a clock device but let clock_add do that and
return the newly created struct. Also, store the device (interface) name in
struct clock.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
This just moves code around to have related functions together and forward
declaration at the beginning of the file. No code changes.
Signed-off-by: Jiri Benc <jbenc@redhat.com>