Skip to content

Commit 7928339

Browse files
multics69rafaeljw
authored andcommitted
PM: EM: Add an iterator and accessor for the performance domain
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>
1 parent e4ed8d2 commit 7928339

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

kernel/power/em_netlink.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
#define _EM_NETLINK_H
1111

1212
#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET)
13+
int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
14+
void *data);
15+
struct em_perf_domain *em_perf_domain_get_by_id(int id);
1316
#else
17+
static inline
18+
int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
19+
void *data)
20+
{
21+
return -EINVAL;
22+
}
23+
static inline
24+
struct em_perf_domain *em_perf_domain_get_by_id(int id)
25+
{
26+
return NULL;
27+
}
1428
#endif
1529

1630
#endif /* _EM_NETLINK_H */

kernel/power/energy_model.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/sched/topology.h>
1818
#include <linux/slab.h>
1919

20+
#include "em_netlink.h"
21+
2022
/*
2123
* Mutex serializing the registrations of performance domains and letting
2224
* callbacks defined by drivers sleep.
@@ -998,3 +1000,39 @@ void em_rebuild_sched_domains(void)
9981000
*/
9991001
schedule_work(&rebuild_sd_work);
10001002
}
1003+
1004+
#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET)
1005+
int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *),
1006+
void *data)
1007+
{
1008+
struct em_perf_domain *pd;
1009+
1010+
lockdep_assert_not_held(&em_pd_mutex);
1011+
guard(mutex)(&em_pd_list_mutex);
1012+
1013+
list_for_each_entry(pd, &em_pd_list, node) {
1014+
int ret;
1015+
1016+
ret = cb(pd, data);
1017+
if (ret)
1018+
return ret;
1019+
}
1020+
1021+
return 0;
1022+
}
1023+
1024+
struct em_perf_domain *em_perf_domain_get_by_id(int id)
1025+
{
1026+
struct em_perf_domain *pd;
1027+
1028+
lockdep_assert_not_held(&em_pd_mutex);
1029+
guard(mutex)(&em_pd_list_mutex);
1030+
1031+
list_for_each_entry(pd, &em_pd_list, node) {
1032+
if (pd->id == id)
1033+
return pd;
1034+
}
1035+
1036+
return NULL;
1037+
}
1038+
#endif

0 commit comments

Comments
 (0)