public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nodemask.h: change any_online_node() to a static inline
@ 2010-01-05 18:17 H Hartley Sweeten
  2010-01-05 18:53 ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: H Hartley Sweeten @ 2010-01-05 18:17 UTC (permalink / raw)
  To: Linux Kernel; +Cc: akpm, bfields

Change any_online_node() from a macro to a static inline function.
 
The macro any_online_node() uses the local symbol 'node', this causes a
sparse warning in net/sunrpc/svc.c.  Changing the macro to a static inline
function quites the sparse warning and will prevent the same warning
from possibly occurring in the future.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: J. Bruce Fields <bfields@fieldses.org>

---

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 454997c..1f66e02 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -467,15 +467,6 @@ static inline int num_node_state(enum node_states state)
 #define node_online_map 	node_states[N_ONLINE]
 #define node_possible_map 	node_states[N_POSSIBLE]
 
-#define any_online_node(mask)			\
-({						\
-	int node;				\
-	for_each_node_mask(node, (mask))	\
-		if (node_online(node))		\
-			break;			\
-	node;					\
-})
-
 #define num_online_nodes()	num_node_state(N_ONLINE)
 #define num_possible_nodes()	num_node_state(N_POSSIBLE)
 #define node_online(node)	node_state((node), N_ONLINE)
@@ -484,6 +475,17 @@ static inline int num_node_state(enum node_states state)
 #define for_each_node(node)	   for_each_node_state(node, N_POSSIBLE)
 #define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
 
