Commit Graph

734 Commits (a7db9bad3790e29689c16a5c6b5aeb6fd4e2c719)

Author SHA1 Message Date
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
Jiri Benc bbe634d790 Let transport_recv/send/peer use ptp_message
The callers of those functions are all using ptp_message. As we're going to
return more information (the address), let those functions just fill in the
ptp_message fields directly.

Some minor reshuffling needed to prevent circular header dependencies.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-17 06:49:38 +02:00
Jiri Benc 3d22154299 raw: separate src and dst addresses
In order to be able to convert to a generic address struct, separate source
and destination address into separate fields.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-17 06:49:37 +02:00
Jiri Benc 8c02ae53f2 raw: replace hard coded constants by MAC_LEN
Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-17 06:49:37 +02:00
Jiri Benc 8bbebdd381 raw: fix reading of uninitialized memory on recv
When less bytes than the header size is read, do not indicate to the caller
that the read was successful, as the caller would read uninitialized memory.
To achieve that, subtract the header size unconditionally (unless an error
was returned by sk_receive).

In addition, do not check for Ethernet type when full Ethernet header was
not read. This again may lead to reading of uninitialized memory.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-10 12:29:26 +02:00
Jiri Benc ea7a7882e5 Move common code into port_prepare_and_send
The task of preparing the message for transmission and sending it appears
at many places. Unify them into a new function.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-03-26 16:59:45 +01:00
Jiri Benc 4ed4c0ef5a Move check of TLV length for management COMMAND messages
Currently, it is assumed that the management TLV data of management COMMAND
messages is always empty. This is not true for the INITIALIZE command and
also for a custom command we'll be introducing.

Move the check to msg_post_recv and let it check only the TLVs defined by
the standard.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-03-26 16:59:45 +01:00
Miroslav Lichvar 683218aee6 Print warning message on deprecated ptp4l options.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-23 12:39:20 +01: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 61de819d56 Include clock rate ratio in delay calculation.
With the new linreg servo the frequency offset and time offset are
controlled separately. The ratio between master's frequency and the
current frequency of the local clock is known and can be used when
calculating delay or peer delay to improve their accuracy.

This greatly improves the stability of the delay when the servo is
correcting a large offset.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-14 09:52:40 +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 72a9212600 Don't always step clock on PI servo reset.
The initial check if the clock should be stepped always passed after the
servo was reset (e.g. from clock sanity check). Fix the condition to
step only when the threshold is exceeded.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-03-13 08:32:37 +01:00
Miroslav Lichvar 91e240679b Restrict SET actions to UDS port.
Setting GRANDMASTER_SETTINGS_NP is allowed only from UDS, but
PORT_DATA_SET can be set from any port. Move the port check to
clock_manage(), so all clock and port SET actions are restricted
to the UDS port.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-25 14:15:49 +01:00
Miroslav Lichvar c0fd772974 pmc: print cumulativeScaledRateOffset as offset.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-25 14:15:49 +01:00
Miroslav Lichvar 7d773a9b93 Initialize clock rate ratio.
This fixes cumulativeScaledRateOffset reported in TIME_STATUS_NP before
the rate ratio is updated from port.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-25 14:15:49 +01:00
Miroslav Lichvar 85cebe0265 Fix conversion of cumulativeScaledRateOffset in TIME_STATUS_NP.
This fixes reporting of negative offsets.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-25 14:15:49 +01:00
Delio Brignoli b2bde6f5ec config: Add min_neighbor_prop_delay configuration variable
When peer delay is < min_neighbor_prop_delay the port is flagged
as non 802.1AS capable. min_neighbor_prop_delay defaults to -20ms.

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2014-02-25 14:14:01 +01:00
Delio Brignoli bd001fdec7 port: adjust peer delay calculation using neighborRateRatio
Previouly the peer delay was not taking into account the
frequency offset between the local clock and the peer's clock.
Reset neighborRateRatio to 1.0 in port_nrate_initialize().

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2014-02-25 14:13:05 +01:00
Richard Cochran 54c9effeba Version 1.4
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2014-02-14 16:20:14 +01:00
Miroslav Lichvar 9190959693 Fix new -Wformat warnings.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-14 16:17:28 +01:00
Miroslav Lichvar 1fa57ac411 Set printf format attribute for print().
This allows gcc to check format strings used in pr_* calls.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-11 21:27:52 +01:00
Miroslav Lichvar 661639420c Clarify units used in clock stepping constants.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-02-11 21:27:52 +01:00
Stephan Gatzka 110849d422 Make functions and structs dealing with string literals const correct.
This allows the compiler to check if someone writes into string
literals.

Signed-off-by: Stephan Gatzka <stephan.gatzka@gmail.com>
2014-02-07 19:41:47 +01:00
Stephan Gatzka 886112e202 Make udp_physical_addr() and udp_protocol_addr() static.
They aren't used outside udp.c

Signed-off-by: Stephan Gatzka <stephan.gatzka@gmail.com>
2014-02-07 19:40:29 +01:00
Delio Brignoli 29063a8227 pmc: support retrieving neighborPropDelayThresh and asCapable using management interface
Define new PORT_DATA_SET_NP TLV
neighborPropDelayThresh can also be set using the same TLV

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2014-02-04 18:59:26 +01:00
Richard Cochran f36af8e0c3 uds: disable the accidentally enabled announce timer.
Commit e425da2f inadvertently enabled the announce timer on the UDS port,
causing it to continually reopen the socket when in slave mode. This patch
fixes the issue by passing zero in the 'span' field of the new function,
set_tmo_random, which disables the timer again.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Rohrer Hansjoerg <hj.rohrer@mobatime.com>
2014-01-08 18:59:20 +01:00
Richard Cochran 21889c5e7e uds: take the interface data off the stack.
The 'struct interface' for the UDS port is allocated on the stack, and
when this gets passed to port_open, the port instance takes a pointer to
the string in the 'name' field. Currently this is harmless for the UDS
port, but it is not good form. This patch fixes the issue by making the
interface part of the clock instance.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-01-08 18:59:11 +01:00
Miroslav Lichvar 5dd5af5565 phc2sys: Mention that PPS output needs to be enabled without -s.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-01-08 16:06:42 +01:00
Miroslav Lichvar cee9397b66 Print current frequency when PI servo is in unlocked state.
Store the current frequency and return it when the servo is in unlocked
state instead of zero. This fixes values printed in log messages.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-01-08 15:50:02 +01:00