Skip to contentSkip to conversation

mask ADT: replace cpumask_t implementation [3/22]

PATCH In review Paul Jackson 2 participants 7 messages Mar 29, 2004 – Apr 1, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mask ADT: replace cpumask_t implementation [3/22]

Patch_3_of_22 - Rework cpumasks to use new mask ADT
Removes many old include/asm-<arch> and asm-generic cpumask files Add intersects, subset, xor and andnot operators. Provides temporary emulators for obsolete const, promote, coerce Presents entire cpumask API clearly in single cpumask.h file

diffstat Patch_3_of_22:

 b/include/linux/cpumask.h                     |  140 +++++++++++++++++++++++---
 include/asm-alpha/cpumask.h                   |    6 -
 include/asm-arm/cpumask.h                     |    6 -
 include/asm-arm26/cpumask.h                   |    6 -
 include/asm-cris/cpumask.h                    |    6 -
 include/asm-generic/cpumask.h                 |   40 -------
 include/asm-generic/cpumask_arith.h           |   49 ---------
 include/asm-generic/cpumask_array.h           |   54 ----------
 include/asm-generic/cpumask_const_reference.h |   29 -----
 include/asm-generic/cpumask_const_value.h     |   21 ---
 include/asm-generic/cpumask_up.h              |   59 ----------
 include/asm-h8300/cpumask.h                   |    6 -
 include/asm-i386/cpumask.h                    |    6 -
 include/asm-ia64/cpumask.h                    |    6 -
 include/asm-m68k/cpumask.h                    |    6 -
 include/asm-m68knommu/cpumask.h               |    6 -
 include/asm-mips/cpumask.h                    |    6 -
 include/asm-parisc/cpumask.h                  |    6 -
 include/asm-ppc/cpumask.h                     |    6 -
 include/asm-ppc64/cpumask.h                   |    6 -
 include/asm-s390/cpumask.h                    |    6 -
 include/asm-sh/cpumask.h                      |    6 -
 include/asm-sparc/cpumask.h                   |    6 -
 include/asm-sparc64/cpumask.h                 |    6 -
 include/asm-um/cpumask.h                      |    6 -
 include/asm-v850/cpumask.h                    |    6 -
 include/asm-x86_64/cpumask.h                  |    6 -
 27 files changed, 129 insertions(+), 383 deletions(-)

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1708 -> 1.1709
# include/asm-cris/cpumask.h 1.1 -> (deleted)
# include/asm-generic/cpumask_const_value.h 1.2 -> (deleted)
# include/asm-i386/cpumask.h 1.1 -> (deleted)
# include/asm-ppc/cpumask.h 1.1 -> (deleted)
# include/asm-generic/cpumask_const_reference.h 1.1 -> (deleted)
# include/asm-generic/cpumask_up.h 1.4 -> (deleted)
# include/asm-v850/cpumask.h 1.1 -> (deleted)
# include/asm-arm/cpumask.h 1.1 -> (deleted)
# include/linux/cpumask.h 1.8 -> 1.9
# include/asm-m68k/cpumask.h 1.1 -> (deleted)
# include/asm-sparc64/cpumask.h 1.1 -> (deleted)
# include/asm-sh/cpumask.h 1.1 -> (deleted)
# include/asm-generic/cpumask_array.h 1.4 -> (deleted)
# include/asm-ppc64/cpumask.h 1.1 -> (deleted)
# include/asm-parisc/cpumask.h 1.1 -> (deleted)
# include/asm-mips/cpumask.h 1.1 -> (deleted)
# include/asm-generic/cpumask_arith.h 1.3 -> (deleted)
# include/asm-x86_64/cpumask.h 1.1 -> (deleted)

#	include/asm-ia64/cpumask.h	1.1     ->         (deleted)      
#	include/asm-s390/cpumask.h	1.1     ->         (deleted)      
#	include/asm-h8300/cpumask.h	1.1     ->         (deleted)      
#	include/asm-alpha/cpumask.h	1.1     ->         (deleted)      
#	include/asm-sparc/cpumask.h	1.1     ->         (deleted)      

# include/asm-um/cpumask.h 1.1 -> (deleted)
# include/asm-generic/cpumask.h 1.1 -> (deleted)
# include/asm-m68knommu/cpumask.h 1.1 -> (deleted)
# include/asm-arm26/cpumask.h 1.1 -> (deleted)
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/03/28 [email protected] 1.1709
# Major new cpumask implementation, based on new mask ADT. # New xor, subset, intersects and andnot operators provided. # (Temporary emulations of soon to be obsolete coerce, promote # and const routines provided, for working with unconverted code.) # --------------------------------------------
#

