Subject: Re: flush_cpumask atomicity?
From: William Lee Irwin III <[email-masked]>
To: Andrew Morton <[email-masked]>
Date: Tue, 5 Aug 2003 23:06:10 -0700

On Tue, Aug 05, 2003 at 07:31:16PM -0700, William Lee Irwin III wrote:
> I can doublecheck performance real quick before I stamp it. It should
> look a lot like page-flags.h that way.

Oh, yeah, it helps if I hit 'y' in mutt:

(a) replace arithmetic cpumasks' cpu-setting and clearing functions
	with the atomic operation equivalents
(b) explain what cpumask_arith means
(c) explain what cpumask_array means

-- wli

diff -prauN mm4-2.6.0-test2-3/include/asm-generic/cpumask_arith.h mm4-2.6.0-test2-4/include/asm-generic/cpumask_arith.h
--- mm4-2.6.0-test2-3/include/asm-generic/cpumask_arith.h	2003-08-05 12:07:33.000000000 -0700
+++ mm4-2.6.0-test2-4/include/asm-generic/cpumask_arith.h	2003-08-05 22:26:57.000000000 -0700
@@ -1,18 +1,15 @@
 #ifndef __ASM_GENERIC_CPUMASK_ARITH_H
 #define __ASM_GENERIC_CPUMASK_ARITH_H
 
-#define cpu_set(cpu, map)				\
-	do {						\
-		map |= ((cpumask_t)1) << (cpu);		\
-	} while (0)
-#define cpu_clear(cpu, map)				\
-	do {						\
-		map &= ~(((cpumask_t)1) << (cpu));	\
-	} while (0)
-#define cpu_isset(cpu, map)				\
-	((map) & (((cpumask_t)1) << (cpu)))
-#define cpu_test_and_set(cpu, map)			\
-	test_and_set_bit(cpu, (unsigned long *)(&(map)))
+/*
+ * Arithmetic type -based cpu bitmaps. A single unsigned long is used
+ * to contain the whole cpu bitmap.
+ */
+
+#define cpu_set(cpu, map)		set_bit(cpu, &(map))
+#define cpu_clear(cpu, map)		clear_bit(cpu, &(map))
+#define cpu_isset(cpu, map)		test_bit(cpu, &(map))
+#define cpu_test_and_set(cpu, map)	test_and_set_bit(cpu, &(map))
 
 #define cpus_and(dst,src1,src2)		do { dst = (src1) & (src2); } while (0)
 #define cpus_or(dst,src1,src2)		do { dst = (src1) | (src2); } while (0)
@@ -41,7 +38,6 @@
 #define cpumask_of_cpu(cpu)		({ ((cpumask_t)1) << (cpu); })
 
 #define first_cpu(map)			__ffs(map)
-#define next_cpu(cpu, map)				\
-	__ffs((map) & ~(((cpumask_t)1 << (cpu)) - 1))
+#define next_cpu(cpu, map)		find_next_bit(&(map), NR_CPUS, cpu + 1)
 
 #endif /* __ASM_GENERIC_CPUMASK_ARITH_H */
diff -prauN mm4-2.6.0-test2-3/include/asm-generic/cpumask_array.h mm4-2.6.0-test2-4/include/asm-generic/cpumask_array.h
--- mm4-2.6.0-test2-3/include/asm-generic/cpumask_array.h	2003-08-05 12:07:52.000000000 -0700
+++ mm4-2.6.0-test2-4/include/asm-generic/cpumask_array.h	2003-08-05 22:37:29.000000000 -0700
@@ -1,6 +1,12 @@
 #ifndef __ASM_GENERIC_CPUMASK_ARRAY_H
 #define __ASM_GENERIC_CPUMASK_ARRAY_H
 
+/*
+ * Array-based cpu bitmaps. An array of unsigned longs is used to contain
+ * the bitmap, and then contained in a structure so it may be passed by
+ * value.
+ */
+
 #define CPU_ARRAY_SIZE		BITS_TO_LONGS(NR_CPUS)
 
 #define cpu_set(cpu, map)		set_bit(cpu, (map).mask)