From: Kuyo Chang <kuyo.chang@mediatek.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
"Ben Segall" <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
"Daniel Bristot de Oliveira" <bristot@redhat.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
<wsd_upstream@mediatek.com>, Ingo Molnar <mingo@kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH 1/1] [PATCH v3]sched/pelt: Fix the attach_entity_load_avg calculate method
Date: Fri, 15 Apr 2022 11:56:27 +0800 [thread overview]
Message-ID: <231503cb93caabb5fc0e1027423e971560493075.camel@mediatek.com> (raw)
In-Reply-To: <YlgzTS+laNNvMukT@hirez.programming.kicks-ass.net>
On Thu, 2022-04-14 at 16:44 +0200, Peter Zijlstra wrote:
> I've taken the liberty of carrying over the tags from v2 and reworked
> the Changelog a little.
Thank you for all your assistance.
> ---
> Subject: sched/pelt: Fix attach_entity_load_avg() corner case
> From: kuyo chang <kuyo.chang@mediatek.com>
> Date: Thu, 14 Apr 2022 17:02:20 +0800
>
> From: kuyo chang <kuyo.chang@mediatek.com>
>
> The warning in cfs_rq_is_decayed() triggered:
>
> SCHED_WARN_ON(cfs_rq->avg.load_avg ||
> cfs_rq->avg.util_avg ||
> cfs_rq->avg.runnable_avg)
>
> There exists a corner case in attach_entity_load_avg() which will
> cause load_sum to be zero while load_avg will not be.
>
> Consider se_weight is 88761 as per the sched_prio_to_weight[] table.
> Further assume the get_pelt_divider() is 47742, this gives:
> se->avg.load_avg is 1.
>
> However, calculating load_sum results in 0:
>
> se->avg.load_sum = div_u64(se->avg.load_avg * se->avg.load_sum,
> se_weight(se));
> se->avg.load_sum = 1*47742/88761 = 0.
>
> Then enqueue_load_avg() adds this to the cfs_rq totals:
>
> cfs_rq->avg.load_avg += se->avg.load_avg;
> cfs_rq->avg.load_sum += se_weight(se) * se->avg.load_sum;
>
> Resulting in load_avg being 1 with load_sum is 0, which will trigger
> the WARN.
>
> Fixes: f207934fb79d ("sched/fair: Align PELT windows between cfs_rq
> and its se")
> Signed-off-by: kuyo chang <kuyo.chang@mediatek.com>
> [peterz: massage changelog]
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Link:
> https://urldefense.com/v3/__https://lkml.kernel.org/r/20220414090229.342-1-kuyo.chang@mediatek.com__;!!CTRNKA9wMg0ARbw!35Im02xxIuUZdLYpPng37Yk7oVNJVJ1tfbu4XRzlq-6VhH3K29Por0gJCFlslT_CMgA$
>
> ---
> kernel/sched/fair.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -3829,11 +3829,11 @@ static void attach_entity_load_avg(struc
>
> se->avg.runnable_sum = se->avg.runnable_avg * divider;
>
> - se->avg.load_sum = divider;
> - if (se_weight(se)) {
> - se->avg.load_sum =
> - div_u64(se->avg.load_avg * se->avg.load_sum,
> se_weight(se));
> - }
> + se->avg.load_sum = se->avg.load_avg * divider;
> + if (se_weight(se) < se->avg.load_sum)
> + se->avg.load_sum = div_u64(se->avg.load_sum,
> se_weight(se));
> + else
> + se->avg.load_sum = 1;
>
> enqueue_load_avg(cfs_rq, se);
> cfs_rq->avg.util_avg += se->avg.util_avg;
next prev parent reply other threads:[~2022-04-15 3:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 9:02 [PATCH 1/1] [PATCH v3]sched/pelt: Fix the attach_entity_load_avg calculate method Kuyo Chang
2022-04-14 14:44 ` Peter Zijlstra
2022-04-15 3:56 ` Kuyo Chang [this message]
2022-04-19 19:35 ` [tip: sched/urgent] sched/pelt: Fix attach_entity_load_avg() corner case tip-bot2 for kuyo chang
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=231503cb93caabb5fc0e1027423e971560493075.camel@mediatek.com \
--to=kuyo.chang@mediatek.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=wsd_upstream@mediatek.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;
as well as URLs for NNTP newsgroup(s).