From: Peter Zijlstra <peterz@infradead.org>
To: Zicheng Qu <quzicheng@huawei.com>
Cc: sashiko-bot@kernel.org, sashiko-reviews@lists.linux.dev,
linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev,
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, quzicheng315@gmail.com
Subject: Re: [PATCH v4 2/2] sched/fair: Keep load_avg in sync after reweighting
Date: Fri, 4 Dec 2026 17:51:15 +0100 [thread overview]
Message-ID: <20261204165115.GV2668804@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260624091648.271891-3-quzicheng@huawei.com>
On Wed, Jun 24, 2026 at 09:16:48AM +0000, Zicheng Qu wrote:
> 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)
This being an old patch it no long applies; but while doing the rebase,
I noticed that there is only one other update_load_set() user
(init_tg_cfs_entry). Calling it there should be a no-op, since load_sum
will be 0 at init.
Does it make sense to do something like so?
---
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4766,6 +4766,13 @@ dequeue_load_avg(struct cfs_rq *cfs_rq,
se_weight(se) * -se->avg.load_sum);
}
+static inline void update_load(struct sched_entity *se, unsigned long load)
+{
+ u32 divider = get_pelt_divider(&se->avg);
+ update_load_set(&se->load, load);
+ se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider);
+}
+
static void
rescale_entity(struct sched_entity *se, unsigned long weight, bool rel_vprot)
{
@@ -4896,7 +4903,7 @@ static void reweight_eevdf(struct cfs_rq
rescale_entity(se, weight, rel_vprot);
- update_load_set(&se->h_load, weight);
+ update_load(se, weight);
if (on_rq) {
if (rel_vprot)
@@ -4923,12 +4930,7 @@ static void reweight_entity(struct cfs_r
}
dequeue_load_avg(cfs_rq, se);
- 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(se, weight);
enqueue_load_avg(cfs_rq, se);
@@ -15514,6 +15516,7 @@ static void switching_to_fair(struct rq
* Rebuild it before the task is enqueued.
*/
set_load_weight(p, false);
+ update_load(&p->se, p->se.load.weight);
}
static void switched_from_fair(struct rq *rq, struct task_struct *p)
@@ -15742,7 +15745,7 @@ void init_tg_cfs_entry(struct task_group
se->my_q = cfs_rq;
/* guarantee group entities always have weight */
- update_load_set(&se->load, NICE_0_LOAD);
+ update_load(se, NICE_0_LOAD);
se->parent = parent;
}
next prev parent reply other threads:[~2026-12-04 16:51 UTC|newest]
Thread overview: 6+ 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 ` [PATCH v4 2/2] sched/fair: Keep load_avg in sync after reweighting Zicheng Qu
2026-12-04 16:51 ` Peter Zijlstra [this message]
2026-12-06 5:57 ` quzicheng315
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=20261204165115.GV2668804@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--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=quzicheng315@gmail.com \
--cc=quzicheng@huawei.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®