Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period
@ 2026-12-02  8:25 Navon John Lukose
  2026-12-02 12:37 ` Christian Loehle
  0 siblings, 1 reply; 3+ messages in thread
From: Navon John Lukose @ 2026-12-02  8:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano
  Cc: Christian Loehle, linux-pm, linux-kernel

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@gmail.com>
---
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;
 	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;
+
 	if (!idx)
 		goto out_tick;
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period
  2026-12-02  8:25 [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period Navon John Lukose
@ 2026-12-02 12:37 ` Christian Loehle
  2026-12-02 14:55   ` Navon John Lukose
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Loehle @ 2026-12-02 12:37 UTC (permalink / raw)
  To: Navon John Lukose, Rafael J. Wysocki, Daniel Lezcano
  Cc: linux-pm, linux-kernel

On 12/2/26 08:25, Navon John Lukose 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@gmail.com>
> ---
> 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%).

Hi,
thanks for the patch, I think it makes sense.
Do you mind just dumping the state counts / duration deltas, IMO that
would be more readable.

> 
>  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;
>  	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;

I did propose something in that direction too, but didn't follow up on it:
https://lore.kernel.org/lkml/20240606090050.327614-3-christian.loehle@arm.com/

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period
  2026-12-02 12:37 ` Christian Loehle
@ 2026-12-02 14:55   ` Navon John Lukose
  0 siblings, 0 replies; 3+ messages in thread
From: Navon John Lukose @ 2026-12-02 14:55 UTC (permalink / raw)
  To: Christian Loehle
  Cc: Rafael J. Wysocki, Daniel Lezcano, linux-pm, linux-kernel

On Wed, 2 Dec 2026 12:37:32 +0000, Christian Loehle wrote:
> thanks for the patch, I think it makes sense.
> Do you mind just dumping the state counts / duration deltas, IMO that
> would be more readable.

Sure. Stock -> patched, summed over all 16 CPUs per second of wall time.
Residency is the share of total CPU time spent in the state. above
counts stays shorter than the state's own target residency, below
counts stays long enough for the next deeper state's (381 us for C1,
3144 us for C2).

The machine has 16 CPUs without SMT: 6 P-cores, 8 E-cores and 2 LP
E-cores. The pipe and timer loads ran on the cores named below; all
other CPUs, the LP E-cores included, only saw background activity.

Idle, display off, 7 stock / 8 patched interleaved rounds of 100 s
(one noisy stock round was dropped), the same runs as the changelog
numbers:

         entries/s       residency %       above/s         below/s
POLL     0.3 ->    0.3   0.00 ->  0.00    0.0 ->   0.0    0.2 ->   0.2
C1     139.6 ->  110.8   3.06 ->  0.21    0.3 ->   0.3   43.1 ->  30.6
C2     121.5 ->  104.8   3.27 ->  2.57   11.4 ->   7.8   12.8 ->   8.6
C3     472.2 ->  501.8  92.99 -> 96.59  115.4 -> 118.2    0.0 ->   0.0

Periodic loads, 6 interleaved rounds of 45 s each.

Pipe wakeups every 1.5 ms, writer and reader on E-cores 7 and 9:

         entries/s       residency %       above/s         below/s
POLL     2.8 ->    5.0   0.00 ->  0.00    0.0 ->   0.0    2.2 ->   4.2
C1     117.3 ->  303.9   2.24 ->  0.88    3.0 ->   4.5   34.9 -> 140.3
C2    1490.2 -> 1452.4  13.52 -> 12.79   36.3 ->  60.7    2.7 ->   2.7
C3     286.2 ->  292.5  83.90 -> 85.98   57.0 ->  57.3    0.0 ->   0.0

Pipe wakeups every 2 ms, writer and reader on E-cores 7 and 9:

         entries/s       residency %       above/s         below/s
POLL     2.3 ->    3.3   0.00 ->  0.00    0.0 ->   0.0    2.0 ->   2.8
C1      81.4 ->  196.1   1.57 ->  0.59    2.1 ->   4.4   28.4 -> 108.3
C2    1060.7 -> 1041.9  13.14 -> 13.01   10.1 ->  10.1    2.1 ->   2.4
C3     285.4 ->  263.6  85.00 -> 86.11   59.5 ->  51.6    0.0 ->   0.0

Pipe wakeups every 2.5 ms, writer and reader on E-cores 7 and 9:

         entries/s       residency %       above/s         below/s
POLL     3.3 ->    3.9   0.00 ->  0.00    0.0 ->   0.0    3.1 ->   3.6
C1      90.6 ->  145.6   1.71 ->  0.41    3.2 ->   4.0   29.0 ->  66.2
C2     874.0 ->  871.8  13.32 -> 13.29   12.2 ->  11.4    2.5 ->   2.9
C3     303.9 ->  291.5  84.69 -> 86.02   62.7 ->  63.9    0.0 ->   0.0

Pipe wakeups every 3 ms, writer and reader on P-cores 2 and 4:

         entries/s       residency %       above/s         below/s
POLL     4.8 ->    3.3   0.00 ->  0.00    0.0 ->   0.0    3.6 ->   2.7
C1      93.0 ->  148.5   1.86 ->  0.48    3.7 ->   2.8   30.7 ->  80.2
C2     749.1 ->  731.3  13.31 -> 13.19   12.1 ->   8.8    3.0 ->   3.1
C3     293.1 ->  282.6  84.50 -> 86.01   63.6 ->  60.4    0.0 ->   0.0

Timer wakeups every 2 ms on P-core 3:

         entries/s       residency %       above/s         below/s
POLL     3.5 ->   10.5   0.00 ->  0.00    0.0 ->   0.0    2.8 ->  10.2
C1      87.2 ->  146.4   2.05 ->  0.45    4.0 ->   2.9   31.1 ->  70.4
C2     568.5 ->  550.2   7.42 ->  7.20    6.3 ->   7.4    3.5 ->   3.3
C3     295.0 ->  294.2  90.14 -> 91.95   61.3 ->  58.1    0.0 ->   0.0

Under the periodic loads C1 is entered more often and its below count
rises because a wrong C1 pick now ends at the next tick and teo selects
again, instead of lasting until the next timer. below counts stays
rather than time, and about half of the C1 stays reach C2's 381 us, so
the count goes up while C1 residency drops by a factor of 2.5 to 4.5
(mean C1 stay 3.0-3.8 ms -> 0.45-0.52 ms).

If any other measurements would help, I can run them.

Navon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02 14:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  8:25 [PATCH] cpuidle: teo: Keep the tick when intercepts predict a short idle period Navon John Lukose
2026-12-02 12:37 ` Christian Loehle
2026-12-02 14:55   ` Navon John Lukose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox