Re: [PATCH 16/20 v3] energy model: Add a get previous state function

From: Rafael J. Wysocki (Intel)

Date: Tue Nov 10 2026 - 14:57:15 EST


On Fri, Nov 6, 2026 at 4:21 PM Vincent Guittot
<vincent.guittot@xxxxxxxxxx> wrote:
>
> Instead of parsing the entire EM table everytime, add a function to get the
> previous state.
>
> Will be used in the scheduler feec() function.
>
> Signed-off-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>

No objections from me.

Acked-by: Rafael J. Wysocki (Intel) <rafael@xxxxxxxxxx>

> ---
> include/linux/energy_model.h | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h
> index c909a8ba22e8..89cf109cbca6 100644
> --- a/include/linux/energy_model.h
> +++ b/include/linux/energy_model.h
> @@ -224,6 +224,26 @@ em_pd_get_efficient_state(struct em_perf_state *table,
> return max_ps;
> }
>
> +static inline int
> +em_pd_get_previous_state(struct em_perf_state *table,
> + struct em_perf_domain *pd, int idx)
> +{
> + unsigned long pd_flags = pd->flags;
> + int min_ps = pd->min_perf_state;
> + struct em_perf_state *ps;
> + int i;
> +
> + for (i = idx - 1; i >= min_ps; i--) {
> + ps = &table[i];
> + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES &&
> + ps->flags & EM_PERF_STATE_INEFFICIENT)
> + continue;
> + return i;
> + }
> +
> + return -1;
> +}
> +
> /**
> * em_cpu_energy() - Estimates the energy consumed by the CPUs of a
> * performance domain
> @@ -375,6 +395,18 @@ static inline struct em_perf_domain *em_pd_get(struct device *dev)
> {
> return NULL;
> }
> +static inline int
> +em_pd_get_efficient_state(struct em_perf_state *table,
> + struct em_perf_domain *pd, unsigned long max_util)
> +{
> + return 0;
> +}
> +static inline int
> +em_pd_get_previous_state(struct em_perf_state *table,
> + struct em_perf_domain *pd, int idx)
> +{
> + return -1;
> +}
> static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
> unsigned long max_util, unsigned long sum_util,
> unsigned long allowed_cpu_cap)
> --
> 2.53.0
>
>