linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
       [not found] <20220123183925.1052919-1-yury.norov@gmail.com>
@ 2022-01-23 18:39 ` Yury Norov
  2022-01-23 22:00   ` Wei Liu
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yury Norov @ 2022-01-23 18:39 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,
	K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, linux-hyperv

init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
We can do it more efficiently with cpumask_weight_eq because conditional
cpumask_weight may stop traversing the cpumask earlier (at least one), as
soon as condition is met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/hv/channel_mgmt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 60375879612f..7420a5fd47b5 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
 		}
 		alloced_mask = &hv_context.hv_numa_map[numa_node];
 
-		if (cpumask_weight(alloced_mask) ==
-		    cpumask_weight(cpumask_of_node(numa_node))) {
+		if (cpumask_weight_eq(alloced_mask,
+			    cpumask_weight(cpumask_of_node(numa_node)))) {
 			/*
 			 * We have cycled through all the CPUs in the node;
 			 * reset the alloced map.
-- 
2.30.2


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

* Re: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
  2022-01-23 18:39 ` [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq Yury Norov
@ 2022-01-23 22:00   ` Wei Liu
  2022-01-23 22:02   ` Haiyang Zhang
  2022-01-24  9:20   ` Vitaly Kuznetsov
  2 siblings, 0 replies; 6+ messages in thread
From: Wei Liu @ 2022-01-23 22:00 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,
	K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, linux-hyperv

On Sun, Jan 23, 2022 at 10:39:14AM -0800, Yury Norov wrote:
> init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
> We can do it more efficiently with cpumask_weight_eq because conditional
> cpumask_weight may stop traversing the cpumask earlier (at least one), as
> soon as condition is met.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Acked-by: Wei Liu <wei.liu@kernel.org>

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

* RE: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
  2022-01-23 18:39 ` [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq Yury Norov
  2022-01-23 22:00   ` Wei Liu
@ 2022-01-23 22:02   ` Haiyang Zhang
  2022-01-24  9:20   ` Vitaly Kuznetsov
  2 siblings, 0 replies; 6+ messages in thread
From: Haiyang Zhang @ 2022-01-23 22:02 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@vger.kernel.org, KY Srinivasan, Stephen Hemminger,
	Wei Liu, Dexuan Cui, linux-hyperv@vger.kernel.org



> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Sunday, January 23, 2022 1:39 PM
> To: Yury Norov <yury.norov@gmail.com>; Andy Shevchenko <andriy.shevchenko@linux.intel.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton <akpm@linux-foundation.org>;
> Michał Mirosław <mirq-linux@rere.qmqm.pl>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>;
> Peter Zijlstra <peterz@infradead.org>; David Laight <David.Laight@aculab.com>; Joe Perches
> <joe@perches.com>; Dennis Zhou <dennis@kernel.org>; Emil Renner Berthing <kernel@esmil.dk>;
> Nicholas Piggin <npiggin@gmail.com>; Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>;
> Alexey Klimov <aklimov@redhat.com>; linux-kernel@vger.kernel.org; KY Srinivasan
> <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Dexuan Cui <decui@microsoft.com>;
> linux-hyperv@vger.kernel.org
> Subject: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
> 
> init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
> We can do it more efficiently with cpumask_weight_eq because conditional
> cpumask_weight may stop traversing the cpumask earlier (at least one), as
> soon as condition is met.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
>  drivers/hv/channel_mgmt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> index 60375879612f..7420a5fd47b5 100644
> --- a/drivers/hv/channel_mgmt.c
> +++ b/drivers/hv/channel_mgmt.c
> @@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
>  		}
>  		alloced_mask = &hv_context.hv_numa_map[numa_node];
> 
> -		if (cpumask_weight(alloced_mask) ==
> -		    cpumask_weight(cpumask_of_node(numa_node))) {
> +		if (cpumask_weight_eq(alloced_mask,
> +			    cpumask_weight(cpumask_of_node(numa_node)))) {
>  			/*
>  			 * We have cycled through all the CPUs in the node;
>  			 * reset the alloced map.

Thanks.

Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>


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

* Re: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
  2022-01-23 18:39 ` [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq Yury Norov
  2022-01-23 22:00   ` Wei Liu
  2022-01-23 22:02   ` Haiyang Zhang
@ 2022-01-24  9:20   ` Vitaly Kuznetsov
  2022-01-27 15:02     ` Michael Kelley (LINUX)
  2 siblings, 1 reply; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-01-24  9:20 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,
	K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, linux-hyperv

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

> init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
> We can do it more efficiently with cpumask_weight_eq because conditional
> cpumask_weight may stop traversing the cpumask earlier (at least one), as
> soon as condition is met.

Same comment as for "PATCH 41/54": cpumask_weight_eq() can only stop
earlier if the condition is not met, to prove the equality all bits need
always have to be examined.

>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
>  drivers/hv/channel_mgmt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> index 60375879612f..7420a5fd47b5 100644
> --- a/drivers/hv/channel_mgmt.c
> +++ b/drivers/hv/channel_mgmt.c
> @@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
>  		}
>  		alloced_mask = &hv_context.hv_numa_map[numa_node];
>  
> -		if (cpumask_weight(alloced_mask) ==
> -		    cpumask_weight(cpumask_of_node(numa_node))) {
> +		if (cpumask_weight_eq(alloced_mask,
> +			    cpumask_weight(cpumask_of_node(numa_node)))) {

This code is not performace critical and I prefer the old version:

 	cpumask_weight() == cpumask_weight()

 looks better than

	cpumask_weight_eq(..., cpumask_weight())

(let alone the inner cpumask_of_node()) to me.

>  			/*
>  			 * We have cycled through all the CPUs in the node;
>  			 * reset the alloced map.

-- 
Vitaly


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

* RE: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
  2022-01-24  9:20   ` Vitaly Kuznetsov
@ 2022-01-27 15:02     ` Michael Kelley (LINUX)
  2022-01-28  9:31       ` Vitaly Kuznetsov
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Kelley (LINUX) @ 2022-01-27 15:02 UTC (permalink / raw)
  To: vkuznets, 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@vger.kernel.org, KY Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Dexuan Cui,
	linux-hyperv@vger.kernel.org

From: Vitaly Kuznetsov <vkuznets@redhat.com> Sent: Monday, January 24, 2022 1:20 AM
> 
> Yury Norov <yury.norov@gmail.com> writes:
> 
> > init_vp_index() calls cpumask_weight() to compare the weights of cpumasks
> > We can do it more efficiently with cpumask_weight_eq because conditional
> > cpumask_weight may stop traversing the cpumask earlier (at least one), as
> > soon as condition is met.
> 
> Same comment as for "PATCH 41/54": cpumask_weight_eq() can only stop
> earlier if the condition is not met, to prove the equality all bits need
> always have to be examined.
> 
> >
> > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > ---
> >  drivers/hv/channel_mgmt.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> > index 60375879612f..7420a5fd47b5 100644
> > --- a/drivers/hv/channel_mgmt.c
> > +++ b/drivers/hv/channel_mgmt.c
> > @@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
> >  		}
> >  		alloced_mask = &hv_context.hv_numa_map[numa_node];
> >
> > -		if (cpumask_weight(alloced_mask) ==
> > -		    cpumask_weight(cpumask_of_node(numa_node))) {
> > +		if (cpumask_weight_eq(alloced_mask,
> > +			    cpumask_weight(cpumask_of_node(numa_node)))) {
> 
> This code is not performace critical and I prefer the old version:
> 
>  	cpumask_weight() == cpumask_weight()
> 
>  looks better than
> 
> 	cpumask_weight_eq(..., cpumask_weight())
> 
> (let alone the inner cpumask_of_node()) to me.
> 
> >  			/*
> >  			 * We have cycled through all the CPUs in the node;
> >  			 * reset the alloced map.
> 
> --
> Vitaly

I agree with Vitaly in preferring the old version, and indeed performance
here is a shrug.  But actually, I think the old version is a poorly coded way
to determine if the two cpumasks are equal. The following would correctly
capture the intent:

	if (cpumask_equal(alloced_mask, cpumask_of_node(numa_node))

Michael




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

* RE: [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq
  2022-01-27 15:02     ` Michael Kelley (LINUX)
@ 2022-01-28  9:31       ` Vitaly Kuznetsov
  0 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-01-28  9:31 UTC (permalink / raw)
  To: Michael Kelley (LINUX)
  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@vger.kernel.org, KY Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Dexuan Cui,
	linux-hyperv@vger.kernel.org, Yury Norov

"Michael Kelley (LINUX)" <mikelley@microsoft.com> writes:

> From: Vitaly Kuznetsov <vkuznets@redhat.com> Sent: Monday, January 24, 2022 1:20 AM
>> 
>> Yury Norov <yury.norov@gmail.com> writes:
>> 
...
>> >
>> > diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
>> > index 60375879612f..7420a5fd47b5 100644
>> > --- a/drivers/hv/channel_mgmt.c
>> > +++ b/drivers/hv/channel_mgmt.c
>> > @@ -762,8 +762,8 @@ static void init_vp_index(struct vmbus_channel *channel)
>> >  		}
>> >  		alloced_mask = &hv_context.hv_numa_map[numa_node];
>> >
>> > -		if (cpumask_weight(alloced_mask) ==
>> > -		    cpumask_weight(cpumask_of_node(numa_node))) {
>> > +		if (cpumask_weight_eq(alloced_mask,
>> > +			    cpumask_weight(cpumask_of_node(numa_node)))) {
>> 
>> This code is not performace critical and I prefer the old version:
>> 
>>  	cpumask_weight() == cpumask_weight()
>> 
>>  looks better than
>> 
>> 	cpumask_weight_eq(..., cpumask_weight())
>> 
>> (let alone the inner cpumask_of_node()) to me.
>> 
>> >  			/*
>> >  			 * We have cycled through all the CPUs in the node;
>> >  			 * reset the alloced map.
>> 
> I agree with Vitaly in preferring the old version, and indeed performance
> here is a shrug.  But actually, I think the old version is a poorly coded way
> to determine if the two cpumasks are equal. The following would correctly
> capture the intent:
>
> 	if (cpumask_equal(alloced_mask, cpumask_of_node(numa_node))
>

Indeed. While it seems that only CPUs from 'cpumask_of_node(numa_node)'
can be set in 'alloced_mask' (and thus the comparison is valid), there's
no real need to weigh anything. I'll send a patch.

-- 
Vitaly


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

end of thread, other threads:[~2022-01-28  9:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20220123183925.1052919-1-yury.norov@gmail.com>
2022-01-23 18:39 ` [PATCH 43/54] drivers/hv: replace cpumask_weight with cpumask_weight_eq Yury Norov
2022-01-23 22:00   ` Wei Liu
2022-01-23 22:02   ` Haiyang Zhang
2022-01-24  9:20   ` Vitaly Kuznetsov
2022-01-27 15:02     ` Michael Kelley (LINUX)
2022-01-28  9:31       ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).