From: Chengming Zhou <chengming.zhou@linux.dev>
To: Chuyi Zhou <zhouchuyi@bytedance.com>,
mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched/fair: Sync se's load_avg with cfs_rq in reweight_entity
Date: Wed, 17 Jul 2024 19:18:44 +0800 [thread overview]
Message-ID: <3faf976d-52ee-4fc7-ad42-70fc0dc53de4@linux.dev> (raw)
In-Reply-To: <20240716150840.23061-1-zhouchuyi@bytedance.com>
On 2024/7/16 23:08, Chuyi Zhou wrote:
> In reweight_entity(), if !se->on_rq (e.g. when we are reweighting a
> sleeping task), we should sync the load_avg of se to cfs_rq before calling
> dequeue_load_avg(). Otherwise, the load_avg of this se can be inaccurate.
Good catch!
>
> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
> ---
> kernel/sched/fair.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 9057584ec06d..2807f6e72ad1 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -3782,6 +3782,8 @@ static void reweight_eevdf(struct sched_entity *se, u64 avruntime,
> se->deadline = avruntime + vslice;
> }
>
> +static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags);
> +
> static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
> unsigned long weight)
> {
> @@ -3795,7 +3797,11 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
> if (!curr)
> __dequeue_entity(cfs_rq, se);
> update_load_sub(&cfs_rq->load, se->load.weight);
> + } else {
> + /* Sync with the cfs_rq before removing our load_avg */
> + update_load_avg(cfs_rq, se, 0);
I think it's suboptimal to update_load_avg() here unconditionally.
Because reweight_entity() has two types of usages:
1. group se, which uses reweight_entity() in update_cfs_group(), which
should already update_load_avg(), so should have no problem.
2. task se, which uses reweight_entity() in reweight_task(), which
should be fixed for sleep task entity as you described above.
So IMHO, we should only update_load_avg() or sync_entity_load_avg() in
reweight_task(), right?
> }
> +
> dequeue_load_avg(cfs_rq, se);
>
> if (se->on_rq) {
next prev parent reply other threads:[~2024-07-17 11:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 15:08 [PATCH] sched/fair: Sync se's load_avg with cfs_rq in reweight_entity Chuyi Zhou
2024-07-17 11:18 ` Chengming Zhou [this message]
2024-07-18 2:32 ` Chuyi Zhou
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=3faf976d-52ee-4fc7-ad42-70fc0dc53de4@linux.dev \
--to=chengming.zhou@linux.dev \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=zhouchuyi@bytedance.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