From: Kuba Piecuch <jpiecuch@google.com>
To: Peter Zijlstra <peterz@infradead.org>, Tejun Heo <tj@kernel.org>
Cc: Kuba Piecuch <jpiecuch@google.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Josh Don <joshdon@google.com>, David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] sched/core: Don't count voluntary idle picks as forced idle
Date: Tue, 1 Dec 2026 12:03:03 +0000 [thread overview]
Message-ID: <20261201120123.3678974-2-jpiecuch@google.com> (raw)
In-Reply-To: <20261201120123.3678974-1-jpiecuch@google.com>
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@vger.kernel.org
Signed-off-by: Kuba Piecuch <jpiecuch@google.com>
---
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
next prev parent reply other threads:[~2026-12-01 12:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:03 [PATCH 0/2] " Kuba Piecuch
2026-12-01 12:03 ` Kuba Piecuch [this message]
2026-12-01 12:03 ` [PATCH 2/2] selftests/sched_ext: Add core_forceidle test for voluntary idle picks Kuba Piecuch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201120123.3678974-2-jpiecuch@google.com \
--to=jpiecuch@google.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®