[PATCH 0/5] sched_ext: bypass state machine cleanup and selftest

zhidao su posted 5 patches 1 month ago
kernel/sched/ext.c                            |  29 ++++-
kernel/sched/ext_internal.h                   |   8 +-
.../sched_ext/include/scx/enum_defs.autogen.h |   1 -
tools/sched_ext/scx_flatcg.bpf.c              |   2 +-
tools/testing/selftests/sched_ext/Makefile    |   1 +
.../testing/selftests/sched_ext/bypass.bpf.c  |  32 ++++++
tools/testing/selftests/sched_ext/bypass.c    | 105 ++++++++++++++++++
7 files changed, 165 insertions(+), 13 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/bypass.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/bypass.c
[PATCH 0/5] sched_ext: bypass state machine cleanup and selftest
Posted by zhidao su 1 month ago
From: Su Zhidao <suzhidao@xiaomi.com>

This series does a small cleanup pass on the sched_ext bypass code path
and adds a selftest for the bypass mechanism.

Patch 1 removes SCX_OPS_HAS_CGROUP_WEIGHT, which was marked deprecated
in 6.15 with a "will be removed on 6.18" comment. We are now past that
point.

Patches 2-3 improve the bypass code in ext.c: add inline comments
explaining the bypass depth counter semantics and the dequeue/enqueue
re-queue loop, and replace rcu_dereference_all() with the more precise
rcu_dereference_bh() in scx_bypass_lb_timerfn() which runs in softirq
context.

Patch 4 adds a selftest that verifies forward progress under bypass
mode: worker processes are spawned while the scheduler is active, then
bpf_link__destroy() is called (triggering bypass), and the test confirms
all workers complete successfully.

Patch 5 adds a comment to the scx_bypass_depth declaration noting its
planned migration into struct scx_sched.

Tested on 6.18.7 with CONFIG_SCHED_CLASS_EXT=y; all existing selftests
pass.

Su Zhidao (5):
  sched_ext: Remove deprecated SCX_OPS_HAS_CGROUP_WEIGHT flag
  sched_ext: Add comments to scx_bypass() for bypass depth semantics
  sched_ext: Use rcu_dereference_bh() in scx_bypass_lb_timerfn()
  sched_ext/selftests: Add bypass mode operational test
  sched_ext: Document scx_bypass_depth migration path

 kernel/sched/ext.c                            |  29 ++++-
 kernel/sched/ext_internal.h                   |   8 +-
 .../sched_ext/include/scx/enum_defs.autogen.h |   1 -
 tools/sched_ext/scx_flatcg.bpf.c              |   2 +-
 tools/testing/selftests/sched_ext/Makefile    |   1 +
 .../testing/selftests/sched_ext/bypass.bpf.c  |  32 ++++++
 tools/testing/selftests/sched_ext/bypass.c    | 105 ++++++++++++++++++
 7 files changed, 165 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/sched_ext/bypass.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/bypass.c

-- 
2.43.0
Re: [PATCH 0/5] sched_ext: bypass state machine cleanup and selftest
Posted by Andrea Righi 1 month ago
Hi,

On Fri, Mar 06, 2026 at 10:03:20PM +0800, zhidao su wrote:
> From: Su Zhidao <suzhidao@xiaomi.com>
> 
> This series does a small cleanup pass on the sched_ext bypass code path
> and adds a selftest for the bypass mechanism.
> 
> Patch 1 removes SCX_OPS_HAS_CGROUP_WEIGHT, which was marked deprecated
> in 6.15 with a "will be removed on 6.18" comment. We are now past that
> point.

See:
https://lore.kernel.org/all/20260306073110.229595-1-zhaomzhao@126.com/

> 
> Patches 2-3 improve the bypass code in ext.c: add inline comments
> explaining the bypass depth counter semantics and the dequeue/enqueue
> re-queue loop, and replace rcu_dereference_all() with the more precise
> rcu_dereference_bh() in scx_bypass_lb_timerfn() which runs in softirq
> context.

These patches don't really improve code, they just add comments. Which is
nice, it's good to improve documentation, but documentation should help
understand better the high-level semantic, or clarify non-obvious
implemenatation details. In this case you're just commenting how the
specific code works, which should be already clear enough just by looking
at the code IMHO.

> 
> Patch 4 adds a selftest that verifies forward progress under bypass
> mode: worker processes are spawned while the scheduler is active, then
> bpf_link__destroy() is called (triggering bypass), and the test confirms
> all workers complete successfully.

Already commented on the patch.

> 
> Patch 5 adds a comment to the scx_bypass_depth declaration noting its
> planned migration into struct scx_sched.

Ditto about documentation.

Thanks,
-Andrea