When the master updated the UTC offset and leap flags in an announce
message after a leap second, only the new flags were accepted for
synchronization of the local clock, which caused a one-second error to
appear until a state decision event updated the UTC offset. Before
commit 14a97dc5da47 ("Remove redundant test on the UTC flags."), the UTC
offset was taken directly from the clock's timePropertiesDS.

Move the update of the UTC offset from clock_update_slave() to
clock_update_time_properties() to enable a synchronous update of the
flags and offset on any announce message.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
Fixes: 14a97dc5da47 ("Remove redundant test on the UTC flags.")
---
 clock.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/clock.c b/clock.c
index ec70f91..f3aa616 100644
--- a/clock.c
+++ b/clock.c
@@ -684,6 +684,7 @@ static void clock_update_grandmaster(struct clock *c)
 static void clock_update_slave(struct clock *c)
 {
        struct parentDS *pds = &c->dad.pds;
+       struct timePropertiesDS tds;
        struct ptp_message *msg;
 
        if (!c->best)
@@ -696,21 +697,16 @@ static void clock_update_slave(struct clock *c)
        pds->grandmasterClockQuality   = msg->announce.grandmasterClockQuality;
        pds->grandmasterPriority1      = msg->announce.grandmasterPriority1;
        pds->grandmasterPriority2      = msg->announce.grandmasterPriority2;
-       c->tds.currentUtcOffset        = msg->announce.currentUtcOffset;
-       c->tds.flags                   = msg->header.flagField[1];
-       c->tds.timeSource              = msg->announce.timeSource;
-       if (!(c->tds.flags & PTP_TIMESCALE)) {
+       tds.currentUtcOffset           = msg->announce.currentUtcOffset;
+       tds.flags                      = msg->header.flagField[1];
+       tds.timeSource                 = msg->announce.timeSource;
+       if (!(tds.flags & PTP_TIMESCALE)) {
                pr_warning("foreign master not using PTP timescale");
        }
-       if (c->tds.currentUtcOffset < c->utc_offset) {
+       if (tds.currentUtcOffset < c->utc_offset) {
                pr_warning("running in a temporal vortex");
        }
-       if (((c->tds.flags & UTC_OFF_VALID && c->tds.flags & TIME_TRACEABLE) &&
-           (c->tds.currentUtcOffset != c->utc_offset)) ||
-           (c->tds.currentUtcOffset > c->utc_offset)) {
-               pr_info("updating UTC offset to %d", c->tds.currentUtcOffset);
-               c->utc_offset = c->tds.currentUtcOffset;
-       }
+       clock_update_time_properties(c, tds);
 }
 
 static int clock_utc_correct(struct clock *c, tmv_t ingress)
@@ -1916,6 +1912,13 @@ struct timePropertiesDS clock_time_properties(struct 
clock *c)
 
 void clock_update_time_properties(struct clock *c, struct timePropertiesDS tds)
 {
+       if ((tds.flags & UTC_OFF_VALID && tds.flags & TIME_TRACEABLE &&
+            tds.currentUtcOffset != c->utc_offset) ||
+           tds.currentUtcOffset > c->utc_offset) {
+               pr_info("updating UTC offset to %d", tds.currentUtcOffset);
+               c->utc_offset = tds.currentUtcOffset;
+       }
+
        c->tds = tds;
 }
 
-- 
2.26.3



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to