Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v2] PM: EM: Add inotify support when the energy model is updated.
@ 2025-05-07  1:47 Changwoo Min
  2025-05-07 17:04 ` Tejun Heo
  2025-05-09 10:55 ` Lukasz Luba
  0 siblings, 2 replies; 11+ messages in thread
From: Changwoo Min @ 2025-05-07  1:47 UTC (permalink / raw)
  To: lukasz.luba, rafael, len.brown, pavel
  Cc: christian.loehle, tj, kernel-dev, linux-pm, linux-kernel,
	Changwoo Min

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 directory of an updated performance domain
(e.g., /sys/kernel/debug/energy_model/cpu0) and its parent directory (e.g.,
/sys/kernel/debug/energy_model) are inotified. Therefore, a sched_ext
scheduler (or any userspace application) monitors the energy model change
in userspace using the regular inotify interface.

Note that accessing the energy model information from userspace has many
advantages over other alternatives, especially adding new BPF kfuncs. The
userspace has much more freedom than the BPF code (e.g., using external
libraries and floating point arithmetics), which may be infeasible (if not
impossible) in the BPF/kernel code.

[1] https://lwn.net/Articles/922405/
[2] https://github.com/sched-ext/scx/pull/1624

Signed-off-by: Changwoo Min <changwoo@igalia.com>
---

ChangeLog v1 -> v2:
  - Change em_debug_update() to only inotify the directory of an updated
    performance domain (and its parent directory).
  - Move the em_debug_update() call outside of the mutex lock.
  - Update the commit message to clarify its motivation and what will be
    inotified when updated. 

 kernel/power/energy_model.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index d9b7e2b38c7a..590e90e8cb66 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -14,6 +14,7 @@
 #include <linux/cpumask.h>
 #include <linux/debugfs.h>
 #include <linux/energy_model.h>
+#include <linux/fsnotify.h>
 #include <linux/sched/topology.h>
 #include <linux/slab.h>
 
@@ -156,9 +157,18 @@ static int __init em_debug_init(void)
 	return 0;
 }
 fs_initcall(em_debug_init);
+
+static void em_debug_update(struct device *dev)
+{
+	struct dentry *d;
+
+	d = debugfs_lookup(dev_name(dev), rootdir);
+	fsnotify_dentry(d, FS_MODIFY);
+}
 #else /* CONFIG_DEBUG_FS */
 static void em_debug_create_pd(struct device *dev) {}
 static void em_debug_remove_pd(struct device *dev) {}
+static void em_debug_update(struct device *dev) {}
 #endif
 
 static void em_release_table_kref(struct kref *kref)
@@ -324,6 +334,8 @@ int em_dev_update_perf_domain(struct device *dev,
 	em_table_free(old_table);
 
 	mutex_unlock(&em_pd_mutex);
+
+	em_debug_update(dev);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(em_dev_update_perf_domain);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-05-22  8:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07  1:47 [PATCH v2] PM: EM: Add inotify support when the energy model is updated Changwoo Min
2025-05-07 17:04 ` Tejun Heo
2025-05-08  6:03   ` Changwoo Min
2025-05-09 10:55 ` Lukasz Luba
2025-05-09 16:41   ` Rafael J. Wysocki
2025-05-10  5:07     ` Changwoo Min
2025-05-10 11:34       ` Rafael J. Wysocki
2025-05-22  8:19         ` Lukasz Luba
2025-05-22  8:35           ` Changwoo Min
2025-05-22  8:43             ` Lukasz Luba
2025-05-10  4:40   ` Changwoo Min

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox