Skip to contentSkip to conversation

sched_ext:SCX is preemptible by the Fair scheduler

PATCH New Cui Jian 2 participants 2 messages Jun 12

Subsystems (2)
lore
Share & tools
lore

Cui Jian

author
#0 lore raw

PATCH 1/1 sched_ext:SCX is preemptible by the Fair scheduler

sched_ext currently distinguishes preemption caused by STOP, DL and RT scheduling classes, but preemption from the Fair scheduler is reported as SCX_CPU_PREEMPT_UNKNOWN.

When analyzing SCX scheduling behavior, it is useful to know whether a task was preempted by RT/DL classes or switched out in favor of a Fair-class task. The lack of a dedicated reason makes debugging and observability more difficult.

Add SCX_CPU_PREEMPT_FAIR and report it when the next scheduled task belongs to fair_sched_class.

This change improves scheduling diagnostics and observability without affecting scheduling behavior.

---
 kernel/sched/ext.c          | 2 ++
 kernel/sched/ext_internal.h | 2 ++
 2 files changed, 4 insertions(+)
kernel/sched/ext.c +2 -0
index 5d2d19473a82..6e0281218197 100644
@@ -3015,6 +3015,8 @@ preempt_reason_from_class(const struct sched_class *class)
 		return SCX_CPU_PREEMPT_DL;
 	if (class == &rt_sched_class)
 		return SCX_CPU_PREEMPT_RT;
+	if (class == &fair_sched_class)
+		return SCX_CPU_PREEMPT_FAIR;
 	return SCX_CPU_PREEMPT_UNKNOWN;
 }
 
kernel/sched/ext_internal.h +2 -0
index a075732d4430..3ce07bec58a5 100644
@@ -241,6 +241,8 @@ enum scx_cpu_preempt_reason {
 	SCX_CPU_PREEMPT_DL,
 	/* next task is being scheduled by &sched_class_stop */
 	SCX_CPU_PREEMPT_STOP,
+	/* next task is being scheduled by &sched_class_fair*/
+	SCX_CPU_PREEMPT_FAIR,
 	/* unknown reason for SCX being preempted */
 	SCX_CPU_PREEMPT_UNKNOWN,
 };
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The autogenerated header enum_defs.autogen.h was not updated to include…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The autogenerated header enum_defs.autogen.h was not updated to include HAVE_SCX_CPU_PREEMPT_FAIR. --

commit 6eebc3231d63fa92ff2758fc84fe12b421fbde6c
Author: Cui Jian <[email protected]>

sched_ext:SCX is preemptible by the Fair scheduler

This commit adds a new SCX_CPU_PREEMPT_FAIR preempt reason for the sched_ext subsystem. It updates the internal enum and preempt reason mapping to make it easier to observe when a task is preempted by the Fair scheduler.

[ ... ]

kernel/sched/ext_internal.h enum scx_cpu_preempt_reason { · line 245

Quoted 9 lines
kernel/sched/ext_internal.h +2 -0
@@ -241,6 +241,8 @@ enum scx_cpu_preempt_reason {
 	SCX_CPU_PREEMPT_DL,
 	/* next task is being scheduled by &sched_class_stop */
 	SCX_CPU_PREEMPT_STOP,
+	/* next task is being scheduled by &sched_class_fair*/
+	SCX_CPU_PREEMPT_FAIR,

[Severity: Medium]
Should tools/sched_ext/include/scx/enum_defs.autogen.h also be updated in this patch to include HAVE_SCX_CPU_PREEMPT_FAIR?

Without adding this to the autogenerated header, external BPF schedulers cannot use #ifdef HAVE_SCX_CPU_PREEMPT_FAIR to safely compile and support both old and new kernels.

Quoted 3 lines
kernel/sched/ext_internal.h +0 -0
 	/* unknown reason for SCX being preempted */
 	SCX_CPU_PREEMPT_UNKNOWN,
 };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1