Commit Graph

663 Commits (1773d21f26eb1aa2da0645af116d6ce27591a9cc)

Author SHA1 Message Date
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
Jiri Benc 1a1e02aa97 phc2sys: man page update for -a and -r options
Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-06-12 11:35:45 +02:00
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 48f6a31cc3 pmc_common: easy way to set port and broadcast target
Implement pmc_target_port to set a port number, leaving clock identity
unchanged, and pmc_target_all to set clock identity and port number to all
1's.

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 5723da950f Remove unused field from struct config.
The sanity_freq_limit field was erroneously added to the config struct
in ed379b40, the right one is in the default_ds struct.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-06-12 11:24:39 +02:00
Richard Cochran abd4338384 Bump the date on the hwstamp_ctl man page.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-06-04 15:17:22 +02:00
Jacob Keller 2462f675c3 hwtstamp_ctl: use SIOCGHWTSTAMP ioctl before destructively setting policy
This patch modifies the hwtstamp_ctl program, so that it will (attempt
to) use the SIOCGHWTSTAMP ioctl to non-destructively read the current
hardware timestamping policy, prior to setting it with SIOCSHWTSTAMP.

This change has 3 primary advantages:

1) It allows reading the current settings of the device, which was
   previously not possible since SIOCSHWTSTAMP is destructive.
2) The default behavior without rx-filter or tx-type selected on the
   command line is no longer destructive, since it does not attempt to
   set the values to 0. The user must explicitly request to disable the
   settings, by using the provided options.
3) It allows only modifying tx-type or rx-filter separately, without
   destroying the other setting.

This patch supersedes a previous submission which added a -g flag. This
new method of getting first is more advantageous and doesn't require
adding an additional option flag.

- v4
* only display results if command succeeds, as the contents are otherwise
  expected to be identical to what we passed in.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2014-06-04 15:09:28 +02:00
Jacob Keller 5e8a34f0b4 missing: add SIOCGHWTSTAMP to missing.h
In order to allow hwtstamp_ctl to use the non-destructive SIOCGHWTSTAMP
ioctl, we need to add it to missing.h, in order to prevent build failure
on older kernels which don't have this support.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
2014-06-04 15:09:28 +02:00
Richard Cochran 8a92b1292c Fix a trivial spelling mistake in a comment.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-06-02 18:00:21 +02:00
Miroslav Lichvar 32ef7c0793 Fix sk_interface_addr().
This was broken in commit e804e6, ifa_addr is a pointer to sockaddr,
it shouldn't be referenced for the memcpy call.

Acked-by: Jiri Benc <jbenc@redhat.com>
2014-05-12 19:12:03 +02:00
Jiri Benc 424bbde8fc Custom management TLV PORT_PROPERTIES_NP
Will be used by phc2sys to find out interfaces corresponding to ports.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:09:00 +02:00
Jiri Benc c8c6f7288f Event notification: port state
Notify subscribers about port state changes.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:08:59 +02:00
Jiri Benc 648197153e clock: event notification
Split management message creation to more fine-grained functions to allow
notification messages to be created.

The new clock_management_fill_response is called from
clock_management_get_response (so the function behaves exactly the same as
before this patch) and from a new clock_notify_event function. The
difference is clock_management_get_response uses the request message to
construct the reply message, while clock_notify_event constructs the reply
message based on the notification id.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:08:59 +02:00
Jiri Benc 122314926a port: event notification
Split management message creation to more fine-grained functions to allow
notification messages to be created.

The new port_management_fill_response is called from
port_management_get_response (so the function behaves exactly the same
as before this patch) and from a new port_notify_event function. The
difference is port_management_get_response uses the request message to
construct the reply message, while port_notify_event constructs the
reply message based on the notification id.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:08:59 +02:00
Jiri Benc 0e8efe418c Subscription time limit
Add expiration time to subscriptions; they need to be renewed before they
expiry. This way, the subscription automatically times out when phc2sys is
killed.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:08:59 +02:00
Jiri Benc 5104e3e56b Event subscribing
This puts groundwork for event subscription and notification. The individual
events are added by subsequent patches.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-06 20:08:58 +02:00
Jiri Benc d0a67e8b1a Implement port_forward_to
Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-03 13:56:57 +02:00
Jiri Benc d6e4173e19 Remove unneeded parameter in port_forward
This parameter was made obsolete by the common address refactoring.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-03 13:56:57 +02:00
Jiri Benc ba577d7123 Respond with an error to management messages to non-existing ports
Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-03 13:56:57 +02:00
Jiri Benc 14742ef566 uds: don't output "Connection refused"
When phc2sys is started before ptp4l or it is interrupted before ptp4l has
a chance to reply to its query, the "uds: sendto failed: Connection refused"
message is output. This is not an interesting message.

Also, don't output the "failed to send message" error from pmc_send, as
all transports output errors in their send routine.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-05-03 13:56:57 +02:00
Jiri Benc 4df924b253 Implement transport_sendto
Also, document transport_send, transport_peer and transport_sendto usage.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-25 14:28:14 +02:00
Jiri Benc e804e6f9a0 Common type holding an address
This modifies all transports to use a new common address type, struct
address. This address is stored in a ptp_message for all received messages.

For sending, the "default" address is used with the default sending
functions, transport_send and transport_peer. The default address depends on
the transport; it's supposed to be the multicast address assigned by the
transport specification.

Later, a new transport_sendto function will be implemented that sends to the
address contained in the passed ptp_message.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-25 14:28:14 +02:00