Re: [PATCH v3 1/1] cpufreq: schedutil: Optimize operations with single CPU capacity lookup

From: Lukasz Luba
Date: Fri Dec 09 2022 - 03:39:21 EST




On 12/8/22 23:38, Viresh Kumar wrote:
On 08-12-22, 16:02, Lukasz Luba wrote:
@@ -332,12 +333,15 @@ static void sugov_update_single_freq(struct update_util_data *hook, u64 time,
struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);
struct sugov_policy *sg_policy = sg_cpu->sg_policy;
unsigned int cached_freq = sg_policy->cached_raw_freq;
+ unsigned long max_cap;
unsigned int next_f;
- if (!sugov_update_single_common(sg_cpu, time, flags))
+ max_cap = arch_scale_cpu_capacity(sg_cpu->cpu);

I will rather do this at all three locations:

unsigned long max_cap = arch_scale_cpu_capacity(sg_cpu->cpu);


In the 2nd location it is called after the check:

if (!arch_scale_freq_invariant())

which can return.

IMO this is more visible and exposed.
The way it's implemented now stresses the fact that
we read this value at runtime (unfortunately). Maybe in the
future someone would find it and simplify.

I sometimes found difficult to spot those important calls in
the variable header section, e.g. how many times are called
or with what kind of arguments. In this case the sg_cpu->cpu
should be clearly visible and effectively matched as the same as
smp_procesor_id() for that running CPU, thus fetching the
same capacity variable from local per-cpu (not remote).
IMO the way how the code is structured could help (or not)
to spot those details. That's why I prefer to keep it as is
in this implementation.