Re: [PATCH v2 2/2] sched/fair, cpufreq: Introduce 'runnable boosting'

From: Dietmar Eggemann
Date: Fri May 12 2023 - 10:40:00 EST


On 12/05/2023 13:22, Peter Zijlstra wrote:
> On Fri, May 12, 2023 at 12:10:29PM +0200, Dietmar Eggemann wrote:
>
>> -static unsigned long cpu_util(int cpu, struct task_struct *p, int dst_cpu)
>> +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);
>> + unsigned long runnable;
>> +
>> + runnable = boost ? READ_ONCE(cfs_rq->avg.runnable_avg) : 0;
>> + util = max(util, runnable);
>>
> if (boost)
> util = max(util, READ_ONCE(cfs_rq->avg.runnable_avg));

I need the util_est = max(util_est, runnable) further down as well. Just
want to fetch runnable only once.

util = 50, task_util = 5, util_est = 60, task_util_est = 10, runnable = 70

max(70 + 5, 60 + 10) != max (70 + 5, 70 + 10) when dst_cpu == cpu

>> @@ -7239,9 +7246,9 @@ static unsigned long cpu_util(int cpu, struct task_struct *p, int dst_cpu)
>> *
>> * Return: (Estimated) utilization for the specified CPU.
>> */
>
> Given that cpu_util() is the base function should this comment move
> there?

Yes, will move it.

>> -unsigned long cpu_util_cfs(int cpu)
>> +unsigned long cpu_util_cfs(int cpu, int boost)
>> {
>> - return cpu_util(cpu, NULL, -1);
>> + return cpu_util(cpu, NULL, -1, boost);
>> }
>
> AFAICT the @boost argument is always a constant (0 or 1). Would it not
> make more sense to simply add:
>
> unsigned long cpu_util_cfs_boost(int cpu)
> {
> return cpu_util(cpu, NULL, -1, 1);
> }
>
> and use that in the few sites that actually need it?

Yes, will change it.