include/asm-alpha/cpumask.h deleted +0 -6
diff -Nru a/include/asm-alpha/cpumask.h b/include/asm-alpha/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_ALPHA_CPUMASK_H
-#define _ASM_ALPHA_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ALPHA_CPUMASK_H */
include/asm-arm/cpumask.h deleted +0 -6
diff -Nru a/include/asm-arm/cpumask.h b/include/asm-arm/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_ARM_CPUMASK_H
-#define _ASM_ARM_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ARM_CPUMASK_H */
include/asm-arm26/cpumask.h deleted +0 -6
diff -Nru a/include/asm-arm26/cpumask.h b/include/asm-arm26/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_ARM26_CPUMASK_H
-#define _ASM_ARM26_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_ARM26_CPUMASK_H */
include/asm-cris/cpumask.h deleted +0 -6
diff -Nru a/include/asm-cris/cpumask.h b/include/asm-cris/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_CRIS_CPUMASK_H
-#define _ASM_CRIS_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_CRIS_CPUMASK_H */
include/asm-generic/cpumask.h deleted +0 -40
diff -Nru a/include/asm-generic/cpumask.h b/include/asm-generic/cpumask.h
@@ -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 */
include/asm-generic/cpumask_arith.h deleted +0 -49

49 lines not on this page · raw message

include/asm-generic/cpumask_array.h deleted +0 -54

54 lines not on this page · raw message

include/asm-generic/cpumask_const_reference.h deleted +0 -29
diff -Nru a/include/asm-generic/cpumask_const_reference.h b/include/asm-generic/cpumask_const_reference.h
@@ -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 */
include/asm-generic/cpumask_const_value.h deleted +0 -21
diff -Nru a/include/asm-generic/cpumask_const_value.h b/include/asm-generic/cpumask_const_value.h
@@ -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 */
include/asm-generic/cpumask_up.h deleted +0 -59

59 lines not on this page · raw message

include/asm-h8300/cpumask.h deleted +0 -6
diff -Nru a/include/asm-h8300/cpumask.h b/include/asm-h8300/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_H8300_CPUMASK_H
-#define _ASM_H8300_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_H8300_CPUMASK_H */
include/asm-i386/cpumask.h deleted +0 -6
diff -Nru a/include/asm-i386/cpumask.h b/include/asm-i386/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_I386_CPUMASK_H
-#define _ASM_I386_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_I386_CPUMASK_H */
include/asm-ia64/cpumask.h deleted +0 -6
diff -Nru a/include/asm-ia64/cpumask.h b/include/asm-ia64/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_IA64_CPUMASK_H
-#define _ASM_IA64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_IA64_CPUMASK_H */
include/asm-m68k/cpumask.h deleted +0 -6
diff -Nru a/include/asm-m68k/cpumask.h b/include/asm-m68k/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_M68K_CPUMASK_H
-#define _ASM_M68K_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_M68K_CPUMASK_H */
include/asm-m68knommu/cpumask.h deleted +0 -6
diff -Nru a/include/asm-m68knommu/cpumask.h b/include/asm-m68knommu/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_M68KNOMMU_CPUMASK_H
-#define _ASM_M68KNOMMU_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_M68KNOMMU_CPUMASK_H */
include/asm-mips/cpumask.h deleted +0 -6
diff -Nru a/include/asm-mips/cpumask.h b/include/asm-mips/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_MIPS_CPUMASK_H
-#define _ASM_MIPS_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_MIPS_CPUMASK_H */
include/asm-parisc/cpumask.h deleted +0 -6
diff -Nru a/include/asm-parisc/cpumask.h b/include/asm-parisc/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_PARISC_CPUMASK_H
-#define _ASM_PARISC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PARISC_CPUMASK_H */
include/asm-ppc/cpumask.h deleted +0 -6
diff -Nru a/include/asm-ppc/cpumask.h b/include/asm-ppc/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_PPC_CPUMASK_H
-#define _ASM_PPC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PPC_CPUMASK_H */
include/asm-ppc64/cpumask.h deleted +0 -6
diff -Nru a/include/asm-ppc64/cpumask.h b/include/asm-ppc64/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_PPC64_CPUMASK_H
-#define _ASM_PPC64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_PPC64_CPUMASK_H */
include/asm-s390/cpumask.h deleted +0 -6
diff -Nru a/include/asm-s390/cpumask.h b/include/asm-s390/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_S390_CPUMASK_H
-#define _ASM_S390_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_S390_CPUMASK_H */
include/asm-sh/cpumask.h deleted +0 -6
diff -Nru a/include/asm-sh/cpumask.h b/include/asm-sh/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_SH_CPUMASK_H
-#define _ASM_SH_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SH_CPUMASK_H */
include/asm-sparc/cpumask.h deleted +0 -6
diff -Nru a/include/asm-sparc/cpumask.h b/include/asm-sparc/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_SPARC_CPUMASK_H
-#define _ASM_SPARC_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SPARC_CPUMASK_H */
include/asm-sparc64/cpumask.h deleted +0 -6
diff -Nru a/include/asm-sparc64/cpumask.h b/include/asm-sparc64/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_SPARC64_CPUMASK_H
-#define _ASM_SPARC64_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_SPARC64_CPUMASK_H */
include/asm-um/cpumask.h deleted +0 -6
diff -Nru a/include/asm-um/cpumask.h b/include/asm-um/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_UM_CPUMASK_H
-#define _ASM_UM_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_UM_CPUMASK_H */
include/asm-v850/cpumask.h deleted +0 -6
diff -Nru a/include/asm-v850/cpumask.h b/include/asm-v850/cpumask.h
@@ -1,6 +0,0 @@
-#ifndef _ASM_V850_CPUMASK_H
-#define _ASM_V850_CPUMASK_H
-
-#include <asm-generic/cpumask.h>
-
-#endif /* _ASM_V850_CPUMASK_H */
include/asm-x86_64/cpumask.h deleted +0 -6
diff -Nru a/include/asm-x86_64/cpumask.h b/include/asm-x86_64/cpumask.h
@@ -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 */
include/linux/cpumask.h +129 -11

