[PATCH 1/2] sched/core: Don't count voluntary idle picks as forced idle
From: Kuba Piecuch
Date: Tue Dec 01 2026 - 07:03:27 EST
In pick_next_task(), the per-sibling loop increments
rq->core->core_forceidle_count whenever p == rq_i->idle and
rq_i->nr_running > 0. That conflates a sibling forced idle by a cookie
mismatch with a sibling whose pick_task() voluntarily returned idle while
rq_i->nr_running > 0.
Voluntary idle with nr_running > 0 is legitimate whenever a scheduling
class keeps queued tasks off the CPU and returns NULL from pick_task(),
such as sched_ext tasks parked on a non-local DSQ. Counting those
voluntary idle picks as forced idle has two effects:
- If all siblings pick idle (occ == 0), core_forceidle_count becomes
non-zero while core_forceidle_occupation is 0, triggering
WARN_ON_ONCE(!rq->core->core_forceidle_occupation) in
__sched_core_account_forceidle() when schedstats is enabled.
- If another sibling is running (occ > 0), the voluntary idle time is
spuriously billed as forced idle to the running sibling's cgroup and
triggers forced-idle-only paths (queue_core_balance(), forced_idle_rq(),
sched_core_idle_needs_pick()).
Increment core_forceidle_count and core_forceidle_seq only inside the
!cookie_equals(p, cookie) branch when sched_core_find() returns NULL and
replaces a non-idle pick with idle. Since cookie_equals() always returns
true for rq_i->idle, voluntary idle picks are never counted as forced
idle, and entering the mismatch branch guarantees a non-idle @max so
core_forceidle_occupation is always non-zero whenever forced idle is
recorded.
Fixes: 4feee7d12603 ("sched/core: Forced idle accounting")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kuba Piecuch <jpiecuch@xxxxxxxxxx>
---
kernel/sched/core.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c9890ed35df7..8cd30021721f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6470,8 +6470,12 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
p = NULL;
if (cookie)
p = sched_core_find(rq_i, cookie);
- if (!p)
+ if (!p) {
p = idle_sched_class.pick_task(rq_i, rf);
+ rq->core->core_forceidle_count++;
+ if (!fi_before)
+ rq->core->core_forceidle_seq++;
+ }
/*
* Neither a core tree pick nor idle comes through a
@@ -6482,15 +6486,8 @@ pick_next_task(struct rq *rq, struct rq_flags *rf)
rq_i->core_pick = p;
- if (p == rq_i->idle) {
- if (rq_i->nr_running) {
- rq->core->core_forceidle_count++;
- if (!fi_before)
- rq->core->core_forceidle_seq++;
- }
- } else {
+ if (p != rq_i->idle)
occ++;
- }
}
if (schedstat_enabled() && rq->core->core_forceidle_count) {
--
2.56.1.839.g22a8290db9-goog