Commit Graph

1197 Commits (01db4c884998246e6599d78004cd7cf06161c30e)

Author SHA1 Message Date
Richard Cochran 01db4c8849 Remove the unfinished SNMP code.
Unfortunately the SNMP code still has issues like not passing the
valgrind test, and no one is able to finish this up right now.  This
patch removes the SNMP program so that the upcoming release does not
contain unfinished work, potentially misleading end users about the
scope and completeness of the features.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-21 04:35:51 -07:00
Richard Cochran 45aa981e4a clock: Safely remove event subscribers from list.
When updating and potentially removing event subscribers, the code uses
the simple list traversal macro.  As a result, the list will become
corrupted whenever a subscriber is removed.  This patch fixes the issue
by using the appropriate macro.

Fixes: 5104e3e56b ("Event subscribing")
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Michael Walle <michael@walle.cc>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-21 04:34:43 -07:00
Richard Cochran 25d4e4fbdd Revert "phc2sys: Notify kernel if clock is not in sync"
This novel use of the STA_UNSYNC flag breaks with the established,
traditional meaning of that flag, which is:

   The clock has is believed to have an error larger than 16 seconds.

This reverts commit 944f5f7ac6.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-06 10:13:50 -08:00
Ville Heikkinen 944f5f7ac6 phc2sys: Notify kernel if clock is not in sync
In case there is no connection to the server, notify the kernel
that the clock is currently unsynchronized.

Signed-off-by: Ville Heikkinen <ville.heikkinen@nokia.com>
2020-03-04 10:01:27 -08:00
Richard Cochran 0a4d85c2ed interface: Remove obsolete method.
Now that all call sites have been converted to interface_create(), there
is no longer any needed for a way to set the interface's name.  This patch
removes the useless method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran b878dd99fa interface: Silence warning from gcc version 8.
When compiling with gcc8 and -O2, the clever compiler complains:

   interface.c: In function ‘interface_ensure_tslabel’:
   interface.c:38:3: error: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 108 [-Werror=stringop-truncation]

