[PATCH 2/5] energy model: Add a get previous state function
From: Vincent Guittot
Date: Fri Aug 30 2024 - 09:05:57 EST
Instead of parsing all 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>
---
include/linux/energy_model.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h
index 1ff52020cf75..ea8ea7e031c0 100644
--- a/include/linux/energy_model.h
+++ b/include/linux/energy_model.h
@@ -207,6 +207,24 @@ em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states,
return nr_perf_states - 1;
}
+static inline int
+em_pd_get_previous_state(struct em_perf_state *table, int nr_perf_states,
+ int idx, unsigned long pd_flags)
+{
+ struct em_perf_state *ps;
+ int i;
+
+ for (i = idx - 1; i >= 0; 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
--
2.34.1