Lines Matching +full:no +full:- +full:idle
1 // SPDX-License-Identifier: GPL-2.0-only
3 * menu.c - the menu idle governor
5 * Copyright (C) 2006-2007 Adam Belay <abelay@novell.com>
39 * -----------------------
43 * need is a good prediction of how long we'll be idle. Like the traditional
56 * expect 500 milliseconds of idle time the likelihood of getting an interrupt
57 * very early is much higher than if we expect 50 micro seconds of idle time.
61 * Repeatable-interval-detector
62 * ----------------------------
102 /* Update the repeating-pattern data. */ in menu_update_intervals()
103 data->intervals[data->interval_ptr++] = interval_us; in menu_update_intervals()
104 if (data->interval_ptr >= INTERVALS) in menu_update_intervals()
105 data->interval_ptr = 0; in menu_update_intervals()
118 s64 value, min_thresh = -1, max_thresh = UINT_MAX; in get_typical_interval()
131 value = data->intervals[i]; in get_typical_interval()
163 variance -= avg_sq; in get_typical_interval()
175 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
193 * any more outliers, allow the deepest available idle state to be in get_typical_interval()
195 * deep idle states is correlated to the maximum frequency the CPUs in get_typical_interval()
196 * can get to. On those systems, shallow idle states should be avoided in get_typical_interval()
204 if (avg - min > max - avg) in get_typical_interval()
213 * menu_select - selects the next idle state to enter
222 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
227 if (data->needs_update) { in menu_select()
229 data->needs_update = 0; in menu_select()
230 } else if (!dev->last_residency_ns) { in menu_select()
233 * idle state and returns an error, so update the recent in menu_select()
240 /* Find the shortest expected idle interval. */ in menu_select()
252 data->next_timer_ns = delta; in menu_select()
253 data->bucket = which_bucket(data->next_timer_ns); in menu_select()
257 data->next_timer_ns * in menu_select()
258 data->correction_factor[data->bucket], in menu_select()
260 /* Use the lowest expected idle interval to pick the idle state. */ in menu_select()
269 data->next_timer_ns = KTIME_MAX; in menu_select()
271 data->bucket = BUCKETS - 1; in menu_select()
274 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
275 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
276 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
277 !dev->states_usage[0].disable)) { in menu_select()
279 * In this case state[0] will be used no matter what, so return in menu_select()
283 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
288 * If the tick is already stopped, the cost of possible short idle in menu_select()
290 * in a shallow idle state for a long time as a result of it. In that in menu_select()
292 * timer event for the idle state selection. in menu_select()
295 predicted_ns = data->next_timer_ns; in menu_select()
298 * Find the idle state with the lowest power while satisfying in menu_select()
301 idx = -1; in menu_select()
302 for (i = 0; i < drv->state_count; i++) { in menu_select()
303 struct cpuidle_state *s = &drv->states[i]; in menu_select()
305 if (dev->states_usage[i].disable) in menu_select()
308 if (idx == -1) in menu_select()
311 if (s->exit_latency_ns > latency_req) in menu_select()
314 if (s->target_residency_ns <= predicted_ns) { in menu_select()
320 * Use a physical idle state, not busy polling, unless a timer in menu_select()
322 * idle state in question is greater than the predicted idle in menu_select()
325 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
326 s->target_residency_ns <= data->next_timer_ns && in menu_select()
327 s->exit_latency_ns <= predicted_ns) { in menu_select()
328 predicted_ns = s->target_residency_ns; in menu_select()
341 * the idle loop. in menu_select()
343 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
353 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
354 s->target_residency_ns <= delta_tick) in menu_select()
360 if (idx == -1) in menu_select()
361 idx = 0; /* No states enabled. Must use 0. */ in menu_select()
365 * expected idle duration is shorter than the tick period length. in menu_select()
367 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
371 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
378 for (i = idx - 1; i >= 0; i--) { in menu_select()
379 if (dev->states_usage[i].disable) in menu_select()
383 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
393 * menu_reflect - records that data structures need update
404 dev->last_state_idx = index; in menu_reflect()
405 data->needs_update = 1; in menu_reflect()
406 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
410 * menu_update - attempts to guess what happened after entry
417 int last_idx = dev->last_state_idx; in menu_update()
418 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
426 * If the entered idle state didn't support residency measurements, in menu_update()
437 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
440 * the tick boundary (if the tick was stopped), but the idle in menu_update()
444 * have been idle long (but not forever) to help the idle in menu_update()
448 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
449 dev->poll_time_limit) { in menu_update()
452 * the idle duration prediction leading to the selection of that in menu_update()
454 * the CPU might have been woken up from idle by the next timer. in menu_update()
457 measured_ns = data->next_timer_ns; in menu_update()
460 measured_ns = dev->last_residency_ns; in menu_update()
463 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
464 measured_ns -= target->exit_latency_ns; in menu_update()
470 if (measured_ns > data->next_timer_ns) in menu_update()
471 measured_ns = data->next_timer_ns; in menu_update()
474 new_factor = data->correction_factor[data->bucket]; in menu_update()
475 new_factor -= new_factor / DECAY; in menu_update()
477 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
479 data->next_timer_ns); in menu_update()
482 * we were idle so long that we count it as a perfect in menu_update()
496 data->correction_factor[data->bucket] = new_factor; in menu_update()
502 * menu_enable_device - scans a CPU's states and does setup
509 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
519 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
533 * init_menu - initializes the governor