[PATCH 1/3] cpumask: add for_each_online_cpu_mask_nr function

Previous thread: [PATCH 0/3] x86: remove extraneous stack cpumask variables by Mike Travis on Tuesday, September 9, 2008 - 8:50 am. (1 message)

Next thread: [PATCH 2/3] x86: modify send_IPI_mask interface to accept cpumask_t pointers by Mike Travis on Tuesday, September 9, 2008 - 8:50 am. (1 message)
From: Mike Travis
Date: Tuesday, September 9, 2008 - 8:50 am

* Add for_each_online_cpu_mask_nr() function to eliminate need for
    a common use of a temporary cpumask_t variable.  When the following
    procedure is being used:

    funcproto(cpumask_t *mask, ...)
    {
	cpumask_t temp;

	cpus_and(temp, *mask, cpu_online_map);
	for_each_cpu_mask_nr(cpu, temp)
		...

    If then becomes:

    funcproto(cpumask_t *mask, ...)
    {
	for_each_online_cpu_mask_nr(cpu, *mask)
		...

  * Note the generic __next_cpu_and (and __next_cpu_and_nr) functions
    allowing AND'ing with any cpumask_t variable, not just the cpu_online_map.


Applies to linux-2.6.tip/master.

Signed-off-by: Mike Travis <travis@sgi.com>
---
 include/linux/cpumask.h |   26 +++++++++++++++++++++++---
 lib/cpumask.c           |   26 ++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)

--- linux-2.6.tip.orig/include/linux/cpumask.h
+++ linux-2.6.tip/include/linux/cpumask.h
@@ -404,23 +404,32 @@ static inline void __cpus_fold(cpumask_t
 #define first_cpu(src)		({ (void)(src); 0; })
 #define next_cpu(n, src)	({ (void)(src); 1; })
 #define any_online_cpu(mask)	0
-#define for_each_cpu_mask(cpu, mask)	\
+
+#define for_each_cpu_mask(cpu, mask)		\
 	for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
+#define for_each_online_cpu_mask(cpu, mask)	\
+	for_each_cpu_mask(cpu, mask)
 
 #else /* NR_CPUS > 1 */
 
 extern int nr_cpu_ids;
 int __first_cpu(const cpumask_t *srcp);
 int __next_cpu(int n, const cpumask_t *srcp);
+int __next_cpu_and(int n, const cpumask_t *srcp, const cpumask_t *andp);
 int __any_online_cpu(const cpumask_t *mask);
 
 #define first_cpu(src)		__first_cpu(&(src))
 #define next_cpu(n, src)	__next_cpu((n), &(src))
 #define any_online_cpu(mask) __any_online_cpu(&(mask))
+
 #define for_each_cpu_mask(cpu, mask)			\
 	for ((cpu) = -1;				\
 		(cpu) = next_cpu((cpu), (mask)),	\
 		(cpu) < NR_CPUS; )
+#define for_each_online_cpu_mask(cpu, mask)				   \
+	for ((cpu) = -1;						   \
+		(cpu) = __next_cpu_and((cpu), &(mask), ...
From: Rusty Russell
Date: Thursday, September 11, 2008 - 9:33 pm

Good idea!  But I really dislike the _nr versions (too many names!).  Do we 
really need them, since by definition cpus after nr_cpu_ids are never 
online...

(And we should initialize nr_cpu_ids to NR_CPUS so even early boot works, if 
we don't already...).

Cheers,
Rusty.
--

From: Mike Travis
Date: Friday, September 12, 2008 - 7:17 am

Yes, the only reason the _nr is there is to be consistent with the
current for_each_cpu_mask{,_nr} functions.  What I'd like to do is
convert all calls to use the nr_cpu_ids and if there's some reason
to need to iterate over NR_CPUS range, then you'd use FOR_EACH_CPU_MASK.

And yes, nr_cpu_ids is init'd to NR_CPUS.

Thanks,
Mike
--

Previous thread: [PATCH 0/3] x86: remove extraneous stack cpumask variables by Mike Travis on Tuesday, September 9, 2008 - 8:50 am. (1 message)

Next thread: [PATCH 2/3] x86: modify send_IPI_mask interface to accept cpumask_t pointers by Mike Travis on Tuesday, September 9, 2008 - 8:50 am. (1 message)