Lines Matching +full:entry +full:- +full:latency +full:- +full:us
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>
38 * 3) Latency tolerance (from pmqos infrastructure)
42 * -----------------------
43 * C state entry and exit have an energy cost, and a certain amount of time in
45 * provides us this duration in the "target_residency" field. So all that we
70 * Repeatable-interval-detector
71 * ----------------------------
81 * ---------------------------
90 * This rule-of-thumb is implemented using a performance-multiplier:
91 * If the exit latency times the performance multiplier is longer than
129 * This allows us to calculate in which_bucket()
149 * Return a multiplier for the exit latency that is intended
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()
223 * small (stddev <= 20 us, variance <= 400 us^2) or standard 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
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()
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()
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()
323 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); 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()
341 * latency_req to determine the maximum exit latency. 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()
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()
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
445 * the overall exit latency.
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()
470 * Try to figure out how much time passed between entry to low in menu_update()
477 * Any measured amount of time will include the exit latency. in menu_update()
479 * was completed, we must subtract the exit latency. However, if in menu_update()
480 * the measured amount of time is less than the exit latency, in menu_update()
481 * assume the state was never reached and the exit latency is 0. in menu_update()
484 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { 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()
504 measured_ns = data->next_timer_ns; in menu_update()
507 measured_ns = dev->last_residency_ns; in menu_update()
509 /* Deduct exit latency */ 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()
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()
569 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
583 * init_menu - initializes the governor