Skip to content

Commit 36050e2

Browse files
johnstultz-workgregkh
authored andcommitted
timekeeping: Fix CLOCK_TAI timer/nanosleep delays
commit 04005f6 upstream. A think-o in the calculation of the monotonic -> tai time offset results in CLOCK_TAI timers and nanosleeps to expire late (the latency is ~2x the tai offset). Fix this by adding the tai offset from the realtime offset instead of subtracting. Cc: Sasha Levin <sasha.levin@oracle.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent de5cfcd commit 36050e2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎kernel/time/timekeeping.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm)
7777
tk->wall_to_monotonic = wtm;
7878
set_normalized_timespec(&tmp, -wtm.tv_sec, -wtm.tv_nsec);
7979
tk->offs_real = timespec_to_ktime(tmp);
80-
tk->offs_tai = ktime_sub(tk->offs_real, ktime_set(tk->tai_offset, 0));
80+
tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tk->tai_offset, 0));
8181
}
8282

8383
static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t)
@@ -595,7 +595,7 @@ s32 timekeeping_get_tai_offset(void)
595595
static void __timekeeping_set_tai_offset(struct timekeeper *tk, s32 tai_offset)
596596
{
597597
tk->tai_offset = tai_offset;
598-
tk->offs_tai = ktime_sub(tk->offs_real, ktime_set(tai_offset, 0));
598+
tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tai_offset, 0));
599599
}
600600

601601
/**

0 commit comments

Comments
 (0)