Re: [PATCH 2/2] cpuidle: Respect latency constraints when accounting below misses

From: Rafael J. Wysocki (Intel)

Date: Tue Nov 10 2026 - 15:14:00 EST


On Fri, Oct 30, 2026 at 9:36 AM Christian Loehle
<christian.loehle@xxxxxxx> wrote:
>
> Only count a below miss when an enabled deeper state meets the latency
> constraint. Save the applicable limit before entry so QoS changes during
> idle do not affect accounting. Continue checking disable flags on exit.
>
> Fixes: 04dab58a39d4 ("cpuidle: Add 'above' and 'below' idle state metrics")
> Signed-off-by: Christian Loehle <christian.loehle@xxxxxxx>
> ---
> drivers/cpuidle/cpuidle.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index faa29f58738e..e9195ea8cfb6 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -219,6 +219,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
> int index)
> {
> int entered_state;
> + s64 latency_req;
>
> struct cpuidle_state *target_state = &drv->states[index];
> bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
> @@ -244,6 +245,8 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
> if (target_state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
> leave_mm();
>
> + latency_req = cpuidle_governor_latency_req(dev->cpu);
> +

What if this is different from what the governor has used? The limits
may change at any time.

> /* Take note of the planned idle state. */
> sched_idle_set_state(target_state);
>
> @@ -327,7 +330,8 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
> }
> } else if (diff > delay) {
> for (i = entered_state + 1; i < drv->state_count; i++) {
> - if (dev->states_usage[i].disable)
> + if (dev->states_usage[i].disable ||
> + drv->states[i].exit_latency_ns > latency_req)
> continue;
>
> /*
> --
> 2.34.1
>