sched_ext:SCX is preemptible by the Fair scheduler
Subsystems (2)
PATCH 1/1 sched_ext:SCX is preemptible by the Fair scheduler
Hi Andrea,
While this callback will eventually be deprecated, SCX is still a relatively new scheduling framework. Incomplete preemption reason enums make it difficult to analyze interactions between different schedulers, and filling this gap significantly improves observability for existing SCX workloads.
This patch does not modify core scheduling logic, introduces zero performance overhead, and adds negligible long-term maintenance cost.
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
Andrea Righi
reviewerHi Cui,
Quoted 5 lines · Cui Jian
Hi Andrea,
While this callback will eventually be deprecated, SCX is still a relatively new scheduling framework. Incomplete preemption reason enums make it difficult to analyze interactions between different schedulers, and filling this gap significantly improves observability for existing SCX workloads.
This patch does not modify core scheduling logic, introduces zero performance overhead, and adds negligible long-term maintenance cost.
Please, don't re-send a new patch just for this, at least you should add a v2 with a proper changelog. But in this case the discussion can continue in the previous email thread.
Thanks,
-Andrea
Quoted 51 lines
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.
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.
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
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Inserting SCX_CPU_PREEMPT_FAIR shifts the value of SCX_CPU_PREEMPT_UNKNOWN without updating…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Inserting SCX_CPU_PREEMPT_FAIR shifts the value of SCX_CPU_PREEMPT_UNKNOWN without updating tools/sched_ext autogenerated headers, breaking feature detection for BPF schedulers. --
commit 19f50c7bbf7f31acfd835724319513f85b45249d
Author: Cui Jian <[email protected]>
sched_ext:SCX is preemptible by the Fair scheduler
This commit adds the SCX_CPU_PREEMPT_FAIR enum value to distinguish preemptions caused by the Fair scheduler. It updates the core sched_ext code to report this reason when the next scheduled task belongs to the fair_sched_class.
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]
Does inserting SCX_CPU_PREEMPT_FAIR here shift the value of SCX_CPU_PREEMPT_UNKNOWN and potentially break existing BPF programs that rely on its previous value or use it as a maximum for array sizing?
Also, should tools/sched_ext/include/scx/enum_defs.autogen.h be updated to include #define HAVE_SCX_CPU_PREEMPT_FAIR? Without it, BPF schedulers might fail to detect this new feature via #ifdef, potentially mishandling the new enum value.
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