From fa575b60f6a9757bca8f2828e23633560d57bac3 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 22 Jul 2017 22:30:10 +0200 Subject: [PATCH] Latch the UTC offset. 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 --- 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)