Lines Matching +full:idle +full:- +full:state

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>
33 * state:
40 * -----------------------
41 * C state entry and exit have an energy cost, and a certain amount of time in
42 * the C state is required to actually break even on this cost. CPUIDLE
44 * need is a good prediction of how long we'll be idle. Like the traditional
57 * duration; if we expect 500 milliseconds of idle time the likelihood of
59 * seconds of idle time. A second independent factor that has big impact on
68 * Repeatable-interval-detector
69 * ----------------------------
79 * ---------------------------
88 * This rule-of-thumb is implemented using a performance-multiplier:
90 * the predicted duration, the C state is not considered a candidate
92 * this multiplier is, the longer we need to be idle to pick a deep C
93 * state, and thus the less likely a busy CPU will hit such a deep
94 * C state.
151 * the barrier to go to an expensive C state.
186 unsigned int value = data->intervals[i]; in get_typical_interval()
213 unsigned int value = data->intervals[i]; in get_typical_interval()
215 int64_t diff = (int64_t)value - avg; in get_typical_interval()
255 thresh = max - 1; in get_typical_interval()
260 * menu_select - selects the next idle state to enter
261 * @drv: cpuidle driver containing state data
269 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
277 if (data->needs_update) { in menu_select()
279 data->needs_update = 0; in menu_select()
283 data->next_timer_ns = tick_nohz_get_sleep_length(&delta_next); in menu_select()
285 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
286 data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); in menu_select()
288 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
289 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
290 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
291 !dev->states_usage[0].disable)) { in menu_select()
293 * In this case state[0] will be used no matter what, so return in menu_select()
294 * it right away and keep the tick running if state[0] is a in menu_select()
297 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
302 predicted_us = div_u64(data->next_timer_ns * in menu_select()
303 data->correction_factor[data->bucket] + in menu_select()
306 /* Use the lowest expected idle interval to pick the idle state. */ in menu_select()
314 * idle duration misprediction is much higher, because the CPU in menu_select()
315 * may be stuck in a shallow idle state for a long time as a in menu_select()
317 * the known time till the closest timer event for the idle in menu_select()
318 * state selection. in menu_select()
324 * Use the performance multiplier and the user-configurable in menu_select()
334 * Find the idle state with the lowest power while satisfying in menu_select()
337 idx = -1; in menu_select()
338 for (i = 0; i < drv->state_count; i++) { in menu_select()
339 struct cpuidle_state *s = &drv->states[i]; in menu_select()
341 if (dev->states_usage[i].disable) in menu_select()
344 if (idx == -1) in menu_select()
345 idx = i; /* first enabled state */ in menu_select()
347 if (s->target_residency_ns > predicted_ns) { in menu_select()
349 * Use a physical idle state, not busy polling, unless in menu_select()
352 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
353 s->exit_latency_ns <= latency_req && in menu_select()
354 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
355 predicted_ns = s->target_residency_ns; in menu_select()
364 * If the state selected so far is shallow, in menu_select()
369 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
374 * If the state selected so far is shallow and this in menu_select()
375 * state's target residency matches the time till the in menu_select()
379 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
380 s->target_residency_ns <= delta_next) in menu_select()
385 if (s->exit_latency_ns > latency_req) in menu_select()
391 if (idx == -1) in menu_select()
395 * Don't stop the tick if the selected state is a polling one or if the in menu_select()
396 * expected idle duration is shorter than the tick period length. in menu_select()
398 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
402 if (idx > 0 && drv->states[idx].target_residency_ns > delta_next) { in menu_select()
405 * residency of the state to be returned is not within in menu_select()
409 for (i = idx - 1; i >= 0; i--) { in menu_select()
410 if (dev->states_usage[i].disable) in menu_select()
414 if (drv->states[i].target_residency_ns <= delta_next) in menu_select()
424 * menu_reflect - records that data structures need update
426 * @index: the index of actual entered state
435 dev->last_state_idx = index; in menu_reflect()
436 data->needs_update = 1; in menu_reflect()
437 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
441 * menu_update - attempts to guess what happened after entry
442 * @drv: cpuidle driver containing state data
448 int last_idx = dev->last_state_idx; in menu_update()
449 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
455 * power state and occurrence of the wakeup event. in menu_update()
457 * If the entered idle state didn't support residency measurements, in menu_update()
465 * assume the state was never reached and the exit latency is 0. in menu_update()
468 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
471 * the tick boundary (if the tick was stopped), but the idle in menu_update()
475 * have been idle long (but not forever) to help the idle in menu_update()
479 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
480 dev->poll_time_limit) { in menu_update()
482 * The CPU exited the "polling" state due to a time limit, so in menu_update()
483 * the idle duration prediction leading to the selection of that in menu_update()
484 * state was inaccurate. If a better prediction had been made, in menu_update()
485 * the CPU might have been woken up from idle by the next timer. in menu_update()
488 measured_ns = data->next_timer_ns; in menu_update()
491 measured_ns = dev->last_residency_ns; in menu_update()
494 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
495 measured_ns -= target->exit_latency_ns; in menu_update()
501 if (measured_ns > data->next_timer_ns) in menu_update()
502 measured_ns = data->next_timer_ns; in menu_update()
505 new_factor = data->correction_factor[data->bucket]; in menu_update()
506 new_factor -= new_factor / DECAY; in menu_update()
508 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
510 data->next_timer_ns); in menu_update()
513 * we were idle so long that we count it as a perfect in menu_update()
527 data->correction_factor[data->bucket] = new_factor; in menu_update()
529 /* update the repeating-pattern data */ in menu_update()
530 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
531 if (data->interval_ptr >= INTERVALS) in menu_update()
532 data->interval_ptr = 0; in menu_update()
536 * menu_enable_device - scans a CPU's states and does setup
543 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
553 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
567 * init_menu - initializes the governor