Commit 5f26bdce authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

cpuidle: menu: Fix wakeup statistics updates for polling state

If the CPU exits the "polling" state due to the time limit in the
loop in poll_idle(), this is not a real wakeup and it just means
that the "polling" state selection was not adequate.  The governor
mispredicted short idle duration, but had a more suitable state been
selected, the CPU might have spent more time in it.  In fact, there
is no reason to expect that there would have been a wakeup event
earlier than the next timer in that case.

Handling such cases as regular wakeups in menu_update() may cause the
menu governor to make suboptimal decisions going forward, but ignoring
them altogether would not be correct either, because every time
menu_select() is invoked, it makes a separate new attempt to predict
the idle duration taking distinct time to the closest timer event as
input and the outcomes of all those attempts should be recorded.

For this reason, make menu_update() always assume that if the
"polling" state was exited due to the time limit, the next proper
wakeup event for the CPU would be the next timer event (not
including the tick).

Fixes: a37b969a "cpuidle: poll_state: Add time limit to poll_idle()"
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent 03dba278
...@@ -511,6 +511,16 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) ...@@ -511,6 +511,16 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
* duration predictor do a better job next time. * duration predictor do a better job next time.
*/ */
measured_us = 9 * MAX_INTERESTING / 10; measured_us = 9 * MAX_INTERESTING / 10;
} else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) &&
dev->poll_time_limit) {
/*
* The CPU exited the "polling" state due to a time limit, so
* the idle duration prediction leading to the selection of that
* state was inaccurate. If a better prediction had been made,
* the CPU might have been woken up from idle by the next timer.
* Assume that to be the case.
*/
measured_us = data->next_timer_us;
} else { } else {
/* measured value */ /* measured value */
measured_us = dev->last_residency; measured_us = dev->last_residency;
......
...@@ -17,6 +17,8 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev, ...@@ -17,6 +17,8 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,
{ {
u64 time_start = local_clock(); u64 time_start = local_clock();
dev->poll_time_limit = false;
local_irq_enable(); local_irq_enable();
if (!current_set_polling_and_test()) { if (!current_set_polling_and_test()) {
unsigned int loop_count = 0; unsigned int loop_count = 0;
...@@ -27,10 +29,12 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev, ...@@ -27,10 +29,12 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,
continue; continue;
loop_count = 0; loop_count = 0;
if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT) if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT) {
dev->poll_time_limit = true;
break; break;
} }
} }
}
current_clr_polling(); current_clr_polling();
return index; return index;
......
...@@ -81,6 +81,7 @@ struct cpuidle_device { ...@@ -81,6 +81,7 @@ struct cpuidle_device {
unsigned int registered:1; unsigned int registered:1;
unsigned int enabled:1; unsigned int enabled:1;
unsigned int use_deepest_state:1; unsigned int use_deepest_state:1;
unsigned int poll_time_limit:1;
unsigned int cpu; unsigned int cpu;
int last_residency; int last_residency;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment