public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Patch 0/23 - Bitmaps, Cpumasks and Nodemasks
@ 2004-04-08 18:50 Paul Jackson
  2004-04-08 19:47 ` Patch 1/23 " Paul Jackson
                   ` (24 more replies)
  0 siblings, 25 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 18:50 UTC (permalink / raw)
  To: Matthew Dobson, William Lee Irwin III, Rusty Russell; +Cc: linux-kernel

					Paul Jackson
					pj@sgi.com
					8 April 2004

	  Bitmaps, Cpumasks and Nodemasks
	  
  [ Status: Certainly not ready to apply yet - needs
            testing, arch-maintainer reviews, ...
	    And I'm vacation these next seven days. ]

This is my third cut at cleaning up cpumasks and providing a common
basis for both cpumasks and Matthew Dobson's nodemask patch series.

A primary goal of this patch set is to simplify the code for cpumask_t
and nodemask_t, making them easier to understand and use, and reducing
code duplication.

Several flavors of cpumask have been reduced to one, with some local
special handling to optimize for normal size systems of less than 32
CPUs.

The other primary goal of this patch set, in particular of Matthew's
nodemask_t patches, which are included here, was to provide a standard
nodemask_t and operations.  This is done to avoid "open" coding of node
masks using ad hoc code.

This cut differs from the second "mask v2" of a week ago
as follows:

 1) The "mask" ADT is gone.  Cpumasks and nodemasks now
    sit directly on top of bitmaps/bitops.  Thanks, Rusty.
 
 2) The patch based migrated from 2.6.4 to 2.6.5 (a couple
    of ia64 files required some hand merging).
 
 3) On ia64, find_first_bit and find_first_zero_bit are
    uninlined - saving quite a bit of kernel text space.
    The architectures: alpha, parisc, ppc, sh, sparc, sparc64
    have this same shift code, and might also want to uninline.

 4) The bitmap.h file got some work:
    - comment listing available ops for ease of browsing
    - MASK_ALL on multiword bitmaps zeros out unused bits
    - compile-time inline logic for optimum small (< 32 cpu) code
 
 5) This patch includes Bill Irwin's very recent rewrite
    of the bitmap_shift operators to avoid assuming some
    fixed upper bound on bitmap sizes.

See significantly more description in my posting last
week of "mask v2", including some of the remaining risk
factors, on my lkml posting:

    Date:      Thu, 1 Apr 2004 12:28:02 -0800
    Subject:   [Patch 0/23] mask v2 - Second version of mask,
                           cpumask and nodemask consolidation
    http://groups.google.com/groups?selm=1Gh90-5aj-51%40gated-at.bofh.it

I've built this for i386 and ia64, and booted ia64.
But it has not received anything resembling real testing.

I need to seek out feedback and approval/disapproval
from the arch maintainers.

I will be on vacation for the next week (until the day
after April 15 ... my fellow Americans can guess why ;).

The actual patches in this set will follow in an hour or
so, as replies to this initial post.


================ Patch Details ================

Here's what each patch does:

P1.bitmap_comment - Document bitmap.c bit model.
        Document the bitmap bit model, including handling of unused bits,
        and operation preconditions and postconditions.

P2.bitmap_complement - Dont generate nonzero unused bits in bitmap
        Tighten up bitmap so it does not generate nonzero bits
        in the unused tail if it is not given any on input.

P3.bitmap_newops - New bitmap operators and two op complement
        Add intersects, subset, xor and andnot operators.
        Change bitmap_complement to take two operands.

P4.bitmap_const - two missing 'const' qualifiers in bitops/bitmap
        Add a couple of missing 'const' qualifiers on
        bitops test_bit and bitmap_equal args.

P5.bitmap_extensions - Optimize and extend bitmap.

        This bitmap improvements make it a suitable basis for
        fully supporting cpumask_t and nodemask_t.  Inline macros
        with compile-time checks enable generating tight code on
        both small and large systems (large meaning cpumask_t
        requires more than one unsigned long's worth of bits).

        The existing bitmap_<op> macros in lib/bitmap.c
        are renamed to __bitmap_<op>, and wrappers for each
        bitmap_<op> are exposed in include/linux/bitmap.h

        This patch _includes_ Bill Irwins rewrite of the
        bitmap_shift operators to not require a fixed length
        intermediate bitmap.

        Improved comments list each available operator for easy
        browsing.

P6a.unline_find_next_bit_ia64 - Uninline find_next_bit on ia64

        Move the page of code (~700 bytes of instructions)
        for find_next_bit and find_next_zero_bit from inline
        in include/asm-ia64/bitops.h to a real function in
        arch/ia64/lib/bitops.c, leaving a declaration and
        macro wrapper behind.

        The other arch's with almost this same code might want to
        also uninline it: alpha, parisc, ppc, sh, sparc, sparc64.

        These are too big to inline.

P6b.new_cpumask.h - Rewrite cpumask.h to use bitmap directly.

        Major rewrite of cpumask to use a single implementation,
        as a struct-wrapped bitmap.

        This patch leaves some 26 include/asm-*/cpumask*.h
        header files orphaned - to be removed next patch.

        Some nine cpumask macros for const variants and to
        coerce and promote between an unsigned long and a
        cpumask are obsolete.  Simple emulation wrappers are
        provided in this patch, which can be removed once each
        of the 3 archs (i386, ppc64, x86_64) using them are
        recoded in follow-on patches to not need them.

        The CPU_MASK_ALL macro now avoids leaving possible
        garbage one bits in any unused portion of the high word.

        An inproved comment lists all available operators, for
        convenient browsing.

P6c.remove_old_cpumask_files - Remove 26 no longer used cpumask headers.
        With the cpumask rewrite in the previous patch, these
        various include/asm-*/cpumask*.h headers are no longer used.

P7.cpumask_i386_fixup - Remove/recode obsolete cpumask macros from arch i386
        Remove by recoding all uses of the obsolete cpumask const,
        coerce and promote macros.

P8.cpumask_ppc64_fixup - Remove/recode obsolete cpumask macros from arch ppc64
        Remove by recoding all uses of the obsolete cpumask const,
        coerce and promote macros.

P9.cpumask_x86_64_fixup - Remove/recode obsolete cpumask macros from arch x86_64
        Remove by recoding all uses of the obsolete cpumask const,
        coerce and promote macros.

P10.rm_old_cpumask_emul - Remove obsolete cpumask emulation from cpumask.h
        Now that the emulation of the obsolete cpumask macros is no
        longer needed, remove it from cpumask.h

P11.cpumask_sparc_simplify - Simplify some sparc64 cpumask loop code
        Make use of for_each_cpu_mask() macro to simplify and optimize
        a couple of sparc64 per-CPU loops.  This code change has _not_
        been tested or reviewed.  Feedback welcome.  There is non-trivial
        risk that I still don't understand the logic here.

P12.cpumask_i386_simplify - Optimize i386 cpumask macro usage.
        Optimize a bit of cpumask code for asm-i386/mach-es7000
        Code untested, unreviewed.  Feedback welcome.

P13.cpumask_physids_complement - Convert physids_complement() to use both args
        Provide for specifying distinct source and dest args to the
        physids_complement().  No one actually uses this macro yet.
        The physid_mask type would be a good candidate to convert to
        using this new mask ADT as a base.

P14.cpumask_x86_64_online - Remove cpumask hack from asm-x86_64/topology.h
        This file had the cpumask cpu_online_map as type
        unsigned long, instead of type cpumask_t, for no good
        reason that I could see.  So I changed it.  Everywhere
        else, cpu_online_map is already of type cpumask_t.

P15.cpumask_sched_refine- Cpumask code clarification in kernel/sched.c
        Clarify and slightly optimize set_cpus_allowed() cpumask check

P16.new_nodemask.h - New nodemask_t, based on bitmap.
        New nodemask_t type, based on bitmap/bitop,
        suitable for use with Matthew Dobson's nodemask
        patch series.  Closely resembles cpumask.h.

P17.nodemask_mmzone - the mmzone.h changes from Matthew's Patch [1/7]
        Just the mmzone.h changes taken from this patch: removing
        extistant definition of node_online_map and helper functions,
        added a #include <nodemask.h>.

P18.nodemask_core - Matthew Dobson's [PATCH] nodemask_t core changes [2/7]
        nodemask_t-02-core.patch - Changes to arch-independent code.
        Surprisingly few references to numnodes, open-coded node loops,
        etc. in generic code.  Most important result of this patch is
        that no generic code assumes anything about node numbering.
        This allows individual arches to use sparse numbering if they
        care to.

P19.nodemask_i386 - Matthew Dobson's [PATCH]_nodemask_t_i386_changes_[3_7]
        Changes to i386 specific code.  As with most arch changes,
        it involves close-coding loops (ie: for_each_online_node(nid)
        rather than for(nid=0;nid<numnodes;nid++)) and replacing the
        use of numnodes with num_online_nodes() and node_set_online(nid).

P20.nodemask_pp64 - Matthew Dobson's [PATCH]_nodemask_t_pp64_changes_[4_7]
        Changes to ppc64 specific code.  Untested.
        Code review & testing requested.

P21.nodemask_x86_64 - Matthew Dobson's [PATCH]_nodemask_t_x86_64_changes_[5_7]
        Changes to x86_64 specific code.
        Untested.  Code review & testing requested.

P22.nodemask_ia64 - Matthew Dobson's [PATCH]_nodemask_t_ia64_changes_[6_7]
        Changes to ia64 specific code.

P23.nodemask_other_archs - Matthew Dobson's [PATCH]_nodemask_t_other_arch [7_7]
        Changes to other arch-specific code (alpha, arm, mips,
        sparc64 & sh).  Untested.  Code review & testing requested.


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

* Patch 1/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
@ 2004-04-08 19:47 ` Paul Jackson
  2004-04-08 19:48 ` Patch 2/23 " Paul Jackson
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:47 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P1.bitmap_comment - Document bitmap.c bit model.
        Document the bitmap bit model, including handling of unused bits,
        and operation preconditions and postconditions.

Index: 2.6.5.bitmap/lib/bitmap.c
===================================================================
--- 2.6.5.bitmap.orig/lib/bitmap.c	2004-04-05 02:00:15.000000000 -0700
+++ 2.6.5.bitmap/lib/bitmap.c	2004-04-05 02:50:25.000000000 -0700
@@ -12,6 +12,26 @@
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
 
+/*
+ * bitmaps provide an array of bits, implemented using an an
+ * array of unsigned longs.  The number of valid bits in a
+ * given bitmap need not be an exact multiple of BITS_PER_LONG.
+ *
+ * The possible unused bits in the last, partially used word
+ * of a bitmap are 'don't care'.  The implementation makes
+ * no particular effort to keep them zero.  It ensures that
+ * their value will not affect the results of any operation.
+ * The bitmap operations that return Boolean (bitmap_empty,
+ * for example) or scalar (bitmap_weight, for example) results
+ * carefully filter out these unused bits from impacting their
+ * results.
+ *
+ * Except for bitmap_complement, these operations hold to a
+ * slightly stronger rule: if you don't input any bitmaps to
+ * these ops that have some unused bits set, then they won't
+ * output any set unused bits in output bitmaps.
+ */
+
 #define MAX_BITMAP_BITS	512U	/* for ia64 NR_CPUS maximum */
 
 int bitmap_empty(const unsigned long *bitmap, int bits)


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 2/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
  2004-04-08 19:47 ` Patch 1/23 " Paul Jackson
@ 2004-04-08 19:48 ` Paul Jackson
  2004-04-08 19:48 ` Patch 3/23 " Paul Jackson
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:48 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P2.bitmap_complement - Dont generate nonzero unused bits in bitmap
        Tighten up bitmap so it does not generate nonzero bits
        in the unused tail if it is not given any on input.

Index: 2.6.5.bitmap/lib/bitmap.c
===================================================================
--- 2.6.5.bitmap.orig/lib/bitmap.c	2004-04-05 02:50:25.000000000 -0700
+++ 2.6.5.bitmap/lib/bitmap.c	2004-04-05 03:02:39.000000000 -0700
@@ -26,10 +26,10 @@
  * carefully filter out these unused bits from impacting their
  * results.
  *
- * Except for bitmap_complement, these operations hold to a
- * slightly stronger rule: if you don't input any bitmaps to
- * these ops that have some unused bits set, then they won't
- * output any set unused bits in output bitmaps.
+ * These operations actually hold to a slightly stronger rule:
+ * if you don't input any bitmaps to these ops that have some
+ * unused bits set, then they won't output any set unused bits
+ * in output bitmaps.
  */
 
 #define MAX_BITMAP_BITS	512U	/* for ia64 NR_CPUS maximum */
@@ -83,11 +83,12 @@
 
 void bitmap_complement(unsigned long *bitmap, int bits)
 {
-	int k;
-	int nr = BITS_TO_LONGS(bits);
-
-	for (k = 0; k < nr; ++k)
+	int k, lim = bits/BITS_PER_LONG;
+	for (k = 0; k < lim; ++k)
 		bitmap[k] = ~bitmap[k];
+
+	if (bits % BITS_PER_LONG)
+		bitmap[k] = ~bitmap[k] & ((1UL << (bits % BITS_PER_LONG)) - 1);
 }
 EXPORT_SYMBOL(bitmap_complement);
 


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 3/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
  2004-04-08 19:47 ` Patch 1/23 " Paul Jackson
  2004-04-08 19:48 ` Patch 2/23 " Paul Jackson
@ 2004-04-08 19:48 ` Paul Jackson
  2004-04-08 19:48 ` Patch 4/23 " Paul Jackson
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:48 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P3.bitmap_newops - New bitmap operators and two op complement
        Add intersects, subset, xor and andnot operators.
        Change bitmap_complement to take two operands.

Index: 2.6.5.bitmap/include/asm-generic/cpumask_array.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_array.h	2004-04-07 20:58:38.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_array.h	2004-04-07 21:14:12.000000000 -0700
@@ -17,7 +17,7 @@
 #define cpus_and(dst,src1,src2)	bitmap_and((dst).mask,(src1).mask, (src2).mask, NR_CPUS)
 #define cpus_or(dst,src1,src2)	bitmap_or((dst).mask, (src1).mask, (src2).mask, NR_CPUS)
 #define cpus_clear(map)		bitmap_clear((map).mask, NR_CPUS)
-#define cpus_complement(map)	bitmap_complement((map).mask, NR_CPUS)
+#define cpus_complement(map)	bitmap_complement((map).mask, (map).mask, NR_CPUS)
 #define cpus_equal(map1, map2)	bitmap_equal((map1).mask, (map2).mask, NR_CPUS)
 #define cpus_empty(map)		bitmap_empty(map.mask, NR_CPUS)
 #define cpus_addr(map)		((map).mask)
Index: 2.6.5.bitmap/include/asm-i386/mpspec.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/mpspec.h	2004-04-07 20:58:38.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/mpspec.h	2004-04-07 20:58:41.000000000 -0700
@@ -53,7 +53,7 @@
 #define physids_and(dst, src1, src2)		bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_or(dst, src1, src2)		bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_clear(map)			bitmap_clear((map).mask, MAX_APICS)
-#define physids_complement(map)			bitmap_complement((map).mask, MAX_APICS)
+#define physids_complement(map)			bitmap_complement((map).mask, (map).mask, MAX_APICS)
 #define physids_empty(map)			bitmap_empty((map).mask, MAX_APICS)
 #define physids_equal(map1, map2)		bitmap_equal((map1).mask, (map2).mask, MAX_APICS)
 #define physids_weight(map)			bitmap_weight((map).mask, MAX_APICS)
Index: 2.6.5.bitmap/include/asm-x86_64/mpspec.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/mpspec.h	2004-04-07 20:58:38.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/mpspec.h	2004-04-07 20:58:41.000000000 -0700
@@ -212,7 +212,7 @@
 #define physids_and(dst, src1, src2)		bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_or(dst, src1, src2)		bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_clear(map)			bitmap_clear((map).mask, MAX_APICS)
-#define physids_complement(map)			bitmap_complement((map).mask, MAX_APICS)
+#define physids_complement(map)			bitmap_complement((map).mask, (map).mask, MAX_APICS)
 #define physids_empty(map)			bitmap_empty((map).mask, MAX_APICS)
 #define physids_equal(map1, map2)		bitmap_equal((map1).mask, (map2).mask, MAX_APICS)
 #define physids_weight(map)			bitmap_weight((map).mask, MAX_APICS)
Index: 2.6.5.bitmap/include/linux/bitmap.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/bitmap.h	2004-04-07 20:58:38.000000000 -0700
+++ 2.6.5.bitmap/include/linux/bitmap.h	2004-04-07 21:14:15.000000000 -0700
@@ -13,8 +13,8 @@
 int bitmap_empty(const unsigned long *bitmap, int bits);
 int bitmap_full(const unsigned long *bitmap, int bits);
 int bitmap_equal(const unsigned long *bitmap1,
-			unsigned long *bitmap2, int bits);
-void bitmap_complement(unsigned long *bitmap, int bits);
+			const unsigned long *bitmap2, int bits);
+void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits);
 
 static inline void bitmap_clear(unsigned long *bitmap, int bits)
 {
@@ -40,6 +40,14 @@
 			const unsigned long *bitmap2, int bits);
 void bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
 			const unsigned long *bitmap2, int bits);
+void bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+void bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+int bitmap_intersects(const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+int bitmap_subset(const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
 int bitmap_weight(const unsigned long *bitmap, int bits);
 int bitmap_scnprintf(char *buf, unsigned int buflen,
 			const unsigned long *maskp, int bits);
Index: 2.6.5.bitmap/lib/bitmap.c
===================================================================
--- 2.6.5.bitmap.orig/lib/bitmap.c	2004-04-07 20:58:41.000000000 -0700
+++ 2.6.5.bitmap/lib/bitmap.c	2004-04-07 21:14:18.000000000 -0700
@@ -81,14 +81,14 @@
 }
 EXPORT_SYMBOL(bitmap_equal);
 
-void bitmap_complement(unsigned long *bitmap, int bits)
+void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
 	for (k = 0; k < lim; ++k)
-		bitmap[k] = ~bitmap[k];
+		dst[k] = ~src[k];
 
 	if (bits % BITS_PER_LONG)
-		bitmap[k] = ~bitmap[k] & ((1UL << (bits % BITS_PER_LONG)) - 1);
+		dst[k] = ~src[k] & ((1UL << (bits % BITS_PER_LONG)) - 1);
 }
 EXPORT_SYMBOL(bitmap_complement);
 
@@ -144,6 +144,60 @@
 }
 EXPORT_SYMBOL(bitmap_or);
 
+void bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+				const unsigned long *bitmap2, int bits)
+{
+	int k;
+	int nr = BITS_TO_LONGS(bits);
+
+	for (k = 0; k < nr; k++)
+		dst[k] = bitmap1[k] ^ bitmap2[k];
+}
+EXPORT_SYMBOL(bitmap_xor);
+
+void bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+				const unsigned long *bitmap2, int bits)
+{
+	int k;
+	int nr = BITS_TO_LONGS(bits);
+
+	for (k = 0; k < nr; k++)
+		dst[k] = bitmap1[k] & ~bitmap2[k];
+}
+EXPORT_SYMBOL(bitmap_andnot);
+
+int bitmap_intersects(const unsigned long *bitmap1,
+				const unsigned long *bitmap2, int bits)
+{
+	int k, lim = bits/BITS_PER_LONG;
+	for (k = 0; k < lim; ++k)
+		if (bitmap1[k] & bitmap2[k])
+			return 1;
+
+	if (bits % BITS_PER_LONG)
+		if ((bitmap1[k] & bitmap2[k]) &
+				((1UL << (bits % BITS_PER_LONG)) - 1))
+			return 1;
+	return 0;
+}
+EXPORT_SYMBOL(bitmap_intersects);
+
+int bitmap_subset(const unsigned long *bitmap1,
+				const unsigned long *bitmap2, int bits)
+{
+	int k, lim = bits/BITS_PER_LONG;
+	for (k = 0; k < lim; ++k)
+		if (bitmap1[k] & ~bitmap2[k])
+			return 0;
+
+	if (bits % BITS_PER_LONG)
+		if ((bitmap1[k] & ~bitmap2[k]) &
+				((1UL << (bits % BITS_PER_LONG)) - 1))
+			return 0;
+	return 1;
+}
+EXPORT_SYMBOL(bitmap_subset);
+
 #if BITS_PER_LONG == 32
 int bitmap_weight(const unsigned long *bitmap, int bits)
 {


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 4/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (2 preceding siblings ...)
  2004-04-08 19:48 ` Patch 3/23 " Paul Jackson
@ 2004-04-08 19:48 ` Paul Jackson
  2004-04-08 19:48 ` Patch 5/23 " Paul Jackson
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:48 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P4.bitmap_const - two missing 'const' qualifiers in bitops/bitmap
        Add a couple of missing 'const' qualifiers on
        bitops test_bit and bitmap_equal args.

Index: 2.6.5.bitmap/include/asm-generic/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/bitops.h	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/bitops.h	2004-04-05 03:15:17.000000000 -0700
@@ -42,7 +42,7 @@
 	return retval;
 }
 
