public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ksysfs:  add a sysfs preemption_mode entry
@ 2024-10-07 18:30 Clark Williams
  0 siblings, 0 replies; only message in thread
From: Clark Williams @ 2024-10-07 18:30 UTC (permalink / raw)
  To: Peter Ziljstra, Steven Rostedt, Thomas Gleixner,
	Sebastian Andrzej Siewior, linux-kernel
  Cc: akpm, bhe, yang.lee, ardb, edumazet

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@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-11  2:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07 18:30 [PATCH] ksysfs: add a sysfs preemption_mode entry Clark Williams

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