This function allows the ports to read configuration variables without
changing the port method signatures.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This will help us to simplify the passing of parameters between the main
program. clock, and ports.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This patch adds support for changing the priority1 and priority2
elements of the "default data set" at run time.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Add weight parameter to the sample function. Samples with smaller weight
are less reliable, they can be ignored by the servo or the adjustments
of the clock can be smaller.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Add new time stamp processing modes to return raw delay and offset based
on the raw delay instead of the long-term filtered delay, and to return
also a weight of the sample. The weight is set to the ratio between the
two delays. This gives smaller weight to samples where the sync and/or
delay messages were delayed significantly in the network and possibly
include a large error.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Introduce a time stamp processor for offset/delay calculations and use
it in the clock and port modules.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Convert time stamps to tmv_t and apply all corrections before passing
them to clock/port functions to reduce the number of parameters.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When switching clock devices in JBOD mode, we need to be able to reset the
servo. The existing servo_reset() function will not serve us well, because
in this case we also need to seed the existing frequency offset and limit.
This patch adds a new method that simply starts the servo from scratch.
In the unlikely event of a resource allocation failure, the method will
simply continue to use the previous device, which is better than nothing
and certainly preferable to bailing out the program.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When adding a new port, put it at the end of the list instead of head.
This restores the order of received management messages as was before
commit 08575133.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
For the ports to be truly created and removed dynamically, the last used
port number has to be remembered by the clock and used for port creation.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
There's no need to regenerate pollfd multiple times during batches of port
operations (like creating of the clock). Just be lazy and regenerate it only
once it's needed.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Remove the limit of MAX_PORTS ports (default 8) and keep the ports in
a linked list. This allows ptp4l to be used on large machines and in the
future, it will allow dynamic adding and removing of ports while ptp4l is
running.
For this to work, pollfd needs to be dynamically allocated. Changed pollfd
handling from clock_install_fda/clock_remove_fda to notification
(clock_fda_changed), where the clock will rebuild pollfd by querying all its
ports.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
The uds port is handled specially in almost all cases, it doesn't behave
like the rest of ports in the port array. Make it a standalone member of
struct clock.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
The fault timer file descriptor is a per port item, put it inside struct
port where other per port file descriptors are kept.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
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>
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>
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>
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>
This puts groundwork for event subscription and notification. The individual
events are added by subsequent patches.
Signed-off-by: Jiri Benc <jbenc@redhat.com>
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>
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>
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>
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>
This fixes cumulativeScaledRateOffset reported in TIME_STATUS_NP before
the rate ratio is updated from port.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
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>
Negative path delay measurements are expected with E2E, the user doesn't
need to know when that happens.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Although it does not need to, the UDS port tries to allocate a filter,
just as any normal port would. Since the given length is zero, the
filter tries to allocate storage of size zero. When running with
uClibc, calloc(1, 0) returns NULL, but glibc is apparently returning
"a unique pointer value that can later be successfully passed to
free()." Both behaviors are allowed (see MALLOC(3)).
This patch works around the issue by letting the UDS port have a
filter of length one.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This patch lets the clock release allocated memory when shutting down. The
main benefit is just to exhibit good form and to make valgrind happier.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>
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>
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>
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>
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>
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>
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>
Add 1 to port numbers printed in the log messages to make them
consistent with messages from port.c. The port number 0 is the UDS port,
which is last in the clock->port array.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>