-extern __inline__ int test_bit(int nr, long * addr)
+extern __inline__ int test_bit(int nr, const unsigned long * addr)
 {
 	int	mask;
 
Index: 2.6.5.bitmap/lib/bitmap.c
===================================================================
--- 2.6.5.bitmap.orig/lib/bitmap.c	2004-04-05 03:12:27.000000000 -0700
+++ 2.6.5.bitmap/lib/bitmap.c	2004-04-05 03:15:17.000000000 -0700
@@ -65,7 +65,7 @@
 EXPORT_SYMBOL(bitmap_full);
 
 int bitmap_equal(const unsigned long *bitmap1,
-		unsigned long *bitmap2, int bits)
+		const unsigned long *bitmap2, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
 	for (k = 0; k < lim; ++k)


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 5/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (3 preceding siblings ...)
  2004-04-08 19:48 ` Patch 4/23 " Paul Jackson
@ 2004-04-08 19:48 ` Paul Jackson
  2004-04-08 19:49 ` Patch 6a/23 " Paul Jackson
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:48 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P5.bitmap_extensions - Optimize and extend bitmap.

        This bitmap improvements make it a suitable basis for
        fully supporting cpumask_t and nodemask_t.  Inline macros
        with compile-time checks enable generating tight code on
        both small and large systems (large meaning cpumask_t
        requires more than one unsigned long's worth of bits).

        The existing bitmap_<op> macros in lib/bitmap.c
        are renamed to __bitmap_<op>, and wrappers for each
        bitmap_<op> are exposed in include/linux/bitmap.h

	This patch _includes_ Bill Irwins rewrite of the
	bitmap_shift operators to not require a fixed length
	intermediate bitmap.

	Improved comments list each available operator for easy
	browsing.

Index: 2.6.5.bitmap/include/linux/bitmap.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/bitmap.h	2004-04-07 21:22:32.000000000 -0700
+++ 2.6.5.bitmap/include/linux/bitmap.h	2004-04-07 21:23:52.000000000 -0700
@@ -1,59 +1,250 @@
-#ifndef __LINUX_BITMAP_H
-#define __LINUX_BITMAP_H
+#ifndef __LINUX__bitmap_H
+#define __LINUX__bitmap_H
 
 #ifndef __ASSEMBLY__
 
-#include <linux/config.h>
-#include <linux/compiler.h>
 #include <linux/types.h>
-#include <linux/kernel.h>
 #include <linux/bitops.h>
 #include <linux/string.h>
 
-int bitmap_empty(const unsigned long *bitmap, int bits);
-int bitmap_full(const unsigned long *bitmap, int bits);
-int bitmap_equal(const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits);
+/*
+ * bitmaps provide bit arrays that consume one or more unsigned
+ * longs.  The bitmap interface and available operations are listed
+ * here, in bitmap.h
+ *
+ * Function implementations generic to all architectures are in
+ * lib/bitmap.c.  Functions implementations that are architecture
+ * specific are in various include/asm-<arch>/bitops.h headers
+ * and other arch/<arch> specific files.
+ * 
+ * See lib/bitmap.c for more details.
+ */
+
+/*
+ * The available bitmap operations and their rough meaning in the
+ * case that the bitmap is a single unsigned long are thus:
+ *
+ * bitmap_clear(dst, nbits)			*dst = 0UL
+ * bitmap_fill(dst, nbits)			*dst = ~0UL
+ * bitmap_copy(dst, src, nbits)			*dst = *src
+ * bitmap_and(dst, src1, src2, nbits)		*dst = *src1 & *src2
+ * bitmap_or(dst, src1, src2, nbits)		*dst = *src1 | *src2
+ * bitmap_xor(dst, src1, src2, nbits)		*dst = *src1 ^ *src2
+ * bitmap_andnot(dst, src1, src2, nbits)	*dst = *src1 & ~(*src2)
+ * bitmap_complement(dst, src, nbits)		*dst = ~(*src)
+ * bitmap_equal(src1, src2, nbits)		Are *src1 and *src2 equal?
+ * bitmap_intersects(src1, src2, nbits) 	Do *src1 and *src2 overlap?
+ * bitmap_subset(src1, src2, nbits)		Is *src1 a subset of *src2?
+ * bitmap_empty(src, nbits)			Are all bits zero in *src?
+ * bitmap_full(src, nbits)			Are all bits set in *src?
+ * bitmap_weight(src, nbits)			Hamming Weight: number set bits
+ * bitmap_shift_right(dst, src, n, nbits)	*dst = *src >> n
+ * bitmap_shift_left(dst, src, n, nbits)	*dst = *src << n
+ * bitmap_scnprintf(buf, len, src, nbits)	Print bitmap src to buf
+ * bitmap_parse(ubuf, ulen, dst, nbits)		Parse bitmap dst from buf
+ */
+
+/*
+ * Also the following operations in asm/bitops.h apply to bitmaps.
+ *
+ * set_bit(bit, addr)			*addr |= bit
+ * clear_bit(bit, addr)			*addr &= ~bit
+ * change_bit(bit, 			*addr ^= bit
+ * test_bit(bit, addr)			Is bit set in *addr?
+ * test_and_set_bit(bit, addr)		Set bit and return old value
+ * test_and_clear_bit(bit, addr)	Clear bit and return old value
+ * test_and_change_bit(bit, addr)	Change bit and return old value
+ * find_first_zero_bit(addr, nbits)	Position first zero bit in *addr
+ * find_first_bit(addr, nbits)		Position first set bit in *addr
+ * find_next_zero_bit(addr, nbits, bit)	Position next zero bit in *addr >= bit
+ * find_next_bit(addr, nbits, bit)	Position next set bit in *addr >= bit
+ */
+
+/*
+ * The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used
+ * to declare an array named 'name' of just enough unsigned longs to
+ * contain all bit positions from 0 to 'bits' - 1.
+ */
+
+/*
+ * lib/bitmap.c provides these functions:
+ */
+
+extern int __bitmap_empty(const unsigned long *bitmap, int bits);
+extern int __bitmap_full(const unsigned long *bitmap, int bits);
+extern int __bitmap_equal(const unsigned long *bitmap1,
+                	const unsigned long *bitmap2, int bits);
+extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
+			int bits);
+extern void __bitmap_shift_right(unsigned long *dst,
+                        const unsigned long *src, int shift, int bits);
+extern void __bitmap_shift_left(unsigned long *dst,
+                        const unsigned long *src, int shift, int bits);
+extern void __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern void __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern int __bitmap_intersects(const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern int __bitmap_subset(const unsigned long *bitmap1,
+			const unsigned long *bitmap2, int bits);
+extern int __bitmap_weight(const unsigned long *bitmap, int bits);
+
+extern int bitmap_scnprintf(char *buf, unsigned int len,
+			const unsigned long *src, int nbits);
+extern int bitmap_parse(const char __user *ubuf, unsigned int ulen,
+			unsigned long *dst, int nbits);
+
+#define BITMAP_LAST_WORD_MASK(nbits)					\
+(									\
+	((nbits) % BITS_PER_LONG) ?					\
+		(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL		\
+)				
 
-static inline void bitmap_clear(unsigned long *bitmap, int bits)
+static inline void bitmap_clear(unsigned long *dst, int nbits)
 {
-	CLEAR_BITMAP((unsigned long *)bitmap, bits);
+	if (nbits <= BITS_PER_LONG)
+		*dst = 0UL;
+	else
+		CLEAR_BITMAP(dst, nbits);
 }
 
-static inline void bitmap_fill(unsigned long *bitmap, int bits)
+static inline void bitmap_fill(unsigned long *dst, int nbits)
 {
-	memset(bitmap, 0xff, BITS_TO_LONGS(bits)*sizeof(unsigned long));
+	size_t nlongs = BITS_TO_LONGS(nbits);
+	if (nlongs > 1) {
+		int len = (nlongs - 1) * sizeof(unsigned long);
+		memset(dst, 0xff,  len);
+	}
+	dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
 }
 
-static inline void bitmap_copy(unsigned long *dst,
-			const unsigned long *src, int bits)
+static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
+			int nbits)
 {
-	memcpy(dst, src, BITS_TO_LONGS(bits)*sizeof(unsigned long));
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src;
+	else {
+		int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+		memcpy(dst, src, len);
+	}
 }
 
-void bitmap_shift_right(unsigned long *dst,
-			const unsigned long *src, int shift, int bits);
-void bitmap_shift_left(unsigned long *dst,
-			const unsigned long *src, int shift, int bits);
-void bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-void bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-void bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-void bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-int bitmap_intersects(const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-int bitmap_subset(const unsigned long *bitmap1,
-			const unsigned long *bitmap2, int bits);
-int bitmap_weight(const unsigned long *bitmap, int bits);
-int bitmap_scnprintf(char *buf, unsigned int buflen,
-			const unsigned long *maskp, int bits);
-int bitmap_parse(const char __user *ubuf, unsigned int ubuflen,
-			unsigned long *maskp, int bits);
+static inline void bitmap_and(unsigned long *dst, const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src1 & *src2;
+	else
+		__bitmap_and(dst, src1, src2, nbits);
+}
+
+static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src1 | *src2;
+	else
+		__bitmap_or(dst, src1, src2, nbits);
+}
+
+static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src1 ^ *src2;
+	else
+		__bitmap_xor(dst, src1, src2, nbits);
+}
+
+static inline void bitmap_andnot(unsigned long *dst, const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src1 & ~(*src2);
+	else
+		__bitmap_andnot(dst, src1, src2, nbits);
+}
+
+static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
+			int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits);
+	else
+		__bitmap_complement(dst, src, nbits);
+}
+
+static inline int bitmap_equal(const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
+	else
+		return __bitmap_equal(src1, src2, nbits);
+}
+
+static inline int bitmap_intersects(const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
+	else
+		return __bitmap_intersects(src1, src2, nbits);
+}
+
+static inline int bitmap_subset(const unsigned long *src1,
+			const unsigned long *src2, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
+	else
+		return __bitmap_subset(src1, src2, nbits);
+}
+
+static inline int bitmap_empty(const unsigned long *src, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
+	else
+		return __bitmap_empty(src, nbits);
+}
+
+static inline int bitmap_full(const unsigned long *src, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
+	else
+		return __bitmap_full(src, nbits);
+}
+
+static inline int bitmap_weight(const unsigned long *src, int nbits)
+{
+	return __bitmap_weight(src, nbits);
+}
+
+static inline void bitmap_shift_right(unsigned long *dst,
+			const unsigned long *src, int n, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = *src >> n;
+	else
+		__bitmap_shift_right(dst, src, n, nbits);
+}
+
+static inline void bitmap_shift_left(unsigned long *dst,
+			const unsigned long *src, int n, int nbits)
+{
+	if (nbits <= BITS_PER_LONG)
+		*dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits);
+	else
+		__bitmap_shift_left(dst, src, n, nbits);
+}
 
 #endif /* __ASSEMBLY__ */
 
-#endif /* __LINUX_BITMAP_H */
+#endif /* __LINUX__bitmap_H */
Index: 2.6.5.bitmap/lib/bitmap.c
===================================================================
--- 2.6.5.bitmap.orig/lib/bitmap.c	2004-04-07 21:22:32.000000000 -0700
+++ 2.6.5.bitmap/lib/bitmap.c	2004-04-07 21:23:52.000000000 -0700
@@ -15,7 +15,8 @@
 /*
  * bitmaps provide an array of bits, implemented using an an
  * array of unsigned longs.  The number of valid bits in a
- * given bitmap need not be an exact multiple of BITS_PER_LONG.
+ * given bitmap does _not_ need to be an exact multiple of
+ * BITS_PER_LONG.
  *
  * The possible unused bits in the last, partially used word
  * of a bitmap are 'don't care'.  The implementation makes
@@ -30,11 +31,14 @@
  * if you don't input any bitmaps to these ops that have some
  * unused bits set, then they won't output any set unused bits
  * in output bitmaps.
+ *
+ * The byte ordering of bitmaps is more natural on little
+ * endian architectures.  See the big-endian headers
+ * include/asm-ppc64/bitops.h and include/asm-s390/bitops.h
+ * for the best explanations of this ordering.
  */
 
-#define MAX_BITMAP_BITS	512U	/* for ia64 NR_CPUS maximum */
-
-int bitmap_empty(const unsigned long *bitmap, int bits)
+int __bitmap_empty(const unsigned long *bitmap, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
 	for (k = 0; k < lim; ++k)
@@ -42,14 +46,14 @@
 			return 0;
 
 	if (bits % BITS_PER_LONG)
-		if (bitmap[k] & ((1UL << (bits % BITS_PER_LONG)) - 1))
+		if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
 			return 0;
 
 	return 1;
 }
-EXPORT_SYMBOL(bitmap_empty);
+EXPORT_SYMBOL(__bitmap_empty);
 
-int bitmap_full(const unsigned long *bitmap, int bits)
+int __bitmap_full(const unsigned long *bitmap, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
 	for (k = 0; k < lim; ++k)
@@ -57,14 +61,14 @@
 			return 0;
 
 	if (bits % BITS_PER_LONG)
-		if (~bitmap[k] & ((1UL << (bits % BITS_PER_LONG)) - 1))
+		if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
 			return 0;
 
 	return 1;
 }
-EXPORT_SYMBOL(bitmap_full);
+EXPORT_SYMBOL(__bitmap_full);
 
-int bitmap_equal(const unsigned long *bitmap1,
+int __bitmap_equal(const unsigned long *bitmap1,
 		const unsigned long *bitmap2, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
@@ -73,56 +77,85 @@
 			return 0;
 
 	if (bits % BITS_PER_LONG)
-		if ((bitmap1[k] ^ bitmap2[k]) &
-				((1UL << (bits % BITS_PER_LONG)) - 1))
+		if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
 			return 0;
 
 	return 1;
 }
-EXPORT_SYMBOL(bitmap_equal);
+EXPORT_SYMBOL(__bitmap_equal);
 
-void bitmap_complement(unsigned long *dst, const unsigned long *src, int bits)
+void __bitmap_complement(unsigned long *dst, const unsigned long *src, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
 	for (k = 0; k < lim; ++k)
 		dst[k] = ~src[k];
 
 	if (bits % BITS_PER_LONG)
-		dst[k] = ~src[k] & ((1UL << (bits % BITS_PER_LONG)) - 1);
+		dst[k] = ~src[k] & BITMAP_LAST_WORD_MASK(bits);
 }
-EXPORT_SYMBOL(bitmap_complement);
+EXPORT_SYMBOL(__bitmap_complement);
 
-void bitmap_shift_right(unsigned long *dst,
+void __bitmap_shift_right(unsigned long *dst,
 			const unsigned long *src, int shift, int bits)
 {
-	int k;
-	DECLARE_BITMAP(__shr_tmp, MAX_BITMAP_BITS);
-
-	BUG_ON(bits > MAX_BITMAP_BITS);
-	bitmap_clear(__shr_tmp, bits);
-	for (k = 0; k < bits - shift; ++k)
-		if (test_bit(k + shift, src))
-			set_bit(k, __shr_tmp);
-	bitmap_copy(dst, __shr_tmp, bits);
+	int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG;
+	int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
+	unsigned long mask = (1UL << left) - 1;
+	for (k = 0; off + k < lim; ++k) {
+		unsigned long upper, lower;
+
+		/*
+		 * If shift is not word aligned, take lower rem bits of
+		 * word above and make them the top rem bits of result.
+		 */
+		if (!rem || off + k + 1 >= lim)
+			upper = 0;
+		else {
+			upper = src[off + k + 1];
+			if (off + k + 1 == lim - 1 && left)
+				upper &= mask;
+		}
+		lower = src[off + k];
+		if (left && off + k == lim - 1)
+			lower &= mask;
+		dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem;
+		if (left && k == lim - 1)
+			dst[k] &= mask;
+	}
+	if (off)
+		memset(&dst[lim - off], 0, off*sizeof(unsigned long));
 }
-EXPORT_SYMBOL(bitmap_shift_right);
+EXPORT_SYMBOL(__bitmap_shift_right);
 
-void bitmap_shift_left(unsigned long *dst,
+void __bitmap_shift_left(unsigned long *dst,
 			const unsigned long *src, int shift, int bits)
 {
-	int k;
-	DECLARE_BITMAP(__shl_tmp, MAX_BITMAP_BITS);
-
-	BUG_ON(bits > MAX_BITMAP_BITS);
-	bitmap_clear(__shl_tmp, bits);
-	for (k = bits; k >= shift; --k)
-		if (test_bit(k - shift, src))
-			set_bit(k, __shl_tmp);
-	bitmap_copy(dst, __shl_tmp, bits);
+	int k, lim = BITS_TO_LONGS(bits), left = bits % BITS_PER_LONG;
+	int off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG;
+	for (k = lim - off - 1; k >= 0; --k) {
+		unsigned long upper, lower;
+
+		/*
+		 * If shift is not word aligned, take upper rem bits of
+		 * word below and make them the bottom rem bits of result.
+		 */
+		if (rem && k > 0)
+			lower = src[k - 1];
+		else
+			lower = 0;
+		upper = src[k];
+		if (left && k == lim - 1)
+			upper &= (1UL << left) - 1;
+		dst[k + off] = lower  >> (BITS_PER_LONG - rem) | upper << rem;
+		if (left && k + off == lim - 1)
+			dst[k + off] &= (1UL << left) - 1;
+	}
+	if (off)
+		memset(dst, 0, off*sizeof(unsigned long));
 }
-EXPORT_SYMBOL(bitmap_shift_left);
+EXPORT_SYMBOL(__bitmap_shift_left);
 
-void bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+void __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k;
@@ -131,9 +164,9 @@
 	for (k = 0; k < nr; k++)
 		dst[k] = bitmap1[k] & bitmap2[k];
 }
-EXPORT_SYMBOL(bitmap_and);
+EXPORT_SYMBOL(__bitmap_and);
 
-void bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k;
@@ -142,9 +175,9 @@
 	for (k = 0; k < nr; k++)
 		dst[k] = bitmap1[k] | bitmap2[k];
 }
-EXPORT_SYMBOL(bitmap_or);
+EXPORT_SYMBOL(__bitmap_or);
 
-void bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
+void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k;
@@ -153,9 +186,9 @@
 	for (k = 0; k < nr; k++)
 		dst[k] = bitmap1[k] ^ bitmap2[k];
 }
-EXPORT_SYMBOL(bitmap_xor);
+EXPORT_SYMBOL(__bitmap_xor);
 
-void bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
+void __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k;
@@ -164,9 +197,9 @@
 	for (k = 0; k < nr; k++)
 		dst[k] = bitmap1[k] & ~bitmap2[k];
 }
-EXPORT_SYMBOL(bitmap_andnot);
+EXPORT_SYMBOL(__bitmap_andnot);
 
-int bitmap_intersects(const unsigned long *bitmap1,
+int __bitmap_intersects(const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
@@ -175,14 +208,13 @@
 			return 1;
 
 	if (bits % BITS_PER_LONG)
-		if ((bitmap1[k] & bitmap2[k]) &
-				((1UL << (bits % BITS_PER_LONG)) - 1))
+		if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
 			return 1;
 	return 0;
 }
-EXPORT_SYMBOL(bitmap_intersects);
+EXPORT_SYMBOL(__bitmap_intersects);
 
-int bitmap_subset(const unsigned long *bitmap1,
+int __bitmap_subset(const unsigned long *bitmap1,
 				const unsigned long *bitmap2, int bits)
 {
 	int k, lim = bits/BITS_PER_LONG;
@@ -191,15 +223,14 @@
 			return 0;
 
 	if (bits % BITS_PER_LONG)
-		if ((bitmap1[k] & ~bitmap2[k]) &
-				((1UL << (bits % BITS_PER_LONG)) - 1))
+		if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
 			return 0;
 	return 1;
 }
-EXPORT_SYMBOL(bitmap_subset);
+EXPORT_SYMBOL(__bitmap_subset);
 
 #if BITS_PER_LONG == 32
-int bitmap_weight(const unsigned long *bitmap, int bits)
+int __bitmap_weight(const unsigned long *bitmap, int bits)
 {
 	int k, w = 0, lim = bits/BITS_PER_LONG;
 
@@ -207,13 +238,12 @@
 		w += hweight32(bitmap[k]);
 
 	if (bits % BITS_PER_LONG)
-		w += hweight32(bitmap[k] &
-				((1UL << (bits % BITS_PER_LONG)) - 1));
+		w += hweight32(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
 
 	return w;
 }
 #else
-int bitmap_weight(const unsigned long *bitmap, int bits)
+int __bitmap_weight(const unsigned long *bitmap, int bits)
 {
 	int k, w = 0, lim = bits/BITS_PER_LONG;
 
@@ -221,13 +251,12 @@
 		w += hweight64(bitmap[k]);
 
 	if (bits % BITS_PER_LONG)
-		w += hweight64(bitmap[k] &
-				((1UL << (bits % BITS_PER_LONG)) - 1));
+		w += hweight64(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
 
 	return w;
 }
 #endif
-EXPORT_SYMBOL(bitmap_weight);
+EXPORT_SYMBOL(__bitmap_weight);
 
 /*
  * Bitmap printing & parsing functions: first version by Bill Irwin,
@@ -344,7 +373,7 @@
 		if (nchunks == 0 && chunk == 0)
 			continue;
 
-		bitmap_shift_right(maskp, maskp, CHUNKSZ, nmaskbits);
+		__bitmap_shift_right(maskp, maskp, CHUNKSZ, nmaskbits);
 		*maskp |= chunk;
 		nchunks++;
 		nbits += (nchunks == 1) ? nbits_to_hold_value(chunk) : CHUNKSZ;


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 6a/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (4 preceding siblings ...)
  2004-04-08 19:48 ` Patch 5/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 6b/23 " Paul Jackson
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P6a.unline_find_next_bit_ia64 - Uninline find_next_bit on ia64

	Move the page of code (~700 bytes of instructions)
	for find_next_bit and find_next_zero_bit from inline
	in include/asm-ia64/bitops.h to a real function in
	arch/ia64/lib/bitops.c, leaving a declaration and
	macro wrapper behind.

	The other arch's with almost this same code might want to
	also uninline it: alpha, parisc, ppc, sh, sparc, sparc64.

	These are too big to inline.

Index: 2.6.5.bitmap/include/asm-ia64/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ia64/bitops.h	2004-04-08 03:02:48.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ia64/bitops.h	2004-04-08 03:03:28.000000000 -0700
@@ -11,7 +11,7 @@
 
 #include <linux/compiler.h>
 #include <linux/types.h>
-
+#include <asm/bitops.h>
 #include <asm/intrinsics.h>
 
 /**
@@ -236,7 +236,7 @@
 }
 
 /**
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to set
  * @addr: Address to count from
  *
@@ -359,93 +359,21 @@
 
 #endif /* __KERNEL__ */
 
-/*
- * Find next zero bit in a bitmap reasonably efficiently..
- */
-static inline int
-find_next_zero_bit (void *addr, unsigned long size, unsigned long offset)
-{
-	unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
-	unsigned long result = offset & ~63UL;
-	unsigned long tmp;
-
-	if (offset >= size)
-		return size;
-	size -= result;
-	offset &= 63UL;
-	if (offset) {
-		tmp = *(p++);
-		tmp |= ~0UL >> (64-offset);
-		if (size < 64)
-			goto found_first;
-		if (~tmp)
-			goto found_middle;
-		size -= 64;
-		result += 64;
-	}
-	while (size & ~63UL) {
-		if (~(tmp = *(p++)))
-			goto found_middle;
-		result += 64;
-		size -= 64;
-	}
-	if (!size)
-		return result;
-	tmp = *p;
-found_first:
-	tmp |= ~0UL << size;
-	if (tmp == ~0UL)		/* any bits zero? */
-		return result + size;	/* nope */
-found_middle:
-	return result + ffz(tmp);
-}
+extern int __find_next_zero_bit (void *addr, unsigned long size, \
+			unsigned long offset);
+extern int __find_next_bit(const void *addr, unsigned long size, \
+			unsigned long offset);
+
+#define find_next_zero_bit(addr, size, offset) \
+			__find_next_zero_bit((addr), (size), (offset))
+#define find_next_bit(addr, size, offset) \
+			__find_next_bit((addr), (size), (offset))
 
 /*
  * The optimizer actually does good code for this case..
  */
 #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
 
-/*
- * Find next bit in a bitmap reasonably efficiently..
- */
-static inline int
-find_next_bit(const void *addr, unsigned long size, unsigned long offset)
-{
-	unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
-	unsigned long result = offset & ~63UL;
-	unsigned long tmp;
-
-	if (offset >= size)
-		return size;
-	size -= result;
-	offset &= 63UL;
-	if (offset) {
-		tmp = *(p++);
-		tmp &= ~0UL << offset;
-		if (size < 64)
-			goto found_first;
-		if (tmp)
-			goto found_middle;
-		size -= 64;
-		result += 64;
-	}
-	while (size & ~63UL) {
-		if ((tmp = *(p++)))
-			goto found_middle;
-		result += 64;
-		size -= 64;
-	}
-	if (!size)
-		return result;
-	tmp = *p;
-  found_first:
-	tmp &= ~0UL >> (64-size);
-	if (tmp == 0UL)		/* Are any bits set? */
-		return result + size; /* Nope. */
-  found_middle:
-	return result + __ffs(tmp);
-}
-
 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
 
 #ifdef __KERNEL__
Index: 2.6.5.bitmap/include/asm-cris/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-cris/bitops.h	2004-04-08 03:02:48.000000000 -0700
+++ 2.6.5.bitmap/include/asm-cris/bitops.h	2004-04-08 03:03:28.000000000 -0700
@@ -169,7 +169,7 @@
 	return retval;
 }
 /**
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to change
  * @addr: Address to count from
  *
Index: 2.6.5.bitmap/include/asm-i386/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/bitops.h	2004-04-08 03:02:48.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/bitops.h	2004-04-08 03:03:28.000000000 -0700
@@ -212,7 +212,7 @@
 }
 
 /**
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to change
  * @addr: Address to count from
  *
Index: 2.6.5.bitmap/include/asm-mips/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-mips/bitops.h	2004-04-08 03:02:48.000000000 -0700
+++ 2.6.5.bitmap/include/asm-mips/bitops.h	2004-04-08 03:03:28.000000000 -0700
@@ -296,7 +296,7 @@
 }
 
 /*
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to change
  * @addr: Address to count from
  *
@@ -567,7 +567,7 @@
 }
 
 /*
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to change
  * @addr: Address to count from
  *
Index: 2.6.5.bitmap/include/asm-x86_64/bitops.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/bitops.h	2004-04-08 03:02:48.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/bitops.h	2004-04-08 03:03:28.000000000 -0700
@@ -204,7 +204,7 @@
 }
 
 /**
- * test_and_change_bit - Change a bit and return its new value
+ * test_and_change_bit - Change a bit and return its old value
  * @nr: Bit to change
  * @addr: Address to count from
  *
Index: 2.6.5.bitmap/arch/ia64/lib/bitop.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/lib/bitop.c	2004-04-08 03:03:18.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/lib/bitop.c	2004-04-08 03:03:28.000000000 -0700
@@ -0,0 +1,88 @@
+#include <linux/compiler.h>
+#include <linux/types.h>
+#include <asm/intrinsics.h>
+#include <linux/module.h>
+#include <asm/bitops.h>
+
+/*
+ * Find next zero bit in a bitmap reasonably efficiently..
+ */
+
+int __find_next_zero_bit (void *addr, unsigned long size, unsigned long offset)
+{
+	unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
+	unsigned long result = offset & ~63UL;
+	unsigned long tmp;
+
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset &= 63UL;
+	if (offset) {
+		tmp = *(p++);
+		tmp |= ~0UL >> (64-offset);
+		if (size < 64)
+			goto found_first;
+		if (~tmp)
+			goto found_middle;
+		size -= 64;
+		result += 64;
+	}
+	while (size & ~63UL) {
+		if (~(tmp = *(p++)))
+			goto found_middle;
+		result += 64;
+		size -= 64;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
+found_first:
+	tmp |= ~0UL << size;
+	if (tmp == ~0UL)		/* any bits zero? */
+		return result + size;	/* nope */
+found_middle:
+	return result + ffz(tmp);
+}
+EXPORT_SYMBOL(__find_next_zero_bit);
+
+/*
+ * Find next bit in a bitmap reasonably efficiently..
+ */
+int __find_next_bit(const void *addr, unsigned long size, unsigned long offset)
+{
+	unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
+	unsigned long result = offset & ~63UL;
+	unsigned long tmp;
+
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset &= 63UL;
+	if (offset) {
+		tmp = *(p++);
+		tmp &= ~0UL << offset;
+		if (size < 64)
+			goto found_first;
+		if (tmp)
+			goto found_middle;
+		size -= 64;
+		result += 64;
+	}
+	while (size & ~63UL) {
+		if ((tmp = *(p++)))
+			goto found_middle;
+		result += 64;
+		size -= 64;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
+  found_first:
+	tmp &= ~0UL >> (64-size);
+	if (tmp == 0UL)		/* Are any bits set? */
+		return result + size; /* Nope. */
+  found_middle:
+	return result + __ffs(tmp);
+}
+EXPORT_SYMBOL(__find_next_bit);
Index: 2.6.5.bitmap/arch/ia64/lib/Makefile
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/lib/Makefile	2004-04-08 03:01:12.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/lib/Makefile	2004-04-08 03:03:28.000000000 -0700
@@ -6,7 +6,7 @@
 
 lib-y := __divsi3.o __udivsi3.o __modsi3.o __umodsi3.o			\
 	__divdi3.o __udivdi3.o __moddi3.o __umoddi3.o			\
-	checksum.o clear_page.o csum_partial_copy.o copy_page.o		\
+	bitop.o checksum.o clear_page.o csum_partial_copy.o copy_page.o	\
 	clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o	\
 	flush.o ip_fast_csum.o do_csum.o				\
 	memset.o strlen.o swiotlb.o


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 6b/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (5 preceding siblings ...)
  2004-04-08 19:49 ` Patch 6a/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 6c/23 " Paul Jackson
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P6b.new_cpumask.h - Rewrite cpumask.h to use bitmap directly.

	Major rewrite of cpumask to use a single implementation,
	as a struct-wrapped bitmap.

	This patch leaves some 26 include/asm-*/cpumask*.h
	header files orphaned - to be removed next patch.

	Some nine cpumask macros for const variants and to
	coerce and promote between an unsigned long and a
	cpumask are obsolete.  Simple emulation wrappers are
	provided in this patch, which can be removed once each
	of the 3 archs (i386, ppc64, x86_64) using them are
	recoded in follow-on patches to not need them.

	The CPU_MASK_ALL macro now avoids leaving possible
	garbage one bits in any unused portion of the high word.

	An inproved comment lists all available operators, for
	convenient browsing.

Index: 2.6.5.bitmap/include/linux/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/cpumask.h	2004-04-08 09:39:25.000000000 -0700
+++ 2.6.5.bitmap/include/linux/cpumask.h	2004-04-08 09:39:29.000000000 -0700
@@ -1,44 +1,330 @@
 #ifndef __LINUX_CPUMASK_H
 #define __LINUX_CPUMASK_H
 
+/*
+ * Cpumasks provide a bitmap suitable for representing the
+ * set of CPU's in a system, one bit position per CPU number.
+ *
+ * See detailed comments in the file linux/bitmap.h describing the
+ * data type on which these cpumasks are based.
+ *
+ * For details of cpumask_scnprintf() and cpumask_parse(),
+ * see bitmap_scnprintf() and bitmap_parse() in lib/bitmap.c.
+ *
+ * The available cpumask operations are:
+ *
+ * void cpu_set(cpu, mask)		turn on bit 'cpu' in mask
+ * void cpu_clear(cpu, mask)		turn off bit 'cpu' in mask
+ * void cpus_setall(mask)		set all bits
+ * void cpus_clear(mask)		clear all bits
+ * int cpu_isset(cpu, mask)		true iff bit 'cpu' set in mask
+ * int cpu_test_and_set(cpu, mask)	test and set bit 'cpu' in mask
+ *
+ * void cpus_and(dst, src1, src2)	dst = src1 & src2  [intersection]
+ * void cpus_or(dst, src1, src2)	dst = src1 | src2  [union]
+ * void cpus_xor(dst, src1, src2)	dst = src1 ^ src2
+ * void cpus_andnot(dst, src1, src2)	dst = src1 & ~src2
+ * void cpus_complement(dst, src)	dst = ~src
+ *
+ * int cpus_equal(mask1, mask2)		Does mask1 == mask2?
+ * int cpus_intersects(mask1, mask2)	Do mask1 and mask2 intersect?
+ * int cpus_subset(mask1, mask2)	Is mask1 a subset of mask2?
+ * int cpus_empty(mask)			Is mask empty (no bits sets)?
+ * int cpus_full(mask)			Is mask full (all bits sets)?
+ * int cpus_weight(mask)		Hamming weigh - number of set bits
+ *
+ * void cpus_shift_right(dst, src, n)	Shift right
+ * void cpus_shift_left(dst, src, n)	Shift left
+ *
+ * int first_cpu(mask)			Number lowest set bit, or NR_CPUS
+ * int next_cpu(cpu, mask)		Next cpu past 'cpu', or NR_CPUS
+ *
+ * cpumask_t cpumask_of_cpu(cpu)	Return cpumask with bit 'cpu' set
+ * CPU_MASK_ALL				Initializer - all bits set
+ * CPU_MASK_NONE			Initializer - no bits set
+ * unsigned long *cpus_addr(mask)	Array of unsigned long's in mask
+ *
+ * int cpumask_scnprintf(buf, len, mask) Format cpumask for printing
+ * int cpumask_parse(ubuf, ulen, mask)	Parse ascii string as cpumask
+ *
+ * int num_online_cpus()		Number of online CPUs
+ * int num_possible_cpus()		Number of all possible CPUs
+ * int cpu_online(cpu)			Is some cpu online?
+ * int cpu_possible(cpu)		Is some cpu possible?
+ * void cpu_set_online(cpu)		set cpu in cpu_online_map
+ * void cpu_set_offline(cpu)		clear cpu in cpu_online_map
+ * int any_online_cpu(mask)		First online cpu in mask
+ *
+ * for_each_cpu_mask(cpu, mask)		for-loop cpu over mask
+ * for_each_cpu(cpu)			for-loop cpu over cpu_possible_map
+ * for_each_online_cpu(cpu)		for-loop cpu over cpu_online_map
+ */
+
 #include <linux/threads.h>
 #include <linux/bitmap.h>
-#include <asm/cpumask.h>
 #include <asm/bug.h>
 
-#ifdef CONFIG_SMP
+typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
+extern cpumask_t _unused_cpumask_arg_;
 
-extern cpumask_t cpu_online_map;
-extern cpumask_t cpu_possible_map;
+#define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
+static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
+{
+	if (cpu < NR_CPUS)
+		set_bit(cpu, dstp->bits);
+}
+
+#define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
+static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
+{
+	clear_bit(cpu, dstp->bits);
+}
+
+#define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
+static inline void __cpus_setall(cpumask_t *dstp, int nbits)
+{
+	bitmap_fill(dstp->bits, nbits);
+}
+
+#define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
+static inline void __cpus_clear(cpumask_t *dstp, int nbits)
+{
+	bitmap_clear(dstp->bits, nbits);
+}
+
+#define cpu_isset(cpu, cpumask) __cpu_isset((cpu), &(cpumask))
+static inline int __cpu_isset(int cpu, const volatile cpumask_t *addr)
+{
+	return test_bit(cpu, addr->bits);
+}
+
+#define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
+static inline int __cpu_test_and_set(int cpu, cpumask_t *addr)
+{
+	if (cpu < NR_CPUS)
+		return test_and_set_bit(cpu, addr->bits);
+	else
+		return 0;
+}
+
+#define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
+static inline void __cpus_and(cpumask_t *dstp, cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
+static inline void __cpus_or(cpumask_t *dstp, cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
+static inline void __cpus_xor(cpumask_t *dstp, cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_andnot(dst, src1, src2) \
+				__cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
+static inline void __cpus_andnot(cpumask_t *dstp, cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_complement(dst, src) __cpus_complement(&(dst), &(src), NR_CPUS)
+static inline void __cpus_complement(cpumask_t *dstp,
+					cpumask_t *srcp, int nbits)
+{
+	bitmap_complement(dstp->bits, srcp->bits, nbits);
+}
+
+#define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
+static inline int __cpus_equal(cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	return bitmap_equal(src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
+static inline int __cpus_intersects(cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	return bitmap_intersects(src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
+static inline int __cpus_subset(cpumask_t *src1p,
+					cpumask_t *src2p, int nbits)
+{
+	return bitmap_subset(src1p->bits, src2p->bits, nbits);
+}
+
+#define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
+static inline int __cpus_empty(cpumask_t *srcp, int nbits)
+{
+	return bitmap_empty(srcp->bits, nbits);
+}
+
+#define cpus_full(cpumask) __cpus_full(&(cpumask), NR_CPUS)
+static inline int __cpus_full(cpumask_t *srcp, int nbits)
+{
+	return bitmap_full(srcp->bits, nbits);
+}
+
+#define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
+static inline int __cpus_weight(cpumask_t *srcp, int nbits)
+{
+	return bitmap_weight(srcp->bits, nbits);
+}
+
+#define cpus_shift_right(dst, src, n) \
+			__cpus_shift_right(&(dst), &(src), (n), NR_CPUS)
+static inline void __cpus_shift_right(cpumask_t *dstp,
+					cpumask_t *srcp, int n, int nbits)
+{
+	bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
+}
+
+#define cpus_shift_left(dst, src, n) \
+			__cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
+static inline void __cpus_shift_left(cpumask_t *dstp,
+					cpumask_t *srcp, int n, int nbits)
+{
+	bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
+}
+
+#define first_cpu(src) __first_cpu(&(src), NR_CPUS)
+static inline int __first_cpu(cpumask_t *srcp, int nbits)
+{
+	return find_first_bit(srcp->bits, nbits);
+}
 
-#define num_online_cpus()		cpus_weight(cpu_online_map)
-#define num_possible_cpus()		cpus_weight(cpu_possible_map)
-#define cpu_online(cpu)			cpu_isset(cpu, cpu_online_map)
-#define cpu_possible(cpu)		cpu_isset(cpu, cpu_possible_map)
-
-#define for_each_cpu_mask(cpu, mask)					\
-	for (cpu = first_cpu_const(mk_cpumask_const(mask));		\
-		cpu < NR_CPUS;						\
-		cpu = next_cpu_const(cpu, mk_cpumask_const(mask)))
+#define next_cpu(n, src) __next_cpu((n), &(src), NR_CPUS)
+static inline int __next_cpu(int n, cpumask_t *srcp, int nbits)
+{
+	return find_next_bit(srcp->bits, nbits, n+1);
+}
+
+#define cpumask_of_cpu(cpu)						\
+({									\
+	typeof(_unused_cpumask_arg_) m;					\
+	int c = cpu;							\
+	if (sizeof(m) == sizeof(unsigned long)) {			\
+		if (c < NR_CPUS)					\
+			m.bits[0] = 1UL<<c;				\
+	} else {							\
+		cpus_clear(m);						\
+		cpu_set(c, m);						\
+	}								\
+	m;								\
+})
+
+#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
+
+#if NR_CPUS <= BITS_PER_LONG
+
+#define CPU_MASK_ALL							\
+{ {									\
+	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD			\
+} }
 
-#define for_each_cpu(cpu) for_each_cpu_mask(cpu, cpu_possible_map)
-#define for_each_online_cpu(cpu) for_each_cpu_mask(cpu, cpu_online_map)
 #else
-#define	cpu_online_map			cpumask_of_cpu(0)
-#define	cpu_possible_map		cpumask_of_cpu(0)
-#define num_online_cpus()		1
-#define num_possible_cpus()		1
-#define cpu_online(cpu)			({ BUG_ON((cpu) != 0); 1; })
-#define cpu_possible(cpu)		({ BUG_ON((cpu) != 0); 1; })
 
-#define for_each_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
-#define for_each_online_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
+#define CPU_MASK_ALL							\
+{ {									\
+	[0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL,			\
+	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD			\
+} }
+
 #endif
 
-#define cpumask_scnprintf(buf, buflen, map)				\
-	bitmap_scnprintf(buf, buflen, cpus_addr(map), NR_CPUS)
+#define CPU_MASK_NONE							\
+{ {									\
+	[0 ... BITS_TO_LONGS(NR_CPUS)-1] =  0UL				\
+} }
+
+#define cpus_addr(src) ((src).bits)
+
+#define cpumask_scnprintf(buf, len, src) \
+			__cpumask_scnprintf((buf), (len), &(src), NR_CPUS)
+static inline int __cpumask_scnprintf(char *buf, int len,
+					cpumask_t *srcp, int nbits)
+{
+	return bitmap_scnprintf(buf, len, srcp->bits, nbits);
+}
+
+#define cpumask_parse(ubuf, ulen, src) \
+			__cpumask_parse((ubuf), (ulen), &(src), NR_CPUS)
+static inline int __cpumask_parse(const char __user *buf, int len,
+					cpumask_t *srcp, int nbits)
+{
+	return bitmap_parse(buf, len, srcp->bits, nbits);
+}
+
+/*
+ * The following particular system cpumasks and operations
+ * on them manage all (possible) and online cpus.
+ */
+
+extern cpumask_t cpu_online_map;
+extern cpumask_t cpu_possible_map;
+
+#ifdef CONFIG_SMP
+
+#define num_online_cpus()	     cpus_weight(cpu_online_map)
+#define num_possible_cpus()	     cpus_weight(cpu_possible_map)
+#define cpu_online(cpu)		     cpu_isset((cpu), cpu_online_map)
+#define cpu_possible(cpu)	     cpu_isset((cpu), cpu_possible_map)
+#define cpu_set_online(cpu)	     cpu_set((cpu), cpu_online_map)
+#define cpu_set_offline(cpu)	     cpu_clear((cpu), cpu_online_map)
+
+#define any_online_cpu(mask)			\
+({						\
+	cpumask_t m;				\
+	cpus_and(m, mask, cpu_online_map);	\
+	first_cpu(m);				\
+})
+
+#define for_each_cpu_mask(cpu, mask)		\
+	for (cpu = first_cpu(mask);		\
+		cpu < NR_CPUS;			\
+		cpu = next_cpu(cpu, mask))
+
+#else /* !CONFIG_SMP */
+
+#define num_online_cpus()	     1
+#define num_possible_cpus()	     1
+#define cpu_online(cpu)		     ({ BUG_ON((cpu) != 0); 1; })
+#define cpu_possible(cpu)	     ({ BUG_ON((cpu) != 0); 1; })
+#define cpu_set_online(cpu)	     ({ BUG_ON((cpu) != 0); })
+#define cpu_set_offline(cpu)	     ({ BUG(); })
+
+#define any_online_cpu(mask)	     0
+
+#define for_each_cpu_mask(cpu, mask) for (cpu = 0; cpu < 1; cpu++)
+
+#endif /* CONFIG_SMP */
+
+#define for_each_cpu(cpu)	     \
+			for_each_cpu_mask(cpu, cpu_possible_map)
+#define for_each_online_cpu(cpu)     \
+			for_each_cpu_mask(cpu, cpu_online_map)
 
-#define cpumask_parse(buf, buflen, map)					\
-	bitmap_parse(buf, buflen, cpus_addr(map), NR_CPUS)
+/* Begin obsolete cpumask operator emulation */
+#define cpu_isset_const(a,b) cpu_isset(a,b)
+#define cpumask_const_t cpumask_t
+#define cpus_coerce(m) (cpus_addr(m)[0])
+#define cpus_coerce_const cpus_coerce
+#define cpus_promote(x) ({ cpumask_t m; m.bits[0] = x; m; })
+#define cpus_weight_const cpus_weight
+#define first_cpu_const first_cpu
+#define mk_cpumask_const(x) x
+#define next_cpu_const next_cpu
+/* End of obsolete cpumask operator emulation */
 
 #endif /* __LINUX_CPUMASK_H */
Index: 2.6.5.bitmap/kernel/sched.c
===================================================================
--- 2.6.5.bitmap.orig/kernel/sched.c	2004-04-08 09:39:25.000000000 -0700
+++ 2.6.5.bitmap/kernel/sched.c	2004-04-08 09:39:29.000000000 -0700
@@ -2349,6 +2349,11 @@
 	return retval;
 }
 
+#ifndef CONFIG_SMP
+cpumask_t cpu_online_map = CPU_MASK_ALL;
+cpumask_t cpu_possible_map = CPU_MASK_ALL;
+#endif
+
 /**
  * sys_sched_getaffinity - get the cpu affinity of a process
  * @pid: pid of the process


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 6c/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (6 preceding siblings ...)
  2004-04-08 19:49 ` Patch 6b/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 7/23 " Paul Jackson
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P6c.remove_old_cpumask_files - Remove 26 no longer used cpumask headers.
	With the cpumask rewrite in the previous patch, these
	various include/asm-*/cpumask*.h headers are no longer used.

Index: 2.6.5.bitmap/include/asm-alpha/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-alpha/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-alpha/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_ALPHA_CPUMASK_H
-#define _ASM_ALPHA_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ALPHA_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-arm/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-arm/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-arm/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_ARM_CPUMASK_H
-#define _ASM_ARM_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ARM_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-arm26/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-arm26/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-arm26/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_ARM26_CPUMASK_H
-#define _ASM_ARM26_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ARM26_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-cris/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-cris/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-cris/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_CRIS_CPUMASK_H
-#define _ASM_CRIS_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_CRIS_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,40 +0,0 @@
-#ifndef __ASM_GENERIC_CPUMASK_H
-#define __ASM_GENERIC_CPUMASK_H
-
-#include <linux/config.h>
-#include <linux/kernel.h>
-#include <linux/threads.h>
-#include <linux/types.h>
-#include <linux/bitmap.h>
-
-#if NR_CPUS > BITS_PER_LONG && NR_CPUS != 1
-#define CPU_ARRAY_SIZE		BITS_TO_LONGS(NR_CPUS)
-
-struct cpumask
-{
-	unsigned long mask[CPU_ARRAY_SIZE];
-};
-
-typedef struct cpumask cpumask_t;
-
-#else
-typedef unsigned long cpumask_t;
-#endif
-
-#ifdef CONFIG_SMP
-#if NR_CPUS > BITS_PER_LONG
-#include <asm-generic/cpumask_array.h>
-#else
-#include <asm-generic/cpumask_arith.h>
-#endif
-#else
-#include <asm-generic/cpumask_up.h>
-#endif
-
-#if NR_CPUS <= 4*BITS_PER_LONG
-#include <asm-generic/cpumask_const_value.h>
-#else
-#include <asm-generic/cpumask_const_reference.h>
-#endif
-
-#endif /* __ASM_GENERIC_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask_arith.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_arith.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_arith.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,49 +0,0 @@
-#ifndef __ASM_GENERIC_CPUMASK_ARITH_H
-#define __ASM_GENERIC_CPUMASK_ARITH_H
-
-/*
- * 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)
-#define cpus_clear(map)			do { map = 0; } while (0)
-#define cpus_complement(map)		do { map = ~(map); } while (0)
-#define cpus_equal(map1, map2)		((map1) == (map2))
-#define cpus_empty(map)			((map) == 0)
-#define cpus_addr(map)			(&(map))
-
-#if BITS_PER_LONG == 32
-#define cpus_weight(map)		hweight32(map)
-#elif BITS_PER_LONG == 64
-#define cpus_weight(map)		hweight64(map)
-#endif
-
-#define cpus_shift_right(dst, src, n)	do { dst = (src) >> (n); } while (0)
-#define cpus_shift_left(dst, src, n)	do { dst = (src) << (n); } while (0)
-
-#define any_online_cpu(map)			\
-({						\
-	cpumask_t __tmp__;			\
-	cpus_and(__tmp__, map, cpu_online_map);	\
-	__tmp__ ? first_cpu(__tmp__) : NR_CPUS;	\
-})
-
-#define CPU_MASK_ALL	(~((cpumask_t)0) >> (8*sizeof(cpumask_t) - NR_CPUS))
-#define CPU_MASK_NONE	((cpumask_t)0)
-
-/* only ever use this for things that are _never_ used on large boxen */
-#define cpus_coerce(map)		((unsigned long)(map))
-#define cpus_promote(map)		({ map; })
-#define cpumask_of_cpu(cpu)		({ ((cpumask_t)1) << (cpu); })
-
-#define first_cpu(map)			__ffs(map)
-#define next_cpu(cpu, map)		find_next_bit(&(map), NR_CPUS, cpu + 1)
-
-#endif /* __ASM_GENERIC_CPUMASK_ARITH_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask_array.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_array.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_array.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,54 +0,0 @@
-#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)
-#define cpu_clear(cpu, map)		clear_bit(cpu, (map).mask)
-#define cpu_isset(cpu, map)		test_bit(cpu, (map).mask)
-#define cpu_test_and_set(cpu, map)	test_and_set_bit(cpu, (map).mask)
-
-#define cpus_and(dst,src1,src2)	bitmap_and((dst).mask,(src1).mask, (src2).mask, NR_CPUS)
-#define cpus_or(dst,src1,src2)	bitmap_or((dst).mask, (src1).mask, (src2).mask, NR_CPUS)
-#define cpus_clear(map)		bitmap_clear((map).mask, NR_CPUS)
-#define cpus_complement(map)	bitmap_complement((map).mask, (map).mask, NR_CPUS)
-#define cpus_equal(map1, map2)	bitmap_equal((map1).mask, (map2).mask, NR_CPUS)
-#define cpus_empty(map)		bitmap_empty(map.mask, NR_CPUS)
-#define cpus_addr(map)		((map).mask)
-#define cpus_weight(map)		bitmap_weight((map).mask, NR_CPUS)
-#define cpus_shift_right(d, s, n)	bitmap_shift_right((d).mask, (s).mask, n, NR_CPUS)
-#define cpus_shift_left(d, s, n)	bitmap_shift_left((d).mask, (s).mask, n, NR_CPUS)
-#define first_cpu(map)		find_first_bit((map).mask, NR_CPUS)
-#define next_cpu(cpu, map)	find_next_bit((map).mask, NR_CPUS, cpu + 1)
-
-/* only ever use this for things that are _never_ used on large boxen */
-#define cpus_coerce(map)	((map).mask[0])
-#define cpus_promote(map)	({ cpumask_t __cpu_mask = CPU_MASK_NONE;\
-					__cpu_mask.mask[0] = map;	\
-					__cpu_mask;			\
-				})
-#define cpumask_of_cpu(cpu)	({ cpumask_t __cpu_mask = CPU_MASK_NONE;\
-					cpu_set(cpu, __cpu_mask);	\
-					__cpu_mask;			\
-				})
-#define any_online_cpu(map)			\
-({						\
-	cpumask_t __tmp__;			\
-	cpus_and(__tmp__, map, cpu_online_map);	\
-	find_first_bit(__tmp__.mask, NR_CPUS);	\
-})
-
-
-/*
- * um, these need to be usable as static initializers
- */
-#define CPU_MASK_ALL	{ {[0 ... CPU_ARRAY_SIZE-1] = ~0UL} }
-#define CPU_MASK_NONE	{ {[0 ... CPU_ARRAY_SIZE-1] =  0UL} }
-
-#endif /* __ASM_GENERIC_CPUMASK_ARRAY_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask_const_reference.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_const_reference.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_const_reference.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,29 +0,0 @@
-#ifndef __ASM_GENERIC_CPUMASK_CONST_REFERENCE_H
-#define __ASM_GENERIC_CPUMASK_CONST_REFERENCE_H
-
-struct cpumask_ref {
-	const cpumask_t *val;
-};
-
-typedef const struct cpumask_ref cpumask_const_t;
-
-#define mk_cpumask_const(map)		((cpumask_const_t){ &(map) })
-#define cpu_isset_const(cpu, map)	cpu_isset(cpu, *(map).val)
-
-#define cpus_and_const(dst,src1,src2)	cpus_and(dst,*(src1).val,*(src2).val)
-#define cpus_or_const(dst,src1,src2)	cpus_or(dst,*(src1).val,*(src2).val)
-
-#define cpus_equal_const(map1, map2)	cpus_equal(*(map1).val, *(map2).val)
-
-#define cpus_copy_const(map1, map2)	bitmap_copy((map1).mask, (map2).val->mask, NR_CPUS)
-
-#define cpus_empty_const(map)		cpus_empty(*(map).val)
-#define cpus_weight_const(map)		cpus_weight(*(map).val)
-#define first_cpu_const(map)		first_cpu(*(map).val)
-#define next_cpu_const(cpu, map)	next_cpu(cpu, *(map).val)
-
-/* only ever use this for things that are _never_ used on large boxen */
-#define cpus_coerce_const(map)		cpus_coerce(*(map).val)
-#define any_online_cpu_const(map)	any_online_cpu(*(map).val)
-
-#endif /* __ASM_GENERIC_CPUMASK_CONST_REFERENCE_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask_const_value.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_const_value.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_const_value.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,21 +0,0 @@
-#ifndef __ASM_GENERIC_CPUMASK_CONST_VALUE_H
-#define __ASM_GENERIC_CPUMASK_CONST_VALUE_H
-
-typedef const cpumask_t cpumask_const_t;
-
-#define mk_cpumask_const(map)		(map)
-#define cpu_isset_const(cpu, map)	cpu_isset(cpu, map)
-#define cpus_and_const(dst,src1,src2)	cpus_and(dst, src1, src2)
-#define cpus_or_const(dst,src1,src2)	cpus_or(dst, src1, src2)
-#define cpus_equal_const(map1, map2)	cpus_equal(map1, map2)
-#define cpus_empty_const(map)		cpus_empty(map)
-#define cpus_copy_const(map1, map2)	do { map1 = (cpumask_t)map2; } while (0)
-#define cpus_weight_const(map)		cpus_weight(map)
-#define first_cpu_const(map)		first_cpu(map)
-#define next_cpu_const(cpu, map)	next_cpu(cpu, map)
-
-/* only ever use this for things that are _never_ used on large boxen */
-#define cpus_coerce_const(map)		cpus_coerce(map)
-#define any_online_cpu_const(map)	any_online_cpu(map)
-
-#endif /* __ASM_GENERIC_CPUMASK_CONST_VALUE_H */
Index: 2.6.5.bitmap/include/asm-generic/cpumask_up.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-generic/cpumask_up.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-generic/cpumask_up.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,59 +0,0 @@
-#ifndef __ASM_GENERIC_CPUMASK_UP_H
-#define __ASM_GENERIC_CPUMASK_UP_H
-
-#define cpus_coerce(map)	(map)
-
-#define cpu_set(cpu, map)		do { (void)(cpu); cpus_coerce(map) = 1UL; } while (0)
-#define cpu_clear(cpu, map)		do { (void)(cpu); cpus_coerce(map) = 0UL; } while (0)
-#define cpu_isset(cpu, map)		((void)(cpu), cpus_coerce(map) != 0UL)
-#define cpu_test_and_set(cpu, map)	((void)(cpu), test_and_set_bit(0, &(map)))
-
-#define cpus_and(dst, src1, src2)					\
-	do {								\
-		if (cpus_coerce(src1) && cpus_coerce(src2))		\
-			cpus_coerce(dst) = 1UL;				\
-		else							\
-			cpus_coerce(dst) = 0UL;				\
-	} while (0)
-
-#define cpus_or(dst, src1, src2)					\
-	do {								\
-		if (cpus_coerce(src1) || cpus_coerce(src2))		\
-			cpus_coerce(dst) = 1UL;				\
-		else							\
-			cpus_coerce(dst) = 0UL;				\
-	} while (0)
-
-#define cpus_clear(map)			do { cpus_coerce(map) = 0UL; } while (0)
-
-#define cpus_complement(map)						\
-	do {								\
-		cpus_coerce(map) = !cpus_coerce(map);			\
-	} while (0)
-
-#define cpus_equal(map1, map2)		(cpus_coerce(map1) == cpus_coerce(map2))
-#define cpus_empty(map)			(cpus_coerce(map) == 0UL)
-#define cpus_addr(map)			(&(map))
-#define cpus_weight(map)		(cpus_coerce(map) ? 1UL : 0UL)
-#define cpus_shift_right(d, s, n)	do { cpus_coerce(d) = 0UL; } while (0)
-#define cpus_shift_left(d, s, n)	do { cpus_coerce(d) = 0UL; } while (0)
-#define first_cpu(map)			(cpus_coerce(map) ? 0 : 1)
-#define next_cpu(cpu, map)		1
-
-/* only ever use this for things that are _never_ used on large boxen */
-#define cpus_promote(map)						\
-	({								\
-		cpumask_t __tmp__;					\
-		cpus_coerce(__tmp__) = map;				\
-		__tmp__;						\
-	})
-#define cpumask_of_cpu(cpu)		((void)(cpu), cpus_promote(1))
-#define any_online_cpu(map)		(cpus_coerce(map) ? 0 : 1)
-
-/*
- * um, these need to be usable as static initializers
- */
-#define CPU_MASK_ALL	1UL
-#define CPU_MASK_NONE	0UL
-
-#endif /* __ASM_GENERIC_CPUMASK_UP_H */
Index: 2.6.5.bitmap/include/asm-h8300/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-h8300/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-h8300/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_H8300_CPUMASK_H
-#define _ASM_H8300_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_H8300_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-i386/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_I386_CPUMASK_H
-#define _ASM_I386_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_I386_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-m68k/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-m68k/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-m68k/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_M68K_CPUMASK_H
-#define _ASM_M68K_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_M68K_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-m68knommu/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-m68knommu/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-m68knommu/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_M68KNOMMU_CPUMASK_H
-#define _ASM_M68KNOMMU_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_M68KNOMMU_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-mips/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-mips/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-mips/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_MIPS_CPUMASK_H
-#define _ASM_MIPS_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_MIPS_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-parisc/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-parisc/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-parisc/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_PARISC_CPUMASK_H
-#define _ASM_PARISC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PARISC_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-ppc/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ppc/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ppc/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_PPC_CPUMASK_H
-#define _ASM_PPC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PPC_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-ppc64/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ppc64/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ppc64/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_PPC64_CPUMASK_H
-#define _ASM_PPC64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PPC64_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-s390/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-s390/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-s390/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_S390_CPUMASK_H
-#define _ASM_S390_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_S390_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-sh/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-sh/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-sh/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_SH_CPUMASK_H
-#define _ASM_SH_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SH_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-sparc/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-sparc/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-sparc/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_SPARC_CPUMASK_H
-#define _ASM_SPARC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SPARC_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-sparc64/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-sparc64/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-sparc64/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_SPARC64_CPUMASK_H
-#define _ASM_SPARC64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SPARC64_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-um/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-um/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-um/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_UM_CPUMASK_H
-#define _ASM_UM_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_UM_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-v850/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-v850/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-v850/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_V850_CPUMASK_H
-#define _ASM_V850_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_V850_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-x86_64/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_X86_64_CPUMASK_H
-#define _ASM_X86_64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_X86_64_CPUMASK_H */
Index: 2.6.5.bitmap/include/asm-ia64/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ia64/cpumask.h	2004-04-08 01:08:17.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ia64/cpumask.h	1969-12-31 16:00:00.000000000 -0800
@@ -1,6 +0,0 @@
-#ifndef _ASM_IA64_CPUMASK_H
-#define _ASM_IA64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_IA64_CPUMASK_H */


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 7/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (7 preceding siblings ...)
  2004-04-08 19:49 ` Patch 6c/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 8/23 " Paul Jackson
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P7.cpumask_i386_fixup - Remove/recode obsolete cpumask macros from arch i386
	Remove by recoding all uses of the obsolete cpumask const,
	coerce and promote macros.

Diffstat Patch_7_of_23:
 arch/i386/kernel/io_apic.c                |    2 +-
 arch/i386/kernel/smp.c                    |    2 +-
 arch/i386/mach-voyager/voyager_smp.c      |   30 +++++++++++++++---------------
 include/asm-i386/genapic.h                |    2 +-
 include/asm-i386/mach-bigsmp/mach_apic.h  |    8 ++++----
 include/asm-i386/mach-default/mach_apic.h |   10 +++++-----
 include/asm-i386/mach-es7000/mach_apic.h  |   10 +++++-----
 include/asm-i386/mach-numaq/mach_apic.h   |    2 +-
 include/asm-i386/mach-summit/mach_apic.h  |    8 ++++----
 include/asm-i386/mach-visws/mach_apic.h   |    4 ++--
 10 files changed, 39 insertions(+), 39 deletions(-)

Index: 2.6.5.mask/arch/i386/kernel/io_apic.c
===================================================================
--- 2.6.5.mask.orig/arch/i386/kernel/io_apic.c	2004-04-03 23:37:35.000000000 -0800
+++ 2.6.5.mask/arch/i386/kernel/io_apic.c	2004-04-03 23:51:51.000000000 -0800
@@ -264,7 +264,7 @@
 	struct irq_pin_list *entry = irq_2_pin + irq;
 	unsigned int apicid_value;
 	
-	apicid_value = cpu_mask_to_apicid(mk_cpumask_const(cpumask));
+	apicid_value = cpu_mask_to_apicid(cpumask);
 	/* Prepare to do the io_apic_write */
 	apicid_value = apicid_value << 24;
 	spin_lock_irqsave(&ioapic_lock, flags);
Index: 2.6.5.mask/arch/i386/kernel/smp.c
===================================================================
--- 2.6.5.mask.orig/arch/i386/kernel/smp.c	2004-04-03 23:37:35.000000000 -0800
+++ 2.6.5.mask/arch/i386/kernel/smp.c	2004-04-03 23:51:51.000000000 -0800
@@ -160,7 +160,7 @@
  */
 inline void send_IPI_mask_bitmask(cpumask_t cpumask, int vector)
 {
-	unsigned long mask = cpus_coerce(cpumask);
+	unsigned long mask = cpus_addr(cpumask)[0];
 	unsigned long cfg;
 	unsigned long flags;
 
Index: 2.6.5.mask/arch/i386/mach-voyager/voyager_smp.c
===================================================================
--- 2.6.5.mask.orig/arch/i386/mach-voyager/voyager_smp.c	2004-04-03 23:37:36.000000000 -0800
+++ 2.6.5.mask/arch/i386/mach-voyager/voyager_smp.c	2004-04-03 23:51:51.000000000 -0800
@@ -154,7 +154,7 @@
 send_CPI_allbutself(__u8 cpi)
 {
 	__u8 cpu = smp_processor_id();
-	__u32 mask = cpus_coerce(cpu_online_map) & ~(1 << cpu);
+	__u32 mask = cpus_addr(cpu_online_map)[0] & ~(1 << cpu);
 	send_CPI(mask, cpi);
 }
 
@@ -403,11 +403,11 @@
 	/* set up everything for just this CPU, we can alter
 	 * this as we start the other CPUs later */
 	/* now get the CPU disposition from the extended CMOS */
-	phys_cpu_present_map = cpus_promote(voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK));
-	cpus_coerce(phys_cpu_present_map) |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 1) << 8;
-	cpus_coerce(phys_cpu_present_map) |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 2) << 16;
-	cpus_coerce(phys_cpu_present_map) |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 3) << 24;
-	printk("VOYAGER SMP: phys_cpu_present_map = 0x%lx\n", cpus_coerce(phys_cpu_present_map));
+	cpus_addr(phys_cpu_present_map)[0] = voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK);
+	cpus_addr(phys_cpu_present_map)[0] |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 1) << 8;
+	cpus_addr(phys_cpu_present_map)[0] |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 2) << 16;
+	cpus_addr(phys_cpu_present_map)[0] |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 3) << 24;
+	printk("VOYAGER SMP: phys_cpu_present_map = 0x%lx\n", cpus_addr(phys_cpu_present_map)[0]);
 	/* Here we set up the VIC to enable SMP */
 	/* enable the CPIs by writing the base vector to their register */
 	outb(VIC_DEFAULT_CPI_BASE, VIC_CPI_BASE_REGISTER);
@@ -709,12 +709,12 @@
 		/* now that the cat has probed the Voyager System Bus, sanity
 		 * check the cpu map */
 		if( ((voyager_quad_processors | voyager_extended_vic_processors)
-		     & cpus_coerce(phys_cpu_present_map)) != cpus_coerce(phys_cpu_present_map)) {
+		     & cpus_addr(phys_cpu_present_map)[0]) != cpus_addr(phys_cpu_present_map)[0]) {
 			/* should panic */
 			printk("\n\n***WARNING*** Sanity check of CPU present map FAILED\n");
 		}
 	} else if(voyager_level == 4)
-		voyager_extended_vic_processors = cpus_coerce(phys_cpu_present_map);
+		voyager_extended_vic_processors = cpus_addr(phys_cpu_present_map)[0];
 
 	/* this sets up the idle task to run on the current cpu */
 	voyager_extended_cpus = 1;
@@ -912,7 +912,7 @@
 
 	if (!cpumask)
 		BUG();
-	if ((cpumask & cpus_coerce(cpu_online_map)) != cpumask)
+	if ((cpumask & cpus_addr(cpu_online_map)[0]) != cpumask)
 		BUG();
 	if (cpumask & (1 << smp_processor_id()))
 		BUG();
@@ -955,7 +955,7 @@
 
 	preempt_disable();
 
-	cpu_mask = cpus_coerce(mm->cpu_vm_mask) & ~(1 << smp_processor_id());
+	cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
 	local_flush_tlb();
 	if (cpu_mask)
 		flush_tlb_others(cpu_mask, mm, FLUSH_ALL);
@@ -971,7 +971,7 @@
 
 	preempt_disable();
 
-	cpu_mask = cpus_coerce(mm->cpu_vm_mask) & ~(1 << smp_processor_id());
+	cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
 
 	if (current->active_mm == mm) {
 		if (current->mm)
@@ -992,7 +992,7 @@
 
 	preempt_disable();
 
-	cpu_mask = cpus_coerce(mm->cpu_vm_mask) & ~(1 << smp_processor_id());
+	cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
 	if (current->active_mm == mm) {
 		if(current->mm)
 			__flush_tlb_one(va);
@@ -1101,7 +1101,7 @@
 		   int wait)
 {
 	struct call_data_struct data;
-	__u32 mask = cpus_coerce(cpu_online_map);
+	__u32 mask = cpus_addr(cpu_online_map)[0];
 
 	mask &= ~(1<<smp_processor_id());
 
@@ -1789,9 +1789,9 @@
 	unsigned long irq_mask = 1 << irq;
 	int cpu;
 
-	real_mask = cpus_coerce(mask) & voyager_extended_vic_processors;
+	real_mask = cpus_addr(mask)[0] & voyager_extended_vic_processors;
 	
-	if(cpus_coerce(mask) == 0)
+	if(cpus_addr(mask)[0] == 0)
 		/* can't have no cpu's to accept the interrupt -- extremely
 		 * bad things will happen */
 		return;
Index: 2.6.5.mask/include/asm-i386/genapic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/genapic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/genapic.h	2004-04-03 23:51:51.000000000 -0800
@@ -62,7 +62,7 @@
 
 	unsigned (*get_apic_id)(unsigned long x);
 	unsigned long apic_id_mask;
-	unsigned int (*cpu_mask_to_apicid)(cpumask_const_t cpumask);
+	unsigned int (*cpu_mask_to_apicid)(cpumask_t cpumask);
 	
 	/* ipi */
 	void (*send_IPI_mask)(cpumask_t mask, int vector);
Index: 2.6.5.mask/include/asm-i386/mach-bigsmp/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-bigsmp/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-bigsmp/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -140,14 +140,14 @@
 	return (1);
 }
 
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
 	int num_bits_set;
 	int cpus_found = 0;
 	int cpu;
 	int apicid;	
 
-	num_bits_set = cpus_weight_const(cpumask);
+	num_bits_set = cpus_weight(cpumask);
 	/* Return id to all */
 	if (num_bits_set == NR_CPUS)
 		return (int) 0xFF;
@@ -155,10 +155,10 @@
 	 * The cpus in the mask must all be on the apic cluster.  If are not 
 	 * on the same apicid cluster return default value of TARGET_CPUS. 
 	 */
-	cpu = first_cpu_const(cpumask);
+	cpu = first_cpu(cpumask);
 	apicid = cpu_to_logical_apicid(cpu);
 	while (cpus_found < num_bits_set) {
-		if (cpu_isset_const(cpu, cpumask)) {
+		if (cpu_isset(cpu, cpumask)) {
 			int new_apicid = cpu_to_logical_apicid(cpu);
 			if (apicid_cluster(apicid) != 
 					apicid_cluster(new_apicid)){
Index: 2.6.5.mask/include/asm-i386/mach-default/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-default/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-default/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -5,12 +5,12 @@
 
 #define APIC_DFR_VALUE	(APIC_DFR_FLAT)
 
-static inline cpumask_const_t target_cpus(void)
+static inline cpumask_t target_cpus(void)
 { 
 #ifdef CONFIG_SMP
-	return mk_cpumask_const(cpu_online_map);
+	return cpu_online_map;
 #else
-	return mk_cpumask_const(cpumask_of_cpu(0));
+	return cpumask_of_cpu(0);
 #endif
 } 
 #define TARGET_CPUS (target_cpus())
@@ -118,9 +118,9 @@
 	return physid_isset(GET_APIC_ID(apic_read(APIC_ID)), phys_cpu_present_map);
 }
 
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
-	return cpus_coerce_const(cpumask);
+	return cpus_addr(cpumask)[0];
 }
 
 static inline void enable_apic_mode(void)
Index: 2.6.5.mask/include/asm-i386/mach-es7000/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-es7000/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-es7000/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -89,7 +89,7 @@
 	int apic = bios_cpu_apicid[smp_processor_id()];
 	printk("Enabling APIC mode:  %s.  Using %d I/O APICs, target cpus %lx\n",
 		(apic_version[apic] == 0x14) ? 
-		"Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_coerce(TARGET_CPUS));
+		"Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(TARGET_CPUS)[0]);
 }
 
 static inline int multi_timer_check(int apic, int irq)
@@ -159,14 +159,14 @@
 	return (1);
 }
 
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
 	int num_bits_set;
 	int cpus_found = 0;
 	int cpu;
 	int apicid;	
 
-	num_bits_set = cpus_weight_const(cpumask);
+	num_bits_set = cpus_weight(cpumask);
 	/* Return id to all */
 	if (num_bits_set == NR_CPUS)
 		return 0xFF;
@@ -174,10 +174,10 @@
 	 * The cpus in the mask must all be on the apic cluster.  If are not 
 	 * on the same apicid cluster return default value of TARGET_CPUS. 
 	 */
-	cpu = first_cpu_const(cpumask);
+	cpu = first_cpu(cpumask);
 	apicid = cpu_to_logical_apicid(cpu);
 	while (cpus_found < num_bits_set) {
-		if (cpu_isset_const(cpu, cpumask)) {
+		if (cpu_isset(cpu, cpumask)) {
 			int new_apicid = cpu_to_logical_apicid(cpu);
 			if (apicid_cluster(apicid) != 
 					apicid_cluster(new_apicid)){
Index: 2.6.5.mask/include/asm-i386/mach-numaq/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-numaq/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-numaq/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -136,7 +136,7 @@
  * We use physical apicids here, not logical, so just return the default
  * physical broadcast to stop people from breaking us
  */
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
 	return (int) 0xF;
 }
Index: 2.6.5.mask/include/asm-i386/mach-summit/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-summit/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-summit/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -140,14 +140,14 @@
 {
 }
 
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
 	int num_bits_set;
 	int cpus_found = 0;
 	int cpu;
 	int apicid;	
 
-	num_bits_set = cpus_weight_const(cpumask);
+	num_bits_set = cpus_weight(cpumask);
 	/* Return id to all */
 	if (num_bits_set == NR_CPUS)
 		return (int) 0xFF;
@@ -155,10 +155,10 @@
 	 * The cpus in the mask must all be on the apic cluster.  If are not 
 	 * on the same apicid cluster return default value of TARGET_CPUS. 
 	 */
-	cpu = first_cpu_const(cpumask);
+	cpu = first_cpu(cpumask);
 	apicid = cpu_to_logical_apicid(cpu);
 	while (cpus_found < num_bits_set) {
-		if (cpu_isset_const(cpu, cpumask)) {
+		if (cpu_isset(cpu, cpumask)) {
 			int new_apicid = cpu_to_logical_apicid(cpu);
 			if (apicid_cluster(apicid) != 
 					apicid_cluster(new_apicid)){
Index: 2.6.5.mask/include/asm-i386/mach-visws/mach_apic.h
===================================================================
--- 2.6.5.mask.orig/include/asm-i386/mach-visws/mach_apic.h	2004-04-03 23:38:10.000000000 -0800
+++ 2.6.5.mask/include/asm-i386/mach-visws/mach_apic.h	2004-04-03 23:51:51.000000000 -0800
@@ -84,9 +84,9 @@
 	return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
 }
 
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
-	return cpus_coerce_const(cpumask);
+	return cpus_addr(cpumask)[0];
 }
 
 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 8/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (8 preceding siblings ...)
  2004-04-08 19:49 ` Patch 7/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 9/23 " Paul Jackson
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P8.cpumask_ppc64_fixup - Remove/recode obsolete cpumask macros from arch ppc64
        Remove by recoding all uses of the obsolete cpumask const,
        coerce and promote macros.

