BACKPORT: time: Fix CLOCK_MONOTONIC_RAW sub-nanosecond accounting
authorJohn Stultz <john.stultz@linaro.org>
Thu, 8 Jun 2017 23:44:21 +0000 (16:44 -0700)
committerMark Salyzyn <salyzyn@google.com>
Wed, 29 Nov 2017 21:35:07 +0000 (13:35 -0800)
commit28850c79d071b4eef0001bb76af2cfb29402f4ac
treec4afbe8bb14fc8d082fc0c033689de50f83326eb
parent67a8ab4adc2d30e3f3442a0659b887b4da83f7c2
BACKPORT: time: Fix CLOCK_MONOTONIC_RAW sub-nanosecond accounting

(cherry pick from commit 3d88d56c5873f6eebe23e05c3da701960146b801)

Due to how the MONOTONIC_RAW accumulation logic was handled,
there is the potential for a 1ns discontinuity when we do
accumulations. This small discontinuity has for the most part
gone un-noticed, but since ARM64 enabled CLOCK_MONOTONIC_RAW
in their vDSO clock_gettime implementation, we've seen failures
with the inconsistency-check test in kselftest.

This patch addresses the issue by using the same sub-ns
accumulation handling that CLOCK_MONOTONIC uses, which avoids
the issue for in-kernel users.

Since the ARM64 vDSO implementation has its own clock_gettime
calculation logic, this patch reduces the frequency of errors,
but failures are still seen. The ARM64 vDSO will need to be
updated to include the sub-nanosecond xtime_nsec values in its
calculation for this issue to be completely fixed.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Tested-by: Daniel Mentz <danielmentz@google.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Stephen Boyd <stephen.boyd@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: "stable #4 . 8+" <stable@vger.kernel.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Link: http://lkml.kernel.org/r/1496965462-20003-3-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Bug: 20045882
Bug: 63737556
Change-Id: I6c55dd7685f6bd212c6af9d09c527528e1dd5fa1
include/linux/timekeeper_internal.h
kernel/time/timekeeping.c