169 lines not on this page · raw message

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#1 lore raw
Quoted 5 lines · Paul Jackson

Patch_3_of_22 - Rework cpumasks to use new mask ADT
Removes many old include/asm-<arch> and asm-generic cpumask files Add intersects, subset, xor and andnot operators. Provides temporary emulators for obsolete const, promote, coerce Presents entire cpumask API clearly in single cpumask.h file

<snip>

Quoted 5 lines

+ * int num_online_cpus() Number of online CPUs
+ * int num_possible_cpus() Number of all possible CPUs
+ * int cpu_online(cpu) Is some cpu < NR_CPUS online?
+ * int cpu_possible(cpu) Is some cpu < NR_CPUS possible?
+ * int any_online_cpu(mask) First online cpu in mask

This made me do a double-take. I don't think it's necessary to specify the passed in cpu number is < NR_CPUS, because that is true for the whole API. This comment seemed to imply at first reading that the call would return true if any CPU with a number less than 'cpu' was online/possible.

Quoted 21 lines
include/linux/cpumask.h +21 -0
+#define cpu_set(cpu, mask) mask_setbit((cpu), (mask))
+#define cpu_clear(cpu, mask) mask_clearbit((cpu), (mask))
+#define cpus_setall(mask) mask_setall(mask, NR_CPUS)
+#define cpus_clear(mask) mask_clearall(mask)
+#define cpu_isset(cpu, mask) mask_isset((cpu), (mask))
+#define cpu_test_and_set(cpu, mask) mask_test_and_set((cpu), (mask))
+#define cpus_and(dst, src1, src2) mask_and((dst), (src1), (src2))
+#define cpus_or(dst, src1, src2) mask_or((dst), (src1), (src2))
+#define cpus_xor(dst, src1, src2) mask_xor((dst), (src1), (src2))
+#define cpus_andnot(dst, src1, src2) mask_andnot((dst), (src1), (src2))
+#define cpus_complement(dst, src) mask_complement((dst), (src), NR_CPUS)
+#define cpus_equal(mask1, mask2) mask_equal((mask1), (mask2))
+#define cpus_intersects(mask1, mask2) mask_intersects(mask1, mask2)
+#define cpus_subset(mask1, mask2) mask_subset(mask1, mask2)
+#define cpus_empty(mask) mask_empty(mask)
+#define cpus_full(mask) mask_full(mask, NR_CPUS)
+#define cpus_weight(mask) mask_weight(mask, NR_CPUS)
+#define cpus_shift_right(dst, src, n) \
+			mask_shift_right((dst), (src), (n), NR_CPUS)
+#define cpus_shift_left(dst, src, n) \
+			mask_shift_left((dst), (src), (n), NR_CPUS)