Diffstat Patch_8_of_23:
 open_pic.c                     |    8 ++++----
 rtasd.c                        |    6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

Index: 2.6.5.mask/arch/ppc64/kernel/open_pic.c
===================================================================
--- 2.6.5.mask.orig/arch/ppc64/kernel/open_pic.c	2004-04-03 23:37:42.000000000 -0800
+++ 2.6.5.mask/arch/ppc64/kernel/open_pic.c	2004-04-03 23:51:59.000000000 -0800
@@ -592,7 +592,7 @@
 void openpic_init_processor(u_int cpumask)
 {
 	openpic_write(&OpenPIC->Global.Processor_Initialization,
-		      physmask(cpumask & cpus_coerce(cpu_online_map)));
+		      physmask(cpumask & cpus_addr(cpu_online_map)[0]));
 }
 
 #ifdef CONFIG_SMP
@@ -626,7 +626,7 @@
 	CHECK_THIS_CPU;
 	check_arg_ipi(ipi);
 	openpic_write(&OpenPIC->THIS_CPU.IPI_Dispatch(ipi),
-		      physmask(cpumask & cpus_coerce(cpu_online_map)));
+		      physmask(cpumask & cpus_addr(cpu_online_map)[0]));
 }
 
 void openpic_request_IPIs(void)
