Commit Graph

82 Commits (1a1e02aa978f1e55e0e8694b1131276a7ba6d541)

Author SHA1 Message Date
Jiri Benc 66c9f9baaf phc2sys: check clockIdentity
Make sure that we handle only one PTP clock (node). This is for an extra
safety.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:45 +02:00
Jiri Benc 3dd4d51c8e phc2sys: autoconfigure realtime clock on demand only
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>
2014-06-12 11:35:45 +02:00
Jiri Benc 46a0b281b9 phc2sys: autoconfiguration
Add automatic configuration option (-a).

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:45 +02:00
Jiri Benc 00a663ca68 phc2sys: propagate received errors
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>
2014-06-12 11:35:45 +02:00
Jiri Benc 175ca678e7 phc2sys: event subscription
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>
2014-06-12 11:35:45 +02:00
Jiri Benc 506271acac phc2sys: track ports
Add tracking of which ports have been added and to which clock they belong.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:44 +02:00
Jiri Benc 90bbdbcfae phc2sys: open devices in clock_add
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>
2014-06-12 11:35:44 +02:00
Jiri Benc b826ce530b phc2sys: rearrange declarations
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>
2014-06-12 11:35:44 +02:00
Jiri Benc 78aaef8a1a phc2sys: store information about clocks being UTC or TAI
For now, only CLOCK_REALTIME can be UTC. This may stay this way forever but
now we have a clean separation between codepaths where CLOCK_REALTIME is
required and codepaths any UTC clock should take.

The main motiviation behind this change is removal of sync_offset_direction.
It has to be computed on the fly based on the source and destination when we
have multiple clocks supported and automatic following of ptp4l state
changes implemented.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:44 +02:00
Jiri Benc be4251a552 phc2sys: split clock and node
Split members that apply to all synchronized clocks and members that apply
to an individual clock. Keep all clocks in a list, with a pointer to the
source clock. This will allow to support multiple clocks synchronization.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:44 +02:00
Jiri Benc 423eb54530 phc2sys: split update_sync_offset
Split the generic (global) part of update_sync_offset and the part that
affects individual clocks. This is in preparation for phc2sys handling
synchronization of more clocks.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:44 +02:00
Jiri Benc a1bee8fbb7 phc2sys: generalize run_pmc
Make run_pmc usable for any kind of management message. Create wrappers for
waiting for ptp4l and for getting UTC offset.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:43 +02:00
Miroslav Lichvar 2b099cfa06 Increase default first step threshold to 20 us.
Most PHC drivers implement stepping (ADJ_SETOFFSET) by reading the
clock, adjusting the value by the offset and writing it back. This is
not perfectly accurate and if the operation is slow (e.g. due to PCIe
latencies), the error can be in microseconds.

Increase the default first step threshold from 100 nanoseconds to 20
microseconds to step only when the initial offset is larger than
the error in the step.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-23 12:39:20 +01:00
Miroslav Lichvar a5890cbe98 Add an adaptive servo based on linear regression.
This servo uses linear regression to estimate current time and
frequency error. The number of points used in the regression is
variable (from 4 to 64 in powers of 2) and is selected by a long-term
statistic of the prediction error.

Future improvements could include tracking of sudden frequency changes
(e.g. due to temperature variations), better stability of the error
statistic when a large offset is corrected, options to set the speed of
the adaptation, minimum and maximum number of points, or an option to
prefer frequency accuracy over time accuracy.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-14 09:52:40 +01:00
Miroslav Lichvar 31feb00194 Move PI step threshold and max frequency settings to common servo code.
These settings will be useful for all implemented servos, so move them
to the common servo code to avoid duplication. The configuration options
are renamed, but the they can be still set by their old names.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-14 09:52:39 +01:00
Miroslav Lichvar e63a6ea89b Adjust tick length with system clock.
This increases the maximum frequency adjustment of the system clock
from 500 ppm to 10%.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-01-04 14:36:35 +01:00
Miroslav Lichvar ed379b4028 Add clock sanity check.
Check the sanity of the synchronized clock by comparing its uncorrected
frequency with the system monotonic clock. When the measured frequency
offset is larger than the value of the sanity_freq_limit option (20% by
default), a warning message will be printed and the servo will be reset.
Setting the option to zero disables the check.

