Lines Matching +full:idle +full:- +full:states
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>
24 * If (MAX_INTERESTING-1) * RESOLUTION > UINT_MAX, the result of
50 * -----------------------
54 * need is a good prediction of how long we'll be idle. Like the traditional
67 * duration; if we expect 500 milliseconds of idle time the likelihood of
69 * seconds of idle time. A second independent factor that has big impact on
78 * Repeatable-interval-detector
79 * ----------------------------
89 * ---------------------------
90 * C states, especially those with large exit latencies, can have a real
96 * The busier the system, the less impact of C states is acceptable
98 * This rule-of-thumb is implemented using a performance-multiplier:
102 * this multiplier is, the longer we need to be idle to pick a deep C
196 unsigned int value = data->intervals[i]; in get_typical_interval()
223 unsigned int value = data->intervals[i]; in get_typical_interval()
225 int64_t diff = (int64_t)value - avg; in get_typical_interval()
265 thresh = max - 1; in get_typical_interval()
270 * menu_select - selects the next idle state to enter
279 int latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
287 if (data->needs_update) { in menu_select()
289 data->needs_update = 0; in menu_select()
293 data->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length(&delta_next)); in menu_select()
295 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
296 data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); in menu_select()
298 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
299 ((data->next_timer_us < drv->states[1].target_residency || in menu_select()
300 latency_req < drv->states[1].exit_latency) && in menu_select()
301 !drv->states[0].disabled && !dev->states_usage[0].disable)) { in menu_select()
307 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
316 predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us * in menu_select()
317 data->correction_factor[data->bucket], in menu_select()
320 * Use the lowest expected idle interval to pick the idle state. in menu_select()
327 * idle duration misprediction is much higher, because the CPU in menu_select()
328 * may be stuck in a shallow idle state for a long time as a in menu_select()
330 * the known time till the closest timer event for the idle in menu_select()
337 * Use the performance multiplier and the user-configurable in menu_select()
346 * Find the idle state with the lowest power while satisfying in menu_select()
349 idx = -1; in menu_select()
350 for (i = 0; i < drv->state_count; i++) { in menu_select()
351 struct cpuidle_state *s = &drv->states[i]; in menu_select()
352 struct cpuidle_state_usage *su = &dev->states_usage[i]; in menu_select()
354 if (s->disabled || su->disable) in menu_select()
357 if (idx == -1) in menu_select()
360 if (s->target_residency > predicted_us) { in menu_select()
362 * Use a physical idle state, not busy polling, unless in menu_select()
365 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
366 s->exit_latency <= latency_req && in menu_select()
367 s->target_residency <= data->next_timer_us) { in menu_select()
368 predicted_us = s->target_residency; in menu_select()
382 predicted_us = drv->states[idx].target_residency; in menu_select()
392 if (drv->states[idx].target_residency < TICK_USEC && in menu_select()
393 s->target_residency <= ktime_to_us(delta_next)) in menu_select()
398 if (s->exit_latency > latency_req) in menu_select()
404 if (idx == -1) in menu_select()
405 idx = 0; /* No states enabled. Must use 0. */ in menu_select()
409 * expected idle duration is shorter than the tick period length. in menu_select()
411 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
417 if (idx > 0 && drv->states[idx].target_residency > delta_next_us) { in menu_select()
424 for (i = idx - 1; i >= 0; i--) { in menu_select()
425 if (drv->states[i].disabled || in menu_select()
426 dev->states_usage[i].disable) in menu_select()
430 if (drv->states[i].target_residency <= delta_next_us) 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_us > TICK_USEC) { 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_us = data->next_timer_us; in menu_update()
507 measured_us = dev->last_residency; in menu_update()
510 if (measured_us > 2 * target->exit_latency) in menu_update()
511 measured_us -= target->exit_latency; in menu_update()
517 if (measured_us > data->next_timer_us) in menu_update()
518 measured_us = data->next_timer_us; 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_us > 0 && measured_us < MAX_INTERESTING) in menu_update()
525 new_factor += RESOLUTION * measured_us / data->next_timer_us; in menu_update()
528 * we were idle so long that we count it as a perfect in menu_update()
542 data->correction_factor[data->bucket] = new_factor; in menu_update()
544 /* update the repeating-pattern data */ in menu_update()
545 data->intervals[data->interval_ptr++] = measured_us; in menu_update()
546 if (data->interval_ptr >= INTERVALS) in menu_update()
547 data->interval_ptr = 0; in menu_update()
551 * menu_enable_device - scans a CPU's states and does setup
558 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
568 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
582 * init_menu - initializes the governor