lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Yr5i+OCeb89YMNZw@yury-laptop>
Date:   Thu, 30 Jun 2022 19:59:04 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
        Alexander Lobakin <alobakin@...me>,
        Huacai Chen <chenhuacai@...nel.org>,
        Jiaxun Yang <jiaxun.yang@...goat.com>,
        Mao Bibo <maobibo@...ngson.cn>,
        Philippe Mathieu-Daudé <f4bug@...at.org>,
        WANG Xuerui <kernel@...0n.name>, linux-kernel@...r.kernel.org,
        linux-mips@...r.kernel.org
Subject: Re: [PATCH] mips: micro-optimize calculate_cpu_foreign_map()

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