mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, rostedt@goodmis.org,
	linux-kernel@vger.kernel.org
Cc: dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, Barry Song <song.bao.hua@hisilicon.com>
Subject: [PATCH v3] sched/fair: Eliminate confusion for the scan number in select_idle_cpu
Date: Fri, 26 Nov 2021 18:51:39 +0800	[thread overview]
Message-ID: <20211126105139.11784-1-21cnbao@gmail.com> (raw)

From: Barry Song <song.bao.hua@hisilicon.com>

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 <song.bao.hua@hisilicon.com>
---
 -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/20211124091546.5072-1-21cnbao@gmail.com/

 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)
 				break;
+			if (!--nr)
+				return -1;
 		}
 	}
 
-- 
1.8.3.1


                 reply	other threads:[~2021-11-26 11:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211126105139.11784-1-21cnbao@gmail.com \
    --to=21cnbao@gmail.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=song.bao.hua@hisilicon.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®