Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0209b937 authored by Thomas Graziadei's avatar Thomas Graziadei Committed by John Stultz
Browse files

timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD



The user notices the problem in a raw and real time drift, calling
clock_gettime with CLOCK_REALTIME / CLOCK_MONOTONIC_RAW on a system
with no ntp correction taking place (no ntpd or ptp stuff running).

The problem is, that old_vsyscall_fixup adds an extra 1ns even though
xtime_nsec is already held in full nsecs and the remainder in this
case is 0. Do the rounding up buisness only if needed.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: default avatarThomas Graziadei <thomas.graziadei@omicronenergy.com>
Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
parent 0fb71d34
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -480,11 +480,13 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk)
	* users are removed, this can be killed.
	* users are removed, this can be killed.
	*/
	*/
	remainder = tk->tkr_mono.xtime_nsec & ((1ULL << tk->tkr_mono.shift) - 1);
	remainder = tk->tkr_mono.xtime_nsec & ((1ULL << tk->tkr_mono.shift) - 1);
	if (remainder != 0) {
		tk->tkr_mono.xtime_nsec -= remainder;
		tk->tkr_mono.xtime_nsec -= remainder;
		tk->tkr_mono.xtime_nsec += 1ULL << tk->tkr_mono.shift;
		tk->tkr_mono.xtime_nsec += 1ULL << tk->tkr_mono.shift;
		tk->ntp_error += remainder << tk->ntp_error_shift;
		tk->ntp_error += remainder << tk->ntp_error_shift;
		tk->ntp_error -= (1ULL << tk->tkr_mono.shift) << tk->ntp_error_shift;
		tk->ntp_error -= (1ULL << tk->tkr_mono.shift) << tk->ntp_error_shift;
	}
	}
}
#else
#else
#define old_vsyscall_fixup(tk)
#define old_vsyscall_fixup(tk)
#endif
#endif