linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mips: micro-optimize calculate_cpu_foreign_map()
@ 2022-06-21 14:47 Yury Norov
  2022-07-01  2:59 ` Yury Norov
  0 siblings, 1 reply; 3+ messages in thread
From: Yury Norov @ 2022-06-21 14:47 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Alexander Lobakin, Huacai Chen, Jiaxun Yang,
	Mao Bibo, Philippe Mathieu-Daudé, WANG Xuerui, linux-kernel,
	linux-mips
  Cc: Yury Norov

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mips: micro-optimize calculate_cpu_foreign_map()
  2022-06-21 14:47 [PATCH] mips: micro-optimize calculate_cpu_foreign_map() Yury Norov
@ 2022-07-01  2:59 ` Yury Norov
  2022-07-05 10:40   ` Thomas Bogendoerfer
  0 siblings, 1 reply; 3+ messages in thread
From: Yury Norov @ 2022-07-01  2:59 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Alexander Lobakin, Huacai Chen, Jiaxun Yang,
	Mao Bibo, Philippe Mathieu-Daudé, WANG Xuerui, linux-kernel,
	linux-mips

On Tue, Jun 21, 2022 at 07:47:29AM -0700, Yury Norov wrote:
> 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>

Ping?

> ---
> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mips: micro-optimize calculate_cpu_foreign_map()
  2022-07-01  2:59 ` Yury Norov
@ 2022-07-05 10:40   ` Thomas Bogendoerfer
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2022-07-05 10:40 UTC (permalink / raw)
  To: Yury Norov
  Cc: Alexander Lobakin, Huacai Chen, Jiaxun Yang, Mao Bibo,
	Philippe Mathieu-Daudé, WANG Xuerui, linux-kernel,
	linux-mips

On Thu, Jun 30, 2022 at 07:59:04PM -0700, Yury Norov wrote:
> On Tue, Jun 21, 2022 at 07:47:29AM -0700, Yury Norov wrote:
> > 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>
> 
> Ping?

as this is touching two different archs, it would have been easier
to send this in two different patches.

Huacai, should I take the patch ?

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-05 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-21 14:47 [PATCH] mips: micro-optimize calculate_cpu_foreign_map() Yury Norov
2022-07-01  2:59 ` Yury Norov
2022-07-05 10:40   ` Thomas Bogendoerfer

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).