[PATCH RFC 4/4] sched: cpufreq: Apply DVFS headroom to CFS only

From: Qais Yousef
Date: Sun Aug 20 2023 - 17:08:43 EST


RT and Deadline have exact performance requirement when running. RT runs
at max or a specific OPP defined by uclamp_min. Deadline's OPP is
defined by its bandwidth. Both of which are known ahead of time and
don't require a headroom to grow into.

IRQs on the other hand have no specific performance requirement and
cruises along at whatever the current OPP happens to be when they occur.

Now they all have PELT pressure signals that does impact frequency
selection and task placement. The question is do they need DVFS
headroom?

I think the answer is no because when CFS is not running at all, these
pressure signal has no real impact on performance for RT, DL or IRQ.

If CFS util is not zero, we already add their pressure as an
*additional* headroom to account for the lost/stolen time. So I argue
that the pressure are headroom themselves and shouldn't need an
additional DVFS headroom applied on top.

In summary final outcome should be:

CFS + DVFS headroom + (RT, DT, IRQ) pressure headroom

Signed-off-by: Qais Yousef (Google) <qyousef@xxxxxxxxxxx>
---
kernel/sched/core.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 441d433c83cd..602e369753a3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7438,10 +7438,11 @@ unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
* When there are no CFS RUNNABLE tasks, clamps are released and
* frequency will be gracefully reduced with the utilization decay.
*/
- util = util_cfs + cpu_util_rt(rq);
if (type == FREQUENCY_UTIL) {
- util = apply_dvfs_headroom(util);
+ util = apply_dvfs_headroom(util_cfs) + cpu_util_rt(rq);
util = uclamp_rq_util_with(rq, util, p);
+ } else {
+ util = util_cfs + cpu_util_rt(rq);
}

dl_util = cpu_util_dl(rq);
@@ -7473,12 +7474,9 @@ unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
* max - irq
* U' = irq + --------- * U
* max
- *
- * We only need to apply dvfs headroom to irq part since the util part
- * already had it applied.
*/
util = scale_irq_capacity(util, irq, max);
- util += type == FREQUENCY_UTIL ? apply_dvfs_headroom(irq) : irq;
+ util += irq;

/*
* Bandwidth required by DEADLINE must always be granted while, for
@@ -7491,7 +7489,7 @@ unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
* an interface. So, we only do the latter for now.
*/
if (type == FREQUENCY_UTIL)
- util += apply_dvfs_headroom(cpu_bw_dl(rq));
+ util += cpu_bw_dl(rq);

return min(max, util);
}
--
2.34.1