Skip to content

Commit 2b9d15c

Browse files
Changwoo Minintel-lab-lkp
Changwoo Min
authored andcommitted
PM: EM: Add inotify support when the energy model is updated.
The sched_ext schedulers [1] currently access the energy model through the debugfs to make energy-aware scheduling decisions [2]. The userspace part of a sched_ext scheduler feeds the necessary (post-processed) energy-model information to the BPF part of the scheduler. However, there is a limitation in the current debugfs support of the energy model. When the energy model is updated (em_dev_update_perf_domain), there is no way for the userspace part to know such changes (besides polling the debugfs files). Therefore, add inotify support (IN_MODIFY) when the energy model is updated. With this inotify support, the sched_ext scheduler can monitor the energy model change in userspace using the regular inotify interface and feed the updated energy model information to make energy-aware scheduling decisions. [1] https://lwn.net/Articles/922405/ [2] sched-ext/scx#1624 Signed-off-by: Changwoo Min <[email protected]>
1 parent 56a49e1 commit 2b9d15c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

kernel/power/energy_model.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/cpumask.h>
1515
#include <linux/debugfs.h>
1616
#include <linux/energy_model.h>
17+
#include <linux/fsnotify.h>
1718
#include <linux/sched/topology.h>
1819
#include <linux/slab.h>
1920

@@ -156,9 +157,53 @@ static int __init em_debug_init(void)
156157
return 0;
157158
}
158159
fs_initcall(em_debug_init);
160+
161+
static void em_debug_update_ps(struct em_perf_domain *em_pd, int i,
162+
struct dentry *pd)
163+
{
164+
static const char *names[] = {
165+
"frequency",
166+
"power",
167+
"cost",
168+
"performance",
169+
"inefficient",
170+
};
171+
struct em_perf_state *table;
172+
unsigned long freq;
173+
struct dentry *d, *cd;
174+
char name[24];
175+
int j;
176+
177+
rcu_read_lock();
178+
table = em_perf_state_from_pd(em_pd);
179+
freq = table[i].frequency;
180+
rcu_read_unlock();
181+
182+
snprintf(name, sizeof(name), "ps:%lu", freq);
183+
d = debugfs_lookup(name, pd);
184+
185+
for (j = 0; j < ARRAY_SIZE(names); j++) {
186+
cd = debugfs_lookup(names[j], d);
187+
if (!cd)
188+
return;
189+
fsnotify_dentry(cd, FS_MODIFY);
190+
cond_resched();
191+
}
192+
}
193+
194+
static void em_debug_update(struct device *dev)
195+
{
196+
struct dentry *d;
197+
int i;
198+
199+
d = debugfs_lookup(dev_name(dev), rootdir);
200+
for (i = 0; i < dev->em_pd->nr_perf_states; i++)
201+
em_debug_update_ps(dev->em_pd, i, d);
202+
}
159203
#else /* CONFIG_DEBUG_FS */
160204
static void em_debug_create_pd(struct device *dev) {}
161205
static void em_debug_remove_pd(struct device *dev) {}
206+
static void em_debug_update(struct device *dev) {}
162207
#endif
163208

164209
static void em_release_table_kref(struct kref *kref)
@@ -323,6 +368,8 @@ int em_dev_update_perf_domain(struct device *dev,
323368

324369
em_table_free(old_table);
325370

371+
em_debug_update(dev);
372+
326373
mutex_unlock(&em_pd_mutex);
327374
return 0;
328375
}

0 commit comments

Comments
 (0)