@@ -712,7 +712,7 @@
 {
 	check_arg_timer(timer);
 	openpic_write(&OpenPIC->Global.Timer[timer].Destination,
-		      physmask(cpumask & cpus_coerce(cpu_online_map)));
+		      physmask(cpumask & cpus_addr(cpu_online_map)[0]));
 }
 
 
@@ -837,7 +837,7 @@
 	cpumask_t tmp;
 
 	cpus_and(tmp, cpumask, cpu_online_map);
-	openpic_mapirq(irq_nr - open_pic_irq_offset, physmask(cpus_coerce(tmp)));
+	openpic_mapirq(irq_nr - open_pic_irq_offset, physmask(cpus_addr(tmp)[0]));
 }
 
 #ifdef CONFIG_SMP
Index: 2.6.5.mask/arch/ppc64/kernel/rtasd.c
===================================================================
--- 2.6.5.mask.orig/arch/ppc64/kernel/rtasd.c	2004-04-03 23:37:42.000000000 -0800
+++ 2.6.5.mask/arch/ppc64/kernel/rtasd.c	2004-04-03 23:51:59.000000000 -0800
@@ -411,7 +411,7 @@
 	}
 
 	lock_cpu_hotplug();
-	cpu = first_cpu_const(mk_cpumask_const(cpu_online_map));
+	cpu = first_cpu(cpu_online_map);
 	for (;;) {
 		set_cpus_allowed(current, cpumask_of_cpu(cpu));
 		do_event_scan(event_scan);
@@ -425,9 +425,9 @@
 		schedule_timeout((HZ*60/rtas_event_scan_rate) / 2);
 		lock_cpu_hotplug();
 
-		cpu = next_cpu_const(cpu, mk_cpumask_const(cpu_online_map));
+		cpu = next_cpu(cpu, cpu_online_map);
 		if (cpu == NR_CPUS)
-			cpu = first_cpu_const(mk_cpumask_const(cpu_online_map));
+			cpu = first_cpu(cpu_online_map);
 	}
 
 error_vfree:


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 9/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (9 preceding siblings ...)
  2004-04-08 19:49 ` Patch 8/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 10/23 " Paul Jackson
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P9.cpumask_x86_64_fixup - Remove/recode obsolete cpumask macros from arch x86_64
        Remove by recoding all uses of the obsolete cpumask const,
        coerce and promote macros.

Diffstat Patch_9_of_23:
 arch/x86_64/kernel/io_apic.c   |    2 +-
 arch/x86_64/kernel/pci-gart.c  |    4 ++--
 arch/x86_64/kernel/smp.c       |    2 +-
 include/asm-x86_64/smp.h       |    4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

Index: 2.6.5.mask/arch/x86_64/kernel/io_apic.c
===================================================================
--- 2.6.5.mask.orig/arch/x86_64/kernel/io_apic.c	2004-04-03 23:37:43.000000000 -0800
+++ 2.6.5.mask/arch/x86_64/kernel/io_apic.c	2004-04-03 23:52:03.000000000 -0800
@@ -1368,7 +1368,7 @@
 	unsigned long flags;
 	unsigned int dest;
 
-	dest = cpu_mask_to_apicid(mk_cpumask_const(mask));
+	dest = cpu_mask_to_apicid(mask);
 
 	/*
 	 * Only the first 8 bits are valid.
Index: 2.6.5.mask/arch/x86_64/kernel/pci-gart.c
===================================================================
--- 2.6.5.mask.orig/arch/x86_64/kernel/pci-gart.c	2004-04-03 23:37:43.000000000 -0800
+++ 2.6.5.mask/arch/x86_64/kernel/pci-gart.c	2004-04-03 23:52:03.000000000 -0800
@@ -149,7 +149,7 @@
 { 
 	unsigned long flags;
 	int bus = dev ? dev->bus->number : -1;
-	cpumask_const_t bus_cpumask = pcibus_to_cpumask(bus);
+	cpumask_t bus_cpumask = pcibus_to_cpumask(bus);
 	int flushed = 0;
 	int i;
 
@@ -159,7 +159,7 @@
 			u32 w;
 			if (!northbridges[i]) 
 				continue;
-			if (bus >= 0 && !(cpu_isset_const(i, bus_cpumask)))
+			if (bus >= 0 && !(cpu_isset(i, bus_cpumask)))
 				continue;
 			pci_write_config_dword(northbridges[i], 0x9c, 
 					       northbridge_flush_word[i] | 1); 
Index: 2.6.5.mask/arch/x86_64/kernel/smp.c
===================================================================
--- 2.6.5.mask.orig/arch/x86_64/kernel/smp.c	2004-04-03 23:37:43.000000000 -0800
+++ 2.6.5.mask/arch/x86_64/kernel/smp.c	2004-04-03 23:52:03.000000000 -0800
@@ -94,7 +94,7 @@
 
 static inline void send_IPI_mask(cpumask_t cpumask, int vector)
 {
-	unsigned long mask = cpus_coerce(cpumask);
+	unsigned long mask = cpus_addr(cpumask)[0];
 	unsigned long cfg;
 	unsigned long flags;
 
Index: 2.6.5.mask/include/asm-x86_64/smp.h
===================================================================
--- 2.6.5.mask.orig/include/asm-x86_64/smp.h	2004-04-03 23:38:16.000000000 -0800
+++ 2.6.5.mask/include/asm-x86_64/smp.h	2004-04-03 23:52:03.000000000 -0800
@@ -95,9 +95,9 @@
 #define TARGET_CPUS 1
 
 #ifndef ASSEMBLY
-static inline unsigned int cpu_mask_to_apicid(cpumask_const_t cpumask)
+static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
 {
-	return cpus_coerce_const(cpumask);
+	return cpus_addr(cpumask)[0];
 }
 #endif
 


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 10/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (10 preceding siblings ...)
  2004-04-08 19:49 ` Patch 9/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 11/23 " Paul Jackson
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P10.rm_old_cpumask_emul - Remove obsolete cpumask emulation from cpumask.h
        Now that the emulation of the obsolete cpumask macros is no
        longer needed, remove it from cpumask.h

Index: 2.6.5.bitmap/include/linux/cpumask.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/cpumask.h	2004-04-07 21:34:10.000000000 -0700
+++ 2.6.5.bitmap/include/linux/cpumask.h	2004-04-07 21:57:34.000000000 -0700
@@ -315,16 +315,4 @@
 #define for_each_online_cpu(cpu)     \
 			for_each_cpu_mask(cpu, cpu_online_map)
 
-/* Begin obsolete cpumask operator emulation */
-#define cpu_isset_const(a,b) cpu_isset(a,b)
-#define cpumask_const_t cpumask_t
-#define cpus_coerce(m) (cpus_addr(m)[0])
-#define cpus_coerce_const cpus_coerce
-#define cpus_promote(x) ({ cpumask_t m; m.bits[0] = x; m; })
-#define cpus_weight_const cpus_weight
-#define first_cpu_const first_cpu
-#define mk_cpumask_const(x) x
-#define next_cpu_const next_cpu
-/* End of obsolete cpumask operator emulation */
-
 #endif /* __LINUX_CPUMASK_H */

