linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Ye Bin <yebin@huaweicloud.com>
Cc: dennis@kernel.org, tj@kernel.org, cl@linux.com,
	linux-mm@kvack.org, andriy.shevchenko@linux.intel.com,
	linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org,
	dchinner@redhat.com, yebin10@huawei.com
Subject: Re: [PATCH 1/2] cpu/hotplug: introduce 'num_dying_cpus' to get dying CPUs count
Date: Mon, 3 Apr 2023 19:24:32 -0700	[thread overview]
Message-ID: <ZCuKYN2ZUJjn752J@yury-laptop> (raw)
In-Reply-To: <20230404014206.3752945-2-yebin@huaweicloud.com>

On Tue, Apr 04, 2023 at 09:42:05AM +0800, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.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@huawei.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);  
}


  reply	other threads:[~2023-04-04  2:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04  1:42 [PATCH 0/2] fix dying cpu compare race Ye Bin
2023-04-04  1:42 ` [PATCH 1/2] cpu/hotplug: introduce 'num_dying_cpus' to get dying CPUs count Ye Bin
2023-04-04  2:24   ` Yury Norov [this message]
2023-04-04  1:42 ` [PATCH 2/2] lib/percpu_counter: fix dying cpu compare race Ye Bin
2023-04-04  2:50   ` Yury Norov
2023-04-04  6:54     ` yebin (H)
2023-04-10 17:38       ` Yury Norov
2023-04-04  7:06     ` yebin (H)
2023-04-04  6:01   ` Dave Chinner
2023-04-04  6:40     ` yebin (H)
2023-04-04  2:11 ` [PATCH 0/2] " Yury Norov

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=ZCuKYN2ZUJjn752J@yury-laptop \
    --to=yury.norov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=cl@linux.com \
    --cc=dchinner@redhat.com \
    --cc=dennis@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=tj@kernel.org \
    --cc=yebin10@huawei.com \
    --cc=yebin@huaweicloud.com \
    /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