Even though this is a false positive, this patch silences the warning
by using memcpy instead of strncpy.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran a8f742528e interface: Hide the implementation details.
Now that a complete functional API is in place, there is no need to expose
the inner workings of the network interface data type.  This patch converts
it into an opaque type while leaving the list marker visible to users
through a simple form of "friendly exposition".

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran 66dc3167e3 pmc: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:38 -08:00
Richard Cochran 812e0df4b8 config: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:34 -08:00
Richard Cochran 52482e0969 clock: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:30 -08:00
Richard Cochran 5316a36422 interface: Introduce methods to create and destroy instances.
In order to eventually hide the implementation details of the interface,
users will need to be able to create and destroy instances thereof.  This
patch adds the needed methods.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:26 -08:00
Richard Cochran 21141a44e6 Convert call sites to the proper method for testing time stamping modes.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:22 -08:00
Richard Cochran 720c9fa08d interface: Introduce a method to test supported time stamping modes.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:19 -08:00
Richard Cochran 605abc45dd Convert call sites to the proper method for testing time stamp info validity.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:15 -08:00
Richard Cochran 3d388e1992 interface: Introduce a method to test the time stamping information validity.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:10 -08:00
Richard Cochran 02bbf36c2a Convert call sites to the proper method for getting the PHC index.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:04 -08:00
Richard Cochran a228de7dff interface: Introduce a method to get the PHC index.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:00 -08:00
Richard Cochran e43a76cbe6 Convert call sites to the proper method for setting the time stamping label.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:00 -08:00
Richard Cochran 5f9d36c76a interface: Introduce a method to set the time stamping label.
The ts_label field of the interface is set in different ways by different
callers.  In order to prevent users from open coding the logic that sets
the label, this patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:56 -08:00
Richard Cochran d471a57aa8 Convert call sites to the proper method for setting the name.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:51 -08:00
Richard Cochran 47982fb8c8 interface: Introduce a method to set the name.
The name field of the interface is set in different ways by different
callers.  In order to prevent users from open coding the logic that sets
the name, this patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:47 -08:00
Richard Cochran a8df585e04 Convert call sites to the proper method for initializing the time stamping label.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:43 -08:00
Richard Cochran b802e3b784 interface: Introduce a method to initialize the time stamping label.
In many cases, the time stamping label will be the same as the name of
the interface.  In order to prevent users from open coding the logic that
initializes the label from the interface name, this patch add an
appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:38 -08:00
Richard Cochran 6d73e755c3 Convert call sites to the proper method for getting time stamp information.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:33 -08:00
Richard Cochran cca19dab99 interface: Introduce a method to get the time stamping information.
In order to prevent users from open coding this logic, this patch
provides a method that populates the time stamping information from
the interface label.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:28 -08:00
Richard Cochran e752cac7b1 Convert call sites to the proper method for getting interface labels.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:24 -08:00
Richard Cochran a3c0a88b82 interface: Introduce an access method for the time stamping label.
Many of the users only require a read only reference to the time
stamping label of the interface.  This patch adds an appropriate
method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:10 -08:00
Richard Cochran 34945679fe Convert call sites to the proper method for getting interface names.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Richard Cochran 380ee349f6 interface: Introduce an access method for the name field.
Many of the users only require a read only reference to the interface name.
This patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Richard Cochran c5b9ab990a Move the network interface into its own header file.
Up until now, the users of the interface data structure simply access
its fields without restriction.  This patch takes the first step
towards abstracting this data structure by giving it a file of its
very own.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:44:57 -08:00
Richard Cochran 9dcd6c31e7 utils: Constify the posix clock interface.
The function to open a posix clock never modifies the passed in
string.  This patch adds the const keyword to ensure this function
stays that way.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:44 -08:00
Richard Cochran e4d1988f54 rtnl: Constify the public interface.
Three of the rtnl methods never modify the strings passed in.  This
patch adds the const keyword to ensure these functions stay that way.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:37 -08:00
Richard Cochran 831f7e073b config: Constify the public interface.
The two methods, config_create_interface and config_read, never modify the
strings passed in.  This patch adds the const keyword to ensure these
functions stay that way.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:31 -08:00
Richard Cochran b8480ef908 Group related objects together within the makefile.
Any program that links to the servo interface must also link with the
implementations of that interface.  Similarly, the filter and network
transport interfaces each require their implementations.  This patch
re-factors the makefile to reflect this fact in order to simplify
adding new programs making use of these interfaces.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:25 -08:00
Erik Hons a380afc482 clock: reset master/local rr when best clock id changes
This fixes an issue with free running clocks. When the master clock id
changes the measured master/local ratio should be reset. If it isn't,
and the local clock becomes master, then the last measured ratio to
the old master continues to be used in peer delay calculations. If a
bad master/local ration calculation triggers this state change the
port can get "stuck" in not "asCapable" mode.

Signed-off-by: Erik Hons <erik.hons@ni.com>
2020-02-09 04:34:43 -08:00
Miroslav Lichvar ee6930a884 unicast: Enable sharing master tables between ports.
Don't require each port to have its own master table specified in the
config. Instead of ports claming configured tables, clone the table in
each port, so different ports don't interfere with each other.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2020-02-09 04:20:08 -08:00
Richard Cochran 581a6bd59b Accept external PHC devices from the command line.
A single, external PTP Hardware Clock device may be wired to one or more
MAC devices, providing the MACs with an input clock.  This patch adds
support for such a hardware architecture by letting the command line PHC
override the one discovered via the ethtool ioctl.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-02-08 07:31:14 -08:00
Richard Cochran e0580929f4 phc2sys: Fix frequency estimation when synchronizing a PHC to the system clock.
When synchronizing a PHC to the Linux system clock (CLOCK_REALTIME),
the phc2sys uses the sysoff method, reversing the master and slave
roles.

