Commit Graph

895 Commits (fa575b60f6a9757bca8f2828e23633560d57bac3)

Author SHA1 Message Date
Richard Cochran e706f48981 port: allow running a boundary clock with multiple clock devices.
If the user has configured the appropriate option, then simply warn
about the clock device mismatch, and then go on in "JBOD" mode.
Whenever the port enters the uncalibrated state, it tells the clock
to switch to the new PHC device.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-18 11:38:00 +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 d70d38ade3 config: add a option to enable a poor man's boundary clock.
This patch adds a configuration option that allows running a boundary clock
using "just a bunch of devices". Normally each port is probed to make sure
they all share the same PTP hardware clock, but this option will allow a
heterogeneous collection of devices, should the user really want it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jiri Benc <jbenc@redhat.com>
2014-12-16 21:33:23 +01:00
Richard Cochran 017235f881 port: correct transmit and receive time stamps for their calibrated delays.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-12 21:44:56 +01:00
Richard Cochran 53a08ec4df config: Introduce options for correcting transmit and receive delays.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-12 21:44:56 +01:00
Richard Cochran ef49629387 Invoke the clock check even if the time stamp nanoseconds field is zero.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-12 21:44:56 +01:00
Richard Cochran b295df24b5 Introduce a helper function to identify valid (non-zero) time stamps.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-12-12 21:44:56 +01:00
Richard Cochran 4fb0346520 Add a bunch more drivers into the support matrix.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-11-30 21:24:29 +01:00
Miroslav Lichvar 37459fd1ad linreg: fix servo resetting
The stats for the maximum size were not reset, which caused the
the servo to reuse old data instead of returning with unlocked
state.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-11-20 20:15:34 +01:00
Jiri Benc 7455c24148 phc2sys: fix overwriting of the clock state
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>
2014-11-18 15:58:25 +01:00
Richard Cochran 7144aa9263 config: remove useless parameter.
The 'cfg' passed to parse_port_setting() is never used, so just remove it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-11-07 19:47:37 +01:00
Richard Cochran 5b36399e35 trivial: update gitignore with the timemaster build product.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-11-07 19:47:37 +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
Richard Cochran 8e8a989720 Coding style: add missing break statement from a switch/case construct.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-11-07 19:47:36 +01:00
Richard Cochran a5911e69c7 Use SO_SELECT_ERR_QUEUE when available.
The current implementation fetches a transmit time stamp by polling on the
socket with pollfd.events set to zero, and then checking if POLLERR has
been returned by the kernel in pollfd.revents. This has the unfortunate
side effect of sleeping in poll() for the entire time out duration,
regardless of when the error queue becomes readable.

Linux kernel version 3.10 introduced a new socket option that allows
polling for transmit time stamps explicitly, waking the process as soon as
a time stamp becomes available. This patch enables the socket option,
falling back to the old behavior if necessary.

Suggested-by: Joe Schaack <jschaack@xes-inc.com>
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
Miroslav Lichvar 594f59c50d port: fix fda initialization.
Initialize all descriptors to prevent polling invalid descriptors from
faulty ports.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-11-07 18:57:05 +01:00
Richard Cochran 6b05b4e7d3 Restore the peer addresses in P2P mode.
Commit ea7a7882 removed the calls to transport_peer(), inadvertently
substituting them with transport_send(), resulting in PDelay messages
being sent with an incorrect destination address.