include/linux/cpumask.h line 99

Quoted 10 lines
include/linux/cpumask.h +10 -0
+#define first_cpu(mask) mask_first(mask, NR_CPUS)
+#define next_cpu(cpu, mask) mask_next(cpu, mask, NR_CPUS)
+#define cpumask_of_cpu(cpu) mask_of_bit((cpu), _unused_cpumask_arg_)
+#define CPU_MASK_ALL MASK_ALL(NR_CPUS)
+#define CPU_MASK_NONE MASK_NONE(NR_CPUS)
+#define cpus_raw(mask) mask_raw(mask)
+#define cpumask_scnprintf(buf, len, mask) \
+			mask_scnprintf(buf, len, mask, NR_CPUS)
+#define cpumask_parse(ubuf, ulen, mask) \
+			mask_parse(ubuf, ulen, mask, NR_CPUS)

What would you think about creating two versions of some of the mask_* functions, one that takes a nrbits argument and one that doesn't. Many (all?) of the bitmap_* functions take a number of bits to operate on, and for the mask_* functions we simply compute the size of the mask and pass that along. We can be smarter in the cpumask/nodemask cases because we *know* how many bits we're really using, and we can pass that information along. Basically, what I'm suggesting is:

mask_empty(mask) -> bitmap_empty(mask, sizeof(mask)) mask_empty_bits(mask, nrbits) -> bitmap_empty(mask, nrbits) cpus_empty(mask) -> mask_empty_bits(mask, NR_CPUS)

This allows anyone using the mask API to specify the exact number of bits if they care to, and it buys us a little protection from non-word sized cpumask/nodemask errors.

include/linux/cpumask.h line 139

Quoted 9 lines

#else

include/linux/cpumask.h +2 -0
+
 #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; })

Might it make more sense to actually define a cpu_online_map & cpu_possible_map for UP, rather than generating this code:

#define mask_of_bit(bit, T)                                            \
({                                                                     \
       typeof(T) m;                                                    \
       mask_clearall(m);                                               \
       mask_setbit((bit), m);                                          \
       m;                                                              \

})

every time some code references cpu_online_map? It'll only cost us 2 unsigned longs on 32-bit == 8 bytes...

-Matt

#2 lore raw
Quoted 12 lines
Quoted 3 lines

#define cpu_online_map cpumask_of_cpu(0)
#define cpu_possible_map cpumask_of_cpu(0)
...

Might it make more sense to actually define a cpu_online_map & cpu_possible_map for UP, rather than generating this code:

#define mask_of_bit(bit, T)                                            \
({                                                                     \
       typeof(T) m;                                                    \
       mask_clearall(m);                                               \
       mask_setbit((bit), m);                                          \
       m;                                                              \
Quoted 4 lines

})

every time some code references cpu_online_map? It'll only cost us 2 unsigned longs on 32-bit == 8 bytes...

Perhaps.

When I looked at the code just now, this only seemed to take a couple of instructions. Do you think that there is much to gain? Better a couple of inline instructions than a possible uncached memory reference, I suspect.

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#3 lore raw
Quoted 17 lines · Paul Jackson
Quoted 12 lines
Quoted 3 lines

#define cpu_online_map cpumask_of_cpu(0)
#define cpu_possible_map cpumask_of_cpu(0)
...

Might it make more sense to actually define a cpu_online_map & cpu_possible_map for UP, rather than generating this code:

#define mask_of_bit(bit, T)                                            \
({                                                                     \
       typeof(T) m;                                                    \
       mask_clearall(m);                                               \
       mask_setbit((bit), m);                                          \
       m;                                                              \
Quoted 4 lines

})

every time some code references cpu_online_map? It'll only cost us 2 unsigned longs on 32-bit == 8 bytes...

Quoted 6 lines

Perhaps.

When I looked at the code just now, this only seemed to take a couple of instructions. Do you think that there is much to gain? Better a couple of inline instructions than a possible uncached memory reference, I suspect.

Yeah, you may be right about that.

On UP it should compile as such:

cpu_online_map => cpumask_of_cpu(0) =>
mask_of_bit(0, _unused_cpumask_arg_) =>
({ typeof(_unused_cpumask_arg_) m; mask_clearall(m); mask_setbit(0, m); m; }) =>
({ cpumask_t m; m._m[0] = 0UL; set_bit(0, m._m); m; })

