From: Qais Yousef <qyousef@layalina.io>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Lukasz Luba <lukasz.luba@arm.com>
Subject: Re: [PATCH 1/4] sched: cpufreq: Rename map_util_perf to apply_dvfs_headroom
Date: Sun, 20 Aug 2023 22:13:07 +0100 [thread overview]
Message-ID: <20230820211307.p6gypri2jztqwf2o@airbuntu> (raw)
In-Reply-To: <20230820210640.585311-2-qyousef@layalina.io>
On 08/20/23 22:06, Qais Yousef wrote:
> We are providing headroom for the utilization to grow until the next
> decision point to pick the next frequency. Give the function a better
> name and give it some documentation. It is not really mapping anything.
>
> Provide a dummy definition for !CONFIG_CPUFREQ which will be required
> for later patches.
>
> Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io>
> ---
> include/linux/energy_model.h | 2 +-
> include/linux/sched/cpufreq.h | 27 ++++++++++++++++++++++++++-
> kernel/sched/cpufreq_schedutil.c | 6 +++---
> 3 files changed, 30 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h
> index b9caa01dfac4..6ebde4e69e98 100644
> --- a/include/linux/energy_model.h
> +++ b/include/linux/energy_model.h
> @@ -243,7 +243,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
> scale_cpu = arch_scale_cpu_capacity(cpu);
> ps = &pd->table[pd->nr_perf_states - 1];
>
> - max_util = map_util_perf(max_util);
> + max_util = apply_dvfs_headroom(max_util);
> max_util = min(max_util, allowed_cpu_cap);
> freq = map_util_freq(max_util, ps->frequency, scale_cpu);
>
> diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h
> index bdd31ab93bc5..f0069b354ac8 100644
> --- a/include/linux/sched/cpufreq.h
> +++ b/include/linux/sched/cpufreq.h
> @@ -29,10 +29,35 @@ static inline unsigned long map_util_freq(unsigned long util,
> return freq * util / cap;
> }
>
> -static inline unsigned long map_util_perf(unsigned long util)
> +/*
> + * DVFS decision are made at discrete points. If CPU stays busy, the util will
> + * continue to grow, which means it could need to run at a higher frequency
> + * before the next decision point was reached. IOW, we can't follow the util as
> + * it grows immediately, but there's a delay before we issue a request to go to
> + * higher frequency. The headroom caters for this delay so the system continues
> + * to run at adequate performance point.
> + *
> + * This function provides enough headroom to provide adequate performance
> + * assuming the CPU continues to be busy.
> + *
> + * At the moment it is a constant multiplication with 1.25.
> + *
> + * TODO: The headroom should be a function of the delay. 25% is too high
> + * especially on powerful systems. For example, if the delay is 500us, it makes
> + * more sense to give a small headroom as the next decision point is not far
> + * away and will follow the util if it continues to rise. On the other hand if
> + * the delay is 10ms, then we need a bigger headroom so the CPU won't struggle
> + * at a lower frequency if it never goes to idle until then.
> + */
I'm happy to drop this TODO if it is controversial. I already have a series
that works in that effect that I will hopefully get a chance to post soon
enough.
Cheers
--
Qais Yousef
> +static inline unsigned long apply_dvfs_headroom(unsigned long util)
> {
> return util + (util >> 2);
> }
> +#else
> +static inline unsigned long apply_dvfs_headroom(unsigned long util)
> +{
> + return util;
> +}
> #endif /* CONFIG_CPU_FREQ */
>
> #endif /* _LINUX_SCHED_CPUFREQ_H */
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 4492608b7d7f..916c4d3d6192 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -143,7 +143,7 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,
> unsigned int freq = arch_scale_freq_invariant() ?
> policy->cpuinfo.max_freq : policy->cur;
>
> - util = map_util_perf(util);
> + util = apply_dvfs_headroom(util);
> freq = map_util_freq(util, freq, max);
>
> if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)
> @@ -406,8 +406,8 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time,
> sugov_cpu_is_busy(sg_cpu) && sg_cpu->util < prev_util)
> sg_cpu->util = prev_util;
>
> - cpufreq_driver_adjust_perf(sg_cpu->cpu, map_util_perf(sg_cpu->bw_dl),
> - map_util_perf(sg_cpu->util), max_cap);
> + cpufreq_driver_adjust_perf(sg_cpu->cpu, apply_dvfs_headroom(sg_cpu->bw_dl),
> + apply_dvfs_headroom(sg_cpu->util), max_cap);
>
> sg_cpu->sg_policy->last_freq_update_time = time;
> }
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-08-20 21:13 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-20 21:06 [PATCH 0/4] Fix dvfs_headroom escaping uclamp constraints Qais Yousef
2023-08-20 21:06 ` [PATCH 1/4] sched: cpufreq: Rename map_util_perf to apply_dvfs_headroom Qais Yousef
2023-08-20 21:13 ` Qais Yousef [this message]
2023-08-21 16:38 ` Dietmar Eggemann
2023-08-26 20:03 ` Qais Yousef
2023-08-20 21:06 ` [PATCH 2/4] sched: cpufreq: Fix apply_dvfs_headroom() escaping uclamp constraints Qais Yousef
2023-08-21 16:39 ` Dietmar Eggemann
2023-08-26 20:08 ` Qais Yousef
2023-09-12 14:34 ` Dietmar Eggemann
2023-09-16 20:30 ` Qais Yousef
2023-08-29 14:35 ` Vincent Guittot
2023-08-29 16:37 ` Qais Yousef
2023-09-07 13:47 ` Vincent Guittot
2023-09-07 21:55 ` Qais Yousef
2023-09-08 14:30 ` Vincent Guittot
2023-09-10 17:46 ` Qais Yousef
2023-09-12 13:40 ` Dietmar Eggemann
2023-09-16 19:25 ` Qais Yousef
2023-09-12 16:03 ` Vincent Guittot
2023-09-16 19:25 ` Qais Yousef
2023-09-24 7:58 ` Vincent Guittot
2023-09-24 17:23 ` Qais Yousef
2023-09-28 17:50 ` Vincent Guittot
2023-09-28 22:05 ` Qais Yousef
2023-09-29 8:01 ` Vincent Guittot
2023-08-20 21:06 ` [PATCH 3/4] sched: cpufreq: Move apply_dvfs_headroom() to sched.h Qais Yousef
2023-08-21 16:40 ` Dietmar Eggemann
2023-08-20 21:06 ` [PATCH RFC 4/4] sched: cpufreq: Apply DVFS headroom to CFS only Qais Yousef
2023-08-21 16:41 ` Dietmar Eggemann
2023-08-26 20:27 ` Qais Yousef
2023-08-21 10:34 ` [PATCH 0/4] Fix dvfs_headroom escaping uclamp constraints Rafael J. Wysocki
2023-08-26 19:17 ` Qais Yousef
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=20230820211307.p6gypri2jztqwf2o@airbuntu \
--to=qyousef@layalina.io \
--cc=dietmar.eggemann@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@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