Lines Matching +full:avg +full:- +full:samples

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 * -----------------------
68 * Repeatable-interval-detector
69 * ----------------------------
79 * ---------------------------
88 * This rule-of-thumb is implemented using a performance-multiplier:
173 unsigned int min, max, thresh, avg; in get_typical_interval() local
186 unsigned int value = data->intervals[i]; in get_typical_interval()
206 avg = sum >> INTERVAL_SHIFT; in get_typical_interval()
208 avg = div_u64(sum, divisor); in get_typical_interval()
213 unsigned int value = data->intervals[i]; in get_typical_interval()
215 int64_t diff = (int64_t)value - avg; in get_typical_interval()
227 * deviation is small compared to the average interval (avg > in get_typical_interval()
228 * 6*stddev, avg^2 > 36*variance). The average is smaller than in get_typical_interval()
237 if ((((u64)avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3)) in get_typical_interval()
239 return avg; in get_typical_interval()
247 * down to the bottom 3/4 of our samples, stop excluding samples. in get_typical_interval()
255 thresh = max - 1; in get_typical_interval()
260 * menu_select - selects the next idle state to enter
269 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
277 if (data->needs_update) { in menu_select()
279 data->needs_update = 0; in menu_select()
288 data->next_timer_ns = delta; in menu_select()
290 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
291 data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); in menu_select()
293 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
294 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
295 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
296 !dev->states_usage[0].disable)) { in menu_select()
302 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
307 predicted_us = div_u64(data->next_timer_ns * in menu_select()
308 data->correction_factor[data->bucket] + in menu_select()
326 predicted_ns = data->next_timer_ns; in menu_select()
329 * Use the performance multiplier and the user-configurable in menu_select()
342 idx = -1; in menu_select()
343 for (i = 0; i < drv->state_count; i++) { in menu_select()
344 struct cpuidle_state *s = &drv->states[i]; in menu_select()
346 if (dev->states_usage[i].disable) in menu_select()
349 if (idx == -1) in menu_select()
352 if (s->target_residency_ns > predicted_ns) { in menu_select()
357 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
358 s->exit_latency_ns <= latency_req && in menu_select()
359 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
360 predicted_ns = s->target_residency_ns; in menu_select()
374 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
384 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
385 s->target_residency_ns <= delta_tick) in menu_select()
390 if (s->exit_latency_ns > latency_req) in menu_select()
396 if (idx == -1) in menu_select()
403 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
407 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
414 for (i = idx - 1; i >= 0; i--) { in menu_select()
415 if (dev->states_usage[i].disable) in menu_select()
419 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
429 * menu_reflect - records that data structures need update
440 dev->last_state_idx = index; in menu_reflect()
441 data->needs_update = 1; in menu_reflect()
442 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
446 * menu_update - attempts to guess what happened after entry
453 int last_idx = dev->last_state_idx; in menu_update()
454 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
473 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
484 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
485 dev->poll_time_limit) { in menu_update()
493 measured_ns = data->next_timer_ns; in menu_update()
496 measured_ns = dev->last_residency_ns; in menu_update()
499 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
500 measured_ns -= target->exit_latency_ns; in menu_update()
506 if (measured_ns > data->next_timer_ns) in menu_update()
507 measured_ns = data->next_timer_ns; in menu_update()
510 new_factor = data->correction_factor[data->bucket]; in menu_update()
511 new_factor -= new_factor / DECAY; in menu_update()
513 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
515 data->next_timer_ns); in menu_update()
532 data->correction_factor[data->bucket] = new_factor; in menu_update()
534 /* update the repeating-pattern data */ in menu_update()
535 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
536 if (data->interval_ptr >= INTERVALS) in menu_update()
537 data->interval_ptr = 0; in menu_update()
541 * menu_enable_device - scans a CPU's states and does setup
548 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
558 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
572 * init_menu - initializes the governor