From: Hongyan Xia <hongyan.xia2@arm.com>
To: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Juri Lelli <juri.lelli@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>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/6] sched/uclamp: Simulate PELT decay in util_avg_uclamp
Date: Thu, 9 Nov 2023 16:50:44 +0000 [thread overview]
Message-ID: <531fd8a0-132e-425b-955b-d60a56004aba@arm.com> (raw)
In-Reply-To: <b09848dc-dea8-46e7-9f24-c11c64fd5d74@arm.com>
On 01/11/2023 16:06, Dietmar Eggemann wrote:
> On 04/10/2023 11:04, Hongyan Xia wrote:
>> From: Hongyan Xia <hongyan.xia2@arm.com>
>>
>> Because util_avg_uclamp is not directly managed by PELT, it lacks the
>> nice property of slowly decaying to a lower value, resulting in
>> performance degredation due to premature frequency drops.
>>
>> Add functions to decay root cfs utilization and tasks that are not on
>> the rq. This way, we get the benefits of PELT while still maintaining
>> uclamp. The rules are simple:
>>
>> 1. When task is se->on_rq, enforce its util_avg_uclamp within uclamp
>> range.
>> 2. When task is !se->on_rq, PELT decay its util_avg_uclamp.
>> 3. When the root CFS util drops, PELT decay to the target frequency
>> instead of immediately dropping to a lower target frequency.
>>
>> TODO: Can we somehow integrate this uclamp sum aggregation directly into
>> util_avg, so that we don't need to introduce a new util_avg_uclamp
>> signal and don't need to simulate PELT decay?
>
> That's a good question. I'm wondering why you were not able to integrate
> the maintenance of the util_avg_uclamp values inside the existing PELT
> update functionality in fair.c ((__update_load_avg_xxx(),
> propagate_entity_load_avg() -> update_tg_cfs_util() etc.)
>
> Why do you need extra functions like ___decay_util_avg_uclamp_towards()
> and ___update_util_avg_uclamp() for this?
These new functions are already in __update_load_avg_xxx(). I just
separate the new code into a separate function for readability.
I think we have talked offline on why we can't do things in
propagate_entity_load_avg() -> update_tg_cfs_util(). Currently cfs_rq
and se utilization is tracked independently. However, we can't track
them separately in sum aggregation. If a cfs_rq has two tasks with
utilization at 1024 and UCLAMP_MAX of 100, the cfs_rq must sum up those
two tasks, at 200, and cannot use the logic inside
propagate_entity_load_avg() -> update_tg_cfs_util() which is for
tracking cfs_rq independently and won't know the utilization is only 200.
Again I may have misunderstood what you meant. Do you have a concrete
example on how to do this without extra functions?
One idea I once had is to use the existing util_avg, and introduce a
'util_bias' variable. When there's no uclamp, this bias is 0 and
util_avg is what it is. When there's uclamp, for example, two tasks at
utilization of 400 but UCLAMP_MAX of 300, then each task has a util_bias
of -100, and cfs_rq will sum up the biases, at -200. Then, the cfs_rq
will run at 600 instead of 800. This way, no PELT simulation is needed.
However, this doesn't work, because say two tasks with utilization of
1024 but UCLAMP_MAX at 100, each will have a bias of -924 and cfs_rq
will sum up and have a bias of -1848, but the cfs_rq will be at 1024,
not 2048, so adding this bias will give you cfs_rq utilization of -824,
which is clearly wrong here.
>> Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>
>> ---
>> kernel/sched/fair.c | 20 +++++++++
>> kernel/sched/pelt.c | 103 ++++++++++++++++++++++++++++++++++++++++---
>> kernel/sched/sched.h | 2 +
>> 3 files changed, 119 insertions(+), 6 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 33e5a6e751c0..420af57d01ee 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -4311,17 +4311,22 @@ static inline int
>> update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
>> {
>> unsigned long removed_load = 0, removed_util = 0, removed_runnable = 0;
>> + unsigned int removed_root_util = 0;
>
> unsigned long removed_load = 0, removed_util = 0, removed_runnable = 0;
> -unsigned int removed_root_util = 0;
> +unsigned int __maybe_unused removed_root_util = 0;
>
> Otherwise you get `warning: unused variable ‘rq’` w/ !CONFIG_UCLAMP_TASK
Thanks. Ack.
>
> [...]
>
>
>> #ifdef CONFIG_UCLAMP_TASK
>> +static void ___decay_util_avg_uclamp_towards(u64 now,
>> + u64 last_update_time,
>> + u32 period_contrib,
>> + unsigned int *old,
>> + unsigned int new_val)
>> +{
>> + unsigned int old_val = READ_ONCE(*old);
>> + u64 delta, periods;
>> +
>> + if (old_val <= new_val) {
>> + WRITE_ONCE(*old, new_val);
>> + return;
>> + }
>
> Why is the function called `decay`? In case `new >= old` you set old =
> new and bail out. So it's also more like an `update` function?
Bad naming indeed. I will rename it to ___update_util_avg_uclamp_towards
>> + if (!last_update_time)
>> + return;
>> + delta = now - last_update_time;
>> + if ((s64)delta < 0)
>> + return;
>> + delta >>= 10;
>> + if (!delta)
>> + return;
>> +
>> + delta += period_contrib;
>> + periods = delta / 1024;
>> + if (periods) {
>> + u64 diff = old_val - new_val;
>> +
>> + /*
>> + * Let's assume 3 tasks, A, B and C. A is still on rq but B and
>> + * C have just been dequeued. The cfs.avg.util_avg_uclamp has
>> + * become A but root_cfs_util_uclamp just starts to decay and is
>> + * now still A + B + C.
>> + *
>> + * After p periods with y being the decay factor, the new
>> + * root_cfs_util_uclamp should become
>> + *
>> + * A + B * y^p + C * y^p == A + (A + B + C - A) * y^p
>> + * == cfs.avg.util_avg_uclamp +
>> + * (root_cfs_util_uclamp_at_the_start - cfs.avg.util_avg_uclamp) * y^p
>> + * == cfs.avg.util_avg_uclamp + diff * y^p
>> + *
>> + * So, instead of summing up each individual decayed values, we
>> + * could just decay the diff and not bother with the summation
>> + * at all. This is why we decay the diff here.
>> + */
>> + diff = decay_load(diff, periods);
>> + WRITE_ONCE(*old, new_val + diff);
>> + }
>> +}
>
> Looks like ___decay_util_avg_uclamp_towards() is used for:
>
> (1) tasks with !se->on_rq to decay before enqueue
>
> (2) rq->root_cfs_util_uclamp to align with
> &rq_of(cfs_rq)->cfs->avg.util_avg_uclamp
>
> All the cfs_rq's and the taskgroup se's seem to be updated only in
> ___update_util_avg_uclamp() (which also handles the propagation towards
> the root taskgroup).
Yes, I would say that's a nice summary.
When !se->on_rq, we never use ___update_util_avg_uclamp() but instead do
___update_util_avg_uclamp_towards().
>
> [...]
next prev parent reply other threads:[~2023-11-09 16:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 9:04 [RFC PATCH 0/6] sched: uclamp sum aggregation Hongyan Xia
2023-10-04 9:04 ` [RFC PATCH 1/6] sched/uclamp: Track uclamped util_avg in sched_avg Hongyan Xia
2023-10-31 15:52 ` Dietmar Eggemann
2023-11-09 16:05 ` Hongyan Xia
2023-11-14 12:59 ` Dietmar Eggemann
2023-12-04 16:07 ` Vincent Guittot
2023-12-05 14:24 ` Hongyan Xia
2023-12-05 16:22 ` Vincent Guittot
2023-10-04 9:04 ` [RFC PATCH 2/6] sched/uclamp: Simulate PELT decay in util_avg_uclamp Hongyan Xia
2023-11-01 16:06 ` Dietmar Eggemann
2023-11-09 16:50 ` Hongyan Xia [this message]
2023-12-04 16:07 ` Vincent Guittot
2023-12-05 14:47 ` Hongyan Xia
2023-10-04 9:04 ` [RFC PATCH 3/6] sched/fair: Use CFS util_avg_uclamp for utilization and frequency Hongyan Xia
2023-11-01 22:34 ` Dietmar Eggemann
2023-10-04 9:04 ` [RFC PATCH 4/6] sched/fair: Rewrite util_fits_cpu() Hongyan Xia
2023-11-02 17:37 ` Dietmar Eggemann
2023-10-04 9:04 ` [RFC PATCH 5/6] sched/uclamp: Remove all uclamp bucket logic Hongyan Xia
2023-11-03 13:50 ` Dietmar Eggemann
2023-11-03 14:01 ` Hongyan Xia
2023-10-04 9:04 ` [RFC PATCH 6/6] sched/uclamp: Simplify uclamp_eff_value() Hongyan Xia
2023-11-03 14:50 ` Dietmar Eggemann
2023-10-30 18:46 ` [RFC PATCH 0/6] sched: uclamp sum aggregation Dietmar Eggemann
2023-11-03 11:19 ` Hongyan Xia
2023-11-13 9:26 ` Dietmar Eggemann
2023-12-03 0:25 ` Qais Yousef
2023-12-04 1:48 ` Hongyan Xia
2023-12-04 16:12 ` Vincent Guittot
2023-12-05 15:18 ` Hongyan Xia
2023-12-05 16:26 ` Vincent Guittot
2023-12-05 17:23 ` 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=531fd8a0-132e-425b-955b-d60a56004aba@arm.com \
--to=hongyan.xia2@arm.com \
--cc=christian.loehle@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--cc=vincent.guittot@linaro.org \
/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
all inboxes | Powered by JetHome®