]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: EM: Add an iterator and accessor for the performance domain
authorChangwoo Min <changwoo@igalia.com>
Mon, 20 Oct 2025 22:09:09 +0000 (07:09 +0900)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 22 Oct 2025 19:44:37 +0000 (21:44 +0200)
Add an iterator function (for_each_em_perf_domain) that iterates all the
performance domains in the global list. A passed callback function (cb) is
called for each performance domain.

Additionally, add a lookup function (em_perf_domain_get_by_id) that
searches for a performance domain by matching the ID in the global list.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/20251020220914.320832-6-changwoo@igalia.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/em_netlink.h
kernel/power/energy_model.c

index acd186c92d6bec35fc087fd610738e05208614dc..8114b018c73b39120d2a89a83afc05c44b4043c2 100644 (file)
 #define _EM_NETLINK_H
 
 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET)
+int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
+                           void *data);
+struct em_perf_domain *em_perf_domain_get_by_id(int id);
 #else
+static inline
+int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
+                           void *data)
+{
+       return -EINVAL;
+}
+static inline
+struct em_perf_domain *em_perf_domain_get_by_id(int id)
+{
+       return NULL;
+}
 #endif
 
 #endif /* _EM_NETLINK_H */
index 756debf5406a8a179dc865a1c418808816a5b5f7..9e35aba4b1139b42bda16ff237fcf365cee9085a 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/sched/topology.h>
 #include <linux/slab.h>
 
+#include "em_netlink.h"
+
 /*
  * Mutex serializing the registrations of performance domains and letting
  * callbacks defined by drivers sleep.
@@ -998,3 +1000,39 @@ void em_rebuild_sched_domains(void)
         */
        schedule_work(&rebuild_sd_work);
 }
+
+#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET)
+int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
+                           void *data)
+{
+       struct em_perf_domain *pd;
+
+       lockdep_assert_not_held(&em_pd_mutex);
+       guard(mutex)(&em_pd_list_mutex);
+
+       list_for_each_entry(pd, &em_pd_list, node) {
+               int ret;
+
+               ret = cb(pd, data);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+struct em_perf_domain *em_perf_domain_get_by_id(int id)
+{
+       struct em_perf_domain *pd;
+
+       lockdep_assert_not_held(&em_pd_mutex);
+       guard(mutex)(&em_pd_list_mutex);
+
+       list_for_each_entry(pd, &em_pd_list, node) {
+               if (pd->id == id)
+                       return pd;
+       }
+
+       return NULL;
+}
+#endif