Lines Matching +full:no +full:- +full:idle +full:- +full:on +full:- +full:init
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>
42 * -----------------------
44 * the C state is required to actually break even on this cost. CPUIDLE
46 * need is a good prediction of how long we'll be idle. Like the traditional
52 * that is based on historic behavior. For example, if in the past the actual
58 * that the ratio is dependent on the order of magnitude of the expected
59 * duration; if we expect 500 milliseconds of idle time the likelihood of
61 * seconds of idle time. A second independent factor that has big impact on
64 * as perfect; there are no power gains for sleeping longer than this)
67 * indexed based on the magnitude of the expected duration as well as the
70 * Repeatable-interval-detector
71 * ----------------------------
81 * ---------------------------
83 * noticeable impact on workloads, which is not acceptable for most sysadmins,
90 * This rule-of-thumb is implemented using a performance-multiplier:
94 * this multiplier is, the longer we need to be idle to pick a deep C
101 * IO on this CPU.
127 * We keep two groups of stats; one with no in which_bucket()
187 unsigned int value = data->intervals[i]; in get_typical_interval()
210 unsigned int value = data->intervals[i]; in get_typical_interval()
212 int64_t diff = (int64_t)value - avg; in get_typical_interval()
231 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
252 thresh = max - 1; in get_typical_interval()
257 * menu_select - selects the next idle state to enter
260 * @stop_tick: indication on whether or not to stop the tick
266 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
273 if (data->needs_update) { in menu_select()
275 data->needs_update = 0; in menu_select()
278 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
280 /* Find the shortest expected idle interval. */ in menu_select()
292 data->next_timer_ns = delta; in menu_select()
293 data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); in menu_select()
297 data->next_timer_ns * in menu_select()
298 data->correction_factor[data->bucket], in menu_select()
300 /* Use the lowest expected idle interval to pick the idle state. */ in menu_select()
309 data->next_timer_ns = KTIME_MAX; in menu_select()
311 data->bucket = which_bucket(KTIME_MAX, nr_iowaiters); in menu_select()
314 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
315 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
316 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
317 !dev->states_usage[0].disable)) { in menu_select()
319 * In this case state[0] will be used no matter what, so return in menu_select()
323 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
330 * idle duration misprediction is much higher, because the CPU in menu_select()
331 * may be stuck in a shallow idle state for a long time as a in menu_select()
333 * the known time till the closest timer event for the idle in menu_select()
337 predicted_ns = data->next_timer_ns; in menu_select()
340 * Use the performance multiplier and the user-configurable in menu_select()
350 * Find the idle state with the lowest power while satisfying in menu_select()
353 idx = -1; in menu_select()
354 for (i = 0; i < drv->state_count; i++) { in menu_select()
355 struct cpuidle_state *s = &drv->states[i]; in menu_select()
357 if (dev->states_usage[i].disable) in menu_select()
360 if (idx == -1) in menu_select()
363 if (s->target_residency_ns > predicted_ns) { in menu_select()
365 * Use a physical idle state, not busy polling, unless in menu_select()
368 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
369 s->exit_latency_ns <= latency_req && in menu_select()
370 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
371 predicted_ns = s->target_residency_ns; in menu_select()
385 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
395 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
396 s->target_residency_ns <= delta_tick) in menu_select()
401 if (s->exit_latency_ns > latency_req) in menu_select()
407 if (idx == -1) in menu_select()
408 idx = 0; /* No states enabled. Must use 0. */ in menu_select()
412 * expected idle duration is shorter than the tick period length. in menu_select()
414 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
418 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
425 for (i = idx - 1; i >= 0; i--) { in menu_select()
426 if (dev->states_usage[i].disable) in menu_select()
430 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
440 * menu_reflect - records that data structures need update
451 dev->last_state_idx = index; in menu_reflect()
452 data->needs_update = 1; in menu_reflect()
453 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
457 * menu_update - attempts to guess what happened after entry
464 int last_idx = dev->last_state_idx; in menu_update()
465 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
473 * If the entered idle state didn't support residency measurements, in menu_update()
484 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
487 * the tick boundary (if the tick was stopped), but the idle in menu_update()
491 * have been idle long (but not forever) to help the idle in menu_update()
495 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
496 dev->poll_time_limit) { in menu_update()
499 * the idle duration prediction leading to the selection of that in menu_update()
501 * the CPU might have been woken up from idle by the next timer. in menu_update()
504 measured_ns = data->next_timer_ns; in menu_update()
507 measured_ns = dev->last_residency_ns; in menu_update()
510 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
511 measured_ns -= target->exit_latency_ns; in menu_update()
517 if (measured_ns > data->next_timer_ns) in menu_update()
518 measured_ns = data->next_timer_ns; in menu_update()
521 new_factor = data->correction_factor[data->bucket]; in menu_update()
522 new_factor -= new_factor / DECAY; in menu_update()
524 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
526 data->next_timer_ns); in menu_update()
529 * we were idle so long that we count it as a perfect in menu_update()
543 data->correction_factor[data->bucket] = new_factor; in menu_update()
545 /* update the repeating-pattern data */ in menu_update()
546 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
547 if (data->interval_ptr >= INTERVALS) in menu_update()
548 data->interval_ptr = 0; in menu_update()
552 * menu_enable_device - scans a CPU's states and does setup
559 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
565 * if the correction factor is 0 (eg first time init or cpu hotplug in menu_enable_device()
569 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
583 * init_menu - initializes the governor