%diffstat
 cpumask.h |   12 ------------
 1 files changed, 12 deletions(-)



-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 11/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (11 preceding siblings ...)
  2004-04-08 19:49 ` Patch 10/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 12/23 " Paul Jackson
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P11.cpumask_sparc_simplify - Simplify some sparc64 cpumask loop code
        Make use of for_each_cpu_mask() macro to simplify and optimize
        a couple of sparc64 per-CPU loops.  This code change has _not_
        been tested or reviewed.  Feedback welcome.  There is non-trivial
        risk that I still don't understand the logic here.

Index: 2.6.5.bitmap/arch/sparc64/kernel/smp.c
===================================================================
--- 2.6.5.bitmap.orig/arch/sparc64/kernel/smp.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/sparc64/kernel/smp.c	2004-04-08 04:18:02.000000000 -0700
@@ -406,14 +406,8 @@
 	int i;
 
 	__asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
-	for (i = 0; i < NR_CPUS; i++) {
-		if (cpu_isset(i, mask)) {
-			spitfire_xcall_helper(data0, data1, data2, pstate, i);
-			cpu_clear(i, mask);
-			if (cpus_empty(mask))
-				break;
-		}
-	}
+	for_each_cpu_mask(i, mask)
+		spitfire_xcall_helper(data0, data1, data2, pstate, i);
 }
 
 /* Cheetah now allows to send the whole 64-bytes of data in the interrupt
@@ -456,25 +450,19 @@
 
 	nack_busy_id = 0;
 	{
-		cpumask_t work_mask = mask;
 		int i;
 
-		for (i = 0; i < NR_CPUS; i++) {
-			if (cpu_isset(i, work_mask)) {
-				u64 target = (i << 14) | 0x70;
-
-				if (!is_jalapeno)
-					target |= (nack_busy_id << 24);
-				__asm__ __volatile__(
-					"stxa	%%g0, [%0] %1\n\t"
-					"membar	#Sync\n\t"
-					: /* no outputs */
-					: "r" (target), "i" (ASI_INTR_W));
-				nack_busy_id++;
- 				cpu_clear(i, work_mask);
-				if (cpus_empty(work_mask))
-					break;
-			}
+		for_each_cpu_mask(i, mask) {
+			u64 target = (i << 14) | 0x70;
+
+			if (!is_jalapeno)
+				target |= (nack_busy_id << 24);
+			__asm__ __volatile__(
+				"stxa	%%g0, [%0] %1\n\t"
+				"membar	#Sync\n\t"
+				: /* no outputs */
+				: "r" (target), "i" (ASI_INTR_W));
+			nack_busy_id++;
 		}
 	}
 
@@ -507,7 +495,6 @@
 			printk("CPU[%d]: mondo stuckage result[%016lx]\n",
 			       smp_processor_id(), dispatch_stat);
 		} else {
-			cpumask_t work_mask = mask;
 			int i, this_busy_nack = 0;
 
 			/* Delay some random time with interrupts enabled
@@ -518,22 +505,17 @@
 			/* Clear out the mask bits for cpus which did not
 			 * NACK us.
 			 */
-			for (i = 0; i < NR_CPUS; i++) {
-				if (cpu_isset(i, work_mask)) {
-					u64 check_mask;
-
-					if (is_jalapeno)
-						check_mask = (0x2UL << (2*i));
-					else
-						check_mask = (0x2UL <<
-							      this_busy_nack);
-					if ((dispatch_stat & check_mask) == 0)
-						cpu_clear(i, mask);
-					this_busy_nack += 2;
-					cpu_clear(i, work_mask);
-					if (cpus_empty(work_mask))
-						break;
-				}
+			for_each_cpu_mask(i, mask) {
+				u64 check_mask;
+
+				if (is_jalapeno)
+					check_mask = (0x2UL << (2*i));
+				else
+					check_mask = (0x2UL <<
+						      this_busy_nack);
+				if ((dispatch_stat & check_mask) == 0)
+					cpu_clear(i, mask);
+				this_busy_nack += 2;
 			}
 
 			goto retry;


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 12/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (12 preceding siblings ...)
  2004-04-08 19:49 ` Patch 11/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 13/23 " Paul Jackson
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P12.cpumask_i386_simplify - Optimize i386 cpumask macro usage.
        Optimize a bit of cpumask code for asm-i386/mach-es7000
        Code untested, unreviewed.  Feedback welcome.

Index: 2.6.5.bitmap/include/asm-i386/mach-es7000/mach_ipi.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/mach-es7000/mach_ipi.h	2004-04-08 04:19:28.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/mach-es7000/mach_ipi.h	2004-04-08 04:19:34.000000000 -0700
@@ -10,9 +10,8 @@
 
 static inline void send_IPI_allbutself(int vector)
 {
-	cpumask_t mask = cpumask_of_cpu(smp_processor_id());
-	cpus_complement(mask);
-	cpus_and(mask, mask, cpu_online_map);
+	cpumask_t mask = cpu_online_map;
+	cpu_clear(smp_processor_id(), mask);
 	if (!cpus_empty(mask))
 		send_IPI_mask(mask, vector);
 }


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 13/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (13 preceding siblings ...)
  2004-04-08 19:49 ` Patch 12/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:49 ` Patch 14/23 " Paul Jackson
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P13.cpumask_physids_complement - Convert physids_complement() to really use both args
        Provide for specifying distinct source and dest args to the
        physids_complement().  No one actually uses this macro yet.
        The physid_mask type would be a good candidate to convert to
        using this new mask ADT as a base.

Index: 2.6.5.bitmap/include/asm-i386/mpspec.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/mpspec.h	2004-04-08 03:50:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/mpspec.h	2004-04-08 04:21:18.000000000 -0700
@@ -53,7 +53,7 @@
 #define physids_and(dst, src1, src2)		bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_or(dst, src1, src2)		bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_clear(map)			bitmap_clear((map).mask, MAX_APICS)
-#define physids_complement(map)			bitmap_complement((map).mask, (map).mask, MAX_APICS)
+#define physids_complement(dst, src)		bitmap_complement((dst).mask, (src).mask, MAX_APICS)
 #define physids_empty(map)			bitmap_empty((map).mask, MAX_APICS)
 #define physids_equal(map1, map2)		bitmap_equal((map1).mask, (map2).mask, MAX_APICS)
 #define physids_weight(map)			bitmap_weight((map).mask, MAX_APICS)
Index: 2.6.5.bitmap/include/asm-x86_64/mpspec.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/mpspec.h	2004-04-08 03:50:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/mpspec.h	2004-04-08 04:21:18.000000000 -0700
@@ -212,7 +212,7 @@
 #define physids_and(dst, src1, src2)		bitmap_and((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_or(dst, src1, src2)		bitmap_or((dst).mask, (src1).mask, (src2).mask, MAX_APICS)
 #define physids_clear(map)			bitmap_clear((map).mask, MAX_APICS)
-#define physids_complement(map)			bitmap_complement((map).mask, (map).mask, MAX_APICS)
+#define physids_complement(dst, src)		bitmap_complement((dst).mask, (src).mask, MAX_APICS)
 #define physids_empty(map)			bitmap_empty((map).mask, MAX_APICS)
 #define physids_equal(map1, map2)		bitmap_equal((map1).mask, (map2).mask, MAX_APICS)
 #define physids_weight(map)			bitmap_weight((map).mask, MAX_APICS)


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 14/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (14 preceding siblings ...)
  2004-04-08 19:49 ` Patch 13/23 " Paul Jackson
@ 2004-04-08 19:49 ` Paul Jackson
  2004-04-08 19:50 ` Patch 15/23 " Paul Jackson
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:49 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P14.cpumask_x86_64_online - Remove cpumask hack from asm-x86_64/topology.h
        This file had the cpumask cpu_online_map as type
        unsigned long, instead of type cpumask_t, for no good
        reason that I could see.  So I changed it.  Everywhere
        else, cpu_online_map is already of type cpumask_t.

Index: 2.6.5.bitmap/include/asm-x86_64/topology.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/topology.h	2004-04-05 02:41:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/topology.h	2004-04-08 04:23:24.000000000 -0700
@@ -10,18 +10,18 @@
 /* Map the K8 CPU local memory controllers to a simple 1:1 CPU:NODE topology */
 
 extern int fake_node;
-/* This is actually a cpumask_t, but doesn't matter because we don't have
-   >BITS_PER_LONG CPUs */
-extern unsigned long cpu_online_map;
+extern cpumask_t cpu_online_map;
 
 #define cpu_to_node(cpu)		(fake_node ? 0 : (cpu))
 #define parent_node(node)		(node)
 #define node_to_first_cpu(node) 	(fake_node ? 0 : (node))
 #define node_to_cpumask(node)	(fake_node ? cpu_online_map : (1UL << (node)))
 
-static inline unsigned long pcibus_to_cpumask(int bus)
+static inline cpumask_t pcibus_to_cpumask(int bus)
 {
-	return mp_bus_to_cpumask[bus] & cpu_online_map; 
+	cpumask_t tmp;
+	cpus_and(tmp, mp_bus_to_cpumask[bus], cpu_online_map);
+	return tmp;
 }
 
 #define NODE_BALANCE_RATE 30	/* CHECKME */ 


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 15/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (15 preceding siblings ...)
  2004-04-08 19:49 ` Patch 14/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 16/23 " Paul Jackson
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P15.cpumask_sched_refine- Cpumask code clarification in kernel/sched.c
        Clarify and slightly optimize set_cpus_allowed() cpumask check

Index: 2.6.5.bitmap/kernel/sched.c
===================================================================
--- 2.6.5.bitmap.orig/kernel/sched.c	2004-04-08 09:39:29.000000000 -0700
+++ 2.6.5.bitmap/kernel/sched.c	2004-04-08 09:40:08.000000000 -0700
@@ -2722,7 +2722,7 @@
 	runqueue_t *rq;
 
 	rq = task_rq_lock(p, &flags);
