Skip to contentSkip to conversation

sched/rt: use for_each_cpu_wrap to iterate over rto_mask

PATCH In review Jon Kohler 2 participants 2 messages Nov 14, 2024 – Nov 15, 2024 Scheduler

lore
Share & tools
lore

Jon Kohler

author
#0 lore raw

PATCH 1/1 sched/rt: use for_each_cpu_wrap to iterate over rto_mask

When using NO_RT_PUSH_IPI, using for_each_cpu() over rto_mask may cause many CPUs to attempt to pull load from the same CPU, causing RQ lock contention.

Use for_each_cpu_wrap instead to spread out which RQ gets evaluated first, similar to how _nohz_idle_balance iterates over idle_cpus_mask. This strategy is beneficial when there are many CPUs in rto_mask and many other CPUs going in and out of schedule() at the same time.

---
 kernel/sched/rt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/rt.c +1 -1
index 172c588de542..c883ff122f5d 100644
@@ -2308,7 +2308,7 @@ static void pull_rt_task(struct rq *this_rq)
 	}
 #endif
 
-	for_each_cpu(cpu, this_rq->rd->rto_mask) {
+	for_each_cpu_wrap(cpu, this_rq->rd->rto_mask, this_cpu+1) {
 		if (this_cpu == cpu)
 			continue;
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 19 lines · Jon Kohler

When using NO_RT_PUSH_IPI, using for_each_cpu() over rto_mask may cause many CPUs to attempt to pull load from the same CPU, causing RQ lock contention.

Use for_each_cpu_wrap instead to spread out which RQ gets evaluated first, similar to how _nohz_idle_balance iterates over idle_cpus_mask. This strategy is beneficial when there are many CPUs in rto_mask and many other CPUs going in and out of schedule() at the same time.

---
 kernel/sched/rt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/rt.c +0 -0
index 172c588de542..c883ff122f5d 100644

kernel/sched/rt.c static void pull_rt_task(struct rq *this_rq) · line 2313

Quoted 7 lines
kernel/sched/rt.c +1 -1
@@ -2308,7 +2308,7 @@ static void pull_rt_task(struct rq *this_rq)
 	}
 #endif
 
-	for_each_cpu(cpu, this_rq->rd->rto_mask) {
+	for_each_cpu_wrap(cpu, this_rq->rd->rto_mask, this_cpu+1) {
 		if (this_cpu == cpu)
 			continue;

Works for me I suppose, but as with that other rt patch, please do the matching change for dl too.