The offset between a master clock and a slave clock is given by

    offset = slave_ts - master_ts,

and the call to sysoff_measure() provides the 'offset' and 'slave_ts'
values.  The needed local time stamp on the 'master' is given by

    master_ts = slave_ts - offset,

but the code calcuates

    master_ts = slave_ts + offset.

When passed to the servo, the local time stamp is used to estimate the
frequency offset between the two clocks before starting the main
synchronization loop.  The effect of the bug may be seen with a simple
test.  Here is a sample output with the existing code.

    $ sudo testptp -d /dev/ptp1 -f 62400000
    frequency adjustment okay
    $ sudo ./phc2sys -m -q -c eth6 -s CLOCK_REALTIME -O0
    phc2sys[90221.239]: eth6 sys offset 191001318 s0 freq -62400000 delay   5547
    phc2sys[90222.239]: eth6 sys offset 253380897 s1 freq  +8265884 delay   5507
    phc2sys[90223.239]: eth6 sys offset  -8301685 s2 freq    -35801 delay   5487
    phc2sys[90224.239]: eth6 sys offset  -8297136 s2 freq  -2521757 delay   5531
    phc2sys[90225.239]: eth6 sys offset  -5806117 s2 freq  -2519879 delay   5542
    phc2sys[90226.239]: eth6 sys offset  -3317009 s2 freq  -1772606 delay   5495
    phc2sys[90227.240]: eth6 sys offset  -1575231 s2 freq  -1025931 delay   5505
    phc2sys[90228.240]: eth6 sys offset   -580249 s2 freq   -503518 delay   5524
    phc2sys[90229.240]: eth6 sys offset   -107770 s2 freq   -205114 delay   5519
    phc2sys[90230.240]: eth6 sys offset     66298 s2 freq    -63377 delay   5490
    phc2sys[90230.881]: eth6 sys offset     86942 s2 freq    -22844 delay   5495

And this is the output with the bug fix in place.

    $ sudo testptp -d /dev/ptp1 -f 62400000
    frequency adjustment okay
    $ sudo ./phc2sys -m -q -c eth6 -s CLOCK_REALTIME -O0
    phc2sys[90365.624]: eth6 sys offset 311912675 s0 freq -62400000 delay   5490
    phc2sys[90366.624]: eth6 sys offset 374292766 s1 freq  -31098 delay   5642
    phc2sys[90367.624]: eth6 sys offset     -3825 s2 freq  -34923 delay   5617
    phc2sys[90368.625]: eth6 sys offset         6 s2 freq  -32240 delay   5564
    phc2sys[90369.625]: eth6 sys offset      1241 s2 freq  -31003 delay   5605
    phc2sys[90370.625]: eth6 sys offset      1131 s2 freq  -30741 delay   5600
    phc2sys[90371.625]: eth6 sys offset       801 s2 freq  -30732 delay   5621
    phc2sys[90372.625]: eth6 sys offset       458 s2 freq  -30834 delay   5640
    phc2sys[90373.626]: eth6 sys offset       186 s2 freq  -30969 delay   5598
    phc2sys[90374.626]: eth6 sys offset       134 s2 freq  -30965 delay   5599
    phc2sys[90375.626]: eth6 sys offset        43 s2 freq  -31016 delay   5595
    phc2sys[90375.681]: eth6 sys offset       -32 s2 freq  -31078 delay   5541

This patch fixes the issue by correcting the calculation of the local
time stamp value.

