LKML Archive on
help / color / mirror / Atom feed
* [PATCH v3] sched/fair: Eliminate confusion for the scan number in select_idle_cpu
@ 2021-11-26 10:51 Barry Song
  0 siblings, 0 replies; only message in thread
From: Barry Song @ 2021-11-26 10:51 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, rostedt, linux-kernel
  Cc: dietmar.eggemann, bsegall, mgorman, bristot, Barry Song

From: Barry Song <>

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.

Signed-off-by: Barry Song <>
  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;

 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6e476f6..5c259aa 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -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)
+			if (!--nr)
+				return -1;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-26 11:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 10:51 [PATCH v3] sched/fair: Eliminate confusion for the scan number in select_idle_cpu Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).