From: Dietmar Eggemann <dietmar.eggemann@arm.com>
To: Hongyan Xia <hongyan.xia2@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Juri Lelli <juri.lelli@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>
Cc: Qais Yousef <qyousef@layalina.io>,
Morten Rasmussen <morten.rasmussen@arm.com>,
Lukasz Luba <lukasz.luba@arm.com>,
Christian Loehle <christian.loehle@arm.com>,
pierre.gondois@arm.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v3 6/6] Propagate negative bias
Date: Mon, 27 May 2024 00:53:03 +0200 [thread overview]
Message-ID: <e308fbfc-d016-4362-998e-e4810321b53a@arm.com> (raw)
In-Reply-To: <f60a29ac1af5098e0d37d426aec27db05d5d43e1.1715082714.git.hongyan.xia2@arm.com>
On 07/05/2024 14:50, Hongyan Xia wrote:
> Negative bias is interesting, because dequeuing such a task will
> actually increase utilization.
>
> Solve by applying PELT decay to negative biases as well. This in fact
> can be implemented easily with some math tricks.
>
> Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>
> ---
> kernel/sched/fair.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 0177d7e8f364..7259a61e9ae5 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4863,6 +4863,45 @@ static inline unsigned long task_util_est_uclamp(struct task_struct *p)
> {
> return max(task_util_uclamp(p), _task_util_est_uclamp(p));
> }
> +
> +/*
> + * Negative biases are tricky. If we remove them right away then dequeuing a
> + * uclamp_max task has the interesting effect that dequeuing results in a higher
> + * rq utilization. Solve this by applying PELT decay to the bias itself.
> + *
> + * Keeping track of a PELT-decayed negative bias is extra overhead. However, we
> + * observe this interesting math property, where y is the decay factor and p is
> + * the number of periods elapsed:
> + *
> + * util_new = util_old * y^p - neg_bias * y^p
> + * = (util_old - neg_bias) * y^p
> + *
> + * Therefore, we simply subtract the negative bias from util_avg the moment we
> + * dequeue, then the PELT signal itself is the total of util_avg and the decayed
> + * negative bias, and we no longer need to track the decayed bias separately.
> + */
> +static void propagate_negative_bias(struct task_struct *p)
> +{
> + if (task_util_bias(p) < 0 && !task_on_rq_migrating(p)) {
> + unsigned long neg_bias = -task_util_bias(p);
> + struct sched_entity *se = &p->se;
> + struct cfs_rq *cfs_rq;
> +
> + p->se.avg.util_avg_bias = 0;
> +
> + for_each_sched_entity(se) {
> + u32 divider, neg_sum;
> +
> + cfs_rq = cfs_rq_of(se);
> + divider = get_pelt_divider(&cfs_rq->avg);
> + neg_sum = neg_bias * divider;
> + sub_positive(&se->avg.util_avg, neg_bias);
> + sub_positive(&se->avg.util_sum, neg_sum);
> + sub_positive(&cfs_rq->avg.util_avg, neg_bias);
> + sub_positive(&cfs_rq->avg.util_sum, neg_sum);
> + }
> + }
So you remove the 'task bias = clamp(util_avg, uclamp_min, uclamp_max) -
util_avg' from the se and cfs_rq util_avg' in case it's negative. I.e.
if the task is capped hard.
Looks like this is the old issue that PELT has blocked contribution
whereas uclamp does not (runnable only).
What's the rationale behind this? Is it because the task didn't get the
runtime it needed so we can remove this (artificially accrued) util_avg?
Normally we wouldn't remove blocked util_avg and let it rather decay
periodically for cfs_rq's and at wakeup for tasks.
[...]
next prev parent reply other threads:[~2024-05-26 22:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 12:50 [RFC PATCH v3 0/6] Uclamp sum aggregation Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 1/6] Revert "sched/uclamp: Set max_spare_cap_cpu even if max_spare_cap is 0" Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 2/6] sched/uclamp: Track a new util_avg_bias signal Hongyan Xia
2024-05-26 22:52 ` Dietmar Eggemann
2024-05-28 11:09 ` Hongyan Xia
2024-06-10 15:29 ` Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 3/6] sched/fair: Use util biases for utilization and frequency Hongyan Xia
2024-05-26 22:52 ` Dietmar Eggemann
2024-05-28 11:38 ` Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 4/6] sched/uclamp: Remove all uclamp bucket logic Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 5/6] sched/uclamp: Simplify uclamp_eff_value() Hongyan Xia
2024-05-26 22:52 ` Dietmar Eggemann
2024-05-28 11:42 ` Hongyan Xia
2024-05-07 12:50 ` [RFC PATCH v3 6/6] Propagate negative bias Hongyan Xia
2024-05-26 22:53 ` Dietmar Eggemann [this message]
2024-05-28 11:53 ` Hongyan Xia
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=e308fbfc-d016-4362-998e-e4810321b53a@arm.com \
--to=dietmar.eggemann@arm.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=christian.loehle@arm.com \
--cc=hongyan.xia2@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=peterz@infradead.org \
--cc=pierre.gondois@arm.com \
--cc=qyousef@layalina.io \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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