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>
39 * -----------------------
42 * provides us this duration in the "target_residency" field. So all that we
61 * Repeatable-interval-detector
62 * ----------------------------
110 s64 value, min_thresh = -1, max_thresh = UINT_MAX; in get_typical_interval()
111 unsigned int max, min, divisor; in get_typical_interval() local
118 min = UINT_MAX; in get_typical_interval()
123 value = data->intervals[i]; in get_typical_interval()
125 * Discard the samples outside the interval between the min and in get_typical_interval()
139 if (value < min) in get_typical_interval()
140 min = value; in get_typical_interval()
155 variance -= avg_sq; in get_typical_interval()
159 * small (stddev <= 20 us, variance <= 400 us^2) or standard in get_typical_interval()
167 * Use this result only if there is no timer to wake us up sooner. in get_typical_interval()
199 if (avg - min > max - avg) in get_typical_interval()
200 min_thresh = min; in get_typical_interval()
208 * menu_select - selects the next idle state to enter
217 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
222 if (data->needs_update) { in menu_select()
224 data->needs_update = 0; in menu_select()
239 data->next_timer_ns = delta; in menu_select()
240 data->bucket = which_bucket(data->next_timer_ns); in menu_select()
244 data->next_timer_ns * in menu_select()
245 data->correction_factor[data->bucket], in menu_select()
248 predicted_ns = min((u64)timer_us * NSEC_PER_USEC, predicted_ns); in menu_select()
256 data->next_timer_ns = KTIME_MAX; in menu_select()
258 data->bucket = which_bucket(KTIME_MAX); in menu_select()
261 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
262 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
263 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
264 !dev->states_usage[0].disable)) { in menu_select()
270 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
284 predicted_ns = data->next_timer_ns; in menu_select()
293 idx = -1; in menu_select()
294 for (i = 0; i < drv->state_count; i++) { in menu_select()
295 struct cpuidle_state *s = &drv->states[i]; in menu_select()
297 if (dev->states_usage[i].disable) in menu_select()
300 if (idx == -1) in menu_select()
303 if (s->target_residency_ns > predicted_ns) { in menu_select()
308 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
309 s->exit_latency_ns <= latency_req && in menu_select()
310 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
311 predicted_ns = s->target_residency_ns; in menu_select()
325 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
331 * state's target residency matches the time till the in menu_select()
335 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
336 s->target_residency_ns <= delta_tick) in menu_select()
341 if (s->exit_latency_ns > latency_req) in menu_select()
347 if (idx == -1) in menu_select()
354 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
358 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
361 * residency of the state to be returned is not within in menu_select()
365 for (i = idx - 1; i >= 0; i--) { in menu_select()
366 if (dev->states_usage[i].disable) in menu_select()
370 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
380 * menu_reflect - records that data structures need update
391 dev->last_state_idx = index; in menu_reflect()
392 data->needs_update = 1; in menu_reflect()
393 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
397 * menu_update - attempts to guess what happened after entry
404 int last_idx = dev->last_state_idx; in menu_update()
405 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
413 * If the entered idle state didn't support residency measurements, in menu_update()
424 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
435 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
436 dev->poll_time_limit) { in menu_update()
444 measured_ns = data->next_timer_ns; in menu_update()
447 measured_ns = dev->last_residency_ns; in menu_update()
450 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
451 measured_ns -= target->exit_latency_ns; in menu_update()
457 if (measured_ns > data->next_timer_ns) in menu_update()
458 measured_ns = data->next_timer_ns; in menu_update()
461 new_factor = data->correction_factor[data->bucket]; in menu_update()
462 new_factor -= new_factor / DECAY; in menu_update()
464 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
466 data->next_timer_ns); in menu_update()
483 data->correction_factor[data->bucket] = new_factor; in menu_update()
485 /* update the repeating-pattern data */ in menu_update()
486 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
487 if (data->interval_ptr >= INTERVALS) in menu_update()
488 data->interval_ptr = 0; in menu_update()
492 * menu_enable_device - scans a CPU's states and does setup
499 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
509 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
523 * init_menu - initializes the governor