Re: [PATCH v7 13/23] PM: EM: Add performance field to struct em_perf_state and optimize

From: Dietmar Eggemann
Date: Mon Jan 29 2024 - 13:14:10 EST


On 17/01/2024 09:57, Lukasz Luba wrote:

[...]

> include/linux/energy_model.h | 24 ++++++++++++------------
> kernel/power/energy_model.c | 27 +++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h
> index 5ebe9dbec8e1..689d71f6b56f 100644
> --- a/include/linux/energy_model.h
> +++ b/include/linux/energy_model.h
> @@ -13,6 +13,7 @@
>
> /**
> * struct em_perf_state - Performance state of a performance domain
> + * @performance: CPU performance (capacity) at a given frequency

I guess this is what we called the 'current CPU capacity' in older
Android versions.

[...]

> @@ -260,26 +262,24 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
> /*
> * In order to predict the performance state, map the utilization of
> * the most utilized CPU of the performance domain to a requested
> - * frequency, like schedutil. Take also into account that the real
> - * frequency might be set lower (due to thermal capping). Thus, clamp
> + * performance, like schedutil. Take also into account that the real
> + * performance might be set lower (due to thermal capping). Thus, clamp
> * max utilization to the allowed CPU capacity before calculating
> - * effective frequency.
> + * effective performance.
> */
> cpu = cpumask_first(to_cpumask(pd->cpus));
> scale_cpu = arch_scale_cpu_capacity(cpu);
> - ref_freq = arch_scale_freq_ref(cpu);
>
> max_util = map_util_perf(max_util);

Didn't apply cleanly on tip sched/code for me.

Looks like it's missing:

9c0b4bb7f630 - sched/cpufreq: Rework schedutil governor performance
estimation (2023-11-23 Vincent Guittot)

> max_util = min(max_util, allowed_cpu_cap);
> - freq = map_util_freq(max_util, ref_freq, scale_cpu);

Since you're removing this here, shouldn't you also remove

* In order to predict the performance state, map the utilization of
* the most utilized CPU of the performance domain to a requested

Looks like with 9c0b4bb7f630 there is no mapping anymore?

[...]

> static int em_compute_costs(struct device *dev, struct em_perf_state *table,
> struct em_data_callback *cb, int nr_states,
> unsigned long flags)
> @@ -318,6 +343,8 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
> table[i].frequency = prev_freq = freq;
> }
>
> + em_init_performance(dev, pd, table, nr_states);

Looks like pd already has 'pd->nr_perf_states' initialized. so just
passing pd seems to be sufficient. Like for em_table_alloc() and
em_create_perf_table().

[...]