Skip to content

Commit f9fccdb

Browse files
Peter Zijlstraingomolnar
authored andcommitted
cpuidle: Fix idle time tracking
Ville reported that on his Core2, which has TSC stop in idle, we would always report very short idle durations. He tracked this down to commit: e93e59c ("cpuidle: Replace ktime_get() with local_clock()") which replaces ktime_get() with local_clock(). Add a sched_clock_idle_wakeup_event() call, which will re-sync the clock with ktime_get_ns() when TSC is unstable and no-op otherwise. Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Tested-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Fixes: e93e59c ("cpuidle: Replace ktime_get() with local_clock()") Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3067a33 commit f9fccdb

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
220220
entered_state = target_state->enter(dev, drv, index);
221221
start_critical_timings();
222222

223+
sched_clock_idle_wakeup_event();
223224
time_end = ns_to_ktime(local_clock());
224225
trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
225226

‎kernel/sched/clock.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,21 @@ void sched_clock_idle_sleep_event(void)
410410
EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event);
411411

412412
/*
413-
* We just idled; resync with ktime. (called with irqs disabled):
413+
* We just idled; resync with ktime.
414414
*/
415415
void sched_clock_idle_wakeup_event(void)
416416
{
417-
if (timekeeping_suspended)
417+
unsigned long flags;
418+
419+
if (sched_clock_stable())
420+
return;
421+
422+
if (unlikely(timekeeping_suspended))
418423
return;
419424

425+
local_irq_save(flags);
420426
sched_clock_tick();
427+
local_irq_restore(flags);
421428
}
422429
EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
423430

0 commit comments

Comments
 (0)