Lines Matching +full:min +full:- +full:residency +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>
40 * -----------------------
43 * provides us this duration in the "target_residency" field. So all that we
68 * Repeatable-interval-detector
69 * ----------------------------
79 * ---------------------------
88 * This rule-of-thumb is implemented using a performance-multiplier:
122 * This allows us to calculate in which_bucket()
167 unsigned int min, max, thresh, avg; in get_typical_interval() local
175 min = UINT_MAX; in get_typical_interval()
180 unsigned int value = data->intervals[i]; in get_typical_interval()
187 if (value < min) in get_typical_interval()
188 min = value; in get_typical_interval()
203 unsigned int value = data->intervals[i]; in get_typical_interval()
205 int64_t diff = (int64_t)value - avg; in get_typical_interval()
216 * small (stddev <= 20 us, variance <= 400 us^2) or standard in get_typical_interval()
224 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
245 thresh = max - 1; in get_typical_interval()
250 * menu_select - selects the next idle state to enter
259 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
266 if (data->needs_update) { in menu_select()
268 data->needs_update = 0; in menu_select()
271 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
285 data->next_timer_ns = delta; in menu_select()
286 data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); in menu_select()
290 data->next_timer_ns * in menu_select()
291 data->correction_factor[data->bucket], in menu_select()
294 predicted_ns = min((u64)timer_us * NSEC_PER_USEC, predicted_ns); in menu_select()
302 data->next_timer_ns = KTIME_MAX; in menu_select()
304 data->bucket = which_bucket(KTIME_MAX, nr_iowaiters); in menu_select()
307 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
308 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
309 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
310 !dev->states_usage[0].disable)) { in menu_select()
316 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
330 predicted_ns = data->next_timer_ns; in menu_select()
333 * Use the performance multiplier and the user-configurable in menu_select()
346 idx = -1; in menu_select()
347 for (i = 0; i < drv->state_count; i++) { in menu_select()
348 struct cpuidle_state *s = &drv->states[i]; in menu_select()
350 if (dev->states_usage[i].disable) in menu_select()
353 if (idx == -1) in menu_select()
356 if (s->target_residency_ns > predicted_ns) { in menu_select()
361 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
362 s->exit_latency_ns <= latency_req && in menu_select()
363 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
364 predicted_ns = s->target_residency_ns; in menu_select()
378 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
384 * state's target residency matches the time till the in menu_select()
388 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
389 s->target_residency_ns <= delta_tick) in menu_select()
394 if (s->exit_latency_ns > latency_req) in menu_select()
400 if (idx == -1) in menu_select()
407 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
411 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
414 * residency of the state to be returned is not within in menu_select()
418 for (i = idx - 1; i >= 0; i--) { in menu_select()
419 if (dev->states_usage[i].disable) in menu_select()
423 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
433 * menu_reflect - records that data structures need update
444 dev->last_state_idx = index; in menu_reflect()
445 data->needs_update = 1; in menu_reflect()
446 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
450 * menu_update - attempts to guess what happened after entry
457 int last_idx = dev->last_state_idx; in menu_update()
458 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
466 * If the entered idle state didn't support residency measurements, in menu_update()
477 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
488 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
489 dev->poll_time_limit) { in menu_update()
497 measured_ns = data->next_timer_ns; in menu_update()
500 measured_ns = dev->last_residency_ns; in menu_update()
503 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
504 measured_ns -= target->exit_latency_ns; in menu_update()
510 if (measured_ns > data->next_timer_ns) in menu_update()
511 measured_ns = data->next_timer_ns; in menu_update()
514 new_factor = data->correction_factor[data->bucket]; in menu_update()
515 new_factor -= new_factor / DECAY; in menu_update()
517 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
519 data->next_timer_ns); in menu_update()
536 data->correction_factor[data->bucket] = new_factor; in menu_update()
538 /* update the repeating-pattern data */ in menu_update()
539 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
540 if (data->interval_ptr >= INTERVALS) in menu_update()
541 data->interval_ptr = 0; in menu_update()
545 * menu_enable_device - scans a CPU's states and does setup
552 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
562 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
576 * init_menu - initializes the governor