Maybe we could #define it better on UP. Something along the lines of:

#define cpu_online_map ({ cpumask_t up_cpu_map = { 1UL }; })

That way we'll get this inlined, plus very little code to execute?

Cheers!

-Matt

#4 lore raw

Matthew suggested:

Quoted 2 lines

Maybe we could #define it better on UP. Something along the lines of:
#define cpu_online_map ({ cpumask_t up_cpu_map = { 1UL }; })

Yeah - I started playing with something like that too ...

Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#5 lore raw
Quoted 5 lines · Paul Jackson

Matthew suggested:

Quoted 2 lines

Maybe we could #define it better on UP. Something along the lines of:
#define cpu_online_map ({ cpumask_t up_cpu_map = { 1UL }; })

Yeah - I started playing with something like that too ...

Cool. I think you're right about an actual cpumask_t for cpu_online_map on UP not being a great idea, but I definitely think we can do better than just #defining it to cpumask_of_cpu(0).

-Matt

#6 lore raw
In reply to Paul Jackson
Quoted 5 lines · Paul Jackson

Patch_3_of_22 - Rework cpumasks to use new mask ADT
Removes many old include/asm-<arch> and asm-generic cpumask files Add intersects, subset, xor and andnot operators. Provides temporary emulators for obsolete const, promote, coerce Presents entire cpumask API clearly in single cpumask.h file

Paul,
Some changes to include/linux/cpumask.h:

1) You didn't provide a set of cpu_set_online/offline() macros. No one is using these, but it may be a nice thing to have all the places that are *writing* to cpu_online_map do it through a macro. If nothing else, it makes cpu_online_map & node_online_map accessed similarly.

2) Dropped #include <linux/config.h>. The very next include (linux/threads.h) includes this file.

3) Indented all the cpu_* and cpus_* macros. Massively more readable.

4) Made sure any macro call with more than 1 argument had its arguments wrapped in parens. It seemed like you were a bit inconsistent as to whether or not the arguments to macros got parens.

5) Moved for_each_cpu() & for_each_online_cpu() definitions outside the #ifdef CONFIG_SMP, because they are identical for the SMP/UP cases.

Cheers!

-Matt

include/linux/cpumask.h +43 -39
diff -Nurp --exclude-from=/home/mcd/.dontdiff linux-2.6.4-pj_nodemask/include/linux/cpumask.h linux-2.6.4-cpumask_h-mcd/include/linux/cpumask.h
@@ -51,6 +51,8 @@
  * int num_possible_cpus()		Number of all possible CPUs
  * int cpu_online(cpu)			Is some cpu < NR_CPUS online?
  * int cpu_possible(cpu)		Is some cpu < NR_CPUS 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
@@ -58,45 +60,44 @@
  * for_each_online_cpu(cpu)		for-loop cpu over cpu_online_map
  */
 
-#include <linux/config.h>
-#include <linux/mask.h>
 #include <linux/threads.h>
+#include <linux/mask.h>
 #include <asm/bug.h>
 
 typedef __mask(NR_CPUS) cpumask_t;
 extern cpumask_t _unused_cpumask_arg_;
 
