sched_ext: don't deliver duplicate ops.cgroup_set_idle() for same value
Subsystems (3)
PATCH 1/1 sched_ext: don't deliver duplicate ops.cgroup_set_idle() for same value
From: Tao Cui <[email protected]>
ops.cgroup_set_idle() is documented to be invoked when a cgroup transitions between idle and non-idle states, and scx_group_set_weight() already skips value-preserving writes. scx_group_set_idle() delivers every write unconditionally, so rewriting an already-correct cpu.idle value feeds the BPF scheduler a transition callback each time, which toggle- or accounting-based schedulers miscount. Mirror the weight guard and only deliver on an actual change.
Verified with a probe scheduler printing each callback: rewriting cpu.idle=1 twice on an already-idle cgroup delivered two callbacks before and none after.
--- kernel/sched/ext/ext.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/ext/ext.c +2 -1
@@ -4933,7 +4933,8 @@ void scx_group_set_idle(struct task_group *tg, bool idle)percpu_down_read (&scx_cgroup_ops_rwsem); sch =scx_tg_knob_sched (tg); -if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle)) +if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle) && + tg->scx.sched_idle != idle)SCX_CALL_OP (sch, cgroup_set_idle,NULL ,tg_cgrp (tg), idle);/* Update the task group's idle state */
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The patch references a non-existent struct member `tg->scx.sched_idle`, which causes a build…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch references a non-existent struct member tg->scx.sched_idle, which causes a build failure. --
commit b3dc4baced455427fac828517318398556404ffa
Author: Tao Cui <[email protected]>
sched_ext: don't deliver duplicate ops.cgroup_set_idle() for same value
This commit modifies scx_group_set_idle() to prevent delivering duplicate cgroup transition callbacks to the BPF scheduler. It checks if the new idle value differs from the existing value before invoking the callback.
kernel/sched/ext/ext.c void scx_group_set_idle(struct task_group *tg, bool idle) · line 4934
Quoted 11 lines
kernel/sched/ext/ext.c +2
-1@@ -4930,7 +4930,8 @@ void scx_group_set_idle(struct task_group *tg, bool idle)percpu_down_read (&scx_cgroup_ops_rwsem); sch =scx_tg_knob_sched (tg); -if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle)) +if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle) && + tg->scx.sched_idle != idle)
[Severity: Low]
Does this code build successfully when CONFIG_EXT_GROUP_SCHED is enabled? It appears tg->scx.sched_idle is referencing a non-existent member in struct scx_task_group.
Looking at include/linux/sched/ext.h, the scx_task_group struct defines the field simply as idle:
struct scx_task_group {
...
bool idle;
...
};Should this condition check tg->scx.idle != idle instead?
Quoted 3 lines
kernel/sched/ext/ext.c +0
-0SCX_CALL_OP (sch, cgroup_set_idle,NULL ,tg_cgrp (tg), idle);/* Update the task group's idle state */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi Tao,
Quoted 10 lines · Tao Cui
From: Tao Cui <[email protected]>
ops.cgroup_set_idle()is documented to be invoked when a cgroup transitions between idle and non-idle states, andscx_group_set_weight()already skips value-preserving writes.scx_group_set_idle()delivers every write unconditionally, so rewriting an already-correct cpu.idle value feeds the BPF scheduler a transition callback each time, which toggle- or accounting-based schedulers miscount. Mirror the weight guard and only deliver on an actual change.
Quoted 6 lines
Verified with a probe scheduler printing each callback: rewriting cpu.idle=1 twice on an already-idle cgroup delivered two callbacks before and none after.
Fixes 347ed2d566da ("sched/ext: Implement cgroup_set_idle() callback")
This link seems broken, I think the right one is:
Quoted 1 line
Signed-off-by Tao Cui <[email protected]>
Other than that looks good to me.
Thanks,
-Andrea
Quoted 21 lines
--- kernel/sched/ext/ext.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/ext/ext.c +2
-1@@ -4933,7 +4933,8 @@ void scx_group_set_idle(struct task_group *tg, bool idle)percpu_down_read (&scx_cgroup_ops_rwsem); sch =scx_tg_knob_sched (tg); -if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle)) +if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle) && + tg->scx.sched_idle != idle)SCX_CALL_OP (sch, cgroup_set_idle,NULL ,tg_cgrp (tg), idle);/* Update the task group's idle state */ Signature · 1 line
2.43.0
Hi Andrea,
Quoted 17 lines · Andrea Righi
Hi Tao,
Quoted 14 lines · Tao Cui
From: Tao Cui <[email protected]>
ops.cgroup_set_idle()is documented to be invoked when a cgroup transitions between idle and non-idle states, andscx_group_set_weight()already skips value-preserving writes.scx_group_set_idle()delivers every write unconditionally, so rewriting an already-correct cpu.idle value feeds the BPF scheduler a transition callback each time, which toggle- or accounting-based schedulers miscount. Mirror the weight guard and only deliver on an actual change.Verified with a probe scheduler printing each callback: rewriting cpu.idle=1 twice on an already-idle cgroup delivered two callbacks before and none after.
Quoted 7 lines
Quoted 2 lines
Fixes 347ed2d566da ("sched/ext: Implement cgroup_set_idle() callback")This link seems broken, I think the right one is:
Thanks! Somehow my vim seems to have eaten the @linux.dev part of the Message-ID. I'll fix the Link tag in the next revision.
Thanks for the review!
Best,
Tao
Quoted 30 lines
Quoted 1 line
Signed-off-by Tao Cui <[email protected]>Other than that looks good to me.
Reviewed-by Andrea Righi <[email protected]>Thanks,
-AndreaQuoted 21 lines
--- kernel/sched/ext/ext.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/ext/ext.c +2
-1@@ -4933,7 +4933,8 @@ void scx_group_set_idle(struct task_group *tg, bool idle)percpu_down_read (&scx_cgroup_ops_rwsem); sch =scx_tg_knob_sched (tg); -if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle)) +if (scx_cgroup_enabled && sch &&SCX_HAS_OP (sch, cgroup_set_idle) && + tg->scx.sched_idle != idle)SCX_CALL_OP (sch, cgroup_set_idle,NULL ,tg_cgrp (tg), idle);/* Update the task group's idle state */ Signature · 1 line
2.43.0