This is useful to detect when the clock is broken or adjusted by another
program.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-27 08:24:01 +01:00
Ken ICHIKAWA b943ea2fba phc2sys: Fix lower bound value of update_rate
Following command produces unexpected update rate.
 # phc2sys -s eth0 -q -m -O0 -R1.0842021724855044e-19
This is caused by wrong validation of phc_interval related to
significant digits of double precision and phc_interval_tp.tv_sec
overflow.

To avoid these unwanted trouble, this patch limits lower bound of
phc_rate to 1e-9.
There is no profound meaning in the lower bound value. I just think
it's enough to actual use and it doesn't cause phc_interval_tp.tv_sec
overflow in not only 64bit environment but also 32bit environment.
Thereby, messy validation of phc_interval is no longer needed.

Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-09-04 18:11:24 +02:00
Richard Cochran b0d789a73e pmc: optional legacy zero length TLV for GET actions.
This patch makes the original behavior of sending the
TLV values for GET actions with a length of zero.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-07-22 21:47:28 +02:00
Miroslav Lichvar 639ebbca13 phc2sys: Set servo sync interval.
[RC: merged servo_sync_interval signature change with earlier patch]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-07-14 21:37:53 +02:00
Ken ICHIKAWA 28b8dc9996 Add a new servo option which specifies first step threshold
Current pi servo steps clock without any condition on start.
This patch adds a new servo option "configured_pi_f_offset". The option is similar
to configured_pi_offset but only affects in the first clock update. Therefore,
if this option is set as 0.0, we can prevent clock step on start.
The new servo option can be specified from phc2sys by using -F option.

This feature is usefull when we need to restart phc2sys without system
clock jump. Restarting phc2sys is needed to change its configuration.

changes since v2:
 - manual page fix.
 - also apply max_offset along with max_f_offset in servo step1.
 - add a variable to check if first update is done.

