Commit 1e123fd7 authored by Tejun Heo's avatar Tejun Heo

sched_ext: Add __COMPAT helpers for features added during v6.12 devel cycle

cgroup support and scx_bpf_dispatch[_vtime]_from_dsq() are newly added since
8bb30798 ("sched_ext: Fixes incorrect type in bpf_scx_init()") which is
the current earliest commit targeted by BPF schedulers. Add compat helpers
for them and apply them in the example schedulers.

These will be dropped after a few kernel releases. The exact backward
compatibility window hasn't been decided yet.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 42268ad0
...@@ -15,6 +15,25 @@ ...@@ -15,6 +15,25 @@
__ret; \ __ret; \
}) })
/* v6.12: 819513666966 ("sched_ext: Add cgroup support") */
#define __COMPAT_scx_bpf_task_cgroup(p) \
(bpf_ksym_exists(scx_bpf_task_cgroup) ? \
scx_bpf_task_cgroup((p)) : NULL)
/* v6.12: 4c30f5ce4f7a ("sched_ext: Implement scx_bpf_dispatch[_vtime]_from_dsq()") */
#define __COMPAT_scx_bpf_dispatch_from_dsq_set_slice(it, slice) \
(bpf_ksym_exists(scx_bpf_dispatch_from_dsq_set_slice) ? \
scx_bpf_dispatch_from_dsq_set_slice((it), (slice)) : (void)0)
#define __COMPAT_scx_bpf_dispatch_from_dsq_set_vtime(it, vtime) \
(bpf_ksym_exists(scx_bpf_dispatch_from_dsq_set_vtime) ? \
scx_bpf_dispatch_from_dsq_set_vtime((it), (vtime)) : (void)0)
#define __COMPAT_scx_bpf_dispatch_from_dsq(it, p, dsq_id, enq_flags) \
(bpf_ksym_exists(scx_bpf_dispatch_from_dsq) ? \
scx_bpf_dispatch_from_dsq((it), (p), (dsq_id), (enq_flags)) : false)
#define __COMPAT_scx_bpf_dispatch_vtime_from_dsq(it, p, dsq_id, enq_flags) \
(bpf_ksym_exists(scx_bpf_dispatch_vtime_from_dsq) ? \
scx_bpf_dispatch_vtime_from_dsq((it), (p), (dsq_id), (enq_flags)) : false)
/* /*
* Define sched_ext_ops. This may be expanded to define multiple variants for * Define sched_ext_ops. This may be expanded to define multiple variants for
* backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH(). * backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH().
......
...@@ -383,7 +383,7 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags) ...@@ -383,7 +383,7 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags)
return; return;
} }
cgrp = scx_bpf_task_cgroup(p); cgrp = __COMPAT_scx_bpf_task_cgroup(p);
cgc = find_cgrp_ctx(cgrp); cgc = find_cgrp_ctx(cgrp);
if (!cgc) if (!cgc)
goto out_release; goto out_release;
...@@ -509,7 +509,7 @@ void BPF_STRUCT_OPS(fcg_runnable, struct task_struct *p, u64 enq_flags) ...@@ -509,7 +509,7 @@ void BPF_STRUCT_OPS(fcg_runnable, struct task_struct *p, u64 enq_flags)
{ {
struct cgroup *cgrp; struct cgroup *cgrp;
cgrp = scx_bpf_task_cgroup(p); cgrp = __COMPAT_scx_bpf_task_cgroup(p);
update_active_weight_sums(cgrp, true); update_active_weight_sums(cgrp, true);
bpf_cgroup_release(cgrp); bpf_cgroup_release(cgrp);
} }
...@@ -522,7 +522,7 @@ void BPF_STRUCT_OPS(fcg_running, struct task_struct *p) ...@@ -522,7 +522,7 @@ void BPF_STRUCT_OPS(fcg_running, struct task_struct *p)
if (fifo_sched) if (fifo_sched)
return; return;
cgrp = scx_bpf_task_cgroup(p); cgrp = __COMPAT_scx_bpf_task_cgroup(p);
cgc = find_cgrp_ctx(cgrp); cgc = find_cgrp_ctx(cgrp);
if (cgc) { if (cgc) {
/* /*
...@@ -565,7 +565,7 @@ void BPF_STRUCT_OPS(fcg_stopping, struct task_struct *p, bool runnable) ...@@ -565,7 +565,7 @@ void BPF_STRUCT_OPS(fcg_stopping, struct task_struct *p, bool runnable)
if (!taskc->bypassed_at) if (!taskc->bypassed_at)
return; return;
cgrp = scx_bpf_task_cgroup(p); cgrp = __COMPAT_scx_bpf_task_cgroup(p);
cgc = find_cgrp_ctx(cgrp); cgc = find_cgrp_ctx(cgrp);
if (cgc) { if (cgc) {
__sync_fetch_and_add(&cgc->cvtime_delta, __sync_fetch_and_add(&cgc->cvtime_delta,
...@@ -579,7 +579,7 @@ void BPF_STRUCT_OPS(fcg_quiescent, struct task_struct *p, u64 deq_flags) ...@@ -579,7 +579,7 @@ void BPF_STRUCT_OPS(fcg_quiescent, struct task_struct *p, u64 deq_flags)
{ {
struct cgroup *cgrp; struct cgroup *cgrp;
cgrp = scx_bpf_task_cgroup(p); cgrp = __COMPAT_scx_bpf_task_cgroup(p);
update_active_weight_sums(cgrp, false); update_active_weight_sums(cgrp, false);
bpf_cgroup_release(cgrp); bpf_cgroup_release(cgrp);
} }
......
...@@ -318,11 +318,11 @@ static bool dispatch_highpri(bool from_timer) ...@@ -318,11 +318,11 @@ static bool dispatch_highpri(bool from_timer)
if (tctx->highpri) { if (tctx->highpri) {
/* exercise the set_*() and vtime interface too */ /* exercise the set_*() and vtime interface too */
scx_bpf_dispatch_from_dsq_set_slice( __COMPAT_scx_bpf_dispatch_from_dsq_set_slice(
BPF_FOR_EACH_ITER, slice_ns * 2); BPF_FOR_EACH_ITER, slice_ns * 2);
scx_bpf_dispatch_from_dsq_set_vtime( __COMPAT_scx_bpf_dispatch_from_dsq_set_vtime(
BPF_FOR_EACH_ITER, highpri_seq++); BPF_FOR_EACH_ITER, highpri_seq++);
scx_bpf_dispatch_vtime_from_dsq( __COMPAT_scx_bpf_dispatch_vtime_from_dsq(
BPF_FOR_EACH_ITER, p, HIGHPRI_DSQ, 0); BPF_FOR_EACH_ITER, p, HIGHPRI_DSQ, 0);
} }
} }
...@@ -340,7 +340,7 @@ static bool dispatch_highpri(bool from_timer) ...@@ -340,7 +340,7 @@ static bool dispatch_highpri(bool from_timer)
else else
cpu = scx_bpf_pick_any_cpu(p->cpus_ptr, 0); cpu = scx_bpf_pick_any_cpu(p->cpus_ptr, 0);
if (scx_bpf_dispatch_from_dsq(BPF_FOR_EACH_ITER, p, if (__COMPAT_scx_bpf_dispatch_from_dsq(BPF_FOR_EACH_ITER, p,
SCX_DSQ_LOCAL_ON | cpu, SCX_DSQ_LOCAL_ON | cpu,
SCX_ENQ_PREEMPT)) { SCX_ENQ_PREEMPT)) {
if (cpu == this_cpu) { if (cpu == this_cpu) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment