All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Dawei Li <dawei.li@shingroup.cn>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: davem@davemloft.net, andreas@gaisler.com,
	sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/7] sparc/leon: Remove on-stack cpumask var
Date: Mon, 22 Apr 2024 14:15:50 +0800	[thread overview]
Message-ID: <77CD3A300783E010+ZiYAllmOeXQ9GJkf@centos8> (raw)
In-Reply-To: <20240420083202.GF614130@ravnborg.org>

Hi Sam,

Thanks for review.

On Sat, Apr 20, 2024 at 10:32:02AM +0200, Sam Ravnborg wrote:
> On Sat, Apr 20, 2024 at 01:15:46PM +0800, Dawei Li wrote:
> > In general it's preferable to avoid placing cpumasks on the stack, as
> > for large values of NR_CPUS these can consume significant amounts of
> > stack space and make stack overflows more likely.
> > 
> > Use cpumask_subset() and cpumask_first_and() to avoid the need for a
> > temporary cpumask on the stack.
> > 
> > Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
> > ---
> >  arch/sparc/kernel/leon_kernel.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
> > index 4c61da491fee..0070655041bb 100644
> > --- a/arch/sparc/kernel/leon_kernel.c
> > +++ b/arch/sparc/kernel/leon_kernel.c
> > @@ -106,13 +106,10 @@ unsigned long leon_get_irqmask(unsigned int irq)
> >  #ifdef CONFIG_SMP
> >  static int irq_choose_cpu(const struct cpumask *affinity)
> >  {
> > -	cpumask_t mask;
> > +	unsigned int cpu = cpumask_first_and(affinity, cpu_online_mask);
> >  
> > -	cpumask_and(&mask, cpu_online_mask, affinity);
> > -	if (cpumask_equal(&mask, cpu_online_mask) || cpumask_empty(&mask))
> > -		return boot_cpu_id;
> > -	else
> > -		return cpumask_first(&mask);
> > +	return cpumask_subset(cpu_online_mask, affinity) || cpu >= nr_cpu_ids ?
> > +	       boot_cpu_id : cpu;
> 
> This looks wrong - or if it is correct is is hard to parse.
> Drop ?: and use an if so the code is more readable.

I am confused a bit here, about its correctness(not coding style).

Per my understanding:

A & B = A <-> For every set bit in A, it's set for B; <-> B is superset
of A. <-> A is subset of B.

-	cpumask_and(&mask, cpu_online_mask, affinity);
-	if (cpumask_equal(&mask, cpu_online_mask))

So, codes above is equivalent to:
	if (cpumask_subset(cpu_online_mask, affinity))

Am I missing something?

About the ?:, I will restore original "if else" style. 

> 
> 	Sam
> 

Thanks,

    Dawei

  reply	other threads:[~2024-04-22  6:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20  5:15 [PATCH v2 0/7] Remove onstack cpumask var for sparc Dawei Li
2024-04-20  5:15 ` [PATCH v2 1/7] sparc/srmmu: Remove on-stack cpumask var Dawei Li
2024-04-20  7:58   ` Sam Ravnborg
2024-04-22  5:46     ` Dawei Li
2024-04-20  5:15 ` [PATCH v2 2/7] sparc/irq: " Dawei Li
2024-04-20  8:22   ` Sam Ravnborg
2024-04-20  5:15 ` [PATCH v2 3/7] sparc/of: " Dawei Li
2024-04-20  8:23   ` Sam Ravnborg
2024-04-20  5:15 ` [PATCH v2 4/7] sparc/pci_msi: " Dawei Li
2024-04-20  8:23   ` Sam Ravnborg
2024-04-20  5:15 ` [PATCH v2 5/7] sparc: " Dawei Li
2024-04-20  8:28   ` Sam Ravnborg
2024-04-22  5:49     ` Dawei Li
2024-04-20  5:15 ` [PATCH v2 6/7] sparc/leon: " Dawei Li
2024-04-20  8:32   ` Sam Ravnborg
2024-04-22  6:15     ` Dawei Li [this message]
2024-04-20  5:15 ` [PATCH v2 7/7] sparc/smp: " Dawei Li
2024-04-20 11:42   ` Sam Ravnborg
2024-04-22  6:19     ` Dawei Li

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=77CD3A300783E010+ZiYAllmOeXQ9GJkf@centos8 \
    --to=dawei.li@shingroup.cn \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@ravnborg.org \
    --cc=sparclinux@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.