diff mbox series

[v5,12/23] PM: EM: Add helpers to read under RCU lock the EM table

Message ID 20231129110853.94344-13-lukasz.luba@arm.com
State Superseded
Headers show
Series Introduce runtime modifiable Energy Model | expand

Commit Message

Lukasz Luba Nov. 29, 2023, 11:08 a.m. UTC
To use the runtime modifiable EM table there is a need to use RCU
read locking properly. Add helper functions for the device drivers and
frameworks to make sure it's done properly.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 include/linux/energy_model.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h
index 520a8c8ad849..ae3ccc8b9f44 100644
--- a/include/linux/energy_model.h
+++ b/include/linux/energy_model.h
@@ -341,6 +341,20 @@  static inline int em_pd_nr_perf_states(struct em_perf_domain *pd)
 	return pd->nr_perf_states;
 }
 
+static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd)
+{
+	struct em_perf_table __rcu *runtime_table;
+
+	rcu_read_lock();
+	runtime_table = rcu_dereference(pd->runtime_table);
+	return runtime_table->state;
+}
+
+static inline void em_put_table(void)
+{
+	rcu_read_unlock();
+}
+
 #else
 struct em_data_callback {};
 #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { }
@@ -387,6 +401,11 @@  int em_dev_update_perf_domain(struct device *dev,
 {
 	return -EINVAL;
 }
+static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd)
+{
+	return NULL;
+}
+static inline void em_put_table(void) {}
 #endif
 
 #endif