Skip to contentSkip to conversation

sched/fair: Eliminate confusion for the scan number in select_idle_cpu

PATCH New Barry Song 1 participant 1 message Nov 26, 2021 Scheduler

lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH v3 1/1 sched/fair: Eliminate confusion for the scan number in select_idle_cpu

From: Barry Song <[email protected]>

Right now, the number of scans is very confusing. For example, if nr==4, the code is iterating 4 times but scanning 3 times only. Because in the 4th iteration, the code returns directly due to --nr==0. So the code is wasting time on doing the 4th cpumask_next_wrap() and it is also very confusing since the actual scan number is nr-1 but not nr. This seems not to be the original intention.

This patch moves to scan nr times rather than nr-1 times, and it also makes the last iteration of cpumask_next_wrap() useful.

---
-v3:
scan nr times instead of nr-1 times with respect to Peter's comments; rewrite commit log and subject since we have changed the behaviour of the code;
-v2:
https://lore.kernel.org/lkml/[email protected]/

 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 6e476f6..5c259aa 100644
@@ -6285,11 +6285,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
 				return i;
 
 		} else {
-			if (!--nr)
-				return -1;
 			idle_cpu = __select_idle_cpu(cpu, p);
 			if ((unsigned int)idle_cpu < nr_cpumask_bits)
 				break;
+			if (!--nr)
+				return -1;
 		}
 	}
 
Signature · 1 line
1.8.3.1