Lines Matching +full:two +full:- +full:factor

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>
42 * -----------------------
51 * more realistic estimate, a correction factor is applied to the estimate,
53 * duration always was 50% of the next timer tick, the correction factor will
56 * menu uses a running average for this correction factor, however it uses a
57 * set of factors, not just a single factor. This stems from the realization
61 * seconds of idle time. A second independent factor that has big impact on
62 * the actual factor is if there is (disk) IO outstanding or not.
66 * For these two reasons we keep an array of 12 independent factors, that gets
70 * Repeatable-interval-detector
71 * ----------------------------
81 * ---------------------------
90 * This rule-of-thumb is implemented using a performance-multiplier:
98 * Two factors are used in determing this multiplier:
104 * The load average factor gives a longer term (few seconds) input to the
106 * The iowait factor may look low, but realize that this is also already
127 * We keep two groups of stats; one with no in which_bucket()
187 unsigned int value = data->intervals[i]; in get_typical_interval()
210 unsigned int value = data->intervals[i]; in get_typical_interval()
212 int64_t diff = (int64_t)value - avg; in get_typical_interval()
263 thresh = max - 1; in get_typical_interval()
268 * menu_select - selects the next idle state to enter
277 s64 latency_req = cpuidle_governor_latency_req(dev->cpu); in menu_select()
284 if (data->needs_update) { in menu_select()
286 data->needs_update = 0; in menu_select()
289 nr_iowaiters = nr_iowait_cpu(dev->cpu); in menu_select()
303 data->next_timer_ns = delta; in menu_select()
304 data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); in menu_select()
308 data->next_timer_ns * in menu_select()
309 data->correction_factor[data->bucket], in menu_select()
320 data->next_timer_ns = KTIME_MAX; in menu_select()
322 data->bucket = which_bucket(KTIME_MAX, nr_iowaiters); in menu_select()
325 if (unlikely(drv->state_count <= 1 || latency_req == 0) || in menu_select()
326 ((data->next_timer_ns < drv->states[1].target_residency_ns || in menu_select()
327 latency_req < drv->states[1].exit_latency_ns) && in menu_select()
328 !dev->states_usage[0].disable)) { in menu_select()
334 *stop_tick = !(drv->states[0].flags & CPUIDLE_FLAG_POLLING); in menu_select()
348 predicted_ns = data->next_timer_ns; in menu_select()
351 * Use the performance multiplier and the user-configurable in menu_select()
364 idx = -1; in menu_select()
365 for (i = 0; i < drv->state_count; i++) { in menu_select()
366 struct cpuidle_state *s = &drv->states[i]; in menu_select()
368 if (dev->states_usage[i].disable) in menu_select()
371 if (idx == -1) in menu_select()
374 if (s->target_residency_ns > predicted_ns) { in menu_select()
379 if ((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && in menu_select()
380 s->exit_latency_ns <= latency_req && in menu_select()
381 s->target_residency_ns <= data->next_timer_ns) { in menu_select()
382 predicted_ns = s->target_residency_ns; in menu_select()
396 predicted_ns = drv->states[idx].target_residency_ns; in menu_select()
406 if (drv->states[idx].target_residency_ns < TICK_NSEC && in menu_select()
407 s->target_residency_ns <= delta_tick) in menu_select()
412 if (s->exit_latency_ns > latency_req) in menu_select()
418 if (idx == -1) in menu_select()
425 if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || in menu_select()
429 if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { in menu_select()
436 for (i = idx - 1; i >= 0; i--) { in menu_select()
437 if (dev->states_usage[i].disable) in menu_select()
441 if (drv->states[i].target_residency_ns <= delta_tick) in menu_select()
451 * menu_reflect - records that data structures need update
462 dev->last_state_idx = index; in menu_reflect()
463 data->needs_update = 1; in menu_reflect()
464 data->tick_wakeup = tick_nohz_idle_got_tick(); in menu_reflect()
468 * menu_update - attempts to guess what happened after entry
475 int last_idx = dev->last_state_idx; in menu_update()
476 struct cpuidle_state *target = &drv->states[last_idx]; in menu_update()
495 if (data->tick_wakeup && data->next_timer_ns > TICK_NSEC) { in menu_update()
506 } else if ((drv->states[last_idx].flags & CPUIDLE_FLAG_POLLING) && in menu_update()
507 dev->poll_time_limit) { in menu_update()
515 measured_ns = data->next_timer_ns; in menu_update()
518 measured_ns = dev->last_residency_ns; in menu_update()
521 if (measured_ns > 2 * target->exit_latency_ns) in menu_update()
522 measured_ns -= target->exit_latency_ns; in menu_update()
528 if (measured_ns > data->next_timer_ns) in menu_update()
529 measured_ns = data->next_timer_ns; in menu_update()
532 new_factor = data->correction_factor[data->bucket]; in menu_update()
533 new_factor -= new_factor / DECAY; in menu_update()
535 if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING) in menu_update()
537 data->next_timer_ns); in menu_update()
546 * We don't want 0 as factor; we always want at least in menu_update()
554 data->correction_factor[data->bucket] = new_factor; in menu_update()
556 /* update the repeating-pattern data */ in menu_update()
557 data->intervals[data->interval_ptr++] = ktime_to_us(measured_ns); in menu_update()
558 if (data->interval_ptr >= INTERVALS) in menu_update()
559 data->interval_ptr = 0; in menu_update()
563 * menu_enable_device - scans a CPU's states and does setup
570 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); in menu_enable_device()
576 * if the correction factor is 0 (eg first time init or cpu hotplug in menu_enable_device()
577 * etc), we actually want to start out with a unity factor. in menu_enable_device()
580 data->correction_factor[i] = RESOLUTION * DECAY; in menu_enable_device()
594 * init_menu - initializes the governor