Re: [PATCH] cpumask 5/10 rewrite cpumask.h - single bitmap based implementation

William Lee Irwin III
2004-06-04T17:53:14Z

On Fri, Jun 04, 2004 at 10:29:46AM -0700, Paul Jackson wrote:
> I'd vote to have the documented form that Andrew speaks of be arrays
> of 32-bit words, which is what I understood Mikael was doing. I agree
> with Andrew's suggested to/from canonical functions.
> I'd prefer not copying arrays of unsigned longs, due to the confusions
> of coding to them across 32/64 bit and big/little endian architectures.
> At times I have wished the kernel had chosen u32 arrays instead of
> unsigned long arrays for bitmaps, for the same reason. The cpumask
> sprintf and parse format is intentionally 32-bit chunk friendly.

Index: irqaction-2.6.7-rc2/include/linux/bitmap.h
===================================================================
--- irqaction-2.6.7-rc2.orig/include/linux/bitmap.h 2004-05-29 23:26:49.000000000 -0700
+++ irqaction-2.6.7-rc2/include/linux/bitmap.h 2004-06-04 10:35:31.982041000 -0700
@@ -46,6 +46,7 @@
const unsigned long *maskp, int bits);
int bitmap_parse(const char __user *ubuf, unsigned int ubuflen,
unsigned long *maskp, int bits);
+void bitmap_to_u32_array(u32 *dst, unsigned long *src, int nlongs);

#endif /* __ASSEMBLY__ */

Index: irqaction-2.6.7-rc2/lib/bitmap.c
===================================================================
--- irqaction-2.6.7-rc2.orig/lib/bitmap.c 2004-05-29 23:26:27.000000000 -0700
+++ irqaction-2.6.7-rc2/lib/bitmap.c 2004-06-04 10:51:46.878834000 -0700
@@ -330,3 +330,22 @@
return 0;
}
EXPORT_SYMBOL(bitmap_parse);
+
+#if defined(__BIG_ENDIAN) && BITS_PER_LONG == 64
+void bitmap_to_u32_array(u32 *dst, unsigned long *src, int nwords)
+{
+ int i;
+
+ for (i = 0; i < nwords; ++i) {
+ u64 word = src[i];
+ dst[2*i] = word >> 32;
+ dst[2*i+1] = word;
+ }
+}
+#else
+void bitmap_to_u32_array(u32 *dst, unsigned long *src, int nwords)
+{
+ memcpy(dst, src, nwords*sizeof(unsigned long));
+}
+#endif
+EXPORT_SYMBOL(bitmap_to_u32_array);