Re: [RFC PATCH v2 4/7] sched/fair: Use CFS util_avg_uclamp for utilization and frequency

From: Hongyan Xia
Date: Fri Mar 15 2024 - 15:49:08 EST


On 15/03/2024 12:31, Dietmar Eggemann wrote:
On 01/02/2024 14:12, Hongyan Xia wrote:

[...]

@@ -7685,11 +7697,13 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
static unsigned long
cpu_util(int cpu, struct task_struct *p, int dst_cpu, int boost)
{
- struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs;
- unsigned long util = READ_ONCE(cfs_rq->avg.util_avg);
+ struct rq *rq = cpu_rq(cpu);
+ struct cfs_rq *cfs_rq = &rq->cfs;
+ unsigned long util = root_cfs_util(rq);
+ bool capped = uclamp_rq_is_capped(rq);

I try to rerun your tests in your 2 ipynbs (cover letter) but this let's
the sum aggr stack go sideways ...

if 'sched_uclamp_used' then uclamp_rq_is_capped() will call
cpu_util_cfs()->cpu_util() which then calls uclamp_rq_is_capped()
recursively resulting in a stack overflow.

Do you have a fix for that you can share? For the time I remove the call
to uclamp_rq_is_capped() in cpu_util().

My apologies. This has long ago been fixed and here is the diff:

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 1ebdd0b9ebca..d5dcda036e0d 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3018,9 +3018,8 @@ static inline bool uclamp_rq_is_capped(struct rq *rq)
if (!static_branch_likely(&sched_uclamp_used))
return false;

- rq_uclamp_util = cpu_util_cfs(cpu_of(rq)) + cpu_util_rt(rq);
- rq_real_util = READ_ONCE(rq->cfs.avg.util_avg) +
- READ_ONCE(rq->avg_rt.util_avg);
+ rq_uclamp_util = READ_ONCE(rq->root_cfs_util_uclamp);
+ rq_real_util = READ_ONCE(rq->cfs.avg.util_avg);

return rq_uclamp_util < SCHED_CAPACITY_SCALE &&
rq_real_util > rq_uclamp_util;

[...]