* [PATCH 1/2] cpuidle: Skip miss accounting for timer broadcast fallbacks
2026-10-30 8:36 [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
@ 2026-10-30 8:36 ` Christian Loehle
2026-10-30 8:36 ` [PATCH 2/2] cpuidle: Respect latency constraints when accounting below misses Christian Loehle
2026-11-05 8:11 ` [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
2 siblings, 0 replies; 5+ messages in thread
From: Christian Loehle @ 2026-10-30 8:36 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: linux-pm, linux-kernel, Christian Loehle
A failed tick_broadcast_enter() can force a shallower state than the
governor selected. Exclude successful broadcast fallbacks from above/below
miss accounting while retaining their usage, residency and governor
feedback.
Fixes: 04dab58a39d4 ("cpuidle: Add 'above' and 'below' idle state metrics")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
drivers/cpuidle/cpuidle.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 2d2f40a2cb81..faa29f58738e 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -222,6 +222,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
struct cpuidle_state *target_state = &drv->states[index];
bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
+ bool broadcast_failed = false;
ktime_t time_start, time_end;
instrumentation_begin();
@@ -232,6 +233,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
* CPU as a broadcast timer, this call may fail if it is not available.
*/
if (broadcast && tick_broadcast_enter()) {
+ broadcast_failed = true;
index = find_deepest_state(drv, dev, target_state->exit_latency_ns,
CPUIDLE_FLAG_TIMER_STOP, false);
@@ -306,6 +308,13 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
dev->states_usage[entered_state].time_ns += diff;
dev->states_usage[entered_state].usage++;
+ /*
+ * The broadcast constraint forced a shallower state, do not
+ * account for it as a cpu_idle_miss.
+ */
+ if (broadcast_failed)
+ goto out;
+
if (diff < drv->states[entered_state].target_residency_ns) {
for (i = entered_state - 1; i >= 0; i--) {
if (dev->states_usage[i].disable)
@@ -338,6 +347,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev,
dev->states_usage[index].rejected++;
}
+out:
instrumentation_end();
return entered_state;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/2] cpuidle: Respect latency constraints when accounting below misses
2026-10-30 8:36 [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
2026-10-30 8:36 ` [PATCH 1/2] cpuidle: Skip miss accounting for timer broadcast fallbacks Christian Loehle
@ 2026-10-30 8:36 ` Christian Loehle
2026-11-05 8:11 ` [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
2 siblings, 0 replies; 5+ messages in thread
From: Christian Loehle @ 2026-10-30 8:36 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: linux-pm, linux-kernel, Christian Loehle
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@arm.com>
---
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);
+
/* 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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 0/2] cpuidle: idle_miss accounting fixes
2026-10-30 8:36 [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
2026-10-30 8:36 ` [PATCH 1/2] cpuidle: Skip miss accounting for timer broadcast fallbacks Christian Loehle
2026-10-30 8:36 ` [PATCH 2/2] cpuidle: Respect latency constraints when accounting below misses Christian Loehle
@ 2026-11-05 8:11 ` Christian Loehle
2026-11-05 12:17 ` Rafael J. Wysocki (Intel)
2 siblings, 1 reply; 5+ messages in thread
From: Christian Loehle @ 2026-11-05 8:11 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano; +Cc: linux-pm, linux-kernel
On 10/30/26 08:36, Christian Loehle wrote:
> These two fixes exclude timer-broadcast fallbacks from governor miss
> accounting and respect the entry-time latency constraint when looking for
> a better deeper state.
> No functional change outside of sysfs above/below and tracing.
>
> Patch 1: Exclude timer-broadcast fallbacks
>
> When tick_broadcast_enter() fails, the core forces a shallower state.
> Exclude these entries from governor miss accounting while retaining
> residency, usage and governor feedback.
>
> On Orion O6, traces with menu and TEO running schbench, tbench and hackbench
> recorded 6930 cpu_idle_miss events on 8172 broadcast fallbacks before the
> fix, and none on 7763 fallbacks with patch 1. All matched fallbacks entered
> WFI.
>
> Patch 2: Respect latency constraints for below misses
>
> An enabled deeper state may violate the latency QoS constraint, causing a
> false below miss. Save the governor latency limit at entry and exclude
> states exceeding it, without an additional state-table walk. Disable flags
> continue to be checked at exit as they are expected to change less frequently.
>
> Christian Loehle (2):
> cpuidle: Skip miss accounting for timer broadcast fallbacks
> cpuidle: Respect latency constraints when accounting below misses
>
> drivers/cpuidle/cpuidle.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
Rafael, any opinions?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] cpuidle: idle_miss accounting fixes
2026-11-05 8:11 ` [PATCH 0/2] cpuidle: idle_miss accounting fixes Christian Loehle
@ 2026-11-05 12:17 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-05 12:17 UTC (permalink / raw)
To: Christian Loehle
Cc: Rafael J . Wysocki, Daniel Lezcano, linux-pm, linux-kernel
On Thu, Nov 5, 2026 at 9:11 AM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> On 10/30/26 08:36, Christian Loehle wrote:
> > These two fixes exclude timer-broadcast fallbacks from governor miss
> > accounting and respect the entry-time latency constraint when looking for
> > a better deeper state.
> > No functional change outside of sysfs above/below and tracing.
> >
> > Patch 1: Exclude timer-broadcast fallbacks
> >
> > When tick_broadcast_enter() fails, the core forces a shallower state.
> > Exclude these entries from governor miss accounting while retaining
> > residency, usage and governor feedback.
> >
> > On Orion O6, traces with menu and TEO running schbench, tbench and hackbench
> > recorded 6930 cpu_idle_miss events on 8172 broadcast fallbacks before the
> > fix, and none on 7763 fallbacks with patch 1. All matched fallbacks entered
> > WFI.
> >
> > Patch 2: Respect latency constraints for below misses
> >
> > An enabled deeper state may violate the latency QoS constraint, causing a
> > false below miss. Save the governor latency limit at entry and exclude
> > states exceeding it, without an additional state-table walk. Disable flags
> > continue to be checked at exit as they are expected to change less frequently.
> >
> > Christian Loehle (2):
> > cpuidle: Skip miss accounting for timer broadcast fallbacks
> > cpuidle: Respect latency constraints when accounting below misses
> >
> > drivers/cpuidle/cpuidle.c | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
>
> Rafael, any opinions?
I have only looked at the patches briefly and I don't seem to have any
concerns ATM.
^ permalink raw reply [flat|nested] 5+ messages in thread