Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched/ext: Implement cgroup_set_idle() callback

Implement the missing cgroup_set_idle() callback that was marked as a
TODO. This allows BPF schedulers to be notified when a cgroup's idle
state changes, enabling them to adjust their scheduling behavior
accordingly.

The implementation follows the same pattern as other cgroup callbacks
like cgroup_set_weight() and cgroup_set_bandwidth(). It checks if the
BPF scheduler has implemented the callback and invokes it with the
appropriate parameters.

Fixes a spelling error in the cgroup_set_bandwidth() documentation.

tj: s/scx_cgroup_rwsem/scx_cgroup_ops_rwsem/ to fix build breakage.

Signed-off-by: zhidao su <soolaugust@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

zhidao su and committed by
Tejun Heo
347ed2d5 bd7143e7

+28 -2
+1
include/linux/sched/ext.h
··· 228 228 u64 bw_period_us; 229 229 u64 bw_quota_us; 230 230 u64 bw_burst_us; 231 + bool idle; 231 232 #endif 232 233 }; 233 234
+15 -1
kernel/sched/ext.c
··· 3066 3066 tg->scx.weight = CGROUP_WEIGHT_DFL; 3067 3067 tg->scx.bw_period_us = default_bw_period_us(); 3068 3068 tg->scx.bw_quota_us = RUNTIME_INF; 3069 + tg->scx.idle = false; 3069 3070 } 3070 3071 3071 3072 int scx_tg_online(struct task_group *tg) ··· 3215 3214 3216 3215 void scx_group_set_idle(struct task_group *tg, bool idle) 3217 3216 { 3218 - /* TODO: Implement ops->cgroup_set_idle() */ 3217 + struct scx_sched *sch = scx_root; 3218 + 3219 + percpu_down_read(&scx_cgroup_ops_rwsem); 3220 + 3221 + if (scx_cgroup_enabled && SCX_HAS_OP(sch, cgroup_set_idle)) 3222 + SCX_CALL_OP(sch, SCX_KF_UNLOCKED, cgroup_set_idle, NULL, 3223 + tg_cgrp(tg), idle); 3224 + 3225 + /* Update the task group's idle state */ 3226 + tg->scx.idle = idle; 3227 + 3228 + percpu_up_read(&scx_cgroup_ops_rwsem); 3219 3229 } 3220 3230 3221 3231 void scx_group_set_bandwidth(struct task_group *tg, ··· 5029 5017 static void sched_ext_ops__cgroup_cancel_move(struct task_struct *p, struct cgroup *from, struct cgroup *to) {} 5030 5018 static void sched_ext_ops__cgroup_set_weight(struct cgroup *cgrp, u32 weight) {} 5031 5019 static void sched_ext_ops__cgroup_set_bandwidth(struct cgroup *cgrp, u64 period_us, u64 quota_us, u64 burst_us) {} 5020 + static void sched_ext_ops__cgroup_set_idle(struct cgroup *cgrp, bool idle) {} 5032 5021 #endif 5033 5022 static void sched_ext_ops__cpu_online(s32 cpu) {} 5034 5023 static void sched_ext_ops__cpu_offline(s32 cpu) {} ··· 5068 5055 .cgroup_cancel_move = sched_ext_ops__cgroup_cancel_move, 5069 5056 .cgroup_set_weight = sched_ext_ops__cgroup_set_weight, 5070 5057 .cgroup_set_bandwidth = sched_ext_ops__cgroup_set_bandwidth, 5058 + .cgroup_set_idle = sched_ext_ops__cgroup_set_idle, 5071 5059 #endif 5072 5060 .cpu_online = sched_ext_ops__cpu_online, 5073 5061 .cpu_offline = sched_ext_ops__cpu_offline,
+12 -1
kernel/sched/ext_internal.h
··· 697 697 * 2_500_000. @cgrp is entitled to 2.5 CPUs. @burst_us can be 698 698 * interpreted in the same fashion and specifies how much @cgrp can 699 699 * burst temporarily. The specific control mechanism and thus the 700 - * interpretation of @period_us and burstiness is upto to the BPF 700 + * interpretation of @period_us and burstiness is up to the BPF 701 701 * scheduler. 702 702 */ 703 703 void (*cgroup_set_bandwidth)(struct cgroup *cgrp, 704 704 u64 period_us, u64 quota_us, u64 burst_us); 705 + 706 + /** 707 + * @cgroup_set_idle: A cgroup's idle state is being changed 708 + * @cgrp: cgroup whose idle state is being updated 709 + * @idle: whether the cgroup is entering or exiting idle state 710 + * 711 + * Update @cgrp's idle state to @idle. This callback is invoked when 712 + * a cgroup transitions between idle and non-idle states, allowing the 713 + * BPF scheduler to adjust its behavior accordingly. 714 + */ 715 + void (*cgroup_set_idle)(struct cgroup *cgrp, bool idle); 705 716 706 717 #endif /* CONFIG_EXT_GROUP_SCHED */ 707 718