Lines Matching +full:duration +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>
39 * -----------------------
42 * provides us this duration in the "target_residency" field. So all that we
50 * duration always was 50% of the next timer tick, the correction factor will
55 * ratio is dependent on the order of magnitude of the expected duration; if we
59 * indexed based on the magnitude of the expected duration.
61 * Repeatable-interval-detector
62 * ----------------------------
66 * For this, we use a different predictor: We track the duration of the last 8
67 * intervals and use them to estimate the duration of the next one.
102 /* Update the repeating-pattern data. */ in menu_update_intervals()
103 data->intervals[data->interval_ptr++] = interval_us; in menu_update_intervals()
104 if (data->interval_ptr >= INTERVALS) in menu_update_intervals()
105 data->interval_ptr = 0; in menu_update_intervals()
118 s64 value, min_thresh = -1, max_thresh = UINT_MAX; in get_typical_interval()
131 value = data->intervals[i]; in get_typical_interval()
163 variance -= avg_sq; in get_typical_interval()
167 * small (stddev <= 20 us, variance <= 400 us^2) or standard in get_typical_interval()
175 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
204 if (avg - min > max - avg) in get_typical_interval()
213 * menu_select - selects the next idle state to enter
222 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
227 if (data->needs_update) { in menu_select()
229 data->needs_update = 0; in menu_select()
230 } else if (!dev->last_residency_ns) { in menu_select()
252 data->next_timer_ns = delta; in menu_select()
253 data->bucket = which_bucket(data->next_timer_ns); in menu_select()
257 data->next_timer_ns * in menu_select()
258 data->correction_factor[data->bucket], in menu_select()
269 data->next_timer_ns = KTIME_MAX; in menu_select()
271 data->bucket = BUCKETS - 1; in menu_select()
274 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
275 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
276 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
277 !dev->states_usage[0].disable)) { in menu_select()
283 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
289 * duration misprediction is much higher, because the CPU may be stuck in menu_select()
295 predicted_ns = data->next_timer_ns; in menu_select()
301 idx = -1; in menu_select()
302 for (i = 0; i < drv->state_count; i++) { in menu_select()
303 struct cpuidle_state *s = &drv->states[i]; in menu_select()
305 if (dev->states_usage[i].disable) in menu_select()
308 if (idx == -1) in menu_select()
311 if (s->exit_latency_ns > latency_req) in menu_select()
314 if (s->target_residency_ns <= predicted_ns) { in menu_select()
323 * duration. in menu_select()
325 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
326 s->target_residency_ns <= data->next_timer_ns && in menu_select()
327 s->exit_latency_ns <= predicted_ns) { in menu_select()
328 predicted_ns = s->target_residency_ns; in menu_select()
343 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
353 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
354 s->target_residency_ns <= delta_tick) in menu_select()
360 if (idx == -1) in menu_select()
365 * expected idle duration is shorter than the tick period length. in menu_select()
367 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
371 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
378 for (i = idx - 1; i >= 0; i--) { in menu_select()
379 if (dev->states_usage[i].disable) in menu_select()
383 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
393 * menu_reflect - records that data structures need update
404 dev->last_state_idx = index; in menu_reflect()
405 data->needs_update = 1; in menu_reflect()
406 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
410 * menu_update - attempts to guess what happened after entry
417 int last_idx = dev->last_state_idx; in menu_update()
418 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
437 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
441 * duration predictor had a differing opinion. Since the CPU in menu_update()
445 * duration predictor do a better job next time. in menu_update()
448 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
449 dev->poll_time_limit) { in menu_update()
452 * the idle duration prediction leading to the selection of that in menu_update()
457 measured_ns = data->next_timer_ns; in menu_update()
460 measured_ns = dev->last_residency_ns; in menu_update()
463 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
464 measured_ns -= target->exit_latency_ns; in menu_update()
470 if (measured_ns > data->next_timer_ns) in menu_update()
471 measured_ns = data->next_timer_ns; in menu_update()
474 new_factor = data->correction_factor[data->bucket]; in menu_update()
475 new_factor -= new_factor / DECAY; in menu_update()
477 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
479 data->next_timer_ns); in menu_update()
496 data->correction_factor[data->bucket] = new_factor; in menu_update()
502 * menu_enable_device - scans a CPU's states and does setup
509 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
519 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
533 * init_menu - initializes the governor