From: Changwoo Min <changwoo@igalia.com>
To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com,
pavel@kernel.org
Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Changwoo Min <changwoo@igalia.com>
Subject: [PATCH] PM: EM: Add inotify support when the energy model is updated.
Date: Tue, 15 Apr 2025 09:42:15 +0900 [thread overview]
Message-ID: <20250415004215.48757-1-changwoo@igalia.com> (raw)
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] https://github.com/sched-ext/scx/pull/1624
Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
kernel/power/energy_model.c | 47 +++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index d9b7e2b38c7a..0c06e0278df6 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,53 @@ static int __init em_debug_init(void)
return 0;
}
fs_initcall(em_debug_init);
+
+static void em_debug_update_ps(struct em_perf_domain *em_pd, int i,
+ struct dentry *pd)
+{
+ static const char *names[] = {
+ "frequency",
+ "power",
+ "cost",
+ "performance",
+ "inefficient",
+ };
+ struct em_perf_state *table;
+ unsigned long freq;
+ struct dentry *d, *cd;
+ char name[24];
+ int j;
+
+ rcu_read_lock();
+ table = em_perf_state_from_pd(em_pd);
+ freq = table[i].frequency;
+ rcu_read_unlock();
+
+ snprintf(name, sizeof(name), "ps:%lu", freq);
+ d = debugfs_lookup(name, pd);
+
+ for (j = 0; j < ARRAY_SIZE(names); j++) {
+ cd = debugfs_lookup(names[j], d);
+ if (!cd)
+ return;
+ fsnotify_dentry(cd, FS_MODIFY);
+ cond_resched();
+ }
+}
+
+static void em_debug_update(struct device *dev)
+{
+ struct dentry *d;
+ int i;
+
+ d = debugfs_lookup(dev_name(dev), rootdir);
+ for (i = 0; i < dev->em_pd->nr_perf_states; i++)
+ em_debug_update_ps(dev->em_pd, i, d);
+}
#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)
@@ -323,6 +368,8 @@ int em_dev_update_perf_domain(struct device *dev,
em_table_free(old_table);
+ em_debug_update(dev);
+
mutex_unlock(&em_pd_mutex);
return 0;
}
--
2.49.0
next reply other threads:[~2025-04-15 0:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-15 0:42 Changwoo Min [this message]
2025-04-15 8:31 ` Lukasz Luba
2025-04-15 17:05 ` Rafael J. Wysocki
2025-04-17 13:28 ` Changwoo Min
2025-04-28 1:10 ` Changwoo Min
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250415004215.48757-1-changwoo@igalia.com \
--to=changwoo@igalia.com \
--cc=christian.loehle@arm.com \
--cc=kernel-dev@igalia.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®