public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
@ 2022-02-10 22:49 ` Yury Norov
  2022-02-11  6:54   ` Sven Schnelle
  0 siblings, 1 reply; 3+ messages in thread
From: Yury Norov @ 2022-02-10 22:49 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev, Sven Schnelle, Thomas Richter,
	Sumanth Korikkar, Sebastian Andrzej Siewior, Jiapeng Chong,
	kernel test robot, linux-s390

cfset_all_start() calls cpumask_weight() to compare the weight of cpumask
with a given number. We can do it more efficiently with
cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
traversing the cpumask earlier, as soon as condition is (or can't be) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/s390/kernel/perf_cpum_cf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index ee8707abdb6a..4d217f7f5ccf 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -975,7 +975,7 @@ static int cfset_all_start(struct cfset_request *req)
 		return -ENOMEM;
 	cpumask_and(mask, &req->mask, cpu_online_mask);
 	on_each_cpu_mask(mask, cfset_ioctl_on, &p, 1);
-	if (atomic_read(&p.cpus_ack) != cpumask_weight(mask)) {
+	if (!cpumask_weight_eq(mask, atomic_read(&p.cpus_ack))) {
 		on_each_cpu_mask(mask, cfset_ioctl_off, &p, 1);
 		rc = -EIO;
 		debug_sprintf_event(cf_dbg, 4, "%s CPUs missing", __func__);
-- 
2.32.0


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

* Re: [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate
  2022-02-10 22:49 ` [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate Yury Norov
@ 2022-02-11  6:54   ` Sven Schnelle
  2022-02-11 23:40     ` Yury Norov
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Schnelle @ 2022-02-11  6:54 UTC (permalink / raw)
  To: Yury Norov
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev, Thomas Richter, Sumanth Korikkar,
	Sebastian Andrzej Siewior, Jiapeng Chong, kernel test robot,
	linux-s390

Hi Yury,

Yury Norov <yury.norov@gmail.com> writes:

> cfset_all_start() calls cpumask_weight() to compare the weight of cpumask
> with a given number. We can do it more efficiently with
> cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
> traversing the cpumask earlier, as soon as condition is (or can't be) met.
>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
>  arch/s390/kernel/perf_cpum_cf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
> index ee8707abdb6a..4d217f7f5ccf 100644
> --- a/arch/s390/kernel/perf_cpum_cf.c
> +++ b/arch/s390/kernel/perf_cpum_cf.c
> @@ -975,7 +975,7 @@ static int cfset_all_start(struct cfset_request *req)
>  		return -ENOMEM;
>  	cpumask_and(mask, &req->mask, cpu_online_mask);
>  	on_each_cpu_mask(mask, cfset_ioctl_on, &p, 1);
> -	if (atomic_read(&p.cpus_ack) != cpumask_weight(mask)) {
> +	if (!cpumask_weight_eq(mask, atomic_read(&p.cpus_ack))) {
>  		on_each_cpu_mask(mask, cfset_ioctl_off, &p, 1);
>  		rc = -EIO;
>  		debug_sprintf_event(cf_dbg, 4, "%s CPUs missing", __func__);

given that you're adding a bunch of these functions - gt,lt,eq and
others, i wonder whether it makes sense to also add cpumask_weight_ne(),
so one could just write:

if (cpumask_weight_ne(mask, atomic_read(&p.cpus_ack))) {
	...
}

?

/Sven

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

* Re: [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate
  2022-02-11  6:54   ` Sven Schnelle
@ 2022-02-11 23:40     ` Yury Norov
  0 siblings, 0 replies; 3+ messages in thread
From: Yury Norov @ 2022-02-11 23:40 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Alexander Gordeev, Thomas Richter, Sumanth Korikkar,
	Sebastian Andrzej Siewior, Jiapeng Chong, kernel test robot,
	linux-s390

On Fri, Feb 11, 2022 at 07:54:26AM +0100, Sven Schnelle wrote:
> Hi Yury,
> 
> Yury Norov <yury.norov@gmail.com> writes:
> 
> > cfset_all_start() calls cpumask_weight() to compare the weight of cpumask
> > with a given number. We can do it more efficiently with
> > cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
> > traversing the cpumask earlier, as soon as condition is (or can't be) met.
> >
> > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > ---
> >  arch/s390/kernel/perf_cpum_cf.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
> > index ee8707abdb6a..4d217f7f5ccf 100644
> > --- a/arch/s390/kernel/perf_cpum_cf.c
> > +++ b/arch/s390/kernel/perf_cpum_cf.c
> > @@ -975,7 +975,7 @@ static int cfset_all_start(struct cfset_request *req)
> >  		return -ENOMEM;
> >  	cpumask_and(mask, &req->mask, cpu_online_mask);
> >  	on_each_cpu_mask(mask, cfset_ioctl_on, &p, 1);
> > -	if (atomic_read(&p.cpus_ack) != cpumask_weight(mask)) {
> > +	if (!cpumask_weight_eq(mask, atomic_read(&p.cpus_ack))) {
> >  		on_each_cpu_mask(mask, cfset_ioctl_off, &p, 1);
> >  		rc = -EIO;
> >  		debug_sprintf_event(cf_dbg, 4, "%s CPUs missing", __func__);
> 
> given that you're adding a bunch of these functions - gt,lt,eq and
> others, i wonder whether it makes sense to also add cpumask_weight_ne(),
> so one could just write:
> 
> if (cpumask_weight_ne(mask, atomic_read(&p.cpus_ack))) {
> 	...
> }
> 
> ?

It will have 3 users in cpumask + 1 in nodemask. I have no strong opinion
whether we need it or not. Let's see what people say.

Thanks,
Yury

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

end of thread, other threads:[~2022-02-11 23:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20220210224933.379149-1-yury.norov@gmail.com>
2022-02-10 22:49 ` [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate Yury Norov
2022-02-11  6:54   ` Sven Schnelle
2022-02-11 23:40     ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox