Use tmv_dbl() to obtain the floating point value passed to
stats_add_value() rather than relying on the existing implicit cast
from the result of tmv_to_nanoseconds().
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This option allows the clock to be updated before the path delay is
measured in order to speed up the initial correction of the clock, e.g.
in domains using a very long logMinDelayReqInterval.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The UDS port is not expected to be used by PTP clocks and forwarding of
management messages to the port can be limited to responses.
This prevents ptp4l from printing error messages when a management
request is received from a non-UDS port and the last client which used
the UDS port is no longer listening.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Now the ts label will be either the bond active slave or the interface
name, which is the exactly interface we need to get ts info.
When the link down/up or there is a fail over and ts_label changed, the
phc index may also changed. So we need to check get new ts info and check
clock_required_modes. We will set the link to LINK_DOWN by force if
the new ts_label's timestamp do not support required mode.
If all good, then we set phc index to new one. Also sync clock interval
after switch phc.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Separate required_modes setting from clock_create so we can obtain the
required time stamping flags from other place.
Add enum timestamping in struct clock to store the time stamping mode.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Now that we test the UTC flags in clock_update_slave(), the similar
code in clock_utc_correct() is redundant.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When acting as a slave, we accept the foreign master's advertised
TAI-UTC offset for as long as that master is present. However, when
the master disappears, we fall back to the initial offset value. As a
result of this behavior, when starting with an out of date initial
offset, losing a foreign master causes a sudden UTC offset error (in
phc2sys for example) in the range of whole seconds.
This patch fixes the issue by remembering the UTC offset when assuming
the slave role.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The clock code uses two different variables to store the TAI-UTC
offset. One variable represents the compile time, configuration file,
or command line initial UTC offset, while the other is used when
taking on the GM role and is settable at run time. However, making
this distinction makes no sense. This patch simplifies and clarifies
the code by using a single variable for the offset.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
With rtnl socket we can track link status per port(except UDS port).
We can make sure we get the correct interface and latest status with function
port_link_status().
At the same time we need to set clock sde after link down. But we return
EV_FAULT_DETECTED in port_event(), which will not set clock sde. So we need
to set it in port_link_status().
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
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>