From: Peng Huang <penghuang@google.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev,
stable@vger.kernel.org, Peng Huang <penghuang@google.com>
Subject: [PATCH v2 2/2] sched_ext, sched/fair: Drain blocked load on scx_switched_all
Date: Mon, 23 Nov 2026 12:13:51 -0800 [thread overview]
Message-ID: <2b1ef28e12d12a1f894827b951910c1979d54d45.1795462673.git.penghuang@google.com> (raw)
In-Reply-To: <cover.1795462673.git.penghuang@google.com>
Tasks that exit or migrate while sleeping queue their PELT load and
utilization in cfs_rq->removed rather than deducting and propagating
immediately. When scx_enable() switches all fair tasks to sched_ext,
switched_from_fair() only visits cfs_rq chains that still hold live
fair tasks, leaving unvisited leaf cfs_rqs undrained in rq->cfs.avg.
Once __scx_switched_all is enabled, scheduler_tick() skips
sched_balance_trigger() and fair_sched_class is bypassed, freezing
blocked-load updates. Stale rq->cfs.avg.util_sum can then combine with
active RT/DL util_sum in update_idle_rq_clock_pelt() to exceed divider,
inflating rq->lost_idle_time and stalling rq_clock_pelt().
Export __sched_balance_update_blocked_averages() and call it on each
CPU in scx_enable()'s per-CPU scx_switched_all() loop so pending
cfs_rq->removed entries and task-group propagations are drained cleanly.
Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Suggested-by: Vincent Guittot <vincent.guittot@linaro.org>
Cc: stable@vger.kernel.org
Signed-off-by: Peng Huang <penghuang@google.com>
---
kernel/sched/ext/ext.c | 9 ++++-----
kernel/sched/fair.c | 7 ++++++-
kernel/sched/sched.h | 1 +
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 10de6bd865e8..f7c573092e17 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -9013,11 +9013,9 @@ static void scx_root_enable_workfn(struct kthread_work *work)
static_branch_enable(&__scx_switched_all);
/*
- * Detach the fair_server bandwidth reservation now that the switch
- * is fully committed. In full mode (!SCX_OPS_SWITCH_PARTIAL) no
- * task will ever run in the fair class, so give that bandwidth
- * back to the RT class. The matching ext_server attach already
- * happened earlier; this only releases bandwidth and cannot fail.
+ * Detach the fair_server bandwidth reservation and drain any
+ * remaining blocked or removed fair load now that the switch is
+ * fully committed and periodic fair blocked-load updates stop.
*
* In partial mode keep fair_server attached.
*/
@@ -9028,6 +9026,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)
guard(rq_lock_irqsave)(rq);
update_rq_clock(rq);
dl_server_detach_bw(&rq->fair_server);
+ __sched_balance_update_blocked_averages(rq);
}
}
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f6c3bbb19557..f19f498e01a4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -11655,10 +11655,15 @@ static unsigned long task_h_load(struct task_struct *p)
}
#endif /* !CONFIG_FAIR_GROUP_SCHED */
-static void __sched_balance_update_blocked_averages(struct rq *rq)
+/*
+ * Update blocked PELT averages for RT/DL/IRQ and fair cfs_rqs on @rq.
+ * Caller must hold @rq's lock and have updated @rq's clock.
+ */
+void __sched_balance_update_blocked_averages(struct rq *rq)
{
bool decayed = false, done = true;
+ lockdep_assert_rq_held(rq);
update_blocked_load_tick(rq);
decayed |= __update_blocked_others(rq, &done);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 220927453a88..71a69f90e5df 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2977,6 +2977,7 @@ extern struct task_struct *pick_task_idle(struct rq *rq, struct rq_flags *rf);
extern void update_group_capacity(struct sched_domain *sd, int cpu);
extern void sched_balance_trigger(struct rq *rq);
+void __sched_balance_update_blocked_averages(struct rq *rq);
extern int __set_cpus_allowed_ptr(struct task_struct *p, struct affinity_context *ctx);
extern void set_cpus_allowed_common(struct task_struct *p, struct affinity_context *ctx);
--
2.56.1.831.g720f3f5937-goog
prev parent reply other threads:[~2026-11-23 20:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 1:57 [PATCH] sched/pelt: Skip dormant cfs util_sum under scx_switched_all Peng Huang
2026-11-23 10:34 ` Vincent Guittot
2026-11-23 16:09 ` Peng Huang
2026-11-23 17:07 ` Vincent Guittot
2026-11-23 20:14 ` Peng Huang
2026-11-23 20:13 ` [PATCH v2 0/2] sched_ext, sched/fair: Drain blocked fair load on scx_switched_all Peng Huang
2026-11-23 20:13 ` [PATCH v2 1/2] sched/fair: Clear residual sums on zero task-group avg propagation Peng Huang
2026-11-23 20:13 ` Peng Huang [this message]
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=2b1ef28e12d12a1f894827b951910c1979d54d45.1795462673.git.penghuang@google.com \
--to=penghuang@google.com \
--cc=arighi@nvidia.com \
--cc=bsegall@google.com \
--cc=changwoo@igalia.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
--cc=vschneid@redhat.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®