[PATCH] ksysfs: add a sysfs preemption_mode entry
From: Clark Williams
Date: Thu Oct 10 2024 - 22:49:59 EST
This patch is the result of a discussion at the last
stable-rt maintainers meeting, regarding what to do about a
commit that basically just made a 'realtime' entry in /sys/kernel
to indicate that the running kernel was compiled with PREEMPT_RT.
Not very useful to non-rt-users.
This commit adds a sysfs entry /sys/kernel/preempt_mode which
allows a user to determine what preemption mode is active for
the running kernel.
When read, the file will return one of the following set of
string values:
NONE
VOLUNTARY
FULL
RT
These values correspond to the options CONFIG_PREEMPT_NONE,
CONFIG_PREEMPT_VOLUNTARY, CONFIG_PREEMPT_FULL and CONFIG_PREEMPT_RT.
Signed-off-by: Clark Williams <williams@xxxxxxxxxx>
---
kernel/ksysfs.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 1bab21b4718f..57ebde28e4b9 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -188,6 +188,27 @@ KERNEL_ATTR_RO(crash_elfcorehdr_size);
#endif /* CONFIG_VMCORE_INFO */
+/*
+ * entry to display the current preemption mode
+ */
+static ssize_t preempt_mode_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ char *mode = NULL;
+
+ if (preempt_model_rt())
+ mode = "RT";
+ else if (preempt_model_full())
+ mode = "FULL";
+ else if (preempt_model_voluntary())
+ mode = "VOLUNTARY";
+ else
+ mode = "NONE";
+ WARN_ON(mode == NULL);
+ return sysfs_emit(buf, "%s\n", mode);
+}
+KERNEL_ATTR_RO(preempt_mode);
+
/* whether file capabilities are enabled */
static ssize_t fscaps_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
@@ -263,6 +284,7 @@ static struct attribute * kernel_attrs[] = {
&uevent_seqnum_attr.attr,
&cpu_byteorder_attr.attr,
&address_bits_attr.attr,
+ &preempt_mode_attr.attr,
#ifdef CONFIG_UEVENT_HELPER
&uevent_helper_attr.attr,
#endif
--
2.46.2