The calls to snprintf() to format /dev/phc%d use the wrong pattern.
That function always properly terminates the string with null.
However, the code passes a hard coded length of 31 to static arrays of
length 32. While this is not a bug, there are two issues here.
First, any (improbable) future increase in the array lengths would
have to also remember to fix up the snprintf() call site as well.
Secondly, the pattern of using buf[N] and then length=N-1 is
appropriate for strncpy(), but is useless for snprintf().
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
Having one fewer port may affect the result of the BMCA. This patch
changes the main loop so that a link down event also causes a state
decision event.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
This global function used to return an error code, but now it always
returns zero. This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.
Signed-off-by: Viliam Lejcik <viliam.lejcik@kistler.com>
Poll for link up/down events. When a link goes down, the port becomes
faulty until the link goes up again. We keep the fault timer from the
existing fault detection, but a downed link prevents clear the fault.
The new state machine is depicted in this ascii art diagram:
+--------+ Fault +---------+
| |------------>| |
| UP | | FAULT |
| |<------------| |
+--------+ Timeout +---------+
A | /
| | /
Link-Up | | Link-Down /
| | /
| V /
+--------+ / Link-Down
| | /
| DOWN |<--------/
| |
+--------+
If the fault timer occurs in the DOWN state, we simply ignore it.
After all, without the link the port is useless.
There is one case where the new code changes the existing behavior.
If the link quickly does down and then up again while another fault
(and its timer) are active, then we will enter the UP state without
waiting for the fault timer expiration. However, this behavior is
acceptable because when a link goes up, you are starting with a clean
slate.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We use a hash table to remember the mapping. Since our existing hash
table is a simply string hash, we convert the integer index into a decimal
string. Although hashing integers in this way is sub-optimal, the table
will not be used in a performance critical path.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The time stamping setup code needlessly queries the configuration data
base over and over, rather than simply using the local variable
already assigned. This patch replaces the extraneous config_get_int()
calls with the local variable.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We activate on-step mode based on the "time_stamping" and
"twoStepFlag" configuration options. If twoStepFlag is false and HW
time stamping is enabled, we upgrade the time stamping mode variable
to one-step.
The code that tests the options and sets the one-step mode moved from
ptp4l.c into clock.c in commit 9b27664c ("clock: simplify the create
method."). However, that commit inadvertently moved the test after
the place where the time stamping mode is latched in a local variable.
As a result, one-step mode is not activated when configured.
This patch fixes the issue by keeping the local time stamping mode
variable up to date during the one-step test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
During the configuration rework, the announce span was wrongly converted
into a hard coded macro. In addition, the announceReceiptTimeout option
inadvertently became non-zero for the UDS port. As a result, the UDS port
sets a useless announce message timer, causing the code to close and reopen
the UDS port every few seconds.
This bug has an interesting history. It was first reported and fixed in
commit f36af8e0 ("uds: disable the accidentally enabled announce timer.").
That very fix was wrongly removed in commit 54f45063 ("port: change
'announce_span' into a macro."). Because of various code changes, this
bad commit cannot be simply reverted now.
This patch re-introduces the 'announce_span' variable and clears both it
and 'announceReceiptTimeout' for the UDS port, effectively disabling the
announce message timer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The code that determines the index of the PHC device is useful to all
kinds of clock devices.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This function will allow the TC code to iterate over the ports without
calling into the clock logic.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The port code is not interested in the number of ports but rather the
clock type. Since the polymorphic clock object will be able to report
its own type, this patch changes the clock interface accordingly.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
There is no need for the 'ifaces' parameter since the list of network
interfaces is already present in the configuration.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
With the new configuration API, there is no need to pass the default data
set. Instead, the clock code can read the configuration directly. This
patch simplifies the clock create method by removing the 'dds' parameter
and moving the code that initialized the data set into the clock module.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The new configuration code inadvertently causes the UDS port to use P2P
messaging when P2P is set as a global option. This results in a never
ending series of "missing timestamp" error messages from the UDS port as
it vainly tries to send peer delay requests.
This patch fixes the bug by changing the UDS delay mechanism back to zero
as it was before. This is the appropriate setting for the UDS port,
because it never leaves the listening state and thus never sends an E2E
delay request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>