-#define cpu_set(cpu, mask) mask_setbit((cpu), (mask))
-#define cpu_clear(cpu, mask) mask_clearbit((cpu), (mask))
-#define cpus_setall(mask) mask_setall(mask, NR_CPUS)
-#define cpus_clear(mask) mask_clearall(mask)
-#define cpu_isset(cpu, mask) mask_isset((cpu), (mask))
-#define cpu_test_and_set(cpu, mask) mask_test_and_set((cpu), (mask))
-#define cpus_and(dst, src1, src2) mask_and((dst), (src1), (src2))
-#define cpus_or(dst, src1, src2) mask_or((dst), (src1), (src2))
-#define cpus_xor(dst, src1, src2) mask_xor((dst), (src1), (src2))
-#define cpus_andnot(dst, src1, src2) mask_andnot((dst), (src1), (src2))
-#define cpus_complement(dst, src) mask_complement((dst), (src), NR_CPUS)
-#define cpus_equal(mask1, mask2) mask_equal((mask1), (mask2))
-#define cpus_intersects(mask1, mask2) mask_intersects(mask1, mask2)
-#define cpus_subset(mask1, mask2) mask_subset(mask1, mask2)
-#define cpus_empty(mask) mask_empty(mask)
-#define cpus_full(mask) mask_full(mask, NR_CPUS)
-#define cpus_weight(mask) mask_weight(mask, NR_CPUS)
-#define cpus_shift_right(dst, src, n) \
+#define cpu_set(cpu, mask)		mask_setbit((cpu), (mask))
+#define cpu_clear(cpu, mask)		mask_clearbit((cpu), (mask))
+#define cpus_setall(mask)		mask_setall((mask), NR_CPUS)
+#define cpus_clear(mask)		mask_clearall(mask)
+#define cpu_isset(cpu, mask)		mask_isset((cpu), (mask))
+#define cpu_test_and_set(cpu, mask)	mask_test_and_set((cpu), (mask))
+#define cpus_and(dst, src1, src2)	mask_and((dst), (src1), (src2))
+#define cpus_or(dst, src1, src2)	mask_or((dst), (src1), (src2))
+#define cpus_xor(dst, src1, src2)	mask_xor((dst), (src1), (src2))
+#define cpus_andnot(dst, src1, src2)	mask_andnot((dst), (src1), (src2))
+#define cpus_complement(dst, src)	mask_complement((dst), (src), NR_CPUS)
+#define cpus_equal(mask1, mask2)	mask_equal((mask1), (mask2))
+#define cpus_intersects(mask1, mask2)	mask_intersects((mask1), (mask2))
+#define cpus_subset(mask1, mask2)	mask_subset((mask1), (mask2))
+#define cpus_empty(mask)		mask_empty(mask)
+#define cpus_full(mask)			mask_full((mask), NR_CPUS)
+#define cpus_weight(mask)		mask_weight((mask), NR_CPUS)
+#define cpus_shift_right(dst, src, n)	\
 			mask_shift_right((dst), (src), (n), NR_CPUS)
-#define cpus_shift_left(dst, src, n) \
+#define cpus_shift_left(dst, src, n)	\
 			mask_shift_left((dst), (src), (n), NR_CPUS)
-#define first_cpu(mask) mask_first(mask, NR_CPUS)
-#define next_cpu(cpu, mask) mask_next(cpu, mask, NR_CPUS)
-#define cpumask_of_cpu(cpu) mask_of_bit((cpu), _unused_cpumask_arg_)
-#define CPU_MASK_ALL MASK_ALL(NR_CPUS)
-#define CPU_MASK_NONE MASK_NONE(NR_CPUS)
-#define cpus_raw(mask) mask_raw(mask)
+#define first_cpu(mask)			mask_first((mask), NR_CPUS)
+#define next_cpu(cpu, mask)		mask_next((cpu), (mask), NR_CPUS)
+#define cpumask_of_cpu(cpu)		mask_of_bit((cpu), _unused_cpumask_arg_)
+#define CPU_MASK_ALL			MASK_ALL(NR_CPUS)
+#define CPU_MASK_NONE			MASK_NONE(NR_CPUS)
+#define cpus_raw(mask)			mask_raw(mask)
 #define cpumask_scnprintf(buf, len, mask) \
-			mask_scnprintf(buf, len, mask, NR_CPUS)
+			mask_scnprintf((buf), (len), (mask), NR_CPUS)
 #define cpumask_parse(ubuf, ulen, mask) \
-			mask_parse(ubuf, ulen, mask, NR_CPUS)
+			mask_parse((ubuf), (ulen), (mask), NR_CPUS)
 
 /*
  * The following particular system cpumasks and operations
@@ -110,8 +111,10 @@ extern cpumask_t cpu_possible_map;
 
 #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_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)			\
 ({						\
@@ -125,10 +128,7 @@ extern cpumask_t cpu_possible_map;
 		cpu < NR_CPUS;			\
 		cpu = next_cpu(cpu, mask))
 
-#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
+#else /* !CONFIG_SMP */
 
 #define	cpu_online_map			cpumask_of_cpu(0)
 #define	cpu_possible_map		cpumask_of_cpu(0)
@@ -137,14 +137,18 @@ extern cpumask_t cpu_possible_map;
 #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++)
+#define for_each_cpu_mask(cpu, mask)	for (cpu = 0; cpu < 1; cpu++)
 
-#define for_each_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
-#define for_each_online_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
+#endif /* CONFIG_SMP */
 
-#endif
+#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)
 
 #endif /* __LINUX_CPUMASK_H */