Skip to content

Commit 87c9fe6

Browse files
committed
cpuidle: menu: Avoid selecting shallow states with stopped tick
If the scheduler tick has been stopped already and the governor selects a shallow idle state, the CPU can spend a long time in that state if the selection is based on an inaccurate prediction of idle time. That effect turns out to be relevant, so it needs to be mitigated. To that end, modify the menu governor to discard the result of the idle time prediction if the tick is stopped and the predicted idle time is less than the tick period length, unless the tick timer is going to expire soon. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
1 parent 296bb1e commit 87c9fe6

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

  • drivers/cpuidle/governors

‎drivers/cpuidle/governors/menu.c‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,28 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
352352
*/
353353
data->predicted_us = min(data->predicted_us, expected_interval);
354354

355-
/*
356-
* Use the performance multiplier and the user-configurable
357-
* latency_req to determine the maximum exit latency.
358-
*/
359-
interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load);
360-
if (latency_req > interactivity_req)
361-
latency_req = interactivity_req;
355+
if (tick_nohz_tick_stopped()) {
356+
/*
357+
* If the tick is already stopped, the cost of possible short
358+
* idle duration misprediction is much higher, because the CPU
359+
* may be stuck in a shallow idle state for a long time as a
360+
* result of it. In that case say we might mispredict and try
361+
* to force the CPU into a state for which we would have stopped
362+
* the tick, unless a timer is going to expire really soon
363+
* anyway.
364+
*/
365+
if (data->predicted_us < TICK_USEC)
366+
data->predicted_us = min_t(unsigned int, TICK_USEC,
367+
ktime_to_us(delta_next));
368+
} else {
369+
/*
370+
* Use the performance multiplier and the user-configurable
371+
* latency_req to determine the maximum exit latency.
372+
*/
373+
interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load);
374+
if (latency_req > interactivity_req)
375+
latency_req = interactivity_req;
376+
}
362377

363378
expected_interval = data->predicted_us;
364379
/*

0 commit comments

Comments
 (0)