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

From: Christian Loehle

Date: Tue Nov 10 2026 - 17:33:28 EST


On 11/10/26 20:13, Rafael J. Wysocki (Intel) wrote:
> 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.

Right, it's just a few cycles after selection, but you're correct.
I will resend with a version that saves the used latency_req in dev.

>
>> /* 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
>>