sched_ext:SCX is preemptible by the Fair scheduler
Subsystems (2)
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
@@ -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
@@ -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
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch adds `SCX_CPU_PREEMPT_FAIR` to `enum scx_cpu_preempt_reason` in…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch adds SCX_CPU_PREEMPT_FAIR to enum scx_cpu_preempt_reason in kernel/sched/ext_internal.h, but fails to update the checked-in autogenerated BPF tool headers in tools/sched_ext/include/scx/enum_defs.autogen.h. --
commit 0e9cc05c20430d666c8c1a1d7ea0741d9c28b2d3
Author: Cui Jian <[email protected]>
sched_ext:SCX is preemptible by the Fair scheduler
This commit adds a new preemption reason, SCX_CPU_PREEMPT_FAIR, to distinguish when a sched_ext task is preempted by the Fair scheduler. It updates the internal enum and mapping function to improve observability and diagnostics.
kernel/sched/ext_internal.h enum scx_cpu_preempt_reason { · line 245
Quoted 10 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 be regenerated and included in this patch?
When adding a new value to enum scx_cpu_preempt_reason, the autogenerated BPF tool headers typically need updating so downstream BPF schedulers can use feature detection macros like HAVE_SCX_CPU_PREEMPT_FAIR.
Without this update, BPF applications cannot conditionally check for this new preemption feature across different kernel versions.
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
Andrea Righi
reviewerHi Cui,
Quoted 9 lines · Cui Jian
sched_extcurrently distinguishes preemption caused by STOP, DL and RT scheduling classes, but preemption from the Fair scheduler is reported asSCX_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.
Quoted 5 lines
Add
SCX_CPU_PREEMPT_FAIRand report it when the next scheduled task belongs tofair_sched_class.This change improves scheduling diagnostics and observability without affecting scheduling behavior.
The preempt reason is only used in ops.cpu_release(), which is a deprecated API and will be removed in the next kernel versions (see the pr_warn() in validate_ops(), kernel/sched/ext.c):
pr_warn("ops->cpu_acquire/release() are deprecated, use sched_switch TP instead\n");
So, your patch makes sense, but I'm not sure it's worth updating the API at this point.
Thanks,
-Andrea
Quoted 36 lines
Signed-off-by Cui Jian <[email protected]>--- kernel/sched/ext.c | 2 ++ kernel/sched/ext_internal.h | 2 ++ 2 files changed, 4 insertions(+)kernel/sched/ext.c +2
-0@@ -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@@ -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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andrea Righi
reviewerQuoted 1 line · On Sat, Jun 13, 2026 at 01:32:28AM +0800, cjian720 wrote:
Hi Andrea, While this callback will be phased out eventually, SCX is still a relatively new scheduling framework. Incomplete preemption reason enums make it hard to analyze interactions between different schedulers, and filling this gap greatly boosts observability for existing SCX workloads. This patch does not touch core scheduling logic, carries zero performance overhead, and adds negligible long-term maintenance cost.
You can get the same information directly from BPF using the sched_switch tracepoint and looking at prev->sched_class and next->sched_class. As I mentioned, ops.cpu_release() is a deprecated API, so I don't see much value updating/improving it.
Thanks,
-Andrea