sched_ext: Rename the cid-form cgroup ops to cpuctl_*
Subsystems (2)
Tejun Heo
reviewerPATCH 1/1 sched_ext: Rename the cid-form cgroup ops to cpuctl_*
Hello,
Two unrelated things go by "cgroup" in the cid form. Sub-schedulers attach to cgroups, and the cgroup_*() ops deliver cpu controller events. While the ops names suggest cgroup2 hierarchy, they actually operate on the cpu controller. The cid form has no users beyond scx_qmap yet, so rename the ops to cpuctl_* while the ABI can still change. The cpu form is deployed ABI and keeps the old names.
- 0001 factors the skeleton open path out of SCX_OPS_OPEN() and adds SCX_OPS_CID_OPEN() so that cid-form skeletons don't depend on the cpu-form member names dereferenced by the compat clears.
- 0002 renames the ops to cpuctl_* in struct sched_ext_ops_cid and updates scx_qmap, the only cid-form scheduler.
Based on sched_ext/for-7.3 (7c2cd767705d) plus the cgroup migration patchset:
https://lore.kernel.org/r/[email protected]
Tejun Heo (2):
tools/sched_ext: Add SCX_OPS_CID_OPEN for cid-form schedulers
sched_ext: Rename the cid-form cgroup ops to cpuctl_*
Git tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git scx-cpuctl-rename
kernel/sched/ext/ext.c | 36 ++++++++++++++++++------------------ kernel/sched/ext/internal.h | 25 ++++++++++++------------- tools/sched_ext/include/scx/compat.h | 30 ++++++++++++++++++++++-------- tools/sched_ext/scx_qmap.bpf.c | 22 +++++++++++----------- tools/sched_ext/scx_qmap.c | 4 ++-- tools/sched_ext/scx_qmap.h | 2 +- 6 files changed, 66 insertions(+), 53 deletions(-)
--
tejun
Tejun Heo
reviewerPATCH 1/2 tools/sched_ext: Add SCX_OPS_CID_OPEN for cid-form schedulers
SCX_OPS_OPEN() clears compat-gated ops fields which the running kernel lacks. The clears dereference cpu-form member names and compile for cid-form skeletons only because both ops structs currently name their cgroup ops identically, which an upcoming rename will end. No load-time fix-up can apply to a cid-form scheduler anyway as the cid form postdates every compat-gated op.
Factor the skeleton open path out of SCX_OPS_OPEN() and add SCX_OPS_CID_OPEN() which uses only that shared part. Switch scx_qmap, the only cid-form scheduler, over.
--- tools/sched_ext/include/scx/compat.h | 30 ++++++++++++++++++++-------- tools/sched_ext/scx_qmap.c | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-)
tools/sched_ext/include/scx/compat.h +22 -8
@@ -154,7 +154,7 @@ static inline long scx_hotplug_seq(void)* struct sched_ext_ops can change over time. Two complementary mechanisms * keep BPF schedulers built against newer headers running on older kernels: * -* 1. Load-time fix-up (this macro). For each optional ops callback or field +* 1. Load-time fix-up (SCX_OPS_OPEN()). For each optional ops callback or field * added to struct sched_ext_ops, an explicit stanza below probes the * running kernel's BTF via __COMPAT_struct_has_field() and, if the field * is missing, clears it in the in-memory struct_ops (with a warning to
@@ -176,16 +176,23 @@ static inline long scx_hotplug_seq(void)* - v6.19: ops.cgroup_set_idle() * - v7.1: ops.sub_attach(), ops.sub_detach(), ops.sub_cgroup_id */ +#define __SCX_OPS_OPEN (__ops_name, __scx_name, __ops_struct) ({ \ + struct __scx_name *__oskel; \ + \ + SCX_BUG_ON(!__COMPAT_struct_has_field(__ops_struct, "dump"), \ + __ops_struct ".dump() missing, kernel too old?"); \ + \ + __oskel = __scx_name##__open(); \ + SCX_BUG_ON(!__oskel, "Could not open " #__scx_name); \ + __oskel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \ + SCX_ENUM_INIT(__oskel); \ + __oskel; \ +}) +#define SCX_OPS_OPEN (__ops_name, __scx_name) ({ \ struct __scx_name *__skel; \ \ - SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "dump"), \ - "sched_ext_ops.dump() missing, kernel too old?"); \ - \ - __skel = __scx_name##__open(); \ - SCX_BUG_ON(!__skel, "Could not open " #__scx_name); \ - __skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \ - SCX_ENUM_INIT(__skel); \ + __skel = __SCX_OPS_OPEN(__ops_name, __scx_name, "sched_ext_ops"); \ if (__skel->struct_ops.__ops_name->cgroup_set_bandwidth && \ !__COMPAT_struct_has_field("sched_ext_ops", "cgroup_set_bandwidth")) { \ fprintf(stderr, "WARNING: kernel doesn't support ops.cgroup_set_bandwidth()\n"); \
@@ -214,6 +221,13 @@ static inline long scx_hotplug_seq(void) __skel; \ }) +/* +* Open a cid-form (struct sched_ext_ops_cid) skeleton. The cid form postdates +* every op the load-time fix-ups above handle, so none of them apply. +*/ +#define SCX_OPS_CID_OPEN (__ops_name, __scx_name) \ + __SCX_OPS_OPEN(__ops_name, __scx_name, "sched_ext_ops_cid") +/* * Associate non-struct_ops BPF programs with the scheduler's struct_ops map so * that scx_prog_sched() can determine which scheduler a BPF program belongs
tools/sched_ext/scx_qmap.c +1 -1
@@ -251,7 +251,7 @@ int main(int argc, char **argv) } restart: optind =1 ; - skel =SCX_OPS_OPEN (qmap_ops, scx_qmap); + skel =SCX_OPS_CID_OPEN (qmap_ops, scx_qmap); skel->rodata->slice_ns =__COMPAT_ENUM_OR_ZERO ("scx_public_consts" ,"SCX_SLICE_DFL" ); skel->rodata->max_tasks =16384 ;
Signature · 1 line
2.55.0
Tejun Heo
reviewerPATCH 2/2 sched_ext: Rename the cid-form cgroup ops to cpuctl_*
In reply to Tejun HeoTwo unrelated things go by "cgroup" in the cid form. Sub-schedulers attach to cgroups, and the cgroup_*() ops deliver cpu controller events. While the ops names suggest cgroup2 hierarchy, they actually operate on the cpu controller.
Rename them to cpuctl_* in struct sched_ext_ops_cid, which has no users outside scx_qmap yet. The cpu form is deployed ABI and keeps the old names. The layout is unchanged and the kernel keeps calling through the cpu-form union view.
--- kernel/sched/ext/ext.c | 36 +++++++++++++++++----------------- kernel/sched/ext/internal.h | 25 ++++++++++++----------- tools/sched_ext/scx_qmap.bpf.c | 22 ++++++++++----------- tools/sched_ext/scx_qmap.c | 2 +- tools/sched_ext/scx_qmap.h | 2 +- 5 files changed, 43 insertions(+), 44 deletions(-)
kernel/sched/ext/ext.c +18 -18
@@ -7952,14 +7952,14 @@ static struct sched_ext_ops_cid __bpf_ops_sched_ext_ops_cid = { .enable = sched_ext_ops__enable, .disable = sched_ext_ops__disable, #ifdef CONFIG_EXT_GROUP_SCHED - .cgroup_init = sched_ext_ops__cgroup_init, - .cgroup_exit = sched_ext_ops__cgroup_exit, - .cgroup_prep_move = sched_ext_ops__cgroup_prep_move, - .cgroup_move = sched_ext_ops__cgroup_move, - .cgroup_cancel_move = sched_ext_ops__cgroup_cancel_move, - .cgroup_set_weight = sched_ext_ops__cgroup_set_weight, - .cgroup_set_bandwidth = sched_ext_ops__cgroup_set_bandwidth, - .cgroup_set_idle = sched_ext_ops__cgroup_set_idle, + .cpuctl_init = sched_ext_ops__cgroup_init, + .cpuctl_exit = sched_ext_ops__cgroup_exit, + .cpuctl_prep_move = sched_ext_ops__cgroup_prep_move, + .cpuctl_move = sched_ext_ops__cgroup_move, + .cpuctl_cancel_move = sched_ext_ops__cgroup_cancel_move, + .cpuctl_set_weight = sched_ext_ops__cgroup_set_weight, + .cpuctl_set_bandwidth = sched_ext_ops__cgroup_set_bandwidth, + .cpuctl_set_idle = sched_ext_ops__cgroup_set_idle, #endif .sub_attach = sched_ext_ops__sub_attach, .sub_detach = sched_ext_ops__sub_detach,
@@ -10479,22 +10479,22 @@ static int __init scx_init(void)CID_OFFSET_MATCH (init_cids, init_cids);CID_OFFSET_MATCH (init, init);CID_OFFSET_MATCH (exit, exit); -#ifdef CONFIG_EXT_GROUP_SCHED -CID_OFFSET_MATCH (cgroup_init, cgroup_init); -CID_OFFSET_MATCH (cgroup_exit, cgroup_exit); -CID_OFFSET_MATCH (cgroup_prep_move, cgroup_prep_move); -CID_OFFSET_MATCH (cgroup_move, cgroup_move); -CID_OFFSET_MATCH (cgroup_cancel_move, cgroup_cancel_move); -CID_OFFSET_MATCH (cgroup_set_weight, cgroup_set_weight); -CID_OFFSET_MATCH (cgroup_set_bandwidth, cgroup_set_bandwidth); -CID_OFFSET_MATCH (cgroup_set_idle, cgroup_set_idle); -#endif /* renamed callbacks must occupy the same slot as their cpu-form sibling */ CID_OFFSET_MATCH (select_cpu, select_cid);CID_OFFSET_MATCH (set_cpumask, set_cmask);CID_OFFSET_MATCH (cpu_online, cid_online);CID_OFFSET_MATCH (cpu_offline, cid_offline);CID_OFFSET_MATCH (dump_cpu, dump_cid); +#ifdef CONFIG_EXT_GROUP_SCHED +CID_OFFSET_MATCH (cgroup_init, cpuctl_init); +CID_OFFSET_MATCH (cgroup_exit, cpuctl_exit); +CID_OFFSET_MATCH (cgroup_prep_move, cpuctl_prep_move); +CID_OFFSET_MATCH (cgroup_move, cpuctl_move); +CID_OFFSET_MATCH (cgroup_cancel_move, cpuctl_cancel_move); +CID_OFFSET_MATCH (cgroup_set_weight, cpuctl_set_weight); +CID_OFFSET_MATCH (cgroup_set_bandwidth, cpuctl_set_bandwidth); +CID_OFFSET_MATCH (cgroup_set_idle, cpuctl_set_idle); +#endif /* @priv tail must align since both share the same data block */ CID_OFFSET_MATCH (priv, priv);/*
kernel/sched/ext/internal.h +12 -13
@@ -992,6 +992,7 @@ struct sched_ext_ops {* - cpu_online -> cid_online * - cpu_offline -> cid_offline * - dump_cpu -> dump_cid +* - cgroup_* -> cpuctl_* (they track the cgroup cpu controller) * - cpu_acquire/cpu_release -> not present (deprecated in sched_ext_ops) * * BPF schedulers using this type cannot call cpu-form scx_bpf_* kfuncs;
@@ -1027,19 +1028,17 @@ struct sched_ext_ops_cid {void (*dump_cid)(struct scx_dump_ctx *ctx,s32 cid,bool idle);void (*dump_task)(struct scx_dump_ctx *ctx,struct task_struct *p);#ifdef CONFIG_EXT_GROUP_SCHED -s32 (*cgroup_init)(struct cgroup *cgrp, -struct scx_cgroup_init_args *args); -void (*cgroup_exit)(struct cgroup *cgrp); -s32 (*cgroup_prep_move)(struct task_struct *p, -struct cgroup *from,struct cgroup *to); -void (*cgroup_move)(struct task_struct *p, -struct cgroup *from,struct cgroup *to); -void (*cgroup_cancel_move)(struct task_struct *p, -struct cgroup *from,struct cgroup *to); -void (*cgroup_set_weight)(struct cgroup *cgrp,u32 weight); -void (*cgroup_set_bandwidth)(struct cgroup *cgrp, -u64 period_us,u64 quota_us,u64 burst_us); -void (*cgroup_set_idle)(struct cgroup *cgrp,bool idle); +s32 (*cpuctl_init)(struct cgroup *cgrp,struct scx_cgroup_init_args *args); +void (*cpuctl_exit)(struct cgroup *cgrp); +s32 (*cpuctl_prep_move)(struct task_struct *p,struct cgroup *from, +struct cgroup *to); +void (*cpuctl_move)(struct task_struct *p,struct cgroup *from,struct cgroup *to); +void (*cpuctl_cancel_move)(struct task_struct *p,struct cgroup *from, +struct cgroup *to); +void (*cpuctl_set_weight)(struct cgroup *cgrp,u32 weight); +void (*cpuctl_set_bandwidth)(struct cgroup *cgrp,u64 period_us,u64 quota_us, +u64 burst_us); +void (*cpuctl_set_idle)(struct cgroup *cgrp,bool idle);#endif /* CONFIG_EXT_GROUP_SCHED */ s32 (*sub_attach)(struct scx_sub_attach_args *args);void (*sub_detach)(struct scx_sub_detach_args *args);
tools/sched_ext/scx_qmap.bpf.c +11 -11
@@ -1014,7 +1014,7 @@ void BPF_STRUCT_OPS(qmap_dump_task, struct scx_dump_ctx *dctx, struct task_struc taskc->force_local, taskc->core_sched_seq); } -s32 BPF_STRUCT_OPS (qmap_cgroup_init ,struct cgroup *cgrp,struct scx_cgroup_init_args *args) +s32 BPF_STRUCT_OPS (qmap_cpuctl_init ,struct cgroup *cgrp,struct scx_cgroup_init_args *args) {QMAP_TOUCH_ARENA ();
@@ -1036,7 +1036,7 @@ s32 BPF_STRUCT_OPS(qmap_cgroup_init, struct cgroup *cgrp, struct scx_cgroup_initstatic void redistribute (void ); -void BPF_STRUCT_OPS (qmap_cgroup_set_weight ,struct cgroup *cgrp,u32 weight) +void BPF_STRUCT_OPS (qmap_cpuctl_set_weight ,struct cgroup *cgrp,u32 weight) {u64 cgid = cgrp->kn->id;s32 i;
@@ -1062,16 +1062,16 @@ void BPF_STRUCT_OPS(qmap_cgroup_set_weight, struct cgroup *cgrp, u32 weight) } } -void BPF_STRUCT_OPS (qmap_cgroup_set_bandwidth ,struct cgroup *cgrp, -u64 period_us,u64 quota_us,u64 burst_us) +void BPF_STRUCT_OPS (qmap_cpuctl_set_bandwidth ,struct cgroup *cgrp,u64 period_us, +u64 quota_us,u64 burst_us) {if (print_msgs)bpf_printk ("CGRP SET %llu period=%lu quota=%ld burst=%lu" , cgrp->kn->id, period_us, quota_us, burst_us); } -void BPF_STRUCT_OPS (qmap_cgroup_move ,struct task_struct *p, -struct cgroup *from,struct cgroup *to) +void BPF_STRUCT_OPS (qmap_cpuctl_move ,struct task_struct *p,struct cgroup *from, +struct cgroup *to) {if (print_msgs) bpf_printk("CGRP MOVE %d %llu -> %llu",
@@ -1890,7 +1890,7 @@ void BPF_STRUCT_OPS(qmap_exit, struct scx_exit_info *ei)/* * Seed a new sub slot with the cgroup's current weight. The kernel delivers -* ops.cgroup_set_weight() only on value-changing writes, so a weight set +* ops.cpuctl_set_weight() only on value-changing writes, so a weight set * before the sub attached would otherwise go unnoticed. */ static u32 cgrp_cur_weight (u64 cgid)
@@ -1989,10 +1989,10 @@ SCX_OPS_CID_DEFINE(qmap_ops, .dump = (void *)qmap_dump, .dump_cid = (void *)qmap_dump_cid, .dump_task = (void *)qmap_dump_task, - .cgroup_init = (void *)qmap_cgroup_init, - .cgroup_set_weight = (void *)qmap_cgroup_set_weight, - .cgroup_set_bandwidth = (void *)qmap_cgroup_set_bandwidth, - .cgroup_move = (void *)qmap_cgroup_move, + .cpuctl_init = (void *)qmap_cpuctl_init, + .cpuctl_set_weight = (void *)qmap_cpuctl_set_weight, + .cpuctl_set_bandwidth = (void *)qmap_cpuctl_set_bandwidth, + .cpuctl_move = (void *)qmap_cpuctl_move, .sub_attach = (void *)qmap_sub_attach, .sub_detach = (void *)qmap_sub_detach, .sub_caps_updated = (void *)qmap_sub_caps_updated,
tools/sched_ext/scx_qmap.c +1 -1
@@ -70,7 +70,7 @@ const char help_fmt[] =" -i SEC Stats interval, seconds (default 5)\n" " -R MS Round-robin period for time-shared cpus, ms (default 200)\n" " -J MODE Fault injection (wrong-cid: dispatch to a cid not held,\n" -" init-fail/cgrp-init-fail: fail init_task/cgroup_init for\n" +" init-fail/cgrp-init-fail: fail init_task/cpuctl_init for\n" " \"qmfail*\" comms/cgroups)\n" " -v Print libbpf debug messages\n" " -h Display this help and exit\n" ;
tools/sched_ext/scx_qmap.h +1 -1
@@ -65,7 +65,7 @@ enum qmap_inject {QMAP_INJ_OFF =0 ,QMAP_INJ_WRONG_CID =1 ,/* dispatch to a cid we don't hold */ QMAP_INJ_INIT_FAIL =2 ,/* fail init_task for "qmfail*" comms */ - QMAP_INJ_CGRP_INIT_FAIL = 3, /* fail cgroup_init for "qmfail*" cgroups */ + QMAP_INJ_CGRP_INIT_FAIL = 3, /* fail cpuctl_init for "qmfail*" cgroups */ };/*
Signature · 1 line
2.55.0
Quoted 8 lines · Tejun Heo
Hello,
Two unrelated things go by "cgroup" in the cid form. Sub-schedulers attach to cgroups, and the cgroup_*() ops deliver cpu controller events. While the ops names suggest cgroup2 hierarchy, they actually operate on the cpu controller. The cid form has no users beyond
scx_qmapyet, so rename the ops to cpuctl_* while the ABI can still change. The cpu form is deployed ABI and keeps the old names.
Conceptually it makes sense, cpuctl_* is a more precise terminology since these callbacks report CPU-controller events.
This breaks existing CID-form schedulers, but I guess it's fine, since we don't have any user of the CID-form API right now (except scx_qmap, which is in tree), so we should be fine with that.
-Andrea
Quoted 29 lines
- 0001 factors the skeleton open path out of
SCX_OPS_OPEN()and addsSCX_OPS_CID_OPEN()so that cid-form skeletons don't depend on the cpu-form member names dereferenced by the compat clears.- 0002 renames the ops to cpuctl_* in struct
sched_ext_ops_cidand updatesscx_qmap, the only cid-form scheduler.Based on sched_ext/for-7.3 (
7c2cd767705d) plus the cgroup migration patchset:https://lore.kernel.org/r/[email protected]
Tejun Heo (2):
tools/sched_ext: AddSCX_OPS_CID_OPENfor cid-form schedulers
sched_ext: Rename the cid-form cgroup ops to cpuctl_*Git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.gitscx-cpuctl-renamekernel/sched/ext/ext.c | 36 ++++++++++++++++++------------------ kernel/sched/ext/internal.h | 25 ++++++++++++------------- tools/sched_ext/include/scx/compat.h | 30 ++++++++++++++++++++++-------- tools/sched_ext/scx_qmap.bpf.c | 22 +++++++++++----------- tools/sched_ext/scx_qmap.c | 4 ++-- tools/sched_ext/scx_qmap.h | 2 +- 6 files changed, 66 insertions(+), 53 deletions(-)--
tejun
Tejun Heo
reviewerApplied 1-2 to sched_ext/for-7.3.
Thanks.
--
tejun