This patch fixes the issue by introducing peer_prepare_and_send(),
analogous to the port_prepare_and_send() function.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jiri Benc <jbenc@redhat.com>
2014-10-11 21:03:27 +02:00
Miroslav Lichvar 82f13c594a Add timemaster.
timemaster is a program that uses ptp4l and phc2sys in combination with
chronyd or ntpd to synchronize the system clock to NTP and PTP time
sources. The PTP time is provided by phc2sys and ptp4l via SHM reference
clocks to chronyd/ntpd, which can compare all time sources and use the
best sources to synchronize the system clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Miroslav Lichvar 2098d7c162 Add string and pointer array utility functions.
Add some functions to work with strings and arrays of pointers that will
be useful later.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Miroslav Lichvar 48046e593e Don't include config.h in util.h
The config module is used by ptp4l only, but util is shared with other
programs.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Miroslav Lichvar aa24ba58e1 Don't print messages in signal handler.
Only reentrant functions should be called here.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Richard Cochran e5f20ea6df Merge Jiri's Dynamic port allocation series. 2014-09-21 19:40:49 +02: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
Jiri Benc 2d1a88ca5d Put fault_fd into struct port
The fault timer file descriptor is a per port item, put it inside struct
port where other per port file descriptors are kept.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-09-21 13:15:59 +02:00
Miroslav Lichvar 6b459abc8c Fix Coverity warning in sk_interface_addr().
Copy the address directly to struct sockaddr_in or sockaddr_in6 instead
of sockaddr as Coverity doesn't seem to understand the union and reports
a buffer overflow.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 13:10:28 +02:00
Miroslav Lichvar 9ddd2a6024 Fix copying of device name to ifreq.
Don't overwrite the last NUL with strncpy() and also replace strcpy()
with strncpy().

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 13:10:27 +02:00
Miroslav Lichvar 3760f8b653 Add option to set NTP SHM segment number.
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>
2014-09-21 12:43:09 +02:00
Miroslav Lichvar 1773d21f26 Append PID to client UDS paths.
This allows running multiple phc2sys and pmc instances at the same time.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 12:34:05 +02:00
Miroslav Lichvar 30841a6849 Close client UDS transport before exit.
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>
2014-09-21 12:34:05 +02:00
Miroslav Lichvar ca637b2067 Move signal handling to util.c.
This will be useful in phc2sys and pmc.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 12:34:05 +02:00
Miroslav Lichvar 2423357754 Remove socket when closing UDS transport.
[RC: added cast to sockaddr to avoid compiler warning. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 12:33:03 +02:00
Miroslav Lichvar 28865f91df phc2sys: Add option to set path to ptp4l UDS.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 11:14:38 +02:00
Jacob Keller bdb6a35883 linuxptp: add phc_ctl program to help debug PHC devices
This is an updated version of a script I wrote a couple years ago for
debugging the PHC when writing a new driver. I figured that it might be
handy for the LinuxPTP project to include, as it can give some insight
into the PHC directly. I have updated it to make use of the shared code
here, in order to reduce duplication. Hopefully this is of some use to
everyone.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2014-07-19 07:15:24 +02:00
Jacob Keller 3e858ba17b gitignore: add .version as this is generated during a make
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2014-07-18 18:57:05 +02:00
Miroslav Lichvar 70dd682349 Prefix TLV IDs.
To avoid conflicts in generic names add TLV_ prefix to all TLV IDs
defined in tlv.h.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-07-09 06:31:25 +02:00
Miroslav Lichvar 93b7807aad Disable clockcheck and kernel leap with ntpshm servo.
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>
2014-06-22 09:30:31 +02:00
Miroslav Lichvar 97f72ceecc linreg: Handle leap second gracefully.
When leap second is inserted/deleted to the reference time, adjust the
reference point as if the clock was stepped in the opposite direction to
keep the slope and error statistics valid and correct the offset
gracefully.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-06-22 09:30:31 +02:00
Miroslav Lichvar bc84b88053 ntpshm: Pass upcoming leap second.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-06-22 09:30:31 +02:00
Miroslav Lichvar 2aa6b10c3b Add leap function to servo.
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>
2014-06-22 09:30:30 +02:00
Miroslav Lichvar 7d740f17e5 phc2sys: Use CLOCK_MONOTONIC to time pmc updates.
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.
2014-06-22 09:28:59 +02:00
Miroslav Lichvar fefd5b4b05 Set TAI offset of system clock.
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>
2014-06-22 09:23:55 +02:00
Miroslav Lichvar a3c32b8c65 phc2sys: track sync offset and leap second status in each clock.
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>
2014-06-22 09:23:54 +02:00
Richard Cochran 07edab48dc Add a macro for ADJ_TAI used when missing from the tool chain headers.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-06-22 09:23:54 +02:00
Miroslav Lichvar 9710fb1a22 Add new servo for NTP SHM reference clock.
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>
2014-06-14 10:49:04 +02:00
Jiri Benc f28a3b3664 phc2sys: reset sync offset if non PTP timescale
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>
2014-06-12 11:35:46 +02:00