Skip to contentSkip to conversation

sched: dynamic: Fix preemption model strings

PATCH Applied Mark Rutland 3 participants 3 messages Sep 2 – Sep 6 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: dynamic: Fix preemption model strings

We recently removed the enum values 'preempt_dynamic_none' and 'preempt_dynamic_voluntary', but forgot to update preempt_modes[] accordingly. Due to this, preempt_model_str() and sched_dynamic_show() produce incorrect output, with the wrong preemption model string in backtraces, and empty output for /sys/kernel/debug/sched/preempt.

Update preempt_modes[] to account for the removed enum values. Given that CONFIG_PREEMPT_DYNAMIC now depends on CONFIG_ARCH_HAS_PREEMPT_LAZY, and given that only 'preempt_dynamic_full' and 'preempt_dynamic_lazy' remain, sched_dynamic_show() no longer needs to skip any model strings.

Fixes 9650ce11f2e3 ("sched: dynamic: Simplify preempt model accessors")
Cc Mete Durlu <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Shrikanth Hegde <[email protected]>
---
 kernel/sched/core.c  |  2 +-
 kernel/sched/debug.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
kernel/sched/core.c +1 -1
index 545f49491bcde..5a61650f12b7d 100644
@@ -7960,7 +7960,7 @@ static inline void preempt_dynamic_init(void) { }
 #endif /* CONFIG_PREEMPT_DYNAMIC */
 
 const char *preempt_modes[] = {
-	"none", "voluntary", "full", "lazy", NULL,
+	"full", "lazy", NULL,
 };
 
 const char *preempt_model_str(void)
kernel/sched/debug.c +2 -8
index 9883e4c4976bf..fda10b3fa249a 100644
@@ -280,16 +280,10 @@ static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
 
 static int sched_dynamic_show(struct seq_file *m, void *v)
 {
-	int i = (IS_ENABLED(CONFIG_PREEMPT_RT) || IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY)) * 2;
 	int mode = READ_ONCE(preempt_dynamic_mode);
-	int j;
 
-	/* Count entries in NULL terminated preempt_modes */
-	for (j = 0; preempt_modes[j]; j++)
-		;
-	j -= !IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY);
-
-	for (; i < j; i++) {
+	/* Stop at NULL terminator */
+	for (int i = 0; preempt_modes[i]; i++) {
 		if (mode == i)
 			seq_puts(m, "(");
 		seq_puts(m, preempt_modes[i]);
Signature · 1 line
2.30.2
merge bot Applied
#1 lore raw
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     ef9293b3b797228fead10b55ed6bfb99bb7976b4
Gitweb:        https://git.kernel.org/tip/ef9293b3b797228fead10b55ed6bfb99bb7976b4
Author:        Mark Rutland <[email protected]>
AuthorDate:    Wed, 02 Sep 2026 11:16:37 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 02 Sep 2026 12:54:21 +02:00

sched: dynamic: Fix preemption model strings

We recently removed the enum values 'preempt_dynamic_none' and 'preempt_dynamic_voluntary', but forgot to update preempt_modes[] accordingly. Due to this, preempt_model_str() and sched_dynamic_show() produce incorrect output, with the wrong preemption model string in backtraces, and empty output for /sys/kernel/debug/sched/preempt.

Update preempt_modes[] to account for the removed enum values. Given that CONFIG_PREEMPT_DYNAMIC now depends on CONFIG_ARCH_HAS_PREEMPT_LAZY, and given that only 'preempt_dynamic_full' and 'preempt_dynamic_lazy' remain, sched_dynamic_show() no longer needs to skip any model strings.

Fixes 9650ce11f2e3 ("sched: dynamic: Simplify preempt model accessors")
---
 kernel/sched/core.c  |  2 +-
 kernel/sched/debug.c | 10 ++--------
 2 files changed, 3 insertions(+), 9 deletions(-)
kernel/sched/core.c +1 -1
index 545f494..5a61650 100644
@@ -7960,7 +7960,7 @@ static inline void preempt_dynamic_init(void) { }
 #endif /* CONFIG_PREEMPT_DYNAMIC */
 
 const char *preempt_modes[] = {
-	"none", "voluntary", "full", "lazy", NULL,
+	"full", "lazy", NULL,
 };
 
 const char *preempt_model_str(void)
kernel/sched/debug.c +2 -8
index 9883e4c..fda10b3 100644
@@ -280,16 +280,10 @@ static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
 
 static int sched_dynamic_show(struct seq_file *m, void *v)
 {
-	int i = (IS_ENABLED(CONFIG_PREEMPT_RT) || IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY)) * 2;
 	int mode = READ_ONCE(preempt_dynamic_mode);
-	int j;
 
-	/* Count entries in NULL terminated preempt_modes */
-	for (j = 0; preempt_modes[j]; j++)
-		;
-	j -= !IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY);
-
-	for (; i < j; i++) {
+	/* Stop at NULL terminator */
+	for (int i = 0; preempt_modes[i]; i++) {
 		if (mode == i)
 			seq_puts(m, "(");
 		seq_puts(m, preempt_modes[i]);
Tested-by on v1 1/1
#2 lore raw
In reply to Mark Rutland
Quoted 6 lines · Mark Rutland

We recently removed the enum values 'preempt_dynamic_none' and 'preempt_dynamic_voluntary', but forgot to update preempt_modes[] accordingly. Due to this, preempt_model_str() and sched_dynamic_show() produce incorrect output, with the wrong preemption model string in backtraces, and empty output for /sys/kernel/debug/sched/preempt.

Quoted 8 lines

Update preempt_modes[] to account for the removed enum values. Given that CONFIG_PREEMPT_DYNAMIC now depends on CONFIG_ARCH_HAS_PREEMPT_LAZY, and given that only 'preempt_dynamic_full' and 'preempt_dynamic_lazy' remain, sched_dynamic_show() no longer needs to skip any model strings.

Fixes 9650ce11f2e3 ("sched: dynamic: Simplify preempt model accessors")

Hi,

I did a quick test on s390.

$ echo full > preempt
$ cat preempt
(full) lazy
$ echo lazy > preempt
$ cat preempt
full (lazy)

The sched_dynamic_show() output looks correct now, and the code looks much nicer without those conditional indices. Feel free to put my tested by.