Skip to contentSkip to conversation

sched_ext: Simplify cpumask computation in balance_scx

PATCH In review lirongqing 2 participants 3 messages Mar 7, 2025 – Mar 8, 2025 Scheduler

lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 sched_ext: Simplify cpumask computation in balance_scx

From: Li RongQing <[email protected]>

Compare SMT CPU against RQ CPU and skip balance it, to avoid calling for_each_cpu_andnot() and cpumask_of(), they are relatively expensive

---
 kernel/sched/ext.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
kernel/sched/ext.c +12 -4
index 0f1da19..7e40ede 100644
@@ -2920,11 +2920,19 @@ static int balance_scx(struct rq *rq, struct task_struct *prev,
 	 */
 	if (sched_core_enabled(rq)) {
 		const struct cpumask *smt_mask = cpu_smt_mask(cpu_of(rq));
-		int scpu;
+		int scpu, cpu;
 
-		for_each_cpu_andnot(scpu, smt_mask, cpumask_of(cpu_of(rq))) {
-			struct rq *srq = cpu_rq(scpu);
-			struct task_struct *sprev = srq->curr;
+		cpu = cpu_of(rq);
+
+		for_each_cpu(scpu, smt_mask) {
+			struct rq *srq;
+			struct task_struct *sprev;
+
+			if (scpu == cpu)
+				continue;
+
+			srq = cpu_rq(scpu);
+			sprev = srq->curr;
 
 			WARN_ON_ONCE(__rq_lockp(rq) != __rq_lockp(srq));
 			update_rq_clock(srq);
Signature · 1 line
2.9.4
#1 lore raw
Quoted 4 lines · lirongqing

From: Li RongQing <[email protected]>

Compare SMT CPU against RQ CPU and skip balance it, to avoid calling for_each_cpu_andnot() and cpumask_of(), they are relatively expensive

How is cpumask_of() expensive? I have a hard time seeing how this would actually improve anything. Do you have any measurements?

Thanks.

Signature · 1 line
tejun
#2 lore raw

答复: [????] Re: [PATCH] sched_ext: Simplify cpumask computation in balance_scx

Quoted 3 lines

How is cpumask_of() expensive? I have a hard time seeing how this would actually improve anything. Do you have any measurements?

for_each_cpu_andnot+cpumask_of is more faster
sorry for this noise

thanks