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 <[email protected]>
---
 clock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clock.c b/clock.c
index aa1a5df..da1fcc4 100644
--- a/clock.c
+++ b/clock.c
@@ -658,6 +658,11 @@ static void clock_update_slave(struct clock *c)
        if (c->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)) {
+               pr_info("updating UTC offset to %d", c->tds.currentUtcOffset);
+               c->utc_offset = c->tds.currentUtcOffset;
+       }
 }
 
 static int clock_utc_correct(struct clock *c, tmv_t ingress)
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to