From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=90.155.92.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796403087; b=Md/ZNdDVzNQgPAGMT6ucfRSGE5gnPu/tD2UzUp1Q6WPQxTS0KvOKO47NXkS8gv1ejCRB LQz9/SSczr9MF2wsIjDcHqxeRYeuJEzBJzm1rR+kLS19s1HwzGATRt9ry7RtWK4q55eZ4 iUerQtSdHb7QOGKCWRJXEuboPfiBATN5hTtH32xR0MtssHL17llbmHn9a6jE5wVx2NfEZ dpv9K3LVKyXKr2lbUlmXQHyhUaPOYBRzJ3wtV+aIPlsUJ67WpgJBQsXDQnBW9kJhPXEfC QAUb4FK7I0bTpVwKFiNN/hnnQVkRP4neiGmsaMQNXUDGg1ojFfXIE8B80zkMqoLPuKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796403087; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=hyffopWi/aqy1whbtNvmMoQ7PHZKvzq9QzboFlSLRH8=; b=YhN8dv76om187lAOFfYmLjCOm+gRfzU0iMztQwCQ7Cx+7RKJknlMGXjVIOotC6ny7AHY XeVHJ8XVebyVU3XCLpp6A7jWDdBE6DZGJMKswN5eGesa63AsgmaPCJFOcztayTV8XuFzl xtf+xhD9OvdYFcQdj9la211RT+U/VGDfKpI0lb1Uk9SogbyUdWqv1UibQ6Lme/UqaOZH5 tnk+AP+ZBYlFzLlxC4TW4BbUef3UWkX6gIdLb4flle0yO2pswsTX+nXufFseVlyXzylXS ZQVF+SudP3ogaxh9AmYDuVGK73dL5+upnrzsYKWCMvG41CKshtAhuhx33FuyDAkhAuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=COXe0xG3; arc=none smtp.remote-ip=90.155.92.199 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C160C606A32C; Fri, 4 Dec 2026 16:51:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C160C606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=COXe0xG3 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hyffopWi/aqy1whbtNvmMoQ7PHZKvzq9QzboFlSLRH8=; b=COXe0xG38PXJ1DeCuyCjP0rs0E BCLaL/X/XRKftnRGHZubK5ygIqgwxg0rwFz+r0q4xI5McYa+SUYmzt7DlLbRZHHDub4Jdm5ayG0vM nnh0kmRWNCCi60uXfrXztBL4m1MqU0OV2FIPPlBKjTSI5TAc3DAUG95ex5D84VIjUpFnOuJc57/L6 v2whqGWMUW8yeRcJ7WnjoWLFWI8tJ7q2XjURSYh4cJxwg2TP3pXHSpb0XlMXbUIZxG7+o9zy/8QIY pfHPJu1HsiwoofUV4whDJpElUpqViIOXuINdir9UiWaR75afhIv7SGV2xgaiAznR8BATqvPRL/per zK1Rx3mA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZWVB-0000000EbV7-0F3l; Fri, 04 Dec 2026 16:51:17 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 3ACD3300673; Fri, 04 Dec 2026 17:51:15 +0100 (CET) Date: Fri, 4 Dec 2026 17:51:15 +0100 From: Peter Zijlstra To: Zicheng Qu 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 Message-ID: <20261204165115.GV2668804@noisy.programming.kicks-ass.net> References: <20260530050609.0D0FB1F00893@smtp.kernel.org> <20260624091648.271891-1-quzicheng@huawei.com> <20260624091648.271891-3-quzicheng@huawei.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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; }