changes since v1:(http://sourceforge.net/mailarchive/message.php?msg_id=31039874)
 - remake as a new servo option.

Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-06-21 07:27:11 +02:00
Libor Pechacek daca2773de phc2sys: common code exit point for bad usage case
Removed duplicate calls to usage() by providing common exit point for the case.

Signed-off-by: Libor Pechacek <lpechacek@suse.cz>
2013-06-18 17:51:21 +02:00
Ken ICHIKAWA 74e703727e ptp4l and phc2sys: Get argument values with strict error checking
Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-06-04 20:16:22 +02:00
Libor Pechacek a29b3bc4f9 phc2sys: Require either -O or -w on command line
The default zero offset can lead to misalignment between system clocks or wrong
time to be broadcast to the domain.  Therefore we require setting offset upon
invocation.

Signed-off-by: Libor Pechacek <lpechacek@suse.cz>
2013-06-03 15:59:01 +02:00
Jacob Keller 2a89756654 phc2sys: update usage/error reporting
This patch updates phc2sys usage reporting to give a slightly better indication
of why the program was unable to run.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2013-05-16 19:58:23 +02:00
Jacob Keller 73105bc65a phc2sys: update open_clock and deprecate '-i' option
This patch modifies phc2sys to enable the use of interface names in clock_open
rather than having to do that by hand. This enables cleaner use of the -s and -c
options as they can accept interface names. This also enables the user to set
the slave clock by network interface as well.

-v2-
* fix clock_open as it used device instead of phc_device in the final call to phc_open

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2013-05-16 19:58:23 +02:00
Richard Cochran 3ae0ff1f44 phc2sys: Use nanosleep instead of usleep.
[RC: use CLOCK_MONOTONIC as suggested on the list.]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-05-16 14:49:20 +02:00
Miroslav Lichvar 9c83fcb3c9 phc2sys: Change update rate parameter to floating-point.
This allows update intervals longer than 1 second.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-05-10 09:44:59 +02:00
Miroslav Lichvar 3414d99609 phc2sys: Use currentUtcOffset only with PTP timescale.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-05-10 08:16:57 +02:00
Jiri Benc 4004273cd8 phc2sys: enable PPS output from PHC
PPS output from a PHC has to be enabled by PTP_ENABLE_PPS ioctl. Call
the ioctl when both PHC device and PPS device are specified and PPS is
supported by the PHC.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2013-04-19 17:52:25 +02:00
Miroslav Lichvar 4929d50a3f Let kernel synchronize RTC to system clock.
Reset the STA_UNSYNC flag and maxerror value with every frequency update
to let the kernel synchronize the RTC to the system clock (11 minute mode).

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:45 +02:00
Miroslav Lichvar 7b162c4821 clockadj: Remove clkid parameter from set_leap function.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Miroslav Lichvar 24c4e851fc phc2sys: Add option to set domain number.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Miroslav Lichvar d5cf47f7f6 phc2sys: Use phc_open().
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Miroslav Lichvar 5835effd2a phc2sys: Don't try PTP_SYS_OFFSET with system clock as source.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Miroslav Lichvar e3f57d1579 phc2sys: Read maximum frequency adjustment.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-09 07:08:44 +02:00
Miroslav Lichvar fce0aa0a2f Fix compiler warnings with -O2.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-05 09:14:29 +02:00
Ken ICHIKAWA 5d7e1b0f18 phc2sys: add help messages for -l, -m and -q
This patch adds help messages for -l, -m and -q options.
Also it swaps -h for -v because ptp4l's help is this order.

Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-03-28 07:10:35 +01:00
Miroslav Lichvar 4e24248a71 Add options to not apply leap seconds in kernel.
Add kernel_leap option for ptp4l and -x option for phc2sys to disable
setting of the STA_INS/STA_DEL bit to slowly correct the one-second
offset by servo.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:40 +01:00
Miroslav Lichvar eb93926bc9 phc2sys: Handle leap seconds.
Update the currentUtcOffset and leap61/59 values at one minute
interval. When a leap second is detected, set the STA_INS/STA_DEL
bit for the system clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:39 +01:00
Miroslav Lichvar a29b1a4105 Move clock_adjtime wrapping to clockadj.c.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:39 +01:00
Miroslav Lichvar 58b1f3f37d phc2sys: Update sync offset periodically with -w.
Modify the pmc to allow non-blocking operation. Run it on each clock
update to have the sync offset updated from currentUtcOffset with every
other call.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:39 +01:00
Miroslav Lichvar 7d8f31da45 Change stats max_count variables to unsigned.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-12 19:59:50 +01:00
Miroslav Lichvar 3136e3e46c Add summary statistics.
Add new options to ptp4l and phc2sys to print summary statistics of the
clock instead of the individual samples.

[ RC - Fix () function prototype with (void).
     - Use unsigned for sample counter.
     - Fix over-zealous line breaks. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-09 10:09:25 +01:00
Miroslav Lichvar 42b305478d phc2sys: Print clock reading delay.
If the delay is known, print it together with the offset and frequency.
Remove the time stamp from the output to fit it into 80 chars.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-08 18:41:34 +01:00
Miroslav Lichvar cb5ebd9b24 Change label of frequency offset.
Change the label of the frequency offset in the clock messages printed
by ptp4l and phc2sys from "adj" to "freq" to indicate it's a frequency
value.

Also, modify clock_no_adjust() to print the frequency offset instead of
the ratio and use PRId64 instead of lld to print int64_t values.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-08 18:41:34 +01:00
Miroslav Lichvar 9e7517a31a Remove trailing whitespaces.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:02 +01:00
Miroslav Lichvar 158daa697d phc2sys: Use printing facility.
Use pr_* functions to print messages and add -m, -q, -l options to allow
configuration of the printing level and where should be the messages sent.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar 11fa191505 phc2sys: Open PPS device sooner.
Possible error messages should be printed before waiting on ptp4l.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar ecbbf4cdb1 Move Unix domain sockets to /var/run.
According to FHS, /var/run is the right place for them.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00