mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zicheng Qu <quzicheng@huawei.com>
To: <sashiko-bot@kernel.org>
Cc: <sashiko-reviews@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<sched-ext@lists.linux.dev>, <peterz@infradead.org>,
	<arighi@nvidia.com>, <brho@google.com>, <bsegall@google.com>,
	<changwoo@igalia.com>, <dietmar.eggemann@arm.com>,
	<haoluo@google.com>, <joshdon@google.com>, <juri.lelli@redhat.co>,
	<kprateek.nayak@amd.com>, <mgorman@suse.de>, <mingo@redhat.com>,
	<rostedt@goodmis.org>, <tj@kernel.org>,
	<vincent.guittot@linaro.org>, <void@manifault.com>,
	<vschneid@redhat.com>, <tanghui20@huawei.com>,
	<zhangqiao22@huawei.com>, <quzicheng@huawei.com>,
	<quzicheng315@gmail.com>
Subject: [PATCH v4 1/2] sched/fair: Rebuild load weight when switching to fair
Date: Wed, 24 Jun 2026 09:16:47 +0000	[thread overview]
Message-ID: <20260624091648.271891-2-quzicheng@huawei.com> (raw)
In-Reply-To: <20260624091648.271891-1-quzicheng@huawei.com>

Tasks that run outside fair may not keep p->se.load in sync with their
current scheduling policy and static priority. sched_ext, for example,
uses p->scx.weight as the active scheduling weight, so p->se.load can be
stale when a task moves back to fair.

The fair_sched_class expects the sched_entity load weight to be valid
before the task is enqueued. Rebuild it from fair's switching_to hook,
which runs after the class has been changed to fair and before enqueue,
so both sched_ext disable and SCHED_EXT to SCHED_NORMAL transitions get
a native fair load weight.

Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
---
Changes in v4:
- No code changes.
- Add Tejun's Acked-by.
- Split the PELT load_avg synchronization into patch 2.

Changes in v3:
- Move the rebuild into fair's switching_to hook, as suggested by Peter.
  This lets fair prepare its own state before enqueue and avoids adding a
  sched_ext/fair-specific fixup to the generic sched_change_end() path.

Changes in v2:
- Move the fix from scx_root_disable() to the class switch path so it also
  covers partial-mode SCHED_EXT to SCHED_NORMAL transitions through
  sched_setscheduler(). Andrea identified this missing case in the v1
  discussion.

 kernel/sched/fair.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d78467ec6ee1..edb11065a9fc 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -14998,6 +14998,15 @@ static void switching_from_fair(struct rq *rq, struct task_struct *p)
 		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);
 }
 
+static void switching_to_fair(struct rq *rq, struct task_struct *p)
+{
+	/*
+	 * Tasks may come from classes that don't keep se.load up to date.
+	 * Rebuild it before the task is enqueued.
+	 */
+	set_load_weight(p, false);
+}
+
 static void switched_from_fair(struct rq *rq, struct task_struct *p)
 {
 	detach_task_cfs_rq(p);
@@ -15379,6 +15388,7 @@ DEFINE_SCHED_CLASS(fair) = {
 	.reweight_task		= reweight_task_fair,
 	.prio_changed		= prio_changed_fair,
 	.switching_from		= switching_from_fair,
+	.switching_to		= switching_to_fair,
 	.switched_from		= switched_from_fair,
 	.switched_to		= switched_to_fair,
 
-- 
2.53.0

  reply	other threads:[~2026-06-24  9:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260530050609.0D0FB1F00893@smtp.kernel.org>
2026-06-24  9:16 ` [PATCH v4 0/2] sched/fair: Fix fair load state " Zicheng Qu
2026-06-24  9:16   ` Zicheng Qu [this message]
2026-06-24  9:16   ` [PATCH v4 2/2] sched/fair: Keep load_avg in sync after reweighting Zicheng Qu
2026-06-24 11:57   ` [PATCH v4 0/2] sched/fair: Fix fair load state when switching to fair Andrea Righi

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=20260624091648.271891-2-quzicheng@huawei.com \
    --to=quzicheng@huawei.com \
    --cc=arighi@nvidia.com \
    --cc=brho@google.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=haoluo@google.com \
    --cc=joshdon@google.com \
    --cc=juri.lelli@redhat.co \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=quzicheng315@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    --cc=tanghui20@huawei.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.com \
    --cc=zhangqiao22@huawei.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®