diff options
author | Chang-An Chen <chang-an.chen@mediatek.com> | 2019-03-28 22:59:09 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2019-04-18 08:34:53 -0400 |
commit | 3f2552f7e9c5abef2775c53f7af66532f8bf65bc (patch) | |
tree | 72ecad8294d9fd9c351feda420c37d769cb7bebd | |
parent | 1c09099188501fd9185b58e79f7c46a15301582c (diff) |
timers/sched_clock: Prevent generic sched_clock wrap caused by tick_freeze()
tick_freeze() introduced by suspend-to-idle in commit 124cf9117c5f ("PM /
sleep: Make it possible to quiesce timers during suspend-to-idle") uses
timekeeping_suspend() instead of syscore_suspend() during
suspend-to-idle. As a consequence generic sched_clock will keep going
because sched_clock_suspend() and sched_clock_resume() are not invoked
during suspend-to-idle which can result in a generic sched_clock wrap.
On a ARM system with suspend-to-idle enabled, sched_clock is registered
as "56 bits at 13MHz, resolution 76ns, wraps every 4398046511101ns", which
means the real wrapping duration is 8796093022202ns.
[ 134.551779] suspend-to-idle suspend (timekeeping_suspend())
[ 1204.912239] suspend-to-idle resume (timekeeping_resume())
......
[ 1206.912239] suspend-to-idle suspend (timekeeping_suspend())
[ 5880.502807] suspend-to-idle resume (timekeeping_resume())
......
[ 6000.403724] suspend-to-idle suspend (timekeeping_suspend())
[ 8035.753167] suspend-to-idle resume (timekeeping_resume())
......
[ 8795.786684] (2)[321:charger_thread]......
[ 8795.788387] (2)[321:charger_thread]......
[ 0.057226] (0)[0:swapper/0]......
[ 0.061447] (2)[0:swapper/2]......
sched_clock was not stopped during suspend-to-idle, and sched_clock_poll
hrtimer was not expired because timekeeping_suspend() was invoked during
suspend-to-idle. It makes sched_clock wrap at kernel time 8796s.
To prevent this, invoke sched_clock_suspend() and sched_clock_resume() in
tick_freeze() together with timekeeping_suspend() and timekeeping_resume().
Fixes: 124cf9117c5f (PM / sleep: Make it possible to quiesce timers during suspend-to-idle)
Signed-off-by: Chang-An Chen <chang-an.chen@mediatek.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Corey Minyard <cminyard@mvista.com>
Cc: <linux-mediatek@lists.infradead.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Stanley Chu <stanley.chu@mediatek.com>
Cc: <kuohong.wang@mediatek.com>
Cc: <freddy.hsin@mediatek.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1553828349-8914-1-git-send-email-chang-an.chen@mediatek.com
-rw-r--r-- | kernel/time/sched_clock.c | 4 | ||||
-rw-r--r-- | kernel/time/tick-common.c | 2 | ||||
-rw-r--r-- | kernel/time/timekeeping.h | 7 |
3 files changed, 11 insertions, 2 deletions
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 094b82ca95e5..930113b9799a 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c | |||
@@ -272,7 +272,7 @@ static u64 notrace suspended_sched_clock_read(void) | |||
272 | return cd.read_data[seq & 1].epoch_cyc; | 272 | return cd.read_data[seq & 1].epoch_cyc; |
273 | } | 273 | } |
274 | 274 | ||
275 | static int sched_clock_suspend(void) | 275 | int sched_clock_suspend(void) |
276 | { | 276 | { |
277 | struct clock_read_data *rd = &cd.read_data[0]; | 277 | struct clock_read_data *rd = &cd.read_data[0]; |
278 | 278 | ||
@@ -283,7 +283,7 @@ static int sched_clock_suspend(void) | |||
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | 285 | ||
286 | static void sched_clock_resume(void) | 286 | void sched_clock_resume(void) |
287 | { | 287 | { |
288 | struct clock_read_data *rd = &cd.read_data[0]; | 288 | struct clock_read_data *rd = &cd.read_data[0]; |
289 | 289 | ||
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 529143b4c8d2..df401463a191 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c | |||
@@ -487,6 +487,7 @@ void tick_freeze(void) | |||
487 | trace_suspend_resume(TPS("timekeeping_freeze"), | 487 | trace_suspend_resume(TPS("timekeeping_freeze"), |
488 | smp_processor_id(), true); | 488 | smp_processor_id(), true); |
489 | system_state = SYSTEM_SUSPEND; | 489 | system_state = SYSTEM_SUSPEND; |
490 | sched_clock_suspend(); | ||
490 | timekeeping_suspend(); | 491 | timekeeping_suspend(); |
491 | } else { | 492 | } else { |
492 | tick_suspend_local(); | 493 | tick_suspend_local(); |
@@ -510,6 +511,7 @@ void tick_unfreeze(void) | |||
510 | 511 | ||
511 | if (tick_freeze_depth == num_online_cpus()) { | 512 | if (tick_freeze_depth == num_online_cpus()) { |
512 | timekeeping_resume(); | 513 | timekeeping_resume(); |
514 | sched_clock_resume(); | ||
513 | system_state = SYSTEM_RUNNING; | 515 | system_state = SYSTEM_RUNNING; |
514 | trace_suspend_resume(TPS("timekeeping_freeze"), | 516 | trace_suspend_resume(TPS("timekeeping_freeze"), |
515 | smp_processor_id(), false); | 517 | smp_processor_id(), false); |
diff --git a/kernel/time/timekeeping.h b/kernel/time/timekeeping.h index 7a9b4eb7a1d5..141ab3ab0354 100644 --- a/kernel/time/timekeeping.h +++ b/kernel/time/timekeeping.h | |||
@@ -14,6 +14,13 @@ extern u64 timekeeping_max_deferment(void); | |||
14 | extern void timekeeping_warp_clock(void); | 14 | extern void timekeeping_warp_clock(void); |
15 | extern int timekeeping_suspend(void); | 15 | extern int timekeeping_suspend(void); |
16 | extern void timekeeping_resume(void); | 16 | extern void timekeeping_resume(void); |
17 | #ifdef CONFIG_GENERIC_SCHED_CLOCK | ||
18 | extern int sched_clock_suspend(void); | ||
19 | extern void sched_clock_resume(void); | ||
20 | #else | ||
21 | static inline int sched_clock_suspend(void) { return 0; } | ||
22 | static inline void sched_clock_resume(void) { } | ||
23 | #endif | ||
17 | 24 | ||
18 | extern void do_timer(unsigned long ticks); | 25 | extern void do_timer(unsigned long ticks); |
19 | extern void update_wall_time(void); | 26 | extern void update_wall_time(void); |