sched_ext, sched/core: Factor out struct scx_task_group
Subsystems (3)
Tejun Heo
reviewerPATCH 1/2 sched_ext, sched/core: Factor out struct scx_task_group
From 55aa129e6add97a98340326451bdadd4c5dd3242 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 13 Jun 2025 15:06:47 -1000
More sched_ext fields will be added to struct task_group. In preparation, factor out sched_ext fields into struct scx_task_group to reduce clutter in the common header. No functional changes.
---
These two patches are on top of:
+ Two fix pathces pending on sched_ext/for-6.16-fixes
http://lkml.kernel.org/r/[email protected]
http://lkml.kernel.org/r/[email protected]
+ tip/sched/core patchset to reorganize bandwidth control interface handling
http://lkml.kernel.org/r/[email protected]
See the following git branch for the merged result:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git scx-bandwidth-control
Peter, while this touches sched.h, the change is contained to scx part and shouldn't cause noticeable problems for other scheduler changes. I'll carry this through sched_ext/for-6.17. Please let me know if there are any concerns.
Thanks.
include/linux/sched/ext.h | 8 ++++++++ kernel/sched/ext.c | 32 ++++++++++++++++---------------- kernel/sched/sched.h | 5 +---- 3 files changed, 25 insertions(+), 20 deletions(-)
include/linux/sched/ext.h +8 -0
@@ -214,4 +214,12 @@ static inline void print_scx_info(const char *log_lvl, struct task_struct *p) {}static inline void scx_softlockup (u32 dur_s) {}#endif /* CONFIG_SCHED_CLASS_EXT */ + +struct scx_task_group { +#ifdef CONFIG_EXT_GROUP_SCHED +u32 flags;/* SCX_TG_* */ +u32 weight; +#endif +}; +#endif /* _LINUX_SCHED_EXT_H */
kernel/sched/ext.c +16 -16
@@ -4058,7 +4058,7 @@ static bool scx_cgroup_enabled;void scx_tg_init (struct task_group *tg) { - tg->scx_weight =CGROUP_WEIGHT_DFL ; + tg->scx.weight =CGROUP_WEIGHT_DFL ; }int scx_tg_online (struct task_group *tg)
@@ -4066,14 +4066,14 @@ int scx_tg_online(struct task_group *tg)struct scx_sched *sch = scx_root;int ret =0 ; -WARN_ON_ONCE (tg->scx_flags & (SCX_TG_ONLINE |SCX_TG_INITED )); +WARN_ON_ONCE (tg->scx.flags & (SCX_TG_ONLINE |SCX_TG_INITED ));percpu_down_read (&scx_cgroup_rwsem);if (scx_cgroup_enabled) {if (SCX_HAS_OP (sch, cgroup_init)) {struct scx_cgroup_init_args args = - { .weight = tg->scx_weight }; + { .weight = tg->scx.weight }; ret =SCX_CALL_OP_RET (sch,SCX_KF_UNLOCKED , cgroup_init,NULL , tg->css.cgroup, &args);
@@ -4081,9 +4081,9 @@ int scx_tg_online(struct task_group *tg) ret =ops_sanitize_err (sch,"cgroup_init" , ret); }if (ret ==0 ) - tg->scx_flags |=SCX_TG_ONLINE |SCX_TG_INITED ; + tg->scx.flags |=SCX_TG_ONLINE |SCX_TG_INITED ; }else { - tg->scx_flags |=SCX_TG_ONLINE ; + tg->scx.flags |=SCX_TG_ONLINE ; }percpu_up_read (&scx_cgroup_rwsem);
@@ -4094,15 +4094,15 @@ void scx_tg_offline(struct task_group *tg) {struct scx_sched *sch = scx_root; -WARN_ON_ONCE (!(tg->scx_flags &SCX_TG_ONLINE )); +WARN_ON_ONCE (!(tg->scx.flags &SCX_TG_ONLINE ));percpu_down_read (&scx_cgroup_rwsem);if (scx_cgroup_enabled &&SCX_HAS_OP (sch, cgroup_exit) && - (tg->scx_flags &SCX_TG_INITED )) + (tg->scx.flags &SCX_TG_INITED ))SCX_CALL_OP (sch,SCX_KF_UNLOCKED , cgroup_exit,NULL , tg->css.cgroup); - tg->scx_flags &= ~(SCX_TG_ONLINE |SCX_TG_INITED ); + tg->scx.flags &= ~(SCX_TG_ONLINE |SCX_TG_INITED );percpu_up_read (&scx_cgroup_rwsem); }
@@ -4211,11 +4211,11 @@ void scx_group_set_weight(struct task_group *tg, unsigned long weight)percpu_down_read (&scx_cgroup_rwsem);if (scx_cgroup_enabled &&SCX_HAS_OP (sch, cgroup_set_weight) && - tg->scx_weight != weight) + tg->scx.weight != weight)SCX_CALL_OP (sch,SCX_KF_UNLOCKED , cgroup_set_weight,NULL ,tg_cgrp (tg), weight); - tg->scx_weight = weight; + tg->scx.weight = weight;percpu_up_read (&scx_cgroup_rwsem); }
@@ -4366,9 +4366,9 @@ static void scx_cgroup_exit(struct scx_sched *sch)css_for_each_descendant_post (css, &root_task_group.css) {struct task_group *tg =css_tg (css); -if (!(tg->scx_flags &SCX_TG_INITED )) +if (!(tg->scx.flags &SCX_TG_INITED ))continue ; - tg->scx_flags &= ~SCX_TG_INITED ; + tg->scx.flags &= ~SCX_TG_INITED ;if (!sch->ops.cgroup_exit)continue ;
@@ -4400,14 +4400,14 @@ static int scx_cgroup_init(struct scx_sched *sch)rcu_read_lock ();css_for_each_descendant_pre (css, &root_task_group.css) {struct task_group *tg =css_tg (css); -struct scx_cgroup_init_args args = { .weight = tg->scx_weight }; +struct scx_cgroup_init_args args = { .weight = tg->scx.weight }; -if ((tg->scx_flags & +if ((tg->scx.flags & (SCX_TG_ONLINE |SCX_TG_INITED )) !=SCX_TG_ONLINE )continue ;if (!sch->ops.cgroup_init) { - tg->scx_flags |=SCX_TG_INITED ; + tg->scx.flags |=SCX_TG_INITED ;continue ; }
@@ -4422,7 +4422,7 @@ static int scx_cgroup_init(struct scx_sched *sch)scx_error (sch,"ops.cgroup_init() failed (%d)" , ret);return ret; } - tg->scx_flags |=SCX_TG_INITED ; + tg->scx.flags |=SCX_TG_INITED ;rcu_read_lock ();css_put (css);
kernel/sched/sched.h +1 -4
@@ -471,10 +471,7 @@ struct task_group {struct rt_bandwidth rt_bandwidth;#endif -#ifdef CONFIG_EXT_GROUP_SCHED -u32 scx_flags;/* SCX_TG_* */ -u32 scx_weight; -#endif +struct scx_task_group scx;struct rcu_head rcu;struct list_head list;
Signature · 1 line
2.49.0
Tejun Heo
reviewerPATCH 2/2 sched_ext: Add support for cgroup bandwidth control interface
From 077814f57f8acce13f91dc34bbd2b7e4911fbf25 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 13 Jun 2025 15:06:47 -1000
- Add CONFIG_GROUP_SCHED_BANDWIDTH which is selected by both CONFIG_CFS_BANDWIDTH and EXT_GROUP_SCHED.
- Put bandwidth control interface files for both cgroup v1 and v2 under CONFIG_GROUP_SCHED_BANDWIDTH.
- Update tg_bandwidth() to fetch configuration parameters from fair if CONFIG_CFS_BANDWIDTH, SCX otherwise.
- Update tg_set_bandwidth() to update the parameters for both fair and SCX.
- Add bandwidth control parameters to struct scx_cgroup_init_args.
- Add sched_ext_ops.cgroup_set_bandwidth() which is invoked on bandwidth control parameter updates.
- Update scx_qmap and maximal selftest to test the new feature.
--- include/linux/sched/ext.h | 3 + init/Kconfig | 5 ++ kernel/sched/core.c | 29 ++++++-- kernel/sched/ext.c | 66 ++++++++++++++++++- kernel/sched/ext.h | 2 + kernel/sched/sched.h | 4 +- tools/sched_ext/scx_qmap.bpf.c | 23 +++++++ .../testing/selftests/sched_ext/maximal.bpf.c | 5 ++ 8 files changed, 127 insertions(+), 10 deletions(-)
include/linux/sched/ext.h +3 -0
@@ -219,6 +219,9 @@ struct scx_task_group {#ifdef CONFIG_EXT_GROUP_SCHED u32 flags;/* SCX_TG_* */ u32 weight; +u64 bw_period_us; +u64 bw_quota_us; +u64 bw_burst_us;#endif };
init/Kconfig +5 -0
@@ -1065,6 +1065,9 @@ if CGROUP_SCHED config GROUP_SCHED_WEIGHT def_bool n +config GROUP_SCHED_BANDWIDTH + def_bool n + config FAIR_GROUP_SCHED bool "Group scheduling for SCHED_OTHER" depends on CGROUP_SCHED
@@ -1074,6 +1077,7 @@ config FAIR_GROUP_SCHED config CFS_BANDWIDTH bool "CPU bandwidth provisioning for FAIR_GROUP_SCHED" depends on FAIR_GROUP_SCHED + select GROUP_SCHED_BANDWIDTH default n help This option allows users to define CPU bandwidth rates (limits) for
@@ -1108,6 +1112,7 @@ config EXT_GROUP_SCHED bool depends on SCHED_CLASS_EXT && CGROUP_SCHED select GROUP_SCHED_WEIGHT + select GROUP_SCHED_BANDWIDTH default y endif #CGROUP_SCHED
kernel/sched/core.c +24 -5
@@ -9544,7 +9544,9 @@ static int cpu_cfs_local_stat_show(struct seq_file *sf, void *v) return 0; } +#endif /* CONFIG_CFS_BANDWIDTH */ +#ifdef CONFIG_GROUP_SCHED_BANDWIDTH const u64 max_bw_quota_period_us =1 *USEC_PER_SEC ;/* 1s */ static const u64 min_bw_quota_period_us =1 *USEC_PER_MSEC ;/* 1ms */ /* More than 203 days if BW_SHIFT equals 20. */
@@ -9553,12 +9555,21 @@ static const u64 max_bw_runtime_us = MAX_BW;static void tg_bandwidth (struct task_group *tg,u64 *period_us_p,u64 *quota_us_p,u64 *burst_us_p) { +#ifdef CONFIG_CFS_BANDWIDTH if (period_us_p) *period_us_p =tg_get_cfs_period (tg);if (quota_us_p) *quota_us_p =tg_get_cfs_quota (tg);if (burst_us_p) *burst_us_p =tg_get_cfs_burst (tg); +#else /* !CONFIG_CFS_BANDWIDTH */ +if (period_us_p) + *period_us_p = tg->scx.bw_period_us; +if (quota_us_p) + *quota_us_p = tg->scx.bw_quota_us; +if (burst_us_p) + *burst_us_p = tg->scx.bw_burst_us; +#endif /* CONFIG_CFS_BANDWIDTH */ } static u64 cpu_period_read_u64(struct cgroup_subsys_state *css,
@@ -9574,6 +9585,7 @@ static int tg_set_bandwidth(struct task_group *tg, u64 period_us, u64 quota_us, u64 burst_us) { const u64 max_usec = U64_MAX / NSEC_PER_USEC; +int ret =0 ;if (tg == &root_task_group)return -EINVAL ;
@@ -9611,7 +9623,12 @@ static int tg_set_bandwidth(struct task_group *tg, burst_us + quota_us > max_bw_runtime_us))return -EINVAL ; -return tg_set_cfs_bandwidth (tg, period_us, quota_us, burst_us); +#ifdef CONFIG_CFS_BANDWIDTH + ret =tg_set_cfs_bandwidth (tg, period_us, quota_us, burst_us); +#endif /* CONFIG_CFS_BANDWIDTH */ +if (!ret) +scx_group_set_bandwidth (tg, period_us, quota_us, burst_us); +return ret; } static s64 cpu_quota_read_s64(struct cgroup_subsys_state *css,
@@ -9664,7 +9681,7 @@ static int cpu_burst_write_u64(struct cgroup_subsys_state *css,tg_bandwidth (tg, &period_us, "a_us,NULL );return tg_set_bandwidth (tg, period_us, quota_us, burst_us); } -#endif /* CONFIG_CFS_BANDWIDTH */ +#endif /* CONFIG_GROUP_SCHED_BANDWIDTH */ #ifdef CONFIG_RT_GROUP_SCHED static int cpu_rt_runtime_write(struct cgroup_subsys_state *css,
@@ -9724,7 +9741,7 @@ static struct cftype cpu_legacy_files[] = { .write_s64 = cpu_idle_write_s64, },#endif -#ifdef CONFIG_CFS_BANDWIDTH +#ifdef CONFIG_GROUP_SCHED_BANDWIDTH { .name = "cfs_period_us", .read_u64 = cpu_period_read_u64,
@@ -9740,6 +9757,8 @@ static struct cftype cpu_legacy_files[] = { .read_u64 = cpu_burst_read_u64, .write_u64 = cpu_burst_write_u64, }, +#endif +#ifdef CONFIG_CFS_BANDWIDTH { .name = "stat", .seq_show = cpu_cfs_stat_show,
@@ -9953,7 +9972,7 @@ static int __maybe_unused cpu_period_quota_parse(char *buf, u64 *period_us_p,return 0 ; } -#ifdef CONFIG_CFS_BANDWIDTH +#ifdef CONFIG_GROUP_SCHED_BANDWIDTH static int cpu_max_show (struct seq_file *sf,void *v) {struct task_group *tg =css_tg (seq_css (sf));
@@ -10000,7 +10019,7 @@ static struct cftype cpu_files[] = { .write_s64 = cpu_idle_write_s64, },#endif -#ifdef CONFIG_CFS_BANDWIDTH +#ifdef CONFIG_GROUP_SCHED_BANDWIDTH { .name = "max", .flags = CFTYPE_NOT_ON_ROOT,
kernel/sched/ext.c +63 -3
116 lines not on this page · raw message
kernel/sched/ext.h +2 -0
@@ -104,6 +104,7 @@ void scx_cgroup_finish_attach(void);void scx_cgroup_cancel_attach (struct cgroup_taskset *tset);void scx_group_set_weight (struct task_group *tg,unsigned long cgrp_weight);void scx_group_set_idle (struct task_group *tg,bool idle); +void scx_group_set_bandwidth (struct task_group *tg,u64 period_us,u64 quota_us,u64 burst_us);#else /* CONFIG_EXT_GROUP_SCHED */ static inline void scx_tg_init (struct task_group *tg) {}static inline int scx_tg_online (struct task_group *tg) {return 0 ; }
@@ -114,5 +115,6 @@ static inline void scx_cgroup_finish_attach(void) {}static inline void scx_cgroup_cancel_attach (struct cgroup_taskset *tset) {}static inline void scx_group_set_weight (struct task_group *tg,unsigned long cgrp_weight) {}static inline void scx_group_set_idle (struct task_group *tg,bool idle) {} +static inline void scx_group_set_bandwidth (struct task_group *tg,u64 period_us,u64 quota_us,u64 burst_us) {}#endif /* CONFIG_EXT_GROUP_SCHED */ #endif /* CONFIG_CGROUP_SCHED */
kernel/sched/sched.h +2 -2
@@ -402,7 +402,7 @@ static inline bool dl_server_active(struct sched_dl_entity *dl_se)extern struct list_head task_groups; -#ifdef CONFIG_CFS_BANDWIDTH +#ifdef CONFIG_GROUP_SCHED_BANDWIDTH extern const u64 max_bw_quota_period_us;/*
@@ -413,7 +413,7 @@ static inline u64 default_bw_period_us(void) {return 100000ULL ; } -#endif /* CONFIG_CFS_BANDWIDTH */ +#endif /* CONFIG_GROUP_SCHED_BANDWIDTH */ struct cfs_bandwidth {#ifdef CONFIG_CFS_BANDWIDTH
tools/sched_ext/scx_qmap.bpf.c +23 -0
@@ -615,6 +615,26 @@ 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) +{ +bpf_printk ("CGRP INIT %llu weight=%u period=%lu quota=%ld burst=%lu" , + cgrp->kn->id, args->weight, args->bw_period_us, + args->bw_quota_us, args->bw_burst_us); +return 0 ; +} + +void BPF_STRUCT_OPS (qmap_cgroup_set_weight ,struct cgroup *cgrp,u32 weight) +{ +bpf_printk ("CGRP SET %llu weight=%u" , cgrp->kn->id, weight); +} + +void BPF_STRUCT_OPS (qmap_cgroup_set_bandwidth ,struct cgroup *cgrp, +u64 period_us,u64 quota_us,u64 burst_us) +{ +bpf_printk ("CGRP SET %llu period=%lu quota=%ld burst=%lu" , cgrp->kn->id, + period_us, quota_us, burst_us); +} +/* * Print out the online and possible CPU map using bpf_printk() as a * demonstration of using the cpumask kfuncs and ops.cpu_on/offline().
@@ -840,6 +860,9 @@ SCX_OPS_DEFINE(qmap_ops, .dump = (void *)qmap_dump, .dump_cpu = (void *)qmap_dump_cpu, .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, .cpu_online = (void *)qmap_cpu_online, .cpu_offline = (void *)qmap_cpu_offline, .init = (void *)qmap_init,
tools/testing/selftests/sched_ext/maximal.bpf.c +5 -0
@@ -123,6 +123,10 @@ void BPF_STRUCT_OPS(maximal_cgroup_cancel_move, struct task_struct *p,void BPF_STRUCT_OPS (maximal_cgroup_set_weight ,struct cgroup *cgrp,u32 weight) {} +void BPF_STRUCT_OPS (maximal_cgroup_set_bandwidth ,struct cgroup *cgrp, +u64 period_us,u64 quota_us,u64 burst_us) +{} +s32 BPF_STRUCT_OPS_SLEEPABLE (maximal_init ) {return scx_bpf_create_dsq (DSQ_ID ,-1 );
@@ -160,6 +164,7 @@ struct sched_ext_ops maximal_ops = { .cgroup_move = (void *) maximal_cgroup_move, .cgroup_cancel_move = (void *) maximal_cgroup_cancel_move, .cgroup_set_weight = (void *) maximal_cgroup_set_weight, + .cgroup_set_bandwidth = (void *) maximal_cgroup_set_bandwidth, .init = (void *) maximal_init, .exit = (void *) maximal_exit, .name = "maximal",
Signature · 1 line
2.49.0
Tejun Heo
reviewerRe: [PATCH sched_ext/for-6.17 2/2] sched_ext: Add support for cgroup bandwidth control interface
Quoted 15 lines · Tejun Heo
From
077814f57f8acce13f91dc34bbd2b7e4911fbf25Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 13 Jun 2025 15:06:47 -1000- Add
CONFIG_GROUP_SCHED_BANDWIDTHwhich is selected by bothCONFIG_CFS_BANDWIDTHandEXT_GROUP_SCHED.- Put bandwidth control interface files for both cgroup v1 and v2 under
CONFIG_GROUP_SCHED_BANDWIDTH.- Update
tg_bandwidth()to fetch configuration parameters from fair ifCONFIG_CFS_BANDWIDTH, SCX otherwise.- Update
tg_set_bandwidth()to update the parameters for both fair and SCX.
Quoted 8 lines
- Add bandwidth control parameters to struct
scx_cgroup_init_args.- Add
sched_ext_ops.cgroup_set_bandwidth()which is invoked on bandwidth control parameter updates.- Update
scx_qmapand maximal selftest to test the new feature.Signed-off-by Tejun Heo <[email protected]>
Applied 1-2 to sched_ext/for-6.17.
Thanks.
Signature · 1 line
tejun
Peter Zijlstra
maintainerQuoted 18 lines · Tejun Heo
From
55aa129e6add97a98340326451bdadd4c5dd3242Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 13 Jun 2025 15:06:47 -1000More
sched_extfields will be added to structtask_group. In preparation, factor outsched_extfields into structscx_task_groupto reduce clutter in the common header. No functional changes.Signed-off-by Tejun Heo <[email protected]>---
These two patches are on top of:+ Two fix pathces pending on sched_ext/for-6.16-fixes
http://lkml.kernel.org/r/[email protected]
http://lkml.kernel.org/r/[email protected]
+ tip/sched/core patchset to reorganize bandwidth control interface handlinghttp://lkml.kernel.org/r/[email protected]
Quoted 8 lines
See the following git branch for the merged result:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.gitscx-bandwidth-controlPeter, while this touches
sched.h, the change is contained to scx part and shouldn't cause noticeable problems for other scheduler changes. I'll carry this through sched_ext/for-6.17. Please let me know if there are any concerns.
How do you want to do this dependency on the bandwidth rework? Should I take those patches into tip/sched/core and then you base your tree on top of that?
Tejun Heo
reviewerQuoted 3 lines · Peter Zijlstra
How do you want to do this dependency on the bandwidth rework? Should I take those patches into tip/sched/core and then you base your tree on top of that?
Yes, if you apply these to tip/sched/core, I can pull that into sched_ext/for-6.17 and apply the rest.
Thanks.
Signature · 1 line
tejun
Peter Zijlstra
maintainerQuoted 7 lines · Tejun Heo
Quoted 3 lines · Peter Zijlstra
How do you want to do this dependency on the bandwidth rework? Should I take those patches into tip/sched/core and then you base your tree on top of that?
Yes, if you apply these to tip/sched/core, I can pull that into sched_ext/for-6.17 and apply the rest.
Done, thanks!