From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Hongyan Xia <hongyan.xia2@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
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>,
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 <pierre.gondois@arm.com>,
Youssef Esmat <youssefesmat@google.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 7/7] Propagate negative bias
Date: Tue, 25 Jun 2024 10:18:35 +0530 [thread overview]
Message-ID: <0aa84916-bf29-2207-e0b4-a99fefba5a2e@amd.com> (raw)
In-Reply-To: <60985d07acd8a2daf4f3adf31ce4bf3be2982306.1719223916.git.hongyan.xia2@arm.com>
Hello Hongyan,
On 6/24/2024 3:53 PM, 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 | 40 ++++++++++++++++++++++++++++++++++++++++
> kernel/sched/sched.h | 4 ++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 3bb077df52ae..d09af6abf464 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4878,6 +4878,45 @@ static inline unsigned long root_cfs_util_uclamp(struct rq *rq)
>
> return max(ret, 0L);
> }
> +
> +/*
> + * 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);
Most cases where I've seen "get_pelt_divider()" followed by
"add_positive()" or "sub_positive()" on "util_avg" and "util_sum" I've
seen a correction step that does:
util_sum = max_t(u32, util_sum, util_avg * PELT_MIN_DIVIDER)
There is a comment on its significance in "update_cfs_rq_load_avg()".
Would it also apply in this case?
> + sub_positive(&cfs_rq->avg.util_avg, neg_bias);
> + sub_positive(&cfs_rq->avg.util_sum, neg_sum);
> + }
> + }
> +}
> #else
> static inline long task_util_bias(struct task_struct *p)
> {
> @@ -6869,6 +6908,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
> /* At this point se is NULL and we are at root level*/
> sub_nr_running(rq, 1);
> util_bias_dequeue(rq, p);
> + propagate_negative_bias(p);
Perhaps I'm pointing to a premature optimization but since the hierarchy
is traversed above in "dequeue_task_fair()", could the "neg_bias" and
"neg_sum" removal be done along the way above instead of
"propagate_negative_bias()" traversing the hierarchy again? I don't see
a dependency on "util_bias_dequeue()" (which modifies
"rq->cfs.avg.util_avg_bias") for "propagate_negative_bias()" (which
works purely with task_util_bias() or "p->se.avg.util_avg_bias") but if
I'm missing something please do let me know.
Since you mentioned this patch isn't strictly necessary in the cover
letter, I would wait for other folks to chime in before changing this :)
>
> /* balance early to pull high priority tasks */
> if (unlikely(!was_sched_idle && sched_idle_rq(rq)))
> [..snip..]
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2024-06-25 4:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 10:23 [PATCH 0/7] uclamp sum aggregation Hongyan Xia
2024-06-24 10:23 ` [PATCH 1/7] Revert "sched/uclamp: Set max_spare_cap_cpu even if max_spare_cap is 0" Hongyan Xia
2024-06-24 10:23 ` [PATCH 2/7] sched/uclamp: Track a new util_avg_bias signal Hongyan Xia
2024-06-24 10:23 ` [PATCH 3/7] sched/uclamp: Add util_est_uclamp Hongyan Xia
2024-06-24 10:23 ` [PATCH 4/7] sched/fair: Use util biases for utilization and frequency Hongyan Xia
2024-06-24 10:23 ` [PATCH 5/7] sched/uclamp: Remove all uclamp bucket logic Hongyan Xia
2024-06-24 10:23 ` [PATCH 6/7] sched/uclamp: Simplify uclamp_eff_value() Hongyan Xia
2024-06-24 10:23 ` [PATCH 7/7] Propagate negative bias Hongyan Xia
2024-06-25 4:48 ` K Prateek Nayak [this message]
2024-06-25 10:30 ` 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=0aa84916-bf29-2207-e0b4-a99fefba5a2e@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=christian.loehle@arm.com \
--cc=dietmar.eggemann@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 \
--cc=youssefesmat@google.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