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: <ZCuKYN2ZUJjn752J@yury-laptop>
Date:   Mon, 3 Apr 2023 19:24:32 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Ye Bin <yebin@...weicloud.com>
Cc:     dennis@...nel.org, tj@...nel.org, cl@...ux.com, linux-mm@...ck.org,
        andriy.shevchenko@...ux.intel.com, linux@...musvillemoes.dk,
        linux-kernel@...r.kernel.org, dchinner@...hat.com,
        yebin10@...wei.com
Subject: Re: [PATCH 1/2] cpu/hotplug: introduce 'num_dying_cpus' to get dying
 CPUs count

On Tue, Apr 04, 2023 at 09:42:05AM +0800, Ye Bin wrote:
> From: Ye Bin <yebin10@...wei.com>
> 
> Introduce '__num_dying_cpus' variable to cache the number of dying CPUs
> in the core and just return the cached variable.
> 
> Signed-off-by: Ye Bin <yebin10@...wei.com>
> ---
>  include/linux/cpumask.h | 20 ++++++++++++++++----
>  kernel/cpu.c            |  2 ++
>  2 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
> index 2a61ddcf8321..8127fd598f51 100644
> --- a/include/linux/cpumask.h
> +++ b/include/linux/cpumask.h
> @@ -135,6 +135,8 @@ extern struct cpumask __cpu_dying_mask;
>  
>  extern atomic_t __num_online_cpus;
>  
> +extern atomic_t __num_dying_cpus;
> +
>  extern cpumask_t cpus_booted_once_mask;
>  
>  static __always_inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
> @@ -1018,10 +1020,14 @@ set_cpu_active(unsigned int cpu, bool active)
>  static __always_inline void
>  set_cpu_dying(unsigned int cpu, bool dying)
>  {
> -	if (dying)
> -		cpumask_set_cpu(cpu, &__cpu_dying_mask);
> -	else
> -		cpumask_clear_cpu(cpu, &__cpu_dying_mask);
> +	if (dying) {
> +		if (!cpumask_test_and_set_cpu(cpu, &__cpu_dying_mask))
> +			atomic_inc(&__num_dying_cpus);
> +	}
> +	else {
> +		if (cpumask_test_and_clear_cpu(cpu, &__cpu_dying_mask))
> +			atomic_dec(&__num_dying_cpus);
> +	}
>  }

Corresponding set_cpu_online() is implemented in C-file probably for a
reason. Are you sure that similar function for dying mask should
reside in a header? If so, can you share your reasoning?

Regardless, now that you added the identical function to
set_cpu_online, I think it's worth to make it a general approach:

void set_cpu_counted(unsigned int cpu, bool set,
                        struct cpumask *mask, atomic_t *cnt);

void __always_inline set_cpu_online(unsigned int cpu, bool online)
{
      set_cpu_counted(cpu, online, &__cpu_online_mask, &__num_online_cpus);  
}

void __always_inline set_cpu_dying(unsigned int cpu, bool dying)
{
      set_cpu_counted(cpu, dying, &__cpu_dying_mask, &__num_dying_cpus);  
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