Re: [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period

From: Rafael J. Wysocki (Intel)

Date: Thu Dec 03 2026 - 12:09:33 EST


On Wed, Dec 2, 2026 at 9:25 AM Navon John Lukose
<navonjohnlukose@xxxxxxxxx> wrote:
>
> When the intercepts metrics make teo_select() pick a state shallower
> than the sleep length allows, the idle duration is expected to be below
> the target residency of the deeper state that was rejected. Whether or
> not to stop the tick is still decided from the sleep length though, so
> if the expected wakeup does not come, the CPU stays in the shallow state
> with the tick stopped until the next timer. Before commit 21d28cd2fa5f
> ("cpuidle: teo: Do not call tick_nohz_get_sleep_length() upfront") the
> middle of the selected state's bin was used as the expected idle
> duration in that case, which kept the tick for shallow states.
>
> Cap duration_ns at the target residency of the shallowest state
> rejected because of intercepts before using it for the tick decision.
>
> On an Arrow Lake-H laptop (HZ=1000, intel_idle _CST states C1/C2/C3
> with target residencies of 1/381/3144 us), idle with the display off,
> psys power drops from 2.23 W to 1.16 W and package C10 residency rises
> from 38% to 57%. Over five loads waking a task every 1.5-3 ms, psys
> drops by 0.86 W on average, and for cross-CPU pipe wakeups every
> 1.5-2 ms the p90 wakeup latency rises by 15-19 us.
>
> Fixes: 21d28cd2fa5f ("cpuidle: teo: Do not call tick_nohz_get_sleep_length() upfront")
> Signed-off-by: Navon John Lukose <navonjohnlukose@xxxxxxxxx>
> ---
> Measured with teo.c built as a module on 7.3, stock and patched, in 8
> interleaved 100 s idle rounds and 6 interleaved rounds of each periodic
> load. menu gets 1.25 W and 67% PC10 at idle on the same machine.
>
> C1 residencies longer than one tick go from 522-1398 to 1-4 per minute.
> C2 can still be entered with the tick stopped, because C3's target
> residency is above one tick and the pre-6.6 code stopped the tick there
> as well. That is where the remaining PC10 gap to menu comes from (PC6
> 16% vs 2%).
>
> drivers/cpuidle/governors/teo.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
> index 735894a1a7f..b8b8b58468c 100644
> --- a/drivers/cpuidle/governors/teo.c
> +++ b/drivers/cpuidle/governors/teo.c
> @@ -319,6 +319,7 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> int intercept_max_idx = -1;
> int constraint_idx = 0;
> int idx0 = 0, idx = -1;
> + s64 intercept_ns = KTIME_MAX;

You only need this to decide whether or not to stop the tick, right?

> s64 duration_ns;
> int i;
>
> @@ -419,6 +420,8 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> if (dev->states_usage[i].disable)
> continue;
>
> + /* State idx is rejected, so expect a shorter idle duration. */
> + intercept_ns = drv->states[idx].target_residency_ns;
> idx = i;
> if (2 * intercept_sum > idx_intercept_sum &&
> i <= intercept_max_idx)
> @@ -500,6 +503,15 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> return idx;
> }
>
> + /*
> + * If the candidate state has been selected because of intercepts, the
> + * idle duration is expected to be below the target residency of the
> + * shallowest state rejected for this reason, so use that value instead
> + * of the sleep length when deciding whether or not to stop the tick.
> + */
> + if (duration_ns > intercept_ns)
> + duration_ns = intercept_ns;

And this is too early AFAICS.

First off, if idx is 0, the tick will not stop anyway.

> +
> if (!idx)
> goto out_tick;
>

Then there is this code

if (drv->states[idx].target_residency_ns > duration_ns)
idx = teo_find_shallower_state(drv, dev, idx, duration_ns);

which compares the target residency of state idx with duration_ns and
the former cannot be greater than intercept_ns. It can only be
greater than duration_ns if duration_ns is less than intercept_ns,
which is not the case in which duration_ns becomes intercept_ns.

The next conditional doesn't even look at duration_ns (even though it
may update it), so the first one for which intercept_ns is relevant is
the one right after the "end" label and that one compares duration_ns
with TICK_NSEC.

This means that the attached patch should work for you if I'm not mistaken.

Can you please check it?
---
drivers/cpuidle/governors/teo.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -309,6 +309,7 @@ static int teo_select(struct cpuidle_dri
bool *stop_tick)
{
struct teo_cpu *cpu_data = this_cpu_ptr(&teo_cpus);
+ bool tick_intercept_unlikely = true;
s64 latency_req = dev->latency_req;
ktime_t delta_tick = TICK_NSEC / 2;
unsigned int idx_intercept_sum = 0;
@@ -419,6 +420,14 @@ static int teo_select(struct cpuidle_dri
if (dev->states_usage[i].disable)
continue;

+ /*
+ * An intercept below the target residency of state idx
+ * is likely, so if it is going to interfere with the
+ * tick, stopping the tick should be avoided.
+ */
+ if (drv->states[idx].target_residency_ns < TICK_NSEC)
+ tick_intercept_unlikely = false;
+
idx = i;
if (2 * intercept_sum > idx_intercept_sum &&
i <= intercept_max_idx)
@@ -520,13 +529,16 @@ static int teo_select(struct cpuidle_dri
duration_ns = TICK_NSEC / 2;

end:
+ if (tick_nohz_tick_stopped())
+ return idx;
+
/*
- * Allow the tick to be stopped unless the selected state is a polling
- * one or the expected idle duration is shorter than the tick period
- * length.
+ * Allow the tick to be stopped if the selected state is not a polling
+ * one, the expected idle duration is at least equal to the tick period
+ * length, and no intercepts below the tick period length are expected.
*/
- if ((!(drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
- duration_ns >= TICK_NSEC) || tick_nohz_tick_stopped())
+ if (!(drv->states[idx].flags & CPUIDLE_FLAG_POLLING) &&
+ duration_ns >= TICK_NSEC && tick_intercept_unlikely)
return idx;

/*