sched_ext: idle: small CPU iteration refactoring
PATCH 1/1 sched_ext: idle: small CPU iteration refactoring
Replace the loop to check if all SMT CPUs are idle with cpumask_subset(). This simplifies the code and slightly improves efficiency, while preserving the original behavior.
Note that idle_masks.smt handling remains racy, which is acceptable as it serves as an optimization and is self-correcting.
--- kernel/sched/ext.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sched/ext.c +2 -4
@@ -3671,10 +3671,8 @@ void __scx_update_idle(struct rq *rq, bool idle)* idle_masks.smt handling is racy but that's fine as * it's only for optimization and self-correcting. */ -for_each_cpu (cpu, smt) { -if (!cpumask_test_cpu (cpu, idle_masks.cpu)) -return ; - } +if (!cpumask_subset (smt, idle_masks.cpu)) +return ;cpumask_or (idle_masks.smt, idle_masks.smt, smt); }else {cpumask_andnot (idle_masks.smt, idle_masks.smt, smt);
Signature · 1 line
2.47.1
Quoted 3 lines · Andrea Righi
loop to check if all SMT CPUs are idle with
cpumask_subset(). This simplifies the code and slightly improves efficiency, while preserving the original behavior.
In my experience, replacing iterator with a dedicated function makes you 400-500 times faster. So 'slightly' sounds like an understatement here.
Quoted 5 lines
Note that idle_masks.smt handling remains racy, which is acceptable as it serves as an optimization and is self-correcting.
Suggested-by Yury Norov <[email protected]>Signed-off-by Andrea Righi <[email protected]>
Quoted 25 lines
--- kernel/sched/ext.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)kernel/sched/ext.c +2
-4@@ -3671,10 +3671,8 @@ void __scx_update_idle(struct rq *rq, bool idle)* idle_masks.smt handling is racy but that's fine as * it's only for optimization and self-correcting. */ -for_each_cpu (cpu, smt) { -if (!cpumask_test_cpu (cpu, idle_masks.cpu)) -return ; - } +if (!cpumask_subset (smt, idle_masks.cpu)) +return ;cpumask_or (idle_masks.smt, idle_masks.smt, smt); }else {cpumask_andnot (idle_masks.smt, idle_masks.smt, smt);Signature · 3 lines
2.47.1 From yury
Hi Yury,
Quoted 8 lines · Yury Norov
Quoted 3 lines · Andrea Righi
loop to check if all SMT CPUs are idle with
cpumask_subset(). This simplifies the code and slightly improves efficiency, while preserving the original behavior.In my experience, replacing iterator with a dedicated function makes you 400-500 times faster. So 'slightly' sounds like an understatement here.
There's also the fact that the smt mask typically will have just 2 bits set (maybe 4 in some high end servers), so I wasn't expecting big improvements. But in any case, it's definitely a good change to do.
Thanks!
-Andrea
Quoted 32 lines
Quoted 6 lines
Note that idle_masks.smt handling remains racy, which is acceptable as it serves as an optimization and is self-correcting.
Suggested-by Yury Norov <[email protected]>Signed-off-by Andrea Righi <[email protected]>Reviewed-by Yury Norov <[email protected]>Quoted 23 lines
--- kernel/sched/ext.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)kernel/sched/ext.c +2
-4@@ -3671,10 +3671,8 @@ void __scx_update_idle(struct rq *rq, bool idle)* idle_masks.smt handling is racy but that's fine as * it's only for optimization and self-correcting. */ -for_each_cpu (cpu, smt) { -if (!cpumask_test_cpu (cpu, idle_masks.cpu)) -return ; - } +if (!cpumask_subset (smt, idle_masks.cpu)) +return ;cpumask_or (idle_masks.smt, idle_masks.smt, smt); }else {cpumask_andnot (idle_masks.smt, idle_masks.smt, smt);Signature · 1 line
2.47.1
Tejun Heo
AppliedQuoted 9 lines · Andrea Righi
Replace the loop to check if all SMT CPUs are idle with
cpumask_subset(). This simplifies the code and slightly improves efficiency, while preserving the original behavior.Note that idle_masks.smt handling remains racy, which is acceptable as it serves as an optimization and is self-correcting.
Suggested-by Yury Norov <[email protected]>Signed-off-by Andrea Righi <[email protected]>
Applied to sched_ext/for-6.14.
Thanks.
Signature · 1 line
tejun