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 2/2] sched/fair: Keep load_avg in sync after reweighting
Date: Wed, 24 Jun 2026 09:16:48 +0000	[thread overview]
Message-ID: <20260624091648.271891-3-quzicheng@huawei.com> (raw)
In-Reply-To: <20260624091648.271891-1-quzicheng@huawei.com>

se->avg.load_avg is derived from se->avg.load_sum and se_weight().
When the fair load weight is rebuilt while switching back to fair,
load_avg must be rebuilt too before the entity is attached.

Factor the existing reweight_entity() calculation into a helper and use
it from switching_to_fair() as well.

Link: https://lore.kernel.org/all/20260530050609.0D0FB1F00893@smtp.kernel.org/
Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
---
Changes in v4:
- New patch.

 kernel/sched/fair.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index edb11065a9fc..19270132a506 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4663,6 +4663,13 @@ rescale_entity(struct sched_entity *se, unsigned long weight, bool rel_vprot)
 		se->vprot = div64_long(se->vprot * old_weight, weight);
 }
 
+static inline void update_load_avg_after_reweight(struct sched_entity *se)
+{
+	u32 divider = get_pelt_divider(&se->avg);
+
+	se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider);
+}
+
 static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 			    unsigned long weight)
 {
@@ -4692,11 +4699,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 	rescale_entity(se, weight, rel_vprot);
 
 	update_load_set(&se->load, weight);
-
-	do {
-		u32 divider = get_pelt_divider(&se->avg);
-		se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider);
-	} while (0);
+	update_load_avg_after_reweight(se);
 
 	enqueue_load_avg(cfs_rq, se);
 	if (se->on_rq) {
@@ -15005,6 +15008,7 @@ static void switching_to_fair(struct rq *rq, struct task_struct *p)
 	 * Rebuild it before the task is enqueued.
 	 */
 	set_load_weight(p, false);
+	update_load_avg_after_reweight(&p->se);
 }
 
 static void switched_from_fair(struct rq *rq, struct task_struct *p)
-- 
2.53.0

  parent 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 when switching to fair Zicheng Qu
2026-06-24  9:16   ` [PATCH v4 1/2] sched/fair: Rebuild load weight " Zicheng Qu
2026-06-24  9:16   ` Zicheng Qu [this message]
2026-06-24 11:57   ` [PATCH v4 0/2] sched/fair: Fix fair load state " 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-3-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®