From c03ceced9a210b48f2552e7dafa9099ef2449370 Mon Sep 17 00:00:00 2001 From: "Gabriel M. Beddingfield" Date: Wed, 4 Oct 2017 08:38:57 -0700 Subject: [PATCH] time: add CONFIG_PERSISTENT_CLOCK_IS_LOW_PRECISION to disable suspend/resume hack Signed-off-by: Gabriel M. Beddingfield Signed-off-by: Guy --- kernel/time/Kconfig | 16 ++++++++++++++++ kernel/time/timekeeping.c | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index ac09bc29eb08..32d54086c96c 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -143,5 +143,21 @@ config HIGH_RES_TIMERS hardware is not capable then this option only increases the size of the kernel image. +config PERSISTENT_CLOCK_IS_LOW_PRECISION + bool "The persistent clock has only single-second precision" + default y + help + When enabled, then on suspend/resume the timekeeping code will + try to maintain a constant offset between the system time and + the persistent clock as a means of compensating for the coarse + (+/- 1 second) sleep time calculation. However, this will discard + any "small" NTP corrections that have happened since the last + resume. However, if the system's persistent clock has better + precision (e.g. because it's backed by a 32kHz clock), this is + not necessary and introduces unneeded time jitter. + + If your persistent clock has only single-second precision, say Y. + If your persistent clock has sub-second precision, say N. + endmenu endif diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 2cafb49aa65e..b2c7b443ef37 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1694,8 +1694,10 @@ int timekeeping_suspend(void) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; +#ifdef CONFIG_PERSISTENT_CLOCK_IS_LOW_PRECISION struct timespec64 delta, delta_delta; static struct timespec64 old_delta; +#endif read_persistent_clock64(&timekeeping_suspend_time); @@ -1712,6 +1714,7 @@ int timekeeping_suspend(void) timekeeping_forward_now(tk); timekeeping_suspended = 1; +#ifdef CONFIG_PERSISTENT_CLOCK_IS_LOW_PRECISION if (persistent_clock_exists) { /* * To avoid drift caused by repeated suspend/resumes, @@ -1733,6 +1736,7 @@ int timekeeping_suspend(void) timespec64_add(timekeeping_suspend_time, delta_delta); } } +#endif timekeeping_update(tk, TK_MIRROR); halt_fast_timekeeper(tk); -- 2.14.2.920.gcf0c67979c-goog