Fixes: 8142da41b6 ("phc2sys: Use reversed sysoff when synchronizing to system clock.")
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Cliff Spradlin <cspradlin@google.com>
Tested-by: Vladimir Oltean <olteanv@gmail.com>
2019-12-25 10:26:04 -08:00
Richard Cochran a920c13413 Correct the signature of the legacy system offset measurement method.
The sysoff_measure() function gained an additional parameter some time
ago, but the legacy method for older kernels without PTP_SYS_OFFSET was
overlooked.  This patch brings the legacy method up to date again.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-12-25 10:25:59 -08:00
Miroslav Lichvar e20d8228f9 port: Avoid calling freed servo after switching PHC.
In port_synchronize(), when the clock returned SERVO_UNLOCKED and
port_dispatch() triggered a switch of the PHC, the variable "s" would
point to a servo which was already freed and the following call of
servo_offset_threshold() would read invalid memory.

Don't save the servo before dispatching the port.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 3f5f5653d7 ("port: Add interval update mechanism.")
2019-10-12 20:42:58 -07:00
Miroslav Lichvar f9e84e69bf port: Don't leak transport when unicast initialization fails.
[RC: Fix two more bad goto labels. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-10-12 20:40:44 -07:00
Petr Machata 7985634179 pmc: Support querying TLV_PORT_PROPERTIES_NP
TLV_PORT_PROPERTIES_NP messages serve for querying of port properties, such
as timestamp type and, prominently, netdevice name associated with the
port. pmc however does not support this query, which makes it difficult to
access this information e.g. from scripts. Add this support to pmc.

Signed-off-by: Mykola Zhuravel <mykola@mellanox.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-10-12 19:42:42 -07:00
Petr Machata f9f00d8fe8 util: Add a function to render timestamp type
TLV_PORT_PROPERTIES_NP carries, among other attributes, a timestamp type
used for that port. In order to make it possible to format the value for
user consumption, introduce a new function ts_str().

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-10-12 19:42:42 -07:00
Petr Machata 48e605ef01 pmc.8: Mention PORT_STATS_NP
In commit 2b5bec8d27 ("pmc: Add a new TLV to obtain per-port
statistics"), pmc gained a new TLV to obtain port stats from ptp4l. Mention
the TLV in the pmc man page.

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-11 21:32:48 -07:00
Petr Machata a48666bee3 udp6: Make mc6_addr transport-local
mc6_addr holds the parsed multicast address to which messages should be sent.
But since each port can have a different scope, and the primary MC address
depends on the scope, it really can't be stored in a global variable. Move both
to struct udp6.

Additionally, document the fact that the primary multicast address is changed at
runtime.

Reported-by: Alex Veber <alexve@mellanox.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Petr Machata 2b5bec8d27 pmc: Add a new TLV to obtain per-port statistics
Add an ability of pmc to query per-port stats added in the previous patch.

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Petr Machata e3f0891996 port: Introduce per-port stats for received and transmitted messages
Add struct PortStats to keep per-port number of messages sent and received,
split by message type. Bump TX counters after messages are sent
successfully, and RX counters after a message is received. To keep things
simple, reserve one counter for each theoretically possible message type,
including the reserved ones.

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Richard Cochran d32758aa09 phc2sys, phc_ctl: Re-factor common code.
The two programs, phc2sys and phc_ctl, use nearly identical subroutines to
open an instance of a dynamic posix clock.  In anticipation of yet a third
program with similar needs, this patch refactors the common code into the
utilities.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-08-25 12:19:36 -07:00
Richard Cochran 46b673792a Keep configuration options in alphabetical order.
The order of the options list has gone a bit astray.  This patch
restores the ordering.

Fixes: 450b1ed844 ("port: Add inhibit_delay_req.")
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-08-19 08:37:23 -07:00
Vladimir Oltean 68337acd10 configs: default.cfg: Fix typo in inhibit_delay_req
ptp4l -f default.cfg complains:

  unknown option inhibit_pdelay_req at line 41 in global section
  failed to parse configuration file /etc/linuxptp/default.cfg

Fixes: 450b1ed844 ("port: Add inhibit_delay_req.")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2019-08-19 08:30:01 -07:00