-	if (any_online_cpu(new_mask) == NR_CPUS) {
+	if (!cpus_intersects(new_mask, cpu_online_map)) {
 		ret = -EINVAL;
 		goto out;
 	}


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 16/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (16 preceding siblings ...)
  2004-04-08 19:50 ` Patch 15/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 17/23 " Paul Jackson
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P16.new_nodemask.h - New nodemask_t, based on bitmap.
	New nodemask_t type, based on bitmap/bitop,
	suitable for use with Matthew Dobson's nodemask
	patch series.  Closely resembles cpumask.h.

Index: 2.6.5.bitmap/include/linux/nodemask.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/nodemask.h	2004-04-08 04:25:24.000000000 -0700
+++ 2.6.5.bitmap/include/linux/nodemask.h	2004-04-08 04:52:56.000000000 -0700
@@ -0,0 +1,323 @@
+#ifndef __LINUX_NODEMASK_H
+#define __LINUX_NODEMASK_H
+
+/*
+ * Nodemasks provide a bitmap suitable for representing the
+ * set of Node's in a system, one bit position per Node number.
+ *
+ * See detailed comments in the file linux/bitmap.h describing the
+ * data type on which these nodemasks are based.
+ *
+ * For details of nodemask_scnprintf() and nodemask_parse(),
+ * see bitmap_scnprintf() and bitmap_parse() in lib/bitmap.c.
+ *
+ * The available nodemask operations are:
+ *
+ * void node_set(node, mask)		turn on bit 'node' in mask
+ * void node_clear(node, mask)		turn off bit 'node' in mask
+ * void nodes_setall(mask)		set all bits
+ * void nodes_clear(mask)		clear all bits
+ * int node_isset(node, mask)		true iff bit 'node' set in mask
+ * int node_test_and_set(node, mask)	test and set bit 'node' in mask
+ *
+ * void nodes_and(dst, src1, src2)	dst = src1 & src2  [intersection]
+ * void nodes_or(dst, src1, src2)	dst = src1 | src2  [union]
+ * void nodes_xor(dst, src1, src2)	dst = src1 ^ src2
+ * void nodes_andnot(dst, src1, src2)	dst = src1 & ~src2
+ * void nodes_complement(dst, src)	dst = ~src
+ *
+ * int nodes_equal(mask1, mask2)	Does mask1 == mask2?
+ * int nodes_intersects(mask1, mask2)	Do mask1 and mask2 intersect?
+ * int nodes_subset(mask1, mask2)	Is mask1 a subset of mask2?
+ * int nodes_empty(mask)		Is mask empty (no bits sets)?
+ * int nodes_full(mask)			Is mask full (all bits sets)?
+ * int nodes_weight(mask)		Hamming weigh - number of set bits
+ *
+ * void nodes_shift_right(dst, src, n)	Shift right
+ * void nodes_shift_left(dst, src, n)	Shift left
+ *
+ * int first_node(mask)			Number lowest set bit, or MAX_NUMNODES
+ * int next_node(node, mask)		Next node past 'node', or MAX_NUMNODES
+ *
+ * nodemask_t nodemask_of_node(node)	Return nodemask with bit 'node' set
+ * NODE_MASK_ALL			Initializer - all bits set
+ * NODE_MASK_NONE			Initializer - no bits set
+ * unsigned long *nodes_addr(mask)	Array of unsigned long's in mask
+ *
+ * int nodemask_scnprintf(buf, len, mask) Format nodemask for printing
+ * int nodemask_parse(ubuf, ulen, mask)	Parse ascii string as nodemask
+ *
+ * int num_online_nodes()		Number of online Nodes
+ * int num_possible_nodes()		Number of all possible Nodes
+ * int node_online(node)		Is some node online?
+ * int node_possible(node)		Is some node possible?
+ * void node_set_online(node)		set node in node_online_map
+ * void node_set_offline(node)		clear node in node_online_map
+ * int any_online_node(mask)		First online node in mask
+ *
+ * for_each_node_mask(node, mask)	for-loop node over mask
+ * for_each_node(node)			for-loop node over node_possible_map
+ * for_each_online_node(node)		for-loop node over node_online_map
+ */
+
+#include <linux/threads.h>
+#include <linux/bitmap.h>
+#include <asm/bug.h>
+
+typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
+extern nodemask_t _unused_nodemask_arg_;
+
+#define node_set(node, dst) __node_set((node), &(dst))
+static inline void __node_set(int node, volatile nodemask_t *dstp)
+{
+	if (node < MAX_NUMNODES)
+		set_bit(node, dstp->bits);
+}
+
+#define node_clear(node, dst) __node_clear((node), &(dst))
+static inline void __node_clear(int node, volatile nodemask_t *dstp)
+{
+	clear_bit(node, dstp->bits);
+}
+
+#define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES)
+static inline void __nodes_setall(nodemask_t *dstp, int nbits)
+{
+	bitmap_fill(dstp->bits, nbits);
+}
+
+#define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES)
+static inline void __nodes_clear(nodemask_t *dstp, int nbits)
+{
+	bitmap_clear(dstp->bits, nbits);
+}
+
+#define node_isset(node, nodemask) __node_isset((node), &(nodemask))
+static inline int __node_isset(int node, const volatile nodemask_t *addr)
+{
+	return test_bit(node, addr->bits);
+}
+
+#define node_test_and_set(node, nodemask) __node_test_and_set((node), &(nodemask))
+static inline int __node_test_and_set(int node, nodemask_t *addr)
+{
+	if (node < MAX_NUMNODES)
+		return test_and_set_bit(node, addr->bits);
+	else
+		return 0;
+}
+
+#define nodes_and(dst, src1, src2) \
+			__nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES)
+static inline void __nodes_and(nodemask_t *dstp, nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_or(dst, src1, src2) \
+			__nodes_or(&(dst), &(src1), &(src2), MAX_NUMNODES)
+static inline void __nodes_or(nodemask_t *dstp, nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_xor(dst, src1, src2) \
+			__nodes_xor(&(dst), &(src1), &(src2), MAX_NUMNODES)
+static inline void __nodes_xor(nodemask_t *dstp, nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_andnot(dst, src1, src2) \
+			__nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES)
+static inline void __nodes_andnot(nodemask_t *dstp, nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_complement(dst, src) \
+			__nodes_complement(&(dst), &(src), MAX_NUMNODES)
+static inline void __nodes_complement(nodemask_t *dstp,
+					nodemask_t *srcp, int nbits)
+{
+	bitmap_complement(dstp->bits, srcp->bits, nbits);
+}
+
+#define nodes_equal(src1, src2) __nodes_equal(&(src1), &(src2), MAX_NUMNODES)
+static inline int __nodes_equal(nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	return bitmap_equal(src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_intersects(src1, src2) \
+			__nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
+static inline int __nodes_intersects(nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	return bitmap_intersects(src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_subset(src1, src2) __nodes_subset(&(src1), &(src2), MAX_NUMNODES)
+static inline int __nodes_subset(nodemask_t *src1p,
+					nodemask_t *src2p, int nbits)
+{
+	return bitmap_subset(src1p->bits, src2p->bits, nbits);
+}
+
+#define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
+static inline int __nodes_empty(nodemask_t *srcp, int nbits)
+{
+	return bitmap_empty(srcp->bits, nbits);
+}
+
+#define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
+static inline int __nodes_full(nodemask_t *srcp, int nbits)
+{
+	return bitmap_full(srcp->bits, nbits);
+}
+
+#define nodes_weight(nodemask) __nodes_weight(&(nodemask), MAX_NUMNODES)
+static inline int __nodes_weight(nodemask_t *srcp, int nbits)
+{
+	return bitmap_weight(srcp->bits, nbits);
+}
+
+#define nodes_shift_right(dst, src, n) \
+			__nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES)
+static inline void __nodes_shift_right(nodemask_t *dstp,
+					nodemask_t *srcp, int n, int nbits)
+{
+	bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
+}
+
+#define nodes_shift_left(dst, src, n) \
+			__nodes_shift_left(&(dst), &(src), (n), MAX_NUMNODES)
+static inline void __nodes_shift_left(nodemask_t *dstp,
+					nodemask_t *srcp, int n, int nbits)
+{
+	bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
+}
+
+#define first_node(src) __first_node(&(src), MAX_NUMNODES)
+static inline int __first_node(nodemask_t *srcp, int nbits)
+{
+	return find_first_bit(srcp->bits, nbits);
+}
+
+#define next_node(n, src) __next_node((n), &(src), MAX_NUMNODES)
+static inline int __next_node(int n, nodemask_t *srcp, int nbits)
+{
+	return find_next_bit(srcp->bits, nbits, n+1);
+}
+
+#define nodemask_of_node(node)						\
+({									\
+	typeof(_unused_nodemask_arg_) m;				\
+	int c = node;							\
+	if (sizeof(m) == sizeof(unsigned long)) {			\
+		if (c < MAX_NUMNODES)					\
+			m.bits[0] = 1UL<<c;				\
+	} else {							\
+		nodes_clear(m);						\
+		node_set(c, m);						\
+	}								\
+	m;								\
+})
+
+#define NODEMASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES)
+
+#if MAX_NUMNODES <= BITS_PER_LONG
+
+#define NODE_MASK_ALL							\
+{ {									\
+	[BITS_TO_LONGS(MAX_NUMNODES)-1] = NODEMASK_LAST_WORD		\
+} }
+
+#else
+
+#define NODE_MASK_ALL							\
+{ {									\
+	[0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL,			\
+	[BITS_TO_LONGS(MAX_NUMNODES)-1] = NODEMASK_LAST_WORD		\
+} }
+
+#endif
+
+#define NODE_MASK_NONE							\
+{ {									\
+	[0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] =  0UL			\
+} }
+
+#define nodes_addr(src) ((src).bits)
+
+#define nodemask_scnprintf(buf, len, src) \
+			__nodemask_scnprintf((buf), (len), &(src), MAX_NUMNODES)
+static inline int __nodemask_scnprintf(char *buf, int len,
+					nodemask_t *srcp, int nbits)
+{
+	return bitmap_scnprintf(buf, len, srcp->bits, nbits);
+}
+
+#define nodemask_parse(ubuf, ulen, src) \
+			__nodemask_parse((ubuf), (ulen), &(src), MAX_NUMNODES)
+static inline int __nodemask_parse(const char __user *buf, int len,
+					nodemask_t *srcp, int nbits)
+{
+	return bitmap_parse(buf, len, srcp->bits, nbits);
+}
+
+/*
+ * The following particular system nodemasks and operations
+ * on them manage all (possible) and online nodes.
+ */
+
+extern nodemask_t node_online_map;
+extern nodemask_t node_possible_map;
+
+#ifdef CONFIG_NUMA
+
+#define num_online_nodes()	     nodes_weight(node_online_map)
+#define num_possible_nodes()	     nodes_weight(node_possible_map)
+#define node_online(node)	     node_isset((node), node_online_map)
+#define node_possible(node)	     node_isset((node), node_possible_map)
+#define node_set_online(node)	     node_set((node), node_online_map)
+#define node_set_offline(node)	     node_clear((node), node_online_map)
+
+#define any_online_node(mask)			\
+({						\
+	nodemask_t m;				\
+	nodes_and(m, mask, node_online_map);	\
+	first_node(m);				\
+})
+
+#define for_each_node_mask(node, mask)		\
+	for (node = first_node(mask);		\
+		node < MAX_NUMNODES;		\
+		node = next_node(node, mask))
+
+#else /* !CONFIG_NUMA */
+
+#define num_online_nodes()	     1
+#define num_possible_nodes()	     1
+#define node_online(node)	     ({ BUG_ON((node) != 0); 1; })
+#define node_possible(node)	     ({ BUG_ON((node) != 0); 1; })
+#define node_set_online(node)	     ({ BUG_ON((node) != 0); })
+#define node_set_offline(node)	     ({ BUG(); })
+
+#define any_online_node(mask)	     0
+
+#define for_each_node_mask(node, mask) for (node = 0; node < 1; node++)
+
+#endif /* CONFIG_NUMA */
+
+#define for_each_node(node)	     \
+			for_each_node_mask(node, node_possible_map)
+#define for_each_online_node(node)     \
+			for_each_node_mask(node, node_online_map)
+
+#endif /* __LINUX_NODEMASK_H */


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 17/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (17 preceding siblings ...)
  2004-04-08 19:50 ` Patch 16/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 18/23 " Paul Jackson
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P17.nodemask_mmzone - the mmzone.h changes from Matthew's Patch [1/7]
        Just the mmzone.h changes taken from this patch: removing
        extistant definition of node_online_map and helper functions,
        added a #include <nodemask.h>.

Index: 2.6.5.bitmap/include/linux/mmzone.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/mmzone.h	2004-04-08 04:42:34.000000000 -0700
+++ 2.6.5.bitmap/include/linux/mmzone.h	2004-04-08 04:45:58.000000000 -0700
@@ -11,6 +11,7 @@
 #include <linux/cache.h>
 #include <linux/threads.h>
 #include <linux/numa.h>
+#include <linux/nodemask.h>
 #include <asm/atomic.h>
 
 /* Free memory management - zoned buddy allocator.  */
@@ -220,7 +221,6 @@
 #define node_present_pages(nid)	(NODE_DATA(nid)->node_present_pages)
 #define node_spanned_pages(nid)	(NODE_DATA(nid)->node_spanned_pages)
 
-extern int numnodes;
 extern struct pglist_data *pgdat_list;
 
 void get_zone_counts(unsigned long *active, unsigned long *inactive,
@@ -343,35 +343,6 @@
 #error ZONES_SHIFT > MAX_ZONES_SHIFT
 #endif
 
-extern DECLARE_BITMAP(node_online_map, MAX_NUMNODES);
-
-#if defined(CONFIG_DISCONTIGMEM) || defined(CONFIG_NUMA)
-
-#define node_online(node)	test_bit(node, node_online_map)
-#define node_set_online(node)	set_bit(node, node_online_map)
-#define node_set_offline(node)	clear_bit(node, node_online_map)
-static inline unsigned int num_online_nodes(void)
-{
-	int i, num = 0;
-
-	for(i = 0; i < MAX_NUMNODES; i++){
-		if (node_online(i))
-			num++;
-	}
-	return num;
-}
-
-#else /* !CONFIG_DISCONTIGMEM && !CONFIG_NUMA */
-
-#define node_online(node) \
-	({ BUG_ON((node) != 0); test_bit(node, node_online_map); })
-#define node_set_online(node) \
-	({ BUG_ON((node) != 0); set_bit(node, node_online_map); })
-#define node_set_offline(node) \
-	({ BUG_ON((node) != 0); clear_bit(node, node_online_map); })
-#define num_online_nodes()	1
-
-#endif /* CONFIG_DISCONTIGMEM || CONFIG_NUMA */
 #endif /* !__ASSEMBLY__ */
 #endif /* __KERNEL__ */
 #endif /* _LINUX_MMZONE_H */


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 18/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (18 preceding siblings ...)
  2004-04-08 19:50 ` Patch 17/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 19/23 " Paul Jackson
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P18.nodemask_core - Matthew Dobson's [PATCH] nodemask_t core changes [2/7]
        nodemask_t-02-core.patch - Changes to arch-independent code.
        Surprisingly few references to numnodes, open-coded node loops,
        etc. in generic code.  Most important result of this patch is
        that no generic code assumes anything about node numbering.
        This allows individual arches to use sparse numbering if they
        care to.

Index: 2.6.5.bitmap/Documentation/vm/numa
===================================================================
--- 2.6.5.bitmap.orig/Documentation/vm/numa	2004-04-08 08:12:31.000000000 -0700
+++ 2.6.5.bitmap/Documentation/vm/numa	2004-04-08 08:12:34.000000000 -0700
@@ -29,7 +29,7 @@
 into a pg_data_t. The bootmem_data_t is just one part of this. To 
 make the code look uniform between NUMA and regular UMA platforms, 
 UMA platforms have a statically allocated pg_data_t too (contig_page_data).
-For the sake of uniformity, the variable "numnodes" is also defined
+For the sake of uniformity, the variable "node_online_map" is also defined
 for all platforms. As we run benchmarks, we might decide to NUMAize 
 more variables like low_on_memory, nr_free_pages etc into the pg_data_t.
 
Index: 2.6.5.bitmap/include/linux/gfp.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/gfp.h	2004-04-08 08:12:31.000000000 -0700
+++ 2.6.5.bitmap/include/linux/gfp.h	2004-04-08 08:12:34.000000000 -0700
@@ -58,7 +58,7 @@
 
 /*
  * We get the zone list from the current node and the gfp_mask.
- * This zone list contains a maximum of MAXNODES*MAX_NR_ZONES zones.
+ * This zone list contains a maximum of MAX_NUMNODES*MAX_NR_ZONES zones.
  *
  * For the normal case of non-DISCONTIGMEM systems the NODE_DATA() gets
  * optimized to &contig_page_data at compile-time.
Index: 2.6.5.bitmap/include/linux/topology.h
===================================================================
--- 2.6.5.bitmap.orig/include/linux/topology.h	2004-04-08 08:12:31.000000000 -0700
+++ 2.6.5.bitmap/include/linux/topology.h	2004-04-08 08:12:34.000000000 -0700
@@ -43,16 +43,21 @@
 	})
 #endif
 
-static inline int __next_node_with_cpus(int node)
+static inline int __next_node_with_cpus(int last_node)
 {
-	do
-		++node;
-	while (node < numnodes && !nr_cpus_node(node));
-	return node;
+	int nid;
+	for_each_online_node(nid)
+		if (nr_cpus_node(nid) && nid > last_node)
+			return nid;
+
+	return MAX_NUMNODES;
 }
 
-#define for_each_node_with_cpus(node) \
-	for (node = 0; node < numnodes; node = __next_node_with_cpus(node))
+/* Assumes first_node(node_online_map) will have CPUs */
+#define for_each_node_with_cpus(node)			\
+	for(node = first_node(node_online_map);		\
+		node < MAX_NUMNODES;			\
+		node = __next_node_with_cpus(node))
 
 #ifndef node_distance
 #define node_distance(from,to)	(from != to)
Index: 2.6.5.bitmap/kernel/sched.c
===================================================================
--- 2.6.5.bitmap.orig/kernel/sched.c	2004-04-08 08:12:31.000000000 -0700
+++ 2.6.5.bitmap/kernel/sched.c	2004-04-08 08:12:34.000000000 -0700
@@ -1084,7 +1084,7 @@
 {
 	int new_cpu;
 
-	if (numnodes > 1) {
+	if (num_online_nodes() > 1) {
 		new_cpu = sched_best_cpu(current);
 		if (new_cpu != smp_processor_id())
 			sched_migrate_task(current, new_cpu);
Index: 2.6.5.bitmap/mm/page_alloc.c
===================================================================
--- 2.6.5.bitmap.orig/mm/page_alloc.c	2004-04-08 08:12:31.000000000 -0700
+++ 2.6.5.bitmap/mm/page_alloc.c	2004-04-08 08:14:14.000000000 -0700
@@ -34,12 +34,12 @@
 
 #include <asm/tlbflush.h>
 
-DECLARE_BITMAP(node_online_map, MAX_NUMNODES);
+nodemask_t node_online_map = NODE_MASK_NONE;
+nodemask_t node_possible_map = NODE_MASK_ALL;
 struct pglist_data *pgdat_list;
 unsigned long totalram_pages;
 unsigned long totalhigh_pages;
 int nr_swap_pages;
-int numnodes = 1;
 int sysctl_lower_zone_protection = 0;
 
 EXPORT_SYMBOL(totalram_pages);
@@ -701,14 +701,14 @@
 	struct page *page;
 
 	for (;;) {
-		if (i > nodenr + numnodes)
+		if (i > nodenr + num_online_nodes())
 			return 0;
-		if (node_present_pages(i%numnodes)) {
+		if (node_present_pages(i%num_online_nodes())) {
 			struct zone **z;
 			/* The node contains memory. Check that there is
 			 * memory in the intended zonelist.
 			 */
-			z = NODE_DATA(i%numnodes)->node_zonelists[gfp_mask & GFP_ZONEMASK].zones;
+			z = NODE_DATA(i%num_online_nodes())->node_zonelists[gfp_mask & GFP_ZONEMASK].zones;
 			while (*z) {
 				if ( (*z)->free_pages > (1UL<<order))
 					goto found_node;
@@ -719,7 +719,7 @@
 	}
 found_node:
 	nodenr = i+1;
-	page = alloc_pages_node(i%numnodes, gfp_mask, order);
+	page = alloc_pages_node(i%num_online_nodes(), gfp_mask, order);
 	if (!page)
 		return 0;
 	return (unsigned long) page_address(page);
@@ -1134,7 +1134,7 @@
 }
 
 #ifdef CONFIG_NUMA
-#define MAX_NODE_LOAD (numnodes)
+#define MAX_NODE_LOAD (num_online_nodes())
 static int __initdata node_load[MAX_NUMNODES];
 /**
  * find_next_best_node - find the next node that should appear in a given
@@ -1157,11 +1157,11 @@
 	int min_val = INT_MAX;
 	int best_node = -1;
 
-	for (i = 0; i < numnodes; i++) {
+	for_each_online_node(i) {
 		cpumask_t tmp;
 
 		/* Start from local node */
-		n = (node+i)%numnodes;
+		n = (node+i)%num_online_nodes();
 
 		/* Don't want a node to appear more than once */
 		if (test_bit(n, used_node_mask))
@@ -1207,7 +1207,7 @@
 
 	/* NUMA-aware ordering of nodes */
 	local_node = pgdat->node_id;
-	load = numnodes;
+	load = num_online_nodes();
 	prev_node = local_node;
 	CLEAR_BITMAP(used_mask, MAX_NUMNODES);
 	while ((node = find_next_best_node(local_node, used_mask)) >= 0) {
@@ -1266,9 +1266,13 @@
  		 * zones coming right after the local ones are those from
  		 * node N+1 (modulo N)
  		 */
- 		for (node = local_node + 1; node < numnodes; node++)
+ 		for (node = next_node(local_node, node_online_map);
+		     node < MAX_NUMNODES;
+		     node = next_node(node, node_online_map))
  			j = build_zonelists_node(NODE_DATA(node), zonelist, j, k);
- 		for (node = 0; node < local_node; node++)
+ 		for (node = first_node(node_online_map);
+		     node < local_node;
+		     node = next_node(node, node_online_map))
  			j = build_zonelists_node(NODE_DATA(node), zonelist, j, k);
  
 		zonelist->zones[j++] = NULL;
@@ -1281,9 +1285,9 @@
 {
 	int i;
 
-	for(i = 0 ; i < numnodes ; i++)
+	for_each_online_node(i)
 		build_zonelists(NODE_DATA(i));
-	printk("Built %i zonelists\n", numnodes);
+	printk("Built %i zonelists\n", num_online_nodes());
 }
 
 /*


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 19/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (19 preceding siblings ...)
  2004-04-08 19:50 ` Patch 18/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 20/23 " Paul Jackson
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P19.nodemask_i386 - Matthew Dobson's [PATCH]_nodemask_t_i386_changes_[3_7]
        Changes to i386 specific code.  As with most arch changes,
        it involves close-coding loops (ie: for_each_online_node(nid)
        rather than for(nid=0;nid<numnodes;nid++)) and replacing the
        use of numnodes with num_online_nodes() and node_set_online(nid).

Index: 2.6.5.bitmap/arch/i386/kernel/mpparse.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/kernel/mpparse.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/kernel/mpparse.c	2004-04-08 04:46:08.000000000 -0700
@@ -294,8 +294,8 @@
 		printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
 	else
 		translation_table[mpc_record] = m; /* stash this for later */
-	if (m->trans_quad+1 > numnodes)
-		numnodes = m->trans_quad+1;
+	if (m->trans_quad+1 > num_online_nodes())
+		node_set_online(m->trans_quad);
 }
 
 /*
Index: 2.6.5.bitmap/arch/i386/kernel/numaq.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/kernel/numaq.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/kernel/numaq.c	2004-04-08 04:46:08.000000000 -0700
@@ -39,8 +39,7 @@
  * Function: smp_dump_qct()
  *
  * Description: gets memory layout from the quad config table.  This
- * function also increments numnodes with the number of nodes (quads)
- * present.
+ * function also updates node_online_map with the nodes (quads) present.
  */
 static void __init smp_dump_qct(void)
 {
@@ -49,11 +48,10 @@
 	struct sys_cfg_data *scd =
 		(struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
 
-	numnodes = 0;
-	for(node = 0; node < MAX_NUMNODES; node++) {
+	nodes_clear(node_online_map);
+	for_each_node(node) {
 		if(scd->quads_present31_0 & (1 << node)) {
 			node_set_online(node);
-			numnodes++;
 			eq = &scd->eq[node];
 			/* Convert to pages */
 			node_start_pfn[node] = MB_TO_PAGES(
@@ -86,7 +84,7 @@
 		(struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
 
 	
-	for(nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		if(scd->quads_present31_0 & (1 << nid)) {
 			eq = &scd->eq[nid];
 			cur = eq->hi_shrd_mem_start;
Index: 2.6.5.bitmap/arch/i386/kernel/smpboot.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/kernel/smpboot.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/kernel/smpboot.c	2004-04-08 04:46:08.000000000 -0700
@@ -520,7 +520,7 @@
 	int node;
 
 	printk("Unmapping cpu %d from all nodes\n", cpu);
-	for (node = 0; node < MAX_NUMNODES; node ++)
+	for_each_node(node)
 		cpu_clear(cpu, node_2_cpu_mask[node]);
 	cpu_2_node[cpu] = -1;
 }
Index: 2.6.5.bitmap/arch/i386/kernel/srat.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/kernel/srat.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/kernel/srat.c	2004-04-08 04:46:08.000000000 -0700
@@ -248,17 +248,16 @@
 	 * a set of sequential node IDs starting at zero.  (ACPI doesn't seem
 	 * to specify the range of _PXM values.)
 	 */
-	numnodes = 0;		/* init total nodes in system */
+	nodes_clear(node_online_map);	/* init total nodes in system */
 	for (i = 0; i < MAX_PXM_DOMAINS; i++) {
 		if (BMAP_TEST(pxm_bitmap, i)) {
-			pxm_to_nid_map[i] = numnodes;
-			nid_to_pxm_map[numnodes] = i;
-			node_set_online(numnodes);
-			++numnodes;
+			pxm_to_nid_map[i] = num_online_nodes();
+			nid_to_pxm_map[num_online_nodes()] = i;
+			node_set_online(num_online_nodes());
 		}
 	}
 
-	if (numnodes == 0)
+	if (num_online_nodes() == 0)
 		BUG();
 
 	/* set cnode id in memory chunk structure */
@@ -272,7 +271,7 @@
 		printk("%02X ", pxm_bitmap[i]);
 	}
 	printk("\n");
-	printk("Number of logical nodes in system = %d\n", numnodes);
+	printk("Number of logical nodes in system = %d\n", num_online_nodes());
 	printk("Number of memory chunks in system = %d\n", num_memory_chunks);
 
 	for (j = 0; j < num_memory_chunks; j++){
@@ -283,7 +282,7 @@
 	}
  
 	/*calculate node_start_pfn/node_end_pfn arrays*/
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		int been_here_before = 0;
 
 		for (j = 0; j < num_memory_chunks; j++){
@@ -415,7 +414,7 @@
 	int first;
 	unsigned long end = 0;
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		first = 1;
 		for (c = 0; c < num_memory_chunks; c++){
 			if (node_memory_chunk[c].nid == nid) {
@@ -443,8 +442,8 @@
 		zholes_size_init++;
 		get_zholes_init();
 	}
-	if((nid >= numnodes) | (nid >= MAX_NUMNODES))
-		printk("%s: nid = %d is invalid. numnodes = %d",
-		       __FUNCTION__, nid, numnodes);
+	if (!node_online(nid))
+		printk("%s: nid = %d is invalid. num_online_nodes() = %d",
+		       __FUNCTION__, nid, num_online_nodes());
 	return &zholes_size[nid * MAX_NR_ZONES];
 }
Index: 2.6.5.bitmap/arch/i386/mm/discontig.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/mm/discontig.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/mm/discontig.c	2004-04-08 04:46:08.000000000 -0700
@@ -39,7 +39,7 @@
  * numa interface - we expect the numa architecture specfic code to have
  *                  populated the following initialisation.
  *
- * 1) numnodes         - the total number of nodes configured in the system
+ * 1) node_online_map  - the bitmap of nodes configured in the system
  * 2) physnode_map     - the mapping between a pfn and owning node
  * 3) node_start_pfn   - the starting page frame number for a node
  * 3) node_end_pfn     - the ending page fram number for a node
@@ -107,7 +107,6 @@
 
          /* Indicate there is one node available. */
 	node_set_online(0);
-	numnodes = 1;
 	return 1;
 }
 
@@ -189,7 +188,7 @@
 	unsigned long pfn;
 	int node;
 
-	for (node = 1; node < numnodes; ++node) {
+	for(node = 1; node < num_online_nodes(); node++) {
 		for (pfn=0; pfn < node_remap_size[node]; pfn += PTRS_PER_PTE) {
 			vaddr = node_remap_start_vaddr[node]+(pfn<<PAGE_SHIFT);
 			set_pmd_pfn((ulong) vaddr, 
@@ -204,7 +203,7 @@
 	int nid;
 	unsigned long size, reserve_pages = 0;
 
-	for (nid = 1; nid < numnodes; nid++) {
+	for(nid = 1; nid < num_online_nodes(); nid++) {
 		/* calculate the size of the mem_map needed in bytes */
 		size = (node_end_pfn[nid] - node_start_pfn[nid] + 1) 
 			* sizeof(struct page) + sizeof(pg_data_t);
@@ -256,7 +255,7 @@
 
 	printk("Low memory ends at vaddr %08lx\n",
 			(ulong) pfn_to_kaddr(max_low_pfn));
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		node_remap_start_vaddr[nid] = pfn_to_kaddr(
 			highstart_pfn - node_remap_offset[nid]);
 		allocate_pgdat(nid);
@@ -267,7 +266,7 @@
 	}
 	printk("High memory starts at vaddr %08lx\n",
 			(ulong) pfn_to_kaddr(highstart_pfn));
-	for (nid = 0; nid < numnodes; nid++)
+	for_each_online_node(nid)
 		find_max_pfn_node(nid);
 
 	NODE_DATA(0)->bdata = &node0_bdata;
@@ -342,14 +341,14 @@
 	 * Clobber node 0's links and NULL out pgdat_list before starting.
 	 */
 	pgdat_list = NULL;
-	for (nid = numnodes - 1; nid >= 0; nid--) {       
+	for(nid = num_online_nodes() - 1; nid >= 0; nid--) {       
 		if (nid)
 			memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
 		NODE_DATA(nid)->pgdat_next = pgdat_list;
 		pgdat_list = NODE_DATA(nid);
 	}
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
 		unsigned long *zholes_size;
 		unsigned int max_dma;
@@ -405,7 +404,7 @@
 #ifdef CONFIG_HIGHMEM
 	int nid;
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long node_pfn, node_high_size, zone_start_pfn;
 		struct page * zone_mem_map;
 		
Index: 2.6.5.bitmap/arch/i386/mm/hugetlbpage.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/mm/hugetlbpage.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/mm/hugetlbpage.c	2004-04-08 04:46:08.000000000 -0700
@@ -39,11 +39,11 @@
 	struct page *page = NULL;
 
 	if (list_empty(&hugepage_freelists[nid])) {
-		for (nid = 0; nid < MAX_NUMNODES; ++nid)
+		for_each_node(nid)
 			if (!list_empty(&hugepage_freelists[nid]))
 				break;
 	}
-	if (nid >= 0 && nid < MAX_NUMNODES && !list_empty(&hugepage_freelists[nid])) {
+	if (node_possible(nid) && !list_empty(&hugepage_freelists[nid])) {
 		page = list_entry(hugepage_freelists[nid].next, struct page, list);
 		list_del(&page->list);
 	}
@@ -55,7 +55,7 @@
 	static int nid = 0;
 	struct page *page;
 	page = alloc_pages_node(nid, GFP_HIGHUSER, HUGETLB_PAGE_ORDER);
-	nid = (nid + 1) % numnodes;
+	nid = (nid + 1) % num_online_nodes();
 	return page;
 }
 
@@ -494,7 +494,7 @@
 	if (!cpu_has_pse)
 		return -ENODEV;
 
-	for (i = 0; i < MAX_NUMNODES; ++i)
+	for_each_node(i)
 		INIT_LIST_HEAD(&hugepage_freelists[i]);
 
 	for (i = 0; i < htlbpage_max; ++i) {
Index: 2.6.5.bitmap/arch/i386/pci/numa.c
===================================================================
--- 2.6.5.bitmap.orig/arch/i386/pci/numa.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/i386/pci/numa.c	2004-04-08 04:46:08.000000000 -0700
@@ -115,13 +115,10 @@
 		return 0;
 
 	pci_root_bus = pcibios_scan_root(0);
-	if (numnodes > 1) {
-		for (quad = 1; quad < numnodes; ++quad) {
-			printk("Scanning PCI bus %d for quad %d\n", 
-				QUADLOCAL2BUS(quad,0), quad);
-			pci_scan_bus(QUADLOCAL2BUS(quad,0), 
-				&pci_root_ops, NULL);
-		}
+	for(quad = 1; quad < num_online_nodes(); quad++) {
+		printk("Scanning PCI bus %d for quad %d\n", 
+			QUADLOCAL2BUS(quad,0), quad);
+		pci_scan_bus(QUADLOCAL2BUS(quad,0), &pci_root_ops, NULL);
 	}
 	return 0;
 }
Index: 2.6.5.bitmap/include/asm-i386/mach-numaq/mach_apic.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-i386/mach-numaq/mach_apic.h	2004-04-08 03:50:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-i386/mach-numaq/mach_apic.h	2004-04-08 04:46:08.000000000 -0700
@@ -114,13 +114,15 @@
 
 static inline void setup_portio_remap(void)
 {
-	if (numnodes <= 1)
+	int num_nodes = num_online_nodes();
+
+	if (num_nodes <= 1)
        		return;
 
-	printk("Remapping cross-quad port I/O for %d quads\n", numnodes);
-	xquad_portio = ioremap (XQUAD_PORTIO_BASE, numnodes*XQUAD_PORTIO_QUAD);
+	printk("Remapping cross-quad port I/O for %d quads\n", num_nodes);
+	xquad_portio = ioremap (XQUAD_PORTIO_BASE, num_nodes*XQUAD_PORTIO_QUAD);
 	printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
-		(u_long) xquad_portio, (u_long) numnodes*XQUAD_PORTIO_QUAD);
+		(u_long) xquad_portio, (u_long) num_nodes*XQUAD_PORTIO_QUAD);
 }
 
 static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 20/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (20 preceding siblings ...)
  2004-04-08 19:50 ` Patch 19/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 21/23 " Paul Jackson
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P20.nodemask_pp64 - Matthew Dobson's [PATCH]_nodemask_t_pp64_changes_[4_7]
        Changes to ppc64 specific code.  Untested.
        Code review & testing requested.

Index: 2.6.5.bitmap/arch/ppc64/kernel/smp.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ppc64/kernel/smp.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ppc64/kernel/smp.c	2004-04-08 04:46:10.000000000 -0700
@@ -737,19 +737,17 @@
 	int i;
 	int ret;
 
-	for (i = 0; i < MAX_NUMNODES; i++) {
-		if (node_online(i)) {
-			int p_node = parent_node(i);
-			struct node *parent = NULL;
-
-			if (p_node != i)
-				parent = &node_devices[p_node];
-
-			ret = register_node(&node_devices[i], i, parent);
-			if (ret)
-				printk(KERN_WARNING "register_nodes: "
-				       "register_node %d failed (%d)", i, ret);
-		}
+	for_each_online_node(i) {
+		int p_node = parent_node(i);
+		struct node *parent = NULL;
+
+		if (p_node != i)
+			parent = &node_devices[p_node];
+
+		ret = register_node(&node_devices[i], i, parent);
+		if (ret)
+			printk(KERN_WARNING "register_nodes: "
+			       "register_node %d failed (%d)", i, ret);
 	}
 }
 #else
Index: 2.6.5.bitmap/arch/ppc64/mm/hugetlbpage.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ppc64/mm/hugetlbpage.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ppc64/mm/hugetlbpage.c	2004-04-08 04:46:10.000000000 -0700
@@ -56,10 +56,10 @@
 	if (!largepage_roundrobin)
 		nid = numa_node_id();
 
-	for (i = 0; i < numnodes; i++) {
+	for_each_online_node(i) {
 		if (!list_empty(&hugepage_freelists[nid]))
 			break;
-		nid = (nid + 1) % numnodes;
+		nid = (nid + 1) % num_online_nodes();
 	}
 
 	if (!list_empty(&hugepage_freelists[nid])) {
@@ -68,7 +68,7 @@
 	}
 
 	if (largepage_roundrobin)
-		nid = (nid + 1) % numnodes;
+		nid = (nid + 1) % num_online_nodes();
 
 	return page;
 }
@@ -83,7 +83,7 @@
 		return NULL;
 
 	nid = page_zone(page)->zone_pgdat->node_id;
-	nid = (nid + 1) % numnodes;
+	nid = (nid + 1) % num_online_nodes();
 	return page;
 }
 
@@ -887,7 +887,7 @@
 	struct page *page;
 
 	if (cur_cpu_spec->cpu_features & CPU_FTR_16M_PAGE) {
-		for (i = 0; i < MAX_NUMNODES; ++i)
+		for_each_node(i)
 			INIT_LIST_HEAD(&hugepage_freelists[i]);
 
 		for (i = 0; i < htlbpage_max; ++i) {
Index: 2.6.5.bitmap/arch/ppc64/mm/init.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ppc64/mm/init.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ppc64/mm/init.c	2004-04-08 04:46:10.000000000 -0700
@@ -637,7 +637,7 @@
 {
 	int nid;
 
-        for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		if (node_data[nid].node_spanned_pages != 0) {
 			printk("freeing bootmem node %x\n", nid);
 			totalram_pages +=
Index: 2.6.5.bitmap/arch/ppc64/mm/numa.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ppc64/mm/numa.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ppc64/mm/numa.c	2004-04-08 04:46:10.000000000 -0700
@@ -64,7 +64,6 @@
 	int *cpu_associativity;
 	int *memory_associativity;
 	int depth;
-	int max_domain = 0;
 
 	if (strstr(saved_command_line, "numa=off")) {
 		printk(KERN_WARNING "NUMA disabled by user\n");
@@ -115,14 +114,11 @@
 			numa_domain = 0;
 		}
 
-		if (numa_domain >= MAX_NUMNODES)
+		if (!node_possible(numa_domain))
 			BUG();
 
 		node_set_online(numa_domain);
 
-		if (max_domain < numa_domain)
-			max_domain = numa_domain;
-
 		map_cpu_to_node(cpu_nr, numa_domain);
 	}
 
@@ -171,11 +167,10 @@
 			numa_domain = 0;
 		}
 
-		if (numa_domain >= MAX_NUMNODES)
+		if (!node_possible(numa_domain))
 			BUG();
 
-		if (max_domain < numa_domain)
-			max_domain = numa_domain;
+		node_set_online(numa_domain);
 
 		/* 
 		 * For backwards compatibility, OF splits the first node
@@ -212,8 +207,6 @@
 			goto new_range;
 	}
 
-	numnodes = max_domain + 1;
-
 	return 0;
 err:
 	of_node_put(cpu);
@@ -256,7 +249,7 @@
 	if (parse_numa_properties())
 		setup_nonnuma();
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long start_paddr, end_paddr;
 		int i;
 		unsigned long bootmem_paddr;
@@ -343,7 +336,7 @@
 	memset(zones_size, 0, sizeof(zones_size));
 	memset(zholes_size, 0, sizeof(zholes_size));
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long start_pfn;
 		unsigned long end_pfn;
 


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 21/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (21 preceding siblings ...)
  2004-04-08 19:50 ` Patch 20/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 22/23 " Paul Jackson
  2004-04-08 19:50 ` Patch 23/23 " Paul Jackson
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P21.nodemask_x86_64 - Matthew Dobson's [PATCH]_nodemask_t_x86_64_changes_[5_7]
        Changes to x86_64 specific code.
        Untested.  Code review & testing requested.

Index: 2.6.5.bitmap/arch/x86_64/kernel/setup64.c
===================================================================
--- 2.6.5.bitmap.orig/arch/x86_64/kernel/setup64.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/x86_64/kernel/setup64.c	2004-04-08 04:46:12.000000000 -0700
@@ -135,11 +135,11 @@
 		unsigned char *ptr;
 		/* If possible allocate on the node of the CPU.
 		   In case it doesn't exist round-robin nodes. */
-		if (!NODE_DATA(i % numnodes)) { 
-			printk("cpu with no node %d, numnodes %d\n", i, numnodes);
+		if (!NODE_DATA(i % num_online_nodes())) { 
+			printk("cpu with no node %d, num_online_nodes() %d\n", i, num_online_nodes());
 			ptr = alloc_bootmem(size);
 		} else { 
-			ptr = alloc_bootmem_node(NODE_DATA(i % numnodes), size);
+			ptr = alloc_bootmem_node(NODE_DATA(i % num_online_nodes()), size);
 		}
 		if (!ptr)
 			panic("Cannot allocate cpu data for CPU %d\n", i);
Index: 2.6.5.bitmap/arch/x86_64/mm/k8topology.c
===================================================================
--- 2.6.5.bitmap.orig/arch/x86_64/mm/k8topology.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/x86_64/mm/k8topology.c	2004-04-08 04:46:12.000000000 -0700
@@ -44,7 +44,7 @@
 int __init k8_scan_nodes(unsigned long start, unsigned long end)
 { 
 	unsigned long prevbase;
-	struct node nodes[MAXNODE];
+	struct node nodes[MAX_NUMNODES];
 	int nodeid, i, nb; 
 	int found = 0;
 	u32 reg;
@@ -57,9 +57,10 @@
 	printk(KERN_INFO "Scanning NUMA topology in Northbridge %d\n", nb); 
 
 	reg = read_pci_config(0, nb, 0, 0x60); 
-	numnodes =  ((reg >> 4) & 7) + 1; 
+	for(i = 0; i <= ((reg >> 4) & 7); i++)
+		node_set_online(i); 
 
-	printk(KERN_INFO "Number of nodes %d (%x)\n", numnodes, reg);
+	printk(KERN_INFO "Number of nodes %d (%x)\n", num_online_nodes(), reg);
 
 	memset(&nodes,0,sizeof(nodes)); 
 	prevbase = 0;
@@ -71,11 +72,11 @@
 
 		nodeid = limit & 7; 
 		if ((base & 3) == 0) { 
-			if (i < numnodes) 
+			if (i < num_online_nodes()) 
 				printk("Skipping disabled node %d\n", i); 
 			continue;
 		} 
-		if (nodeid >= numnodes) { 
+		if (nodeid >= num_online_nodes()) { 
 			printk("Ignoring excess node %d (%lx:%lx)\n", nodeid,
 			       base, limit); 
 			continue;
@@ -91,7 +92,7 @@
 			       nodeid, (base>>8)&3, (limit>>8) & 3); 
 			return -1; 
 		}	
-		if ((1UL << nodeid) & nodes_present) { 
+		if (node_online(nodeid)) {
 			printk(KERN_INFO "Node %d already present. Skipping\n", 
 			       nodeid);
 			continue;
@@ -151,7 +152,7 @@
 	} 
 	printk(KERN_INFO "Using node hash shift of %d\n", memnode_shift); 
 
-	for (i = 0; i < MAXNODE; i++) { 
+	for_each_node(i) {
 		if (nodes[i].start != nodes[i].end)
 		setup_node_bootmem(i, nodes[i].start, nodes[i].end); 
 	} 
@@ -161,15 +162,16 @@
 	   mapping. To avoid this fill in the mapping for all possible
 	   CPUs, as the number of CPUs is not known yet. 
 	   We round robin the existing nodes. */
-	rr = 0;
-	for (i = 0; i < MAXNODE; i++) {
-		if (nodes_present & (1UL<<i))
-			continue;
-		if ((nodes_present >> rr) == 0) 
-			rr = 0; 
-		rr = ffz(~nodes_present >> rr); 
+	rr = first_node(node_online_map);
+	for_each_node(i) {
+		if (node_online(i))
+			continue;
+
 		node_data[i] = node_data[rr];
-		rr++; 
+
+		rr = next_node(rr, node_online_map);
+		if (rr >= MAX_NUMNODES)
+			rr = first_node(node_online_map);
 	}
 
 	if (found == 1) 
Index: 2.6.5.bitmap/arch/x86_64/mm/numa.c
===================================================================
--- 2.6.5.bitmap.orig/arch/x86_64/mm/numa.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/x86_64/mm/numa.c	2004-04-08 04:46:12.000000000 -0700
@@ -18,7 +18,7 @@
 #define Dprintk(x...)
 #endif
 
-struct pglist_data *node_data[MAXNODE];
+struct pglist_data *node_data[MAX_NUMNODES];
 bootmem_data_t plat_node_bdata[MAX_NUMNODES];
 
 int memnode_shift;
@@ -26,8 +26,6 @@
 
 static int numa_off __initdata; 
 
-unsigned long nodes_present; 
-
 int __init compute_hash_shift(struct node *nodes)
 {
 	int i; 
@@ -37,7 +35,7 @@
 	/* When in doubt use brute force. */
 	while (shift < 48) { 
 		memset(memnodemap,0xff,sizeof(*memnodemap) * NODEMAPSIZE); 
-		for (i = 0; i < numnodes; i++) { 
+		for_each_online_node(i) {
 			if (nodes[i].start == nodes[i].end) 
 				continue;
 			for (addr = nodes[i].start; 
@@ -103,9 +101,6 @@
 
 	reserve_bootmem_node(NODE_DATA(nodeid), nodedata_phys, pgdat_size); 
 	reserve_bootmem_node(NODE_DATA(nodeid), bootmap_start, bootmap_pages<<PAGE_SHIFT);
-	if (nodeid + 1 > numnodes)
-		numnodes = nodeid + 1;
-	nodes_present |= (1UL << nodeid); 
 	node_set_online(nodeid);
 } 
 
@@ -154,7 +149,8 @@
 	fake_node = 1; 	
 	memnode_shift = 63; 
 	memnodemap[0] = 0;
-	numnodes = 1;
+	nodes_clear(node_online_map);
+	node_set_online(0);
 	setup_node_bootmem(0, start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
 	return -1; 
 } 
@@ -163,7 +159,7 @@
 { 
 	int i;
 	unsigned long pages = 0;
-	for_all_nodes(i) {
+	for_each_online_node(i) {
 		pages += free_all_bootmem_node(NODE_DATA(i));
 	}
 	return pages;
@@ -172,7 +168,7 @@
 void __init paging_init(void)
 { 
 	int i;
-	for_all_nodes(i) { 
+	for_each_online_node(i) { 
 		setup_node_zones(i); 
 	}
 } 
Index: 2.6.5.bitmap/include/asm-x86_64/mmzone.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/mmzone.h	2004-04-05 02:41:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/mmzone.h	2004-04-08 04:46:12.000000000 -0700
@@ -12,7 +12,6 @@
 
 #include <asm/smp.h>
 
-#define MAXNODE 8 
 #define NODEMAPSIZE 0xff
 
 /* Simple perfect hash to map physical addresses to node numbers */
Index: 2.6.5.bitmap/include/asm-x86_64/numa.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-x86_64/numa.h	2004-04-05 02:41:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-x86_64/numa.h	2004-04-08 04:46:12.000000000 -0700
@@ -1,19 +1,13 @@
 #ifndef _ASM_X8664_NUMA_H 
 #define _ASM_X8664_NUMA_H 1
 
-#define MAXNODE 8 
 #define NODEMASK 0xff
 
 struct node { 
 	u64 start,end; 
 };
 
-#define for_all_nodes(x) for ((x) = 0; (x) < numnodes; (x)++) \
-				if ((1UL << (x)) & nodes_present)
-
-
 extern int compute_hash_shift(struct node *nodes);
-extern unsigned long nodes_present;
 
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
 


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 22/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (22 preceding siblings ...)
  2004-04-08 19:50 ` Patch 21/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  2004-04-08 19:50 ` Patch 23/23 " Paul Jackson
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P22.nodemask_ia64 - Matthew Dobson's [PATCH]_nodemask_t_ia64_changes_[6_7]
        Changes to ia64 specific code.

Index: 2.6.5.bitmap/arch/ia64/kernel/acpi.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/kernel/acpi.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/kernel/acpi.c	2004-04-08 04:46:14.000000000 -0700
@@ -448,14 +448,15 @@
 	}
 
 	/* calculate total number of nodes in system from PXM bitmap */
-	numnodes = 0;		/* init total nodes in system */
+	nodes_clear(node_online_map);	/* init total nodes in system */
 
 	memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
 	memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
 	for (i = 0; i < MAX_PXM_DOMAINS; i++) {
 		if (pxm_bit_test(i)) {
-			pxm_to_nid_map[i] = numnodes;
-			nid_to_pxm_map[numnodes++] = i;
+			pxm_to_nid_map[i] = num_online_nodes();
+			nid_to_pxm_map[num_online_nodes()] = i;
+			node_set_online(num_online_nodes());
 		}
 	}
 
@@ -464,7 +465,7 @@
 		node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
 
 	/* assign memory bank numbers for each chunk on each node */
-	for (i = 0; i < numnodes; i++) {
+	for_each_online_node(i) {
 		int bank;
 
 		bank = 0;
@@ -477,7 +478,7 @@
 	for (i = 0; i < srat_num_cpus; i++)
 		node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
 
-	printk(KERN_INFO "Number of logical nodes in system = %d\n", numnodes);
+	printk(KERN_INFO "Number of logical nodes in system = %d\n", num_online_nodes());
 	printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
 
 	if (!slit_table) return;
@@ -497,8 +498,8 @@
 
 #ifdef SLIT_DEBUG
 	printk("ACPI 2.0 SLIT locality table:\n");
-	for (i = 0; i < numnodes; i++) {
-		for (j = 0; j < numnodes; j++)
+	for_each_online_node(i) {
+		for_each_online_node(j)
 			printk("%03d ", node_distance(i,j));
 		printk("\n");
 	}
Index: 2.6.5.bitmap/arch/ia64/kernel/smpboot.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/kernel/smpboot.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/kernel/smpboot.c	2004-04-08 04:46:14.000000000 -0700
@@ -470,7 +470,7 @@
 {
 	int cpu, i, node;
 
-	for(node=0; node<MAX_NUMNODES; node++)
+	for_each_node(node)
 		cpus_clear(node_to_cpu_mask[node]);
 	for(cpu = 0; cpu < NR_CPUS; ++cpu) {
 		/*
Index: 2.6.5.bitmap/arch/ia64/mm/discontig.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/mm/discontig.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/mm/discontig.c	2004-04-08 04:46:14.000000000 -0700
@@ -68,7 +68,7 @@
 	/*
 	 * All nids with memory.
 	 */
-	if (nnode == numnodes)
+	if (nnode == num_online_nodes())
 		return;
 
 	/*
@@ -77,10 +77,11 @@
 	 * For reassigned CPU nodes a nid can't be arrived at
 	 * until after this loop because the target nid's new
 	 * identity might not have been established yet. So
-	 * new nid values are fabricated above numnodes and
+	 * new nid values are fabricated above num_online_nodes() and
 	 * mapped back later to their true value.
 	 */
-	for (nid = 0, i = 0; i < numnodes; i++)  {
+	nid = 0;
+	for_each_online_node(i) {
 		if (test_bit(i, (void *) nodes_with_mem)) {
 			/*
 			 * Save original nid value for numa_slit
@@ -100,12 +101,12 @@
 			cpunid = nid;
 			nid++;
 		} else
-			cpunid = numnodes;
+			cpunid = num_online_nodes();
 
 		for (cpu = 0; cpu < NR_CPUS; cpu++)
 			if (node_cpuid[cpu].nid == i) {
 				/* For nodes not being reassigned just fix the cpu's nid. */
-				if (cpunid < numnodes) {
+				if (cpunid < num_online_nodes()) {
 					node_cpuid[cpu].nid = cpunid;
 					continue;
 				}
@@ -113,15 +114,17 @@
 				/*
 				 * For nodes being reassigned, find best node by
 				 * numa_slit information and then make a temporary
-				 * nid value based on current nid and numnodes.
+				 * nid value based on current nid and num_online_nodes().
 				 */
-				for (slit = 0xff, k = numnodes + numnodes, j = 0; j < numnodes; j++)
+				slit = 0xff;
+				k = 2 * num_online_nodes();
+				for_each_online_node(j)
 					if (i == j)
 						continue;
 					else if (test_bit(j, (void *) nodes_with_mem)) {
-						cslit = numa_slit[i * numnodes + j];
+						cslit = numa_slit[i * num_online_nodes() + j];
 						if (cslit < slit) {
-							k = numnodes + j;
+							k = num_online_nodes() + j;
 							slit = cslit;
 						}
 					}
@@ -134,11 +137,11 @@
 	 * Fixup temporary nid values for CPU-only nodes.
 	 */
 	for (cpu = 0; cpu < NR_CPUS; cpu++)
-		if (node_cpuid[cpu].nid == (numnodes + numnodes))
+		if (node_cpuid[cpu].nid == (2 * num_online_nodes()))
 			node_cpuid[cpu].nid = nnode - 1;
 		else
 			for (i = 0; i < nnode; i++)
-				if (node_flip[i] == (node_cpuid[cpu].nid - numnodes)) {
+				if (node_flip[i] == (node_cpuid[cpu].nid - num_online_nodes())) {
 					node_cpuid[cpu].nid = i;
 					break;
 				}
@@ -150,11 +153,12 @@
 	for (i = 0; i < nnode; i++)
 		for (j = 0; j < nnode; j++)
 			numa_slit_fix[i * nnode + j] =
-				numa_slit[node_flip[i] * numnodes + node_flip[j]];
+				numa_slit[node_flip[i] * num_online_nodes() + node_flip[j]];
 
 	memcpy(numa_slit, numa_slit_fix, sizeof (numa_slit));
 
-	numnodes = nnode;
+	for(i = 0; i < nnode; i++)
+		node_set_online(i);
 
 	return;
 }
@@ -353,7 +357,7 @@
 	struct bootmem_data *bdp;
 	int node;
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		pg_data_t *pdp = mem_data[node].pgdat;
 
 		bdp = pdp->bdata;
@@ -384,11 +388,11 @@
 	int cpu, node;
 	pg_data_t *pgdat_list[NR_NODES];
 
-	for (node = 0; node < numnodes; node++)
+	for_each_online_node(node)
 		pgdat_list[node] = mem_data[node].pgdat;
 
 	/* Copy the pg_data_t list to each node and init the node field */
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		memcpy(mem_data[node].node_data->pg_data_ptrs, pgdat_list,
 		       sizeof(pgdat_list));
 	}
@@ -412,15 +416,15 @@
 
 	reserve_memory();
 
-	if (numnodes == 0) {
+	if (num_online_nodes() == 0) {
 		printk(KERN_ERR "node info missing!\n");
-		numnodes = 1;
+		node_set_online(0);
 	}
 
 	min_low_pfn = -1;
 	max_low_pfn = 0;
 
-	if (numnodes > 1)
+	if (num_online_nodes() > 1)
 		reassign_cpu_only_nodes();
 
 	/* These actually end up getting called by call_pernode_memory() */
@@ -431,7 +435,7 @@
 	 * Initialize the boot memory maps in reverse order since that's
 	 * what the bootmem allocator expects
 	 */
-	for (node = numnodes - 1; node >= 0; node--) {
+	for (node = num_online_nodes() - 1; node >= 0; node--) {
 		unsigned long pernode, pernodesize, map;
 		struct bootmem_data *bdp;
 
@@ -612,12 +616,12 @@
 	efi_memmap_walk(find_largest_hole, &max_gap);
 
 	/* so min() will work in count_node_pages */
-	for (node = 0; node < numnodes; node++)
+	for_each_online_node(node)
 		mem_data[node].min_pfn = ~0UL;
 
 	efi_memmap_walk(filter_rsvd_memory, count_node_pages);
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		memset(zones_size, 0, sizeof(zones_size));
 		memset(zholes_size, 0, sizeof(zholes_size));
 
Index: 2.6.5.bitmap/arch/ia64/mm/hugetlbpage.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/mm/hugetlbpage.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/mm/hugetlbpage.c	2004-04-08 04:46:14.000000000 -0700
@@ -42,12 +42,11 @@
 	struct page *page = NULL;
 
 	if (list_empty(&hugepage_freelists[nid])) {
-		for (nid = 0; nid < MAX_NUMNODES; ++nid)
+		for_each_node(nid)
 			if (!list_empty(&hugepage_freelists[nid]))
 				break;
 	}
-	if (nid >= 0 && nid < MAX_NUMNODES &&
-	    !list_empty(&hugepage_freelists[nid])) {
+	if (node_possible(nid) && !list_empty(&hugepage_freelists[nid])) {
 		page = list_entry(hugepage_freelists[nid].next, struct page, list);
 		list_del(&page->list);
 	}
@@ -59,7 +58,7 @@
 	static int nid = 0;
 	struct page *page;
 	page = alloc_pages_node(nid, GFP_HIGHUSER, HUGETLB_PAGE_ORDER);
-	nid = (nid + 1) % numnodes;
+	nid = (nid + 1) % num_online_nodes();
 	return page;
 }
 
@@ -557,7 +556,7 @@
 	int i;
 	struct page *page;
 
-	for (i = 0; i < MAX_NUMNODES; ++i)
+	for_each_node(i)
 		INIT_LIST_HEAD(&hugepage_freelists[i]);
 
 	for (i = 0; i < htlbpage_max; ++i) {
Index: 2.6.5.bitmap/arch/ia64/mm/numa.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/mm/numa.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/mm/numa.c	2004-04-08 04:46:14.000000000 -0700
@@ -54,12 +54,12 @@
 {
 	int i, err = 0;
 
-	sysfs_nodes = kmalloc(sizeof(struct node) * numnodes, GFP_KERNEL);
+	sysfs_nodes = kmalloc(sizeof(struct node) * num_online_nodes(), GFP_KERNEL);
 	if (!sysfs_nodes) {
 		err = -ENOMEM;
 		goto out;
 	}
-	memset(sysfs_nodes, 0, sizeof(struct node) * numnodes);
+	memset(sysfs_nodes, 0, sizeof(struct node) * num_online_nodes());
 
 	sysfs_cpus = kmalloc(sizeof(struct cpu) * NR_CPUS, GFP_KERNEL);
 	if (!sysfs_cpus) {
@@ -69,7 +69,7 @@
 	}
 	memset(sysfs_cpus, 0, sizeof(struct cpu) * NR_CPUS);
 
-	for (i = 0; i < numnodes; i++)
+	for_each_online_node(i)
 		if ((err = register_node(&sysfs_nodes[i], i, 0)))
 			goto out;
 
Index: 2.6.5.bitmap/arch/ia64/sn/fakeprom/fpmem.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/fakeprom/fpmem.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/fakeprom/fpmem.c	2004-04-08 04:46:14.000000000 -0700
@@ -26,7 +26,7 @@
  *
  *		32 bit		32 bit
  *
- * 		numnodes	numcpus
+ * 		num_nodes	numcpus
  *
  *		16 bit   16 bit		   32 bit
  *		nasid0	cpuconf		membankdesc0
@@ -59,7 +59,7 @@
 #endif
 
 /*
- * For SN, this may not take an arg and gets the numnodes from 
+ * For SN, this may not take an arg and gets the num_nodes from 
  * the prom variable or by traversing klcfg or promcfg
  */
 int
@@ -144,7 +144,7 @@
 int
 build_efi_memmap(void *md, int mdsize)
 {
-	int		numnodes = GetNumNodes() ;
+	int		num_nodes = GetNumNodes() ;
 	int		cnode,bank ;
 	int		nasid ;
 	node_memmap_t	membank_info ;
@@ -153,7 +153,7 @@
 	long		paddr, hole, numbytes;
 
 
-	for (cnode=0;cnode<numnodes;cnode++) {
+	for (cnode=0; cnode<num_nodes; cnode++) {
 		nasid = GetNasid(cnode) ;
 		membank_info = GetMemBankInfo(cnode) ;
 		for (bank=0;bank<MD_BANKS_PER_NODE;bank++) {
Index: 2.6.5.bitmap/arch/ia64/sn/io/machvec/pci_bus_cvlink.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/machvec/pci_bus_cvlink.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/machvec/pci_bus_cvlink.c	2004-04-08 04:46:14.000000000 -0700
@@ -791,7 +791,6 @@
 	struct list_head *ln;
 	struct pci_bus *pci_bus = NULL;
 	struct pci_dev *pci_dev = NULL;
-	extern int numnodes;
 	int cnode, ret;
 #ifdef CONFIG_PROC_FS
 	extern void register_sn_procfs(void);
@@ -814,7 +813,7 @@
 
 	sgi_master_io_infr_init();
 
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		extern void intr_init_vecblk(cnodeid_t);
 		intr_init_vecblk(cnode);
 	}
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/klconflib.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/klconflib.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/klconflib.c	2004-04-08 04:46:14.000000000 -0700
@@ -62,7 +62,7 @@
 		    (start->brd_nasid == nasid))
 			return start;
 
-		if (numionodes == numnodes)
+		if (numionodes == num_online_nodes())
 			start = KLCF_NEXT_ANY(start);
 		else
 			start = KLCF_NEXT(start);
@@ -95,7 +95,7 @@
 		    (start->brd_nasid == nasid))
 			return start;
 
-		if (numionodes == numnodes)
+		if (numionodes == num_online_nodes())
 			start = KLCF_NEXT_ANY(start);
 		else
 			start = KLCF_NEXT(start);
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/klgraph.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/klgraph.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/klgraph.c	2004-04-08 04:46:14.000000000 -0700
@@ -279,7 +279,7 @@
 	char path_buffer[100];
 	int rv;
 
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		nasid = COMPACT_TO_NASID_NODEID(cnode);
 		brd = find_lboard_class_any((lboard_t *)KL_CONFIG_INFO(nasid),
 				KLTYPE_ROUTER);
@@ -413,7 +413,7 @@
 	cnodeid_t cnode;
 	lboard_t *brd;
 
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		nasid = COMPACT_TO_NASID_NODEID(cnode);
 		brd = find_lboard_class_any((lboard_t *)KL_CONFIG_INFO(nasid),
 				KLTYPE_ROUTER);
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_SN_init.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/ml_SN_init.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_SN_init.c	2004-04-08 04:46:14.000000000 -0700
@@ -38,7 +38,7 @@
 	/* Allocate per-node platform-dependent data */
 	
 	nasid = COMPACT_TO_NASID_NODEID(node);
-	if (node >= numnodes) /* Headless/memless IO nodes */
+	if (node >= num_online_nodes()) /* Headless/memless IO nodes */
 		hubinfo = (hubinfo_t)alloc_bootmem_node(NODE_DATA(0), sizeof(struct hubinfo_s));
 	else
 		hubinfo = (hubinfo_t)alloc_bootmem_node(NODE_DATA(node), sizeof(struct hubinfo_s));
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_SN_intr.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/ml_SN_intr.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_SN_intr.c	2004-04-08 04:46:14.000000000 -0700
@@ -256,12 +256,12 @@
 	cnodeid_t candidate_node;
 	cpuid_t cpuid;
 
-	if (last_node >= numnodes)
+	if (last_node >= num_online_nodes())
 		last_node = 0;
 
 	for (candidate_node = last_node + 1; candidate_node != last_node;
 			candidate_node++) {
-		if (candidate_node == numnodes)
+		if (candidate_node == num_online_nodes())
 			candidate_node = 0;
 		cpuid = intr_cpu_choose_from_node(candidate_node);
 		if (cpuid != CPU_NONE)
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_iograph.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/ml_iograph.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/ml_iograph.c	2004-04-08 04:46:14.000000000 -0700
@@ -680,7 +680,7 @@
 		DBG("init_all_devices: Done io_init_node() for cnode %d\n", cnodeid);
 	}
 
-	for (cnodeid = 0; cnodeid < numnodes; cnodeid++) {
+	for_each_online_node(cnodeid) {
 		/*
 	 	 * Update information generated by IO init.
 		 */
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/module.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/module.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/module.c	2004-04-08 04:46:14.000000000 -0700
@@ -195,7 +195,7 @@
      * First pass just scan for compute node boards KLTYPE_SNIA.
      * We do not support memoryless compute nodes.
      */
-    for (node = 0; node < numnodes; node++) {
+    for_each_online_node(node) {
 	nasid = COMPACT_TO_NASID_NODEID(node);
 	board = find_lboard_nasid((lboard_t *) KL_CONFIG_INFO(nasid), nasid, KLTYPE_SNIA);
 	ASSERT(board);
@@ -210,7 +210,7 @@
     /*
      * Second scan, look for headless/memless board hosted by compute nodes.
      */
-    for (node = numnodes; node < numionodes; node++) {
+    for (node = num_online_nodes(); node < numionodes; node++) {
 	nasid_t		nasid;
 	char		serial_number[16];
 
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c	2004-04-08 04:46:14.000000000 -0700
@@ -2639,7 +2639,7 @@
 		if (brd->brd_flags & LOCAL_MASTER_IO6) {
 			return 1;
 		}
-                if (numionodes == numnodes)
+                if (numionodes == num_online_nodes())
                         brd = KLCF_NEXT_ANY(brd);
                 else
                         brd = KLCF_NEXT(brd);
@@ -2652,7 +2652,7 @@
 		if (brd->brd_flags & LOCAL_MASTER_IO6) {
 			return 1;
 		}
-                if (numionodes == numnodes)
+                if (numionodes == num_online_nodes())
                         brd = KLCF_NEXT_ANY(brd);
                 else
                         brd = KLCF_NEXT(brd);
Index: 2.6.5.bitmap/arch/ia64/sn/io/sn2/shub.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/io/sn2/shub.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/io/sn2/shub.c	2004-04-08 04:46:14.000000000 -0700
@@ -167,7 +167,7 @@
 	int		nasid;
 
         cnode = (cnodeid_t)(u64)file->f_dentry->d_fsdata;
-        if (cnode < 0 || cnode >= numnodes)
+        if (cnode < 0 || cnode >= num_online_nodes())
                 return -ENODEV;
 
         switch (cmd) {
Index: 2.6.5.bitmap/arch/ia64/sn/kernel/setup.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/kernel/setup.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/kernel/setup.c	2004-04-08 04:46:14.000000000 -0700
@@ -221,7 +221,7 @@
 {
 	int	cnode;
 
-	for (cnode=0; cnode< numnodes; cnode++)
+	for_each_online_node(cnode)
 		if (is_shub_1_1(cnodeid_to_nasid(cnode)))
 			shub_1_1_found = 1;
 }
@@ -369,16 +369,16 @@
 		panic("overflow of cpu_data page");
 
 	memset(pda->cnodeid_to_nasid_table, -1, sizeof(pda->cnodeid_to_nasid_table));
-	for (cnode=0; cnode<numnodes; cnode++)
+	for_each_online_node(cnode)
 		pda->cnodeid_to_nasid_table[cnode] = pxm_to_nasid(nid_to_pxm_map[cnode]);
 
-	numionodes = numnodes;
+	numionodes = num_online_nodes();
 	scan_for_ionodes();
 
         /*
          * Allocate & initalize the nodepda for each node.
          */
-        for (cnode=0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		nodepdaindr[cnode] = alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
 		memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
         }
@@ -395,7 +395,7 @@
 	 * The following routine actually sets up the hubinfo struct
 	 * in nodepda.
 	 */
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		init_platform_nodepda(nodepdaindr[cnode], cnode);
 		bte_init_node (nodepdaindr[cnode], cnode);
 	}
@@ -483,7 +483,7 @@
 
 	if (nodepda->node_first_cpu == cpuid) {
 		int	buddy_nasid;
-		buddy_nasid = cnodeid_to_nasid(numa_node_id() == numnodes-1 ? 0 : numa_node_id()+ 1);
+		buddy_nasid = cnodeid_to_nasid(numa_node_id() == num_online_nodes()-1 ? 0 : numa_node_id()+ 1);
 		pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
 	}
 
Index: 2.6.5.bitmap/arch/ia64/sn/kernel/sn2/prominfo_proc.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/kernel/sn2/prominfo_proc.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/kernel/sn2/prominfo_proc.c	2004-04-08 04:46:14.000000000 -0700
@@ -320,16 +320,15 @@
 	TRACE();
 
 	DPRINTK("running on cpu %d\n", smp_processor_id());
-	DPRINTK("numnodes %d\n", numnodes);
+	DPRINTK("num_online_nodes() %d\n", num_online_nodes());
 
-	proc_entries = kmalloc(numnodes * sizeof(struct proc_dir_entry *),
+	proc_entries = kmalloc(num_online_nodes() * sizeof(struct proc_dir_entry *),
 			       GFP_KERNEL);
 
 	sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
 
-	for (cnodeid = 0, entp = proc_entries;
-	     cnodeid < numnodes;
-	     cnodeid++, entp++) {
+	entp = proc_entries;
+	for_each_online_node(cnodeid) {
 		sprintf(name, "node%d", cnodeid);
 		*entp = proc_mkdir(name, sgi_prominfo_entry);
 		nasid = cnodeid_to_nasid(cnodeid);
@@ -339,6 +338,7 @@
 		create_proc_read_entry(
 			"version", 0, *entp, read_version_entry,
 			lookup_fit(nasid));
+		entp++;
 	}
 
 	return 0;
@@ -353,13 +353,13 @@
 
 	TRACE();
 
-	for (cnodeid = 0, entp = proc_entries;
-	     cnodeid < numnodes;
-	     cnodeid++, entp++) {
+	entp = proc_entries;
+	for_each_online_node(cnodeid) {
 		remove_proc_entry("fit", *entp);
 		remove_proc_entry("version", *entp);
 		sprintf(name, "node%d", cnodeid);
 		remove_proc_entry(name, sgi_prominfo_entry);
+		entp++;
 	}
 	remove_proc_entry("sgi_prominfo", NULL);
 	kfree(proc_entries);
Index: 2.6.5.bitmap/arch/ia64/sn/kernel/sn2/sn2_smp.c
===================================================================
--- 2.6.5.bitmap.orig/arch/ia64/sn/kernel/sn2/sn2_smp.c	2004-04-05 02:41:32.000000000 -0700
+++ 2.6.5.bitmap/arch/ia64/sn/kernel/sn2/sn2_smp.c	2004-04-08 04:46:14.000000000 -0700
@@ -183,7 +183,7 @@
 
 	mycnode = numa_node_id();
 
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		if (is_headless_node(cnode) || cnode == mycnode)
 			continue;
 		nasid = cnodeid_to_nasid(cnode);
Index: 2.6.5.bitmap/include/asm-ia64/numa.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ia64/numa.h	2004-04-05 02:41:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ia64/numa.h	2004-04-08 04:46:14.000000000 -0700
@@ -59,7 +59,7 @@
  */
 
 extern u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
-#define node_distance(from,to) (numa_slit[from * numnodes + to])
+#define node_distance(from,to) (numa_slit[from * num_online_nodes() + to])
 
 extern int paddr_to_nid(unsigned long paddr);
 
Index: 2.6.5.bitmap/include/asm-ia64/sn/sn2/sn_private.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-ia64/sn/sn2/sn_private.h	2004-04-05 02:41:33.000000000 -0700
+++ 2.6.5.bitmap/include/asm-ia64/sn/sn2/sn_private.h	2004-04-08 04:46:14.000000000 -0700
@@ -87,9 +87,7 @@
 void install_klidbg_functions(void);
 
 /* klnuma.c */
-extern void replicate_kernel_text(int numnodes);
 extern unsigned long get_freemem_start(cnodeid_t cnode);
-extern void setup_replication_mask(int maxnodes);
 
 /* init.c */
 extern cnodeid_t get_compact_nodeid(void);	/* get compact node id */


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

* Patch 23/23 - Bitmaps, Cpumasks and Nodemasks
  2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
                   ` (23 preceding siblings ...)
  2004-04-08 19:50 ` Patch 22/23 " Paul Jackson
@ 2004-04-08 19:50 ` Paul Jackson
  24 siblings, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-04-08 19:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: colpatch, wli, rusty, linux-kernel

P23.nodemask_other_archs - Matthew Dobson's [PATCH]_nodemask_t_other_arch_changes_[7_7]
        Changes to other arch-specific code (alpha, arm, mips,
        sparc64 & sh).  Untested.  Code review & testing requested.

Index: 2.6.5.bitmap/arch/alpha/mm/numa.c
===================================================================
--- 2.6.5.bitmap.orig/arch/alpha/mm/numa.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/alpha/mm/numa.c	2004-04-08 08:17:17.000000000 -0700
@@ -246,7 +246,7 @@
 	reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(bootmap_start), bootmap_size);
 	printk(" reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
 
-	numnodes++;
+	node_set_online(nid);
 }
 
 void __init
@@ -256,11 +256,11 @@
 
 	show_mem_layout();
 
-	numnodes = 0;
+	nodes_clear(node_online_map);
 
 	min_low_pfn = ~0UL;
 	max_low_pfn = 0UL;
-	for (nid = 0; nid < MAX_NUMNODES; nid++)
+	for_each_node(nid)
 		setup_memory_node(nid, kernel_end);
 
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -303,7 +303,7 @@
 	 */
 	dma_local_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
 
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long start_pfn = node_bdata[nid].node_boot_start >> PAGE_SHIFT;
 		unsigned long end_pfn = node_bdata[nid].node_low_pfn;
 
@@ -332,7 +332,7 @@
 	high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
 
 	reservedpages = 0;
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		/*
 		 * This will free up the bootmem, ie, slot 0 memory
 		 */
@@ -372,7 +372,7 @@
 	printk("\nMem-info:\n");
 	show_free_areas();
 	printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
-	for (nid = 0; nid < numnodes; nid++) {
+	for_each_online_node(nid) {
 		struct page * lmem_map = node_mem_map(nid);
 		i = node_spanned_pages(nid);
 		while (i-- > 0) {
Index: 2.6.5.bitmap/arch/arm/mm/init.c
===================================================================
--- 2.6.5.bitmap.orig/arch/arm/mm/init.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/arm/mm/init.c	2004-04-08 08:17:17.000000000 -0700
@@ -69,7 +69,7 @@
 	show_free_areas();
 	printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		struct page *page, *end;
 
 		page = NODE_MEM_MAP(node);
@@ -172,7 +172,7 @@
 {
 	unsigned int i, bootmem_pages = 0, memend_pfn = 0;
 
-	for (i = 0; i < MAX_NUMNODES; i++) {
+	for_each_node(i) {
 		np[i].start = -1U;
 		np[i].end = 0;
 		np[i].bootmap_pages = 0;
@@ -192,18 +192,13 @@
 
 		node = mi->bank[i].node;
 
-		if (node >= numnodes) {
-			numnodes = node + 1;
-
-			/*
-			 * Make sure we haven't exceeded the maximum number
-			 * of nodes that we have in this configuration.  If
-			 * we have, we're in trouble.  (maybe we ought to
-			 * limit, instead of bugging?)
-			 */
-			if (numnodes > MAX_NUMNODES)
-				BUG();
-		}
+		/*
+		 * Make sure we haven't exceeded the maximum number of nodes 
+		 * that we have in this configuration.  If we have, we're in 
+		 * trouble.
+		 */
+		if (!node_online(node) && node_possible(node))
+			node_set_online(node);
 
 		/*
 		 * Get the start and end pfns for this bank
@@ -225,7 +220,7 @@
 	 * Calculate the number of pages we require to
 	 * store the bootmem bitmaps.
 	 */
-	for (i = 0; i < numnodes; i++) {
+	for_each_online_node(i) {
 		if (np[i].end == 0)
 			continue;
 
@@ -388,8 +383,8 @@
 	 * (we could also do with rolling bootmem_init and paging_init
 	 * into one generic "memory_init" type function).
 	 */
-	np += numnodes - 1;
-	for (node = numnodes - 1; node >= 0; node--, np--) {
+	np += num_online_nodes() - 1;
+	for (node = num_online_nodes() - 1; node >= 0; node--, np--) {
 		/*
 		 * If there are no pages in this node, ignore it.
 		 * Note that node 0 must always have some pages.
@@ -457,7 +452,7 @@
 	/*
 	 * initialise the zones within each node
 	 */
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		unsigned long zone_size[MAX_NR_ZONES];
 		unsigned long zhole_size[MAX_NR_ZONES];
 		struct bootmem_data *bdata;
@@ -567,7 +562,7 @@
 		create_memmap_holes(&meminfo);
 
 	/* this will put all unused low memory onto the freelists */
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		pg_data_t *pgdat = NODE_DATA(node);
 
 		if (pgdat->node_spanned_pages != 0)
Index: 2.6.5.bitmap/arch/arm/mm/mm-armv.c
===================================================================
--- 2.6.5.bitmap.orig/arch/arm/mm/mm-armv.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/arm/mm/mm-armv.c	2004-04-08 08:17:17.000000000 -0700
@@ -653,6 +653,6 @@
 {
 	int node;
 
-	for (node = 0; node < numnodes; node++)
+	for_each_online_node(node)
 		free_unused_memmap_node(node, mi);
 }
Index: 2.6.5.bitmap/arch/arm26/mm/init.c
===================================================================
--- 2.6.5.bitmap.orig/arch/arm26/mm/init.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/arm26/mm/init.c	2004-04-08 08:17:17.000000000 -0700
@@ -156,7 +156,8 @@
 {
 	unsigned int memend_pfn = 0;
 
-	numnodes = 1;
+	nodes_clear(node_online_map);
+	node_set_online(0);
 
 	np->bootmap_pages = 0;
 
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-init.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-init.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-init.c	2004-04-08 08:17:17.000000000 -0700
@@ -10,7 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/sched.h>
-#include <linux/mmzone.h>	/* for numnodes */
+#include <linux/nodemask.h>	/* for node_online_map */
 #include <linux/mm.h>
 #include <linux/cpumask.h>
 #include <asm/cpu.h>
@@ -56,14 +56,13 @@
 		return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_COARSEREG_SHFT;
 }
 
-static void gen_region_mask(hubreg_t *region_mask, int maxnodes)
+static void gen_region_mask(hubreg_t *region_mask)
 {
 	cnodeid_t cnode;
 
 	(*region_mask) = 0;
-	for (cnode = 0; cnode < maxnodes; cnode++) {
+	for_each_online_node(cnode)
 		(*region_mask) |= 1ULL << get_region(cnode);
-	}
 }
 
 static int is_fine_dirmode(void)
@@ -168,7 +167,7 @@
 	int port;
 
 	/* Figure out which routers nodes in question are connected to */
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		nasid = COMPACT_TO_NASID_NODEID(cnode);
 
 		if (nasid == -1) continue;
@@ -235,9 +234,9 @@
 		for (col = 0; col < MAX_COMPACT_NODES; col++)
 			node_distances[row][col] = -1;
 
-	for (row = 0; row < numnodes; row++) {
+	for_each_online_node(row) {
 		nasid = COMPACT_TO_NASID_NODEID(row);
-		for (col = 0; col < numnodes; col++) {
+		for_each_online_node(col) {
 			nasid2 = COMPACT_TO_NASID_NODEID(col);
 			node_distances[row][col] = node_distance(nasid, nasid2);
 		}
@@ -257,17 +256,17 @@
 	printk("************** Topology ********************\n");
 
 	printk("    ");
-	for (col = 0; col < numnodes; col++)
+	for_each_online_node(col)
 		printk("%02d ", col);
 	printk("\n");
-	for (row = 0; row < numnodes; row++) {
+	for_each_online_node(row) {
 		printk("%02d  ", row);
-		for (col = 0; col < numnodes; col++)
+		for_each_online_node(col)
 			printk("%2d ", node_distances[row][col]);
 		printk("\n");
 	}
 
-	for (cnode = 0; cnode < numnodes; cnode++) {
+	for_each_online_node(cnode) {
 		nasid = COMPACT_TO_NASID_NODEID(cnode);
 
 		if (nasid == -1) continue;
@@ -323,14 +322,14 @@
 	init_topology_matrix();
 	dump_topology();
 
-	gen_region_mask(&region_mask, numnodes);
+	gen_region_mask(&region_mask);
 
-	setup_replication_mask(numnodes);
+	setup_replication_mask();
 
 	/*
 	 * Set all nodes' calias sizes to 8k
 	 */
-	for (i = 0; i < numnodes; i++) {
+	for_each_online_node(i) {
 		nasid_t nasid;
 
 		nasid = COMPACT_TO_NASID_NODEID(i);
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-klnuma.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-klnuma.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-klnuma.c	2004-04-08 08:17:17.000000000 -0700
@@ -27,7 +27,7 @@
  * kernel.  For example, we should never put a copy on a headless node,
  * and we should respect the topology of the machine.
  */
-void __init setup_replication_mask(int maxnodes)
+void __init setup_replication_mask(void)
 {
 	static int 	numa_kernel_replication_ratio;
 	cnodeid_t	cnode;
@@ -44,7 +44,7 @@
 	numa_kernel_replication_ratio = 1;
 #endif
 
-	for (cnode = 1; cnode < numnodes; cnode++) {
+	for (cnode = 1; cnode < num_online_nodes(); cnode++) {
 		/* See if this node should get a copy of the kernel */
 		if (numa_kernel_replication_ratio &&
 		    !(cnode % numa_kernel_replication_ratio)) {
@@ -92,7 +92,7 @@
 	memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
 }
 
-void __init replicate_kernel_text(int maxnodes)
+void __init replicate_kernel_text(void)
 {
 	cnodeid_t cnode;
 	nasid_t client_nasid;
@@ -103,7 +103,7 @@
 	/* Record where the master node should get its kernel text */
 	set_ktext_source(master_nasid, master_nasid);
 
-	for (cnode = 1; cnode < maxnodes; cnode++) {
+	for (cnode = 1; cnode < num_online_nodes(); cnode++) {
 		client_nasid = COMPACT_TO_NASID_NODEID(cnode);
 
 		/* Check if this node should get a copy of the kernel */
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-memory.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-memory.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-memory.c	2004-04-08 08:17:17.000000000 -0700
@@ -137,7 +137,7 @@
 	pfn_t slot0sz = 0, nodebytes;	/* Hack to detect problem configs */
 	int ignore;
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		numslots = node_getnumslots(node);
 		ignore = nodebytes = 0;
 		for (slot = 0; slot < numslots; slot++) {
@@ -183,7 +183,7 @@
 
 	num_physpages = szmem();
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		pfn_t slot_firstpfn = slot_getbasepfn(node, 0);
 		pfn_t slot_lastpfn = slot_firstpfn + slot_getsize(node, 0);
 		pfn_t slot_freepfn = node_getfirstfree(node);
@@ -225,7 +225,7 @@
 
 	pagetable_init();
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		pfn_t start_pfn = slot_getbasepfn(node, 0);
 		pfn_t end_pfn = node_getmaxclick(node) + 1;
 
@@ -245,7 +245,7 @@
 
 	high_memory = (void *) __va(num_physpages << PAGE_SHIFT);
 
-	for (node = 0; node < numnodes; node++) {
+	for_each_online_node(node) {
 		unsigned slot, numslots;
 		struct page *end, *p;
 	
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-nmi.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-nmi.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-nmi.c	2004-04-08 08:17:17.000000000 -0700
@@ -183,7 +183,7 @@
 {
 	cnodeid_t	cnode;
 
-	for(cnode = 0 ; cnode < numnodes; cnode++)
+	for_each_online_node(cnode)
 		nmi_node_eframe_save(cnode);
 }
 
@@ -214,13 +214,13 @@
 	 * send NMIs to all cpus on a 256p system.
 	 */
 	for (i=0; i < 1500; i++) {
-		for (node=0; node < numnodes; node++)
+		for_each_online_node(node)
 			if (NODEPDA(node)->dump_count == 0)
 				break;
-		if (node == numnodes)
+		if (node == num_online_nodes())
 			break;
 		if (i == 1000) {
-			for (node=0; node < numnodes; node++)
+			for_each_online_node(node)
 				if (NODEPDA(node)->dump_count == 0) {
 					cpu = CNODE_TO_CPU_BASE(node);
 					for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-reset.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-reset.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-reset.c	2004-04-08 08:17:17.000000000 -0700
@@ -43,7 +43,7 @@
 	smp_send_stop();
 #endif
 #if 0
-	for (i = 0; i < numnodes; i++)
+	for_each_online_node(i)
 		REMOTE_HUB_S(COMPACT_TO_NASID_NODEID(i), PROMOP_REG,
 							PROMOP_REBOOT);
 #else
@@ -59,7 +59,7 @@
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
-	for (i = 0; i < numnodes; i++)
+	for_each_online_node(i)
 		REMOTE_HUB_S(COMPACT_TO_NASID_NODEID(i), PROMOP_REG,
 							PROMOP_RESTART);
 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
Index: 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-smp.c
===================================================================
--- 2.6.5.bitmap.orig/arch/mips/sgi-ip27/ip27-smp.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/mips/sgi-ip27/ip27-smp.c	2004-04-08 08:17:17.000000000 -0700
@@ -108,18 +108,18 @@
 	for (i = 0; i < MAXCPUS; i++)
 		cpuid_to_compact_node[i] = INVALID_CNODEID;
 
-	numnodes = 0;
+	nodes_clear(node_online_map);
 	for (i = 0; i < MAX_COMPACT_NODES; i++) {
 		nasid_t nasid = gdap->g_nasidtable[i];
 		if (nasid == INVALID_NASID)
 			break;
 		compact_to_nasid_node[i] = nasid;
 		nasid_to_compact_node[nasid] = i;
-		numnodes++;
+		node_set_online(i);
 		highest = do_cpumask(i, nasid, highest);
 	}
 
-	printk("Discovered %d cpus on %d nodes\n", highest + 1, numnodes);
+	printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
 }
 
 void __init prom_build_cpu_map(void)
@@ -155,13 +155,13 @@
 {
 	cnodeid_t	cnode;
 
-	for (cnode = 0; cnode < numnodes; cnode++)
+	for_each_online_node(cnode)
 		intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
 
 	/* Master has already done per_cpu_init() */
 	install_ipi();
 
-	replicate_kernel_text(numnodes);
+	replicate_kernel_text();
 
 	/*
 	 * Assumption to be fixed: we're always booted on logical / physical
Index: 2.6.5.bitmap/arch/sh/mm/hugetlbpage.c
===================================================================
--- 2.6.5.bitmap.orig/arch/sh/mm/hugetlbpage.c	2004-04-08 08:04:03.000000000 -0700
+++ 2.6.5.bitmap/arch/sh/mm/hugetlbpage.c	2004-04-08 08:17:58.000000000 -0700
@@ -61,7 +61,7 @@
 	static int nid = 0;
 	struct page *page;
 	page = alloc_pages_node(nid, GFP_HIGHUSER, HUGETLB_PAGE_ORDER);
-	nid = (nid + 1) % numnodes;
+	nid = (nid + 1) % num_online_nodes();
 	return page;
 }
 
Index: 2.6.5.bitmap/arch/sparc64/mm/hugetlbpage.c
===================================================================
--- 2.6.5.bitmap.orig/arch/sparc64/mm/hugetlbpage.c	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/arch/sparc64/mm/hugetlbpage.c	2004-04-08 08:17:17.000000000 -0700
@@ -39,12 +39,11 @@
 	struct page *page = NULL;
 
 	if (list_empty(&hugepage_freelists[nid])) {
-		for (nid = 0; nid < MAX_NUMNODES; ++nid)
+		for_each_node(nid)
 			if (!list_empty(&hugepage_freelists[nid]))
 				break;
 	}
-	if (nid >= 0 && nid < MAX_NUMNODES &&
-	    !list_empty(&hugepage_freelists[nid])) {
+	if (node_possible(nid) && !list_empty(&hugepage_freelists[nid])) {
 		page = list_entry(hugepage_freelists[nid].next,
 				  struct page, list);
 		list_del(&page->list);
@@ -57,7 +56,7 @@
 	static int nid = 0;
 	struct page *page;
 	page = alloc_pages_node(nid, GFP_HIGHUSER, HUGETLB_PAGE_ORDER);
-	nid = (nid + 1) % numnodes;
+	nid = (nid + 1) % num_online_nodes();
 	return page;
 }
 
@@ -464,7 +463,7 @@
 	int i;
 	struct page *page;
 
-	for (i = 0; i < MAX_NUMNODES; ++i)
+	for_each_node(i)
 		INIT_LIST_HEAD(&hugepage_freelists[i]);
 
 	for (i = 0; i < htlbpage_max; ++i) {
Index: 2.6.5.bitmap/include/asm-mips/sn/sn_private.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-mips/sn/sn_private.h	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/include/asm-mips/sn/sn_private.h	2004-04-08 08:17:17.000000000 -0700
@@ -13,8 +13,8 @@
 extern void per_hub_init(cnodeid_t cnode);
 extern void install_cpu_nmi_handler(int slice);
 extern void install_ipi(void);
-extern void setup_replication_mask(int);
-extern void replicate_kernel_text(int);
+extern void setup_replication_mask(void);
+extern void replicate_kernel_text(void);
 extern pfn_t node_getfirstfree(cnodeid_t);
 
 #endif /* __ASM_SN_SN_PRIVATE_H */
Index: 2.6.5.bitmap/include/asm-sh/mmzone.h
===================================================================
--- 2.6.5.bitmap.orig/include/asm-sh/mmzone.h	2004-04-08 08:17:10.000000000 -0700
+++ 2.6.5.bitmap/include/asm-sh/mmzone.h	2004-04-08 08:17:17.000000000 -0700
@@ -46,7 +46,7 @@
 {
 	unsigned int i;
 
-	for (i = 0; i < MAX_NUMNODES; i++) {
+	for_each_node(i) {
 		if (page >= NODE_MEM_MAP(i) &&
 		    page < NODE_MEM_MAP(i) + NODE_DATA(i)->node_size)
 			return 1;


-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

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

end of thread, other threads:[~2004-04-08 20:39 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-08 18:50 Patch 0/23 - Bitmaps, Cpumasks and Nodemasks Paul Jackson
2004-04-08 19:47 ` Patch 1/23 " Paul Jackson
2004-04-08 19:48 ` Patch 2/23 " Paul Jackson
2004-04-08 19:48 ` Patch 3/23 " Paul Jackson
2004-04-08 19:48 ` Patch 4/23 " Paul Jackson
2004-04-08 19:48 ` Patch 5/23 " Paul Jackson
2004-04-08 19:49 ` Patch 6a/23 " Paul Jackson
2004-04-08 19:49 ` Patch 6b/23 " Paul Jackson
2004-04-08 19:49 ` Patch 6c/23 " Paul Jackson
2004-04-08 19:49 ` Patch 7/23 " Paul Jackson
2004-04-08 19:49 ` Patch 8/23 " Paul Jackson
2004-04-08 19:49 ` Patch 9/23 " Paul Jackson
2004-04-08 19:49 ` Patch 10/23 " Paul Jackson
2004-04-08 19:49 ` Patch 11/23 " Paul Jackson
2004-04-08 19:49 ` Patch 12/23 " Paul Jackson
2004-04-08 19:49 ` Patch 13/23 " Paul Jackson
2004-04-08 19:49 ` Patch 14/23 " Paul Jackson
2004-04-08 19:50 ` Patch 15/23 " Paul Jackson
2004-04-08 19:50 ` Patch 16/23 " Paul Jackson
2004-04-08 19:50 ` Patch 17/23 " Paul Jackson
2004-04-08 19:50 ` Patch 18/23 " Paul Jackson
2004-04-08 19:50 ` Patch 19/23 " Paul Jackson
2004-04-08 19:50 ` Patch 20/23 " Paul Jackson
2004-04-08 19:50 ` Patch 21/23 " Paul Jackson
2004-04-08 19:50 ` Patch 22/23 " Paul Jackson
2004-04-08 19:50 ` Patch 23/23 " Paul Jackson

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