+static inline int any_online_node(nodemask_t mask)
+{
+	int node;
+
+	for_each_node_mask(node, mask) {
+		if (node_online(node))
+			break;
+	}
+	return node;
+}
+
 /*
  * For nodemask scrach area.
  * NODEMASK_ALLOC(type, name) allocates an object with a specified type and

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

* Re: [PATCH] nodemask.h: change any_online_node() to a static inline
  2010-01-05 18:17 [PATCH] nodemask.h: change any_online_node() to a static inline H Hartley Sweeten
@ 2010-01-05 18:53 ` David Rientjes
  2010-01-06  0:19   ` H Hartley Sweeten
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2010-01-05 18:53 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, akpm, bfields

On Tue, 5 Jan 2010, H Hartley Sweeten wrote:

> diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
> index 454997c..1f66e02 100644
> --- a/include/linux/nodemask.h
> +++ b/include/linux/nodemask.h
> @@ -467,15 +467,6 @@ static inline int num_node_state(enum node_states state)
>  #define node_online_map 	node_states[N_ONLINE]
>  #define node_possible_map 	node_states[N_POSSIBLE]
>  
> -#define any_online_node(mask)			\
> -({						\
> -	int node;				\
> -	for_each_node_mask(node, (mask))	\
> -		if (node_online(node))		\
> -			break;			\
> -	node;					\
> -})
> -
>  #define num_online_nodes()	num_node_state(N_ONLINE)
>  #define num_possible_nodes()	num_node_state(N_POSSIBLE)
>  #define node_online(node)	node_state((node), N_ONLINE)
> @@ -484,6 +475,17 @@ static inline int num_node_state(enum node_states state)
>  #define for_each_node(node)	   for_each_node_state(node, N_POSSIBLE)
>  #define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
>  
> +static inline int any_online_node(nodemask_t mask)
> +{
> +	int node;
> +
> +	for_each_node_mask(node, mask) {
> +		if (node_online(node))
> +			break;
> +	}
> +	return node;
> +}
> +
>  /*
>   * For nodemask scrach area.
>   * NODEMASK_ALLOC(type, name) allocates an object with a specified type and

Could you simply remove any_online_node() and replace its callers with 
first_node(node_online_map) instead?

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

* RE: [PATCH] nodemask.h: change any_online_node() to a static inline
  2010-01-05 18:53 ` David Rientjes
@ 2010-01-06  0:19   ` H Hartley Sweeten
  2010-01-06 10:35     ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: H Hartley Sweeten @ 2010-01-06  0:19 UTC (permalink / raw)
  To: David Rientjes; +Cc: Linux Kernel, akpm, bfields

On Tuesday, January 05, 2010 11:54 AM, David Rientjes wrote:
> On Tue, 5 Jan 2010, H Hartley Sweeten wrote:
>
>> diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
>> index 454997c..1f66e02 100644
>> --- a/include/linux/nodemask.h
>> +++ b/include/linux/nodemask.h
>> @@ -467,15 +467,6 @@ static inline int num_node_state(enum node_states state)
>>  #define node_online_map 	node_states[N_ONLINE]
>>  #define node_possible_map 	node_states[N_POSSIBLE]
>>  
>> -#define any_online_node(mask)			\
>> -({						\
>> -	int node;				\
>> -	for_each_node_mask(node, (mask))	\
>> -		if (node_online(node))		\
>> -			break;			\
>> -	node;					\
>> -})
>> -
>>  #define num_online_nodes()	num_node_state(N_ONLINE)
>>  #define num_possible_nodes()	num_node_state(N_POSSIBLE)
>>  #define node_online(node)	node_state((node), N_ONLINE)
>> @@ -484,6 +475,17 @@ static inline int num_node_state(enum node_states state)
>>  #define for_each_node(node)	   for_each_node_state(node, N_POSSIBLE)
>>  #define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
>>  
>> +static inline int any_online_node(nodemask_t mask)
>> +{
>> +	int node;
>> +
>> +	for_each_node_mask(node, mask) {
>> +		if (node_online(node))
>> +			break;
>> +	}
>> +	return node;
>> +}
>> +
>>  /*
>>   * For nodemask scrach area.
>>   * NODEMASK_ALLOC(type, name) allocates an object with a specified type and
>
> Could you simply remove any_online_node() and replace its callers with 
> first_node(node_online_map) instead?

No idea ;-)

My main intention with this patch was to quite some sparse noise in
net/sunrpc/svc.c.  This seemed the cleanest way to do it.

It looks like any_online_node is, currently, only called by:

arch/powerpc/mm/numa.c
  3 places, twice setting a local int variable called 'nid' and once just
  returning the 'node' from the macro.  All three call the marco as:

	... any_online_node(NODE_MASK_ALL);

net/sunrpc/svc.c
  1 place, setting a local unsigned int variable called 'node'.  Calls the
  macro as:

	... any_online_node(node_online_map);

I really don't know if the macro could be replaced by first_node(node_online_map).

Regards,
Hartley

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

* RE: [PATCH] nodemask.h: change any_online_node() to a static inline
  2010-01-06  0:19   ` H Hartley Sweeten
@ 2010-01-06 10:35     ` David Rientjes
  0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2010-01-06 10:35 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, akpm, bfields

On Tue, 5 Jan 2010, H Hartley Sweeten wrote:

> > Could you simply remove any_online_node() and replace its callers with 
> > first_node(node_online_map) instead?
> 
> No idea ;-)
> 
> My main intention with this patch was to quite some sparse noise in
> net/sunrpc/svc.c.  This seemed the cleanest way to do it.
> 

It certainly silents the warning, which is good, but it also leaves behind 
a macro that can simply be removed and reimplemented with 
first_node(node_online_map) given the current use cases.

> It looks like any_online_node is, currently, only called by:
> 
> arch/powerpc/mm/numa.c
>   3 places, twice setting a local int variable called 'nid' and once just
>   returning the 'node' from the macro.  All three call the marco as:
> 
> 	... any_online_node(NODE_MASK_ALL);
> 

NODE_MASK_ALL is a nodemask_t with all bits set, so this will simply 
return the first nid where node_online(nid) is true.  That's equivalent to 
first_node(node_online_map).

> net/sunrpc/svc.c
>   1 place, setting a local unsigned int variable called 'node'.  Calls the
>   macro as:
> 
> 	... any_online_node(node_online_map);
> 

Same thing, except this doesn't require any iteration since node_online() 
for the first bit in node_online_map will always be true.

> I really don't know if the macro could be replaced by first_node(node_online_map).
> 

It can, so I think an even better step would be to remove 
any_online_node() completely and convert the callers you've identified to 
use the new implementation.

Thanks!

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

end of thread, other threads:[~2010-01-06 10:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-05 18:17 [PATCH] nodemask.h: change any_online_node() to a static inline H Hartley Sweeten
2010-01-05 18:53 ` David Rientjes
2010-01-06  0:19   ` H Hartley Sweeten
2010-01-06 10:35     ` David Rientjes

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