Reset delay timer when switching to P2P delay mechanism.

When ptp4l was configured to use the auto delay mechanism and the first
pdelay request was not received in the slave or uncalibrated state, it
would not make any pdelay requests itself, because there was no delay
timer running.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Don't try to forward messages to faulty UDS port.

When the socket couldn't be opened (e.g. in clknetsim), the file
descriptor is invalid and shouldn't be used for sending.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Make the CFLAGS more robust.

This patch introduces a shell script to figure out the proper definitions
for the HAVE_CLOCK_ADJTIME and HAVE_ONESTEP_SYNC macros, as well as the
include path. The intent is to "do the right thing" for three different
user scenarios, namely cross compiling, compiling against a custom kernel,
and using a plain old disto kernel.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Convert the hard coded UDS server path into a variable.

This patch changes the macro for the server socket address into a global
variable so that a subsequent patch can provide a way to set the variable.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Introduce a configuration file option for the server's UDS address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
pmc: add a command line option to select the server's UDS address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Extend the interface name length to allow any UDS address.

This patch increases the maximum length of an interface name to
accommodate a UNIX domain socket address of 108 bytes. (This value is
hard coded in the glibc headers, and so we cannot use the Linux kernel
header macro, UNIX_PATH_MAX.)

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
pmc: bring the man page more up to date.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Ignore delay_resp messages from foreign masters.

When a new master appears, it will start to respond to our delay_req
messages. Make sure we process only responses from our current master
before switching to the new master.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Don't calculate delay with old master's sync time stamp.

When a new master is selected, drop the old sync time stamp to prevent
calculating invalid delay in case delay_resp will be received before
first sync from the new master.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Merge the configurable UDS server path branch.
Add reset function to servo.

This will be used with clock sanity checking.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
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>
Add random delay to announce timeout.

According to 9.2.6.11 of the spec the ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
timeout in addition to announceReceiptTimeoutInterval includes a random
number up to one announceInterval.

Add a new function for setting random timeout and use it in
port_set_announce_tmo().

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Drop tmtab module.

Instead of maintaining a table of precalculated values, use the
newly added set_tmo_random() function to set the delay request timeout.
It saves some memory and improves the timeout granularity, but has a
higher computational cost. It follows the requirements from section
9.5.11.2 of the spec.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Make random() more random between machines.

Include also nanoseconds from the current time in the srandom() call.
This should significantly decrease the chance of two machines using the
same random sequence.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
sk: update error message for Tx timestamp polling

This patch cleans up the error message for the Tx timestamp polling, and adds a
line which indicates where the bug might have originated. This should help a
user more easily diagnose what went wrong.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Add modular filter interface.

Similarly to the servo interface, allow multiple filters to be
used for delay filtering. Convert mave to the new interface.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Add median filter.

Median filter has an advantage over moving average that it is much less
sensitive to outliers.

For instance, it allows much faster recovery from an external clock
time step which happened between receiving sync message and sending
delay_req message. The measured delay includes a large error, but the
median is still a good estimate of the delay and the first step
correction applied by the servo is right.

In this implementation the median update has linear time complexity.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Add options to configure delay filter.

Add new options delay_filter and delay_filter_length to select the
filter and its length. They set both the clock delay filter and the port
peer delay filter. The default is now moving median with 10 samples.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>