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 <[email protected]>
39 * -----------------------
42 * provides us this duration in the "target_residency" field. So all that we
67 * Repeatable-interval-detector
68 * ----------------------------
120 unsigned int min, max, thresh, avg; in get_typical_interval() local
128 min = UINT_MAX; in get_typical_interval()
133 unsigned int value = data->intervals[i]; in get_typical_interval()
140 if (value < min) in get_typical_interval()
141 min = value; in get_typical_interval()
156 unsigned int value = data->intervals[i]; in get_typical_interval()
158 int64_t diff = (int64_t)value - avg; in get_typical_interval()
169 * small (stddev <= 20 us, variance <= 400 us^2) or standard in get_typical_interval()
177 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
198 thresh = max - 1; in get_typical_interval()
203 * menu_select - selects the next idle state to enter
212 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
217 if (data->needs_update) { in menu_select()
219 data->needs_update = 0; in menu_select()
234 data->next_timer_ns = delta; in menu_select()
235 data->bucket = which_bucket(data->next_timer_ns); in menu_select()
239 data->next_timer_ns * in menu_select()
240 data->correction_factor[data->bucket], in menu_select()
243 predicted_ns = min((u64)timer_us * NSEC_PER_USEC, predicted_ns); in menu_select()
251 data->next_timer_ns = KTIME_MAX; in menu_select()
253 data->bucket = which_bucket(KTIME_MAX); in menu_select()
256 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
257 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
258 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
259 !dev->states_usage[0].disable)) { in menu_select()
265 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
279 predicted_ns = data->next_timer_ns; in menu_select()
288 idx = -1; in menu_select()
289 for (i = 0; i < drv->state_count; i++) { in menu_select()
290 struct cpuidle_state *s = &drv->states[i]; in menu_select()
292 if (dev->states_usage[i].disable) in menu_select()
295 if (idx == -1) in menu_select()
298 if (s->target_residency_ns > predicted_ns) { in menu_select()
303 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
304 s->exit_latency_ns <= latency_req && in menu_select()
305 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
306 predicted_ns = s->target_residency_ns; in menu_select()
320 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
326 * state's target residency matches the time till the in menu_select()
330 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
331 s->target_residency_ns <= delta_tick) in menu_select()
336 if (s->exit_latency_ns > latency_req) in menu_select()
342 if (idx == -1) in menu_select()
349 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
353 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
356 * residency of the state to be returned is not within in menu_select()
360 for (i = idx - 1; i >= 0; i--) { in menu_select()
361 if (dev->states_usage[i].disable) in menu_select()
365 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
375 * menu_reflect - records that data structures need update
386 dev->last_state_idx = index; in menu_reflect()
387 data->needs_update = 1; in menu_reflect()
388 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
392 * menu_update - attempts to guess what happened after entry
399 int last_idx = dev->last_state_idx; in menu_update()
400 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
408 * If the entered idle state didn't support residency measurements, in menu_update()
419 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
430 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
431 dev->poll_time_limit) { in menu_update()
439 measured_ns = data->next_timer_ns; in menu_update()
442 measured_ns = dev->last_residency_ns; in menu_update()
445 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
446 measured_ns -= target->exit_latency_ns; in menu_update()
452 if (measured_ns > data->next_timer_ns) in menu_update()
453 measured_ns = data->next_timer_ns; in menu_update()
456 new_factor = data->correction_factor[data->bucket]; in menu_update()
457 new_factor -= new_factor / DECAY; in menu_update()
459 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
461 data->next_timer_ns); in menu_update()
478 data->correction_factor[data->bucket] = new_factor; in menu_update()
480 /* update the repeating-pattern data */ in menu_update()
481 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
482 if (data->interval_ptr >= INTERVALS) in menu_update()
483 data->interval_ptr = 0; in menu_update()
487 * menu_enable_device - scans a CPU's states and does setup
494 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
504 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
518 * init_menu - initializes the governor