linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: "Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	"Alexander Lobakin" <alobakin@pm.me>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Mao Bibo" <maobibo@loongson.cn>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"WANG Xuerui" <kernel@xen0n.name>,
	linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>
Subject: [PATCH] mips: micro-optimize calculate_cpu_foreign_map()
Date: Tue, 21 Jun 2022 07:47:29 -0700	[thread overview]
Message-ID: <20220621144729.533026-1-yury.norov@gmail.com> (raw)

The inner loop in calculate_cpu_foreign_map() walks the whole
cpumask to check if we have siblings for a given cpu.

We can just break after a 1st match and avoid useless traversing
the rest of mask.

Loongarch has an identical function, so fix it here as well.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---

It looks like loongarch copied quite a lot from arch/mips/kernel/smp.c.
For loongarch folks: Guys, can you consider moving shared code into a
shared file(s)?

 arch/loongarch/kernel/smp.c | 7 +++----
 arch/mips/kernel/smp.c      | 7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c
index b8c53b755a25..c1c91df3c8ac 100644
--- a/arch/loongarch/kernel/smp.c
+++ b/arch/loongarch/kernel/smp.c
@@ -463,17 +463,16 @@ static inline void set_cpu_core_map(int cpu)
  */
 void calculate_cpu_foreign_map(void)
 {
-	int i, k, core_present;
+	int i, k;
 	cpumask_t temp_foreign_map;
 
 	/* Re-calculate the mask */
 	cpumask_clear(&temp_foreign_map);
 	for_each_online_cpu(i) {
-		core_present = 0;
 		for_each_cpu(k, &temp_foreign_map)
 			if (cpus_are_siblings(i, k))
-				core_present = 1;
-		if (!core_present)
+				break;
+		if (k >= nr_cpu_ids)
 			cpumask_set_cpu(i, &temp_foreign_map);
 	}
 
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 1d93b85271ba..a2ce641f5f18 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -115,17 +115,16 @@ static inline void set_cpu_core_map(int cpu)
  */
 void calculate_cpu_foreign_map(void)
 {
-	int i, k, core_present;
+	int i, k;
 	cpumask_t temp_foreign_map;
 
 	/* Re-calculate the mask */
 	cpumask_clear(&temp_foreign_map);
 	for_each_online_cpu(i) {
-		core_present = 0;
 		for_each_cpu(k, &temp_foreign_map)
 			if (cpus_are_siblings(i, k))
-				core_present = 1;
-		if (!core_present)
+				break;
+		if (k >= nr_cpu_ids)
 			cpumask_set_cpu(i, &temp_foreign_map);
 	}
 
-- 
2.32.0


             reply	other threads:[~2022-06-21 14:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 14:47 Yury Norov [this message]
2022-07-01  2:59 ` [PATCH] mips: micro-optimize calculate_cpu_foreign_map() Yury Norov
2022-07-05 10:40   ` Thomas Bogendoerfer

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=20220621144729.533026-1-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=alobakin@pm.me \
    --cc=chenhuacai@kernel.org \
    --cc=f4bug@amsat.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=maobibo@loongson.cn \
    --cc=tsbogend@alpha.franken.de \
    /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;
as well as URLs for NNTP newsgroup(s).