* [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs
@ 2026-03-15 8:24 Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 1/2] sched_ext: Update demo schedulers and selftests to use scx_bpf_task_set_dsq_vtime() Cheng-Yang Chou
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Cheng-Yang Chou @ 2026-03-15 8:24 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai, yphbchou0911
Two sets of sched_ext APIs have been deprecated:
- Direct writes to p->scx.dsq_vtime in favor of
scx_bpf_task_set_dsq_vtime()
- ops.cpu_acquire/release() in favor of handling CPU preemption via the
sched_switch tracepoint, as introduced by commit a3f5d4822253
("sched_ext: Allow scx_bpf_reenqueue_local() to be called from
anywhere")
This series updates the demo schedulers (scx_simple, scx_flatcg) and
selftests (select_cpu_vtime, maximal) to use the new APIs, keeping them
in sync with current best practices.
Patch 1 updates scx_simple, scx_flatcg, and select_cpu_vtime to use
scx_bpf_task_set_dsq_vtime() with scale_by_task_weight_inverse(), with
the delta computation moved inside the if block.
Patch 2 replaces the cpu_acquire/release stubs in the maximal selftest
with a minimal sched_switch TP program, and fixes the maximal and
reload_loop tests to properly attach the sched_switch tracepoint via
bpf_map__set_autoattach() and maximal__attach(), as both tests use the
maximal skeleton.
Changes in v5:
- Fix trailing blank line in select_cpu_vtime_stopping() (Tejun Heo)
- Fix prev_state type: unsigned long -> unsigned int in
maximal_sched_switch (Tejun Heo)
- Link to v4:
https://lore.kernel.org/all/20260314033708.26483-1-yphbchou0911@gmail.com/
Changes in v4:
- Drop scx_qmap changes from patch 2, already applied in commit
3229ac4a5ef5 ("sched_ext: Add SCX_OPS_ALWAYS_ENQ_IMMED ops flag")
- Move delta computation inside the if block (Tejun)
- Link to v3:
https://lore.kernel.org/all/20260313014944.1234667-1-yphbchou0911@gmail.com/
Changes in v3:
- Use scale_by_task_weight_inverse() instead of scale_by_task_weight()
(Andrea Righi)
- Link to v2:
https://lore.kernel.org/all/20260312175527.1220540-1-yphbchou0911@gmail.com/
Changes in v2:
- Use scx_bpf_task_set_dsq_vtime() with scale_by_task_weight instead
of direct assignment and remove redundant bpf_ksym_exists() logic
(Andrea Righi)
- Mention commit a3f5d4822253 ("sched_ext: Allow
scx_bpf_reenqueue_local() to be called from anywhere") in the commit
message to clarify why ops.cpu_acquire/release() are being deprecated
(Andrea Righi)
- Fix maximal.c and reload_loop.c to actually attach the sched_switch
tracepoint by calling bpf_map__set_autoattach() and maximal__attach()
(Andrea Righi)
- Link to v1:
https://lore.kernel.org/all/20260312042001.955675-1-yphbchou0911@gmail.com/
Thanks,
Cheng-Yang
---
Cheng-Yang Chou (2):
sched_ext: Update demo schedulers and selftests to use
scx_bpf_task_set_dsq_vtime()
sched_ext: Update selftests to drop ops.cpu_acquire/release()
tools/sched_ext/scx_flatcg.bpf.c | 12 +++++++-----
tools/sched_ext/scx_simple.bpf.c | 6 ++++--
tools/testing/selftests/sched_ext/maximal.bpf.c | 15 ++++++---------
tools/testing/selftests/sched_ext/maximal.c | 3 +++
tools/testing/selftests/sched_ext/reload_loop.c | 3 +++
.../selftests/sched_ext/select_cpu_vtime.bpf.c | 6 ++++--
6 files changed, 27 insertions(+), 18 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/2] sched_ext: Update demo schedulers and selftests to use scx_bpf_task_set_dsq_vtime()
2026-03-15 8:24 [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
@ 2026-03-15 8:24 ` Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 2/2] sched_ext: Update selftests to drop ops.cpu_acquire/release() Cheng-Yang Chou
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Cheng-Yang Chou @ 2026-03-15 8:24 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai, yphbchou0911
Direct writes to p->scx.dsq_vtime are deprecated in favor of
scx_bpf_task_set_dsq_vtime(). Update scx_simple, scx_flatcg, and
select_cpu_vtime selftest to use the new kfunc with
scale_by_task_weight_inverse().
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
---
tools/sched_ext/scx_flatcg.bpf.c | 12 +++++++-----
tools/sched_ext/scx_simple.bpf.c | 6 ++++--
.../selftests/sched_ext/select_cpu_vtime.bpf.c | 6 ++++--
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/tools/sched_ext/scx_flatcg.bpf.c b/tools/sched_ext/scx_flatcg.bpf.c
index 1351377f64d5..6d3a028d7b59 100644
--- a/tools/sched_ext/scx_flatcg.bpf.c
+++ b/tools/sched_ext/scx_flatcg.bpf.c
@@ -551,9 +551,11 @@ void BPF_STRUCT_OPS(fcg_stopping, struct task_struct *p, bool runnable)
* too much, determine the execution time by taking explicit timestamps
* instead of depending on @p->scx.slice.
*/
- if (!fifo_sched)
- p->scx.dsq_vtime +=
- (SCX_SLICE_DFL - p->scx.slice) * 100 / p->scx.weight;
+ if (!fifo_sched) {
+ u64 delta = scale_by_task_weight_inverse(p, SCX_SLICE_DFL - p->scx.slice);
+
+ scx_bpf_task_set_dsq_vtime(p, p->scx.dsq_vtime + delta);
+ }
taskc = bpf_task_storage_get(&task_ctx, p, 0, 0);
if (!taskc) {
@@ -822,7 +824,7 @@ s32 BPF_STRUCT_OPS(fcg_init_task, struct task_struct *p,
if (!(cgc = find_cgrp_ctx(args->cgroup)))
return -ENOENT;
- p->scx.dsq_vtime = cgc->tvtime_now;
+ scx_bpf_task_set_dsq_vtime(p, cgc->tvtime_now);
return 0;
}
@@ -924,7 +926,7 @@ void BPF_STRUCT_OPS(fcg_cgroup_move, struct task_struct *p,
return;
delta = time_delta(p->scx.dsq_vtime, from_cgc->tvtime_now);
- p->scx.dsq_vtime = to_cgc->tvtime_now + delta;
+ scx_bpf_task_set_dsq_vtime(p, to_cgc->tvtime_now + delta);
}
s32 BPF_STRUCT_OPS_SLEEPABLE(fcg_init)
diff --git a/tools/sched_ext/scx_simple.bpf.c b/tools/sched_ext/scx_simple.bpf.c
index 9ad6f0949987..cc40552b2b5f 100644
--- a/tools/sched_ext/scx_simple.bpf.c
+++ b/tools/sched_ext/scx_simple.bpf.c
@@ -121,12 +121,14 @@ void BPF_STRUCT_OPS(simple_stopping, struct task_struct *p, bool runnable)
* too much, determine the execution time by taking explicit timestamps
* instead of depending on @p->scx.slice.
*/
- p->scx.dsq_vtime += (SCX_SLICE_DFL - p->scx.slice) * 100 / p->scx.weight;
+ u64 delta = scale_by_task_weight_inverse(p, SCX_SLICE_DFL - p->scx.slice);
+
+ scx_bpf_task_set_dsq_vtime(p, p->scx.dsq_vtime + delta);
}
void BPF_STRUCT_OPS(simple_enable, struct task_struct *p)
{
- p->scx.dsq_vtime = vtime_now;
+ scx_bpf_task_set_dsq_vtime(p, vtime_now);
}
s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init)
diff --git a/tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c b/tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c
index bfcb96cd4954..aad8de51723e 100644
--- a/tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c
+++ b/tools/testing/selftests/sched_ext/select_cpu_vtime.bpf.c
@@ -66,12 +66,14 @@ void BPF_STRUCT_OPS(select_cpu_vtime_running, struct task_struct *p)
void BPF_STRUCT_OPS(select_cpu_vtime_stopping, struct task_struct *p,
bool runnable)
{
- p->scx.dsq_vtime += (SCX_SLICE_DFL - p->scx.slice) * 100 / p->scx.weight;
+ u64 delta = scale_by_task_weight_inverse(p, SCX_SLICE_DFL - p->scx.slice);
+
+ scx_bpf_task_set_dsq_vtime(p, p->scx.dsq_vtime + delta);
}
void BPF_STRUCT_OPS(select_cpu_vtime_enable, struct task_struct *p)
{
- p->scx.dsq_vtime = vtime_now;
+ scx_bpf_task_set_dsq_vtime(p, vtime_now);
}
s32 BPF_STRUCT_OPS_SLEEPABLE(select_cpu_vtime_init)
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] sched_ext: Update selftests to drop ops.cpu_acquire/release()
2026-03-15 8:24 [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 1/2] sched_ext: Update demo schedulers and selftests to use scx_bpf_task_set_dsq_vtime() Cheng-Yang Chou
@ 2026-03-15 8:24 ` Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
2026-03-15 8:58 ` [PATCH v5 " Tejun Heo
3 siblings, 0 replies; 6+ messages in thread
From: Cheng-Yang Chou @ 2026-03-15 8:24 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai, yphbchou0911
ops.cpu_acquire/release() are deprecated by commit a3f5d4822253
("sched_ext: Allow scx_bpf_reenqueue_local() to be called from
anywhere") in favor of handling CPU preemption via the sched_switch
tracepoint.
In the maximal selftest, replace the cpu_acquire/release stubs with a
minimal sched_switch TP program. Attach all non-struct_ops programs
(including the new TP) via maximal__attach() after disabling auto-attach
for the maximal_ops struct_ops map, which is managed manually in run().
Apply the same fix to reload_loop, which also uses the maximal skeleton.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
---
tools/testing/selftests/sched_ext/maximal.bpf.c | 15 ++++++---------
tools/testing/selftests/sched_ext/maximal.c | 3 +++
tools/testing/selftests/sched_ext/reload_loop.c | 3 +++
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/sched_ext/maximal.bpf.c b/tools/testing/selftests/sched_ext/maximal.bpf.c
index 01cf4f3da4e0..06379eaa06df 100644
--- a/tools/testing/selftests/sched_ext/maximal.bpf.c
+++ b/tools/testing/selftests/sched_ext/maximal.bpf.c
@@ -67,13 +67,12 @@ void BPF_STRUCT_OPS(maximal_set_cpumask, struct task_struct *p,
void BPF_STRUCT_OPS(maximal_update_idle, s32 cpu, bool idle)
{}
-void BPF_STRUCT_OPS(maximal_cpu_acquire, s32 cpu,
- struct scx_cpu_acquire_args *args)
-{}
-
-void BPF_STRUCT_OPS(maximal_cpu_release, s32 cpu,
- struct scx_cpu_release_args *args)
-{}
+SEC("tp_btf/sched_switch")
+int BPF_PROG(maximal_sched_switch, bool preempt, struct task_struct *prev,
+ struct task_struct *next, unsigned int prev_state)
+{
+ return 0;
+}
void BPF_STRUCT_OPS(maximal_cpu_online, s32 cpu)
{}
@@ -150,8 +149,6 @@ struct sched_ext_ops maximal_ops = {
.set_weight = (void *) maximal_set_weight,
.set_cpumask = (void *) maximal_set_cpumask,
.update_idle = (void *) maximal_update_idle,
- .cpu_acquire = (void *) maximal_cpu_acquire,
- .cpu_release = (void *) maximal_cpu_release,
.cpu_online = (void *) maximal_cpu_online,
.cpu_offline = (void *) maximal_cpu_offline,
.init_task = (void *) maximal_init_task,
diff --git a/tools/testing/selftests/sched_ext/maximal.c b/tools/testing/selftests/sched_ext/maximal.c
index c6be50a9941d..1dc369224670 100644
--- a/tools/testing/selftests/sched_ext/maximal.c
+++ b/tools/testing/selftests/sched_ext/maximal.c
@@ -19,6 +19,9 @@ static enum scx_test_status setup(void **ctx)
SCX_ENUM_INIT(skel);
SCX_FAIL_IF(maximal__load(skel), "Failed to load skel");
+ bpf_map__set_autoattach(skel->maps.maximal_ops, false);
+ SCX_FAIL_IF(maximal__attach(skel), "Failed to attach skel");
+
*ctx = skel;
return SCX_TEST_PASS;
diff --git a/tools/testing/selftests/sched_ext/reload_loop.c b/tools/testing/selftests/sched_ext/reload_loop.c
index 308211d80436..49297b83d748 100644
--- a/tools/testing/selftests/sched_ext/reload_loop.c
+++ b/tools/testing/selftests/sched_ext/reload_loop.c
@@ -23,6 +23,9 @@ static enum scx_test_status setup(void **ctx)
SCX_ENUM_INIT(skel);
SCX_FAIL_IF(maximal__load(skel), "Failed to load skel");
+ bpf_map__set_autoattach(skel->maps.maximal_ops, false);
+ SCX_FAIL_IF(maximal__attach(skel), "Failed to attach skel");
+
return SCX_TEST_PASS;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs
2026-03-15 8:24 [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 1/2] sched_ext: Update demo schedulers and selftests to use scx_bpf_task_set_dsq_vtime() Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 2/2] sched_ext: Update selftests to drop ops.cpu_acquire/release() Cheng-Yang Chou
@ 2026-03-15 8:24 ` Cheng-Yang Chou
2026-03-15 8:34 ` Cheng-Yang Chou
2026-03-15 8:58 ` [PATCH v5 " Tejun Heo
3 siblings, 1 reply; 6+ messages in thread
From: Cheng-Yang Chou @ 2026-03-15 8:24 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai, yphbchou0911
Two sets of sched_ext APIs have been deprecated:
- Direct writes to p->scx.dsq_vtime in favor of
scx_bpf_task_set_dsq_vtime()
- ops.cpu_acquire/release() in favor of handling CPU preemption via the
sched_switch tracepoint, as introduced by commit a3f5d4822253
("sched_ext: Allow scx_bpf_reenqueue_local() to be called from
anywhere")
This series updates the demo schedulers (scx_simple, scx_flatcg) and
selftests (select_cpu_vtime, maximal) to use the new APIs, keeping them
in sync with current best practices.
Patch 1 updates scx_simple, scx_flatcg, and select_cpu_vtime to use
scx_bpf_task_set_dsq_vtime() with scale_by_task_weight_inverse(), with
the delta computation moved inside the if block.
Patch 2 replaces the cpu_acquire/release stubs in the maximal selftest
with a minimal sched_switch TP program, and fixes the maximal and
reload_loop tests to properly attach the sched_switch tracepoint via
bpf_map__set_autoattach() and maximal__attach(), as both tests use the
maximal skeleton.
Changes in v4:
- Drop scx_qmap changes from patch 2, already applied in commit
3229ac4a5ef5 ("sched_ext: Add SCX_OPS_ALWAYS_ENQ_IMMED ops flag")
- Move delta computation inside the if block (Tejun Heo)
- Link to v3:
https://lore.kernel.org/all/20260313014944.1234667-1-yphbchou0911@gmail.com/
Changes in v3:
- Use scale_by_task_weight_inverse() instead of scale_by_task_weight()
(Andrea Righi)
- Link to v2:
https://lore.kernel.org/all/20260312175527.1220540-1-yphbchou0911@gmail.com/
Changes in v2:
- Use scx_bpf_task_set_dsq_vtime() with scale_by_task_weight instead
of direct assignment and remove redundant bpf_ksym_exists() logic
(Andrea Righi)
- Mention commit a3f5d4822253 ("sched_ext: Allow
scx_bpf_reenqueue_local() to be called from anywhere") in the commit
message to clarify why ops.cpu_acquire/release() are being deprecated
(Andrea Righi)
- Fix maximal.c and reload_loop.c to actually attach the sched_switch
tracepoint by calling bpf_map__set_autoattach() and maximal__attach()
(Andrea Righi)
- Link to v1:
https://lore.kernel.org/all/20260312042001.955675-1-yphbchou0911@gmail.com/
Thanks,
Cheng-Yang
---
Cheng-Yang Chou (2):
sched_ext: Update demo schedulers and selftests to use
scx_bpf_task_set_dsq_vtime()
sched_ext: Update selftests to drop ops.cpu_acquire/release()
tools/sched_ext/scx_flatcg.bpf.c | 12 +++++++-----
tools/sched_ext/scx_simple.bpf.c | 6 ++++--
tools/testing/selftests/sched_ext/maximal.bpf.c | 15 ++++++---------
tools/testing/selftests/sched_ext/maximal.c | 3 +++
tools/testing/selftests/sched_ext/reload_loop.c | 3 +++
.../selftests/sched_ext/select_cpu_vtime.bpf.c | 7 +++++--
6 files changed, 28 insertions(+), 18 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs
2026-03-15 8:24 ` [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
@ 2026-03-15 8:34 ` Cheng-Yang Chou
0 siblings, 0 replies; 6+ messages in thread
From: Cheng-Yang Chou @ 2026-03-15 8:34 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai
Please disregard this outdated cover letter, as I accidentally sent it.
My apologies for the mess!
--
Thanks,
Cheng-Yang
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs
2026-03-15 8:24 [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
` (2 preceding siblings ...)
2026-03-15 8:24 ` [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
@ 2026-03-15 8:58 ` Tejun Heo
3 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2026-03-15 8:58 UTC (permalink / raw)
To: Cheng-Yang Chou
Cc: sched-ext, David Vernet, Andrea Righi, Changwoo Min,
Ching-Chun Huang, Chia-Ping Tsai, Emil Tsalapatis, linux-kernel
Hello,
> Cheng-Yang Chou (2):
> sched_ext: Update demo schedulers and selftests to use
> scx_bpf_task_set_dsq_vtime()
> sched_ext: Update selftests to drop ops.cpu_acquire/release()
Applied 1-2 to sched_ext/for-7.1.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-15 8:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-15 8:24 [PATCH v5 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 1/2] sched_ext: Update demo schedulers and selftests to use scx_bpf_task_set_dsq_vtime() Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v5 2/2] sched_ext: Update selftests to drop ops.cpu_acquire/release() Cheng-Yang Chou
2026-03-15 8:24 ` [PATCH v4 0/2] sched_ext: Update demo schedulers and selftests for deprecated APIs Cheng-Yang Chou
2026-03-15 8:34 ` Cheng-Yang Chou
2026-03-15 8:58 ` [PATCH v5 " Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox