1 #ifndef __LINUX_NODEMASK_H
2 #define __LINUX_NODEMASK_H
5 * Nodemasks provide a bitmap suitable for representing the
6 * set of Node's in a system, one bit position per Node number.
8 * See detailed comments in the file linux/bitmap.h describing the
9 * data type on which these nodemasks are based.
11 * For details of nodemask_scnprintf() and nodemask_parse(),
12 * see bitmap_scnprintf() and bitmap_parse() in lib/bitmap.c.
14 * The available nodemask operations are:
16 * void node_set(node, mask) turn on bit 'node' in mask
17 * void node_clear(node, mask) turn off bit 'node' in mask
18 * void nodes_setall(mask) set all bits
19 * void nodes_clear(mask) clear all bits
20 * int node_isset(node, mask) true iff bit 'node' set in mask
21 * int node_test_and_set(node, mask) test and set bit 'node' in mask
23 * void nodes_and(dst, src1, src2) dst = src1 & src2 [intersection]
24 * void nodes_or(dst, src1, src2) dst = src1 | src2 [union]
25 * void nodes_xor(dst, src1, src2) dst = src1 ^ src2
26 * void nodes_andnot(dst, src1, src2) dst = src1 & ~src2
27 * void nodes_complement(dst, src) dst = ~src
29 * int nodes_equal(mask1, mask2) Does mask1 == mask2?
30 * int nodes_intersects(mask1, mask2) Do mask1 and mask2 intersect?
31 * int nodes_subset(mask1, mask2) Is mask1 a subset of mask2?
32 * int nodes_empty(mask) Is mask empty (no bits sets)?
33 * int nodes_full(mask) Is mask full (all bits sets)?
34 * int nodes_weight(mask) Hamming weight - number of set bits
36 * void nodes_shift_right(dst, src, n) Shift right
37 * void nodes_shift_left(dst, src, n) Shift left
39 * int first_node(mask) Number lowest set bit, or MAX_NUMNODES
40 * int next_node(node, mask) Next node past 'node', or MAX_NUMNODES
42 * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set
43 * NODE_MASK_ALL Initializer - all bits set
44 * NODE_MASK_NONE Initializer - no bits set
45 * unsigned long *nodes_addr(mask) Array of unsigned long's in mask
47 * int nodemask_scnprintf(buf, len, mask) Format nodemask for printing
48 * int nodemask_parse(ubuf, ulen, mask) Parse ascii string as nodemask
50 * for_each_node_mask(node, mask) for-loop node over mask
52 * int num_online_nodes() Number of online Nodes
53 * int num_possible_nodes() Number of all possible Nodes
55 * int node_online(node) Is some node online?
56 * int node_possible(node) Is some node possible?
58 * int any_online_node(mask) First online node in mask
60 * node_set_online(node) set bit 'node' in node_online_map
61 * node_set_offline(node) clear bit 'node' in node_online_map
63 * for_each_node(node) for-loop node over node_possible_map
64 * for_each_online_node(node) for-loop node over node_online_map
67 * 1) The 'type-checked' form of node_isset() causes gcc (3.3.2, anyway)
68 * to generate slightly worse code. So use a simple one-line #define
69 * for node_isset(), instead of wrapping an inline inside a macro, the
70 * way we do the other calls.
73 #include <linux/kernel.h>
74 #include <linux/threads.h>
75 #include <linux/bitmap.h>
76 #include <linux/numa.h>
79 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
80 extern nodemask_t _unused_nodemask_arg_;
82 #define node_set(node, dst) __node_set((node), &(dst))
83 static inline void __node_set(int node, volatile nodemask_t *dstp)
85 set_bit(node, dstp->bits);
88 #define node_clear(node, dst) __node_clear((node), &(dst))
89 static inline void __node_clear(int node, volatile nodemask_t *dstp)
91 clear_bit(node, dstp->bits);
94 #define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES)
95 static inline void __nodes_setall(nodemask_t *dstp, int nbits)
97 bitmap_fill(dstp->bits, nbits);
100 #define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES)
101 static inline void __nodes_clear(nodemask_t *dstp, int nbits)
103 bitmap_zero(dstp->bits, nbits);
106 /* No static inline type checking - see Subtlety (1) above. */
107 #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
109 #define node_test_and_set(node, nodemask) \
110 __node_test_and_set((node), &(nodemask))
111 static inline int __node_test_and_set(int node, nodemask_t *addr)
113 return test_and_set_bit(node, addr->bits);
116 #define nodes_and(dst, src1, src2) \
117 __nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES)
118 static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,
119 const nodemask_t *src2p, int nbits)
121 bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
124 #define nodes_or(dst, src1, src2) \
125 __nodes_or(&(dst), &(src1), &(src2), MAX_NUMNODES)
126 static inline void __nodes_or(nodemask_t *dstp, const nodemask_t *src1p,
127 const nodemask_t *src2p, int nbits)
129 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
132 #define nodes_xor(dst, src1, src2) \
133 __nodes_xor(&(dst), &(src1), &(src2), MAX_NUMNODES)
134 static inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1p,
135 const nodemask_t *src2p, int nbits)
137 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
140 #define nodes_andnot(dst, src1, src2) \
141 __nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES)
142 static inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,
143 const nodemask_t *src2p, int nbits)
145 bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
148 #define nodes_complement(dst, src) \
149 __nodes_complement(&(dst), &(src), MAX_NUMNODES)
150 static inline void __nodes_complement(nodemask_t *dstp,
151 const nodemask_t *srcp, int nbits)
153 bitmap_complement(dstp->bits, srcp->bits, nbits);
156 #define nodes_equal(src1, src2) \
157 __nodes_equal(&(src1), &(src2), MAX_NUMNODES)
158 static inline int __nodes_equal(const nodemask_t *src1p,
159 const nodemask_t *src2p, int nbits)
161 return bitmap_equal(src1p->bits, src2p->bits, nbits);
164 #define nodes_intersects(src1, src2) \
165 __nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
166 static inline int __nodes_intersects(const nodemask_t *src1p,
167 const nodemask_t *src2p, int nbits)
169 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
172 #define nodes_subset(src1, src2) \
173 __nodes_subset(&(src1), &(src2), MAX_NUMNODES)
174 static inline int __nodes_subset(const nodemask_t *src1p,
175 const nodemask_t *src2p, int nbits)
177 return bitmap_subset(src1p->bits, src2p->bits, nbits);
180 #define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
181 static inline int __nodes_empty(const nodemask_t *srcp, int nbits)
183 return bitmap_empty(srcp->bits, nbits);
186 #define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
187 static inline int __nodes_full(const nodemask_t *srcp, int nbits)
189 return bitmap_full(srcp->bits, nbits);
192 #define nodes_weight(nodemask) __nodes_weight(&(nodemask), MAX_NUMNODES)
193 static inline int __nodes_weight(const nodemask_t *srcp, int nbits)
195 return bitmap_weight(srcp->bits, nbits);
198 #define nodes_shift_right(dst, src, n) \
199 __nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES)
200 static inline void __nodes_shift_right(nodemask_t *dstp,
201 const nodemask_t *srcp, int n, int nbits)
203 bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
206 #define nodes_shift_left(dst, src, n) \
207 __nodes_shift_left(&(dst), &(src), (n), MAX_NUMNODES)
208 static inline void __nodes_shift_left(nodemask_t *dstp,
209 const nodemask_t *srcp, int n, int nbits)
211 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
214 #define first_node(src) __first_node(&(src), MAX_NUMNODES)
215 static inline int __first_node(const nodemask_t *srcp, int nbits)
217 return min_t(int, nbits, find_first_bit(srcp->bits, nbits));
220 #define next_node(n, src) __next_node((n), &(src), MAX_NUMNODES)
221 static inline int __next_node(int n, const nodemask_t *srcp, int nbits)
223 return min_t(int, nbits, find_next_bit(srcp->bits, nbits, n+1));
226 #define nodemask_of_node(node) \
228 typeof(_unused_nodemask_arg_) m; \
229 if (sizeof(m) == sizeof(unsigned long)) { \
230 m.bits[0] = 1UL<<(node); \
233 node_set((node), m); \
238 #define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES)
240 #if MAX_NUMNODES <= BITS_PER_LONG
242 #define NODE_MASK_ALL \
244 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
249 #define NODE_MASK_ALL \
251 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL, \
252 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
257 #define NODE_MASK_NONE \
259 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] = 0UL \
262 #define nodes_addr(src) ((src).bits)
264 #define nodemask_scnprintf(buf, len, src) \
265 __nodemask_scnprintf((buf), (len), &(src), MAX_NUMNODES)
266 static inline int __nodemask_scnprintf(char *buf, int len,
267 const nodemask_t *srcp, int nbits)
269 return bitmap_scnprintf(buf, len, srcp->bits, nbits);
272 #define nodemask_parse(ubuf, ulen, src) \
273 __nodemask_parse((ubuf), (ulen), &(src), MAX_NUMNODES)
274 static inline int __nodemask_parse(const char __user *buf, int len,
275 nodemask_t *dstp, int nbits)
277 return bitmap_parse(buf, len, dstp->bits, nbits);
281 #define for_each_node_mask(node, mask) \
282 for ((node) = first_node(mask); \
283 (node) < MAX_NUMNODES; \
284 (node) = next_node((node), (mask)))
285 #else /* MAX_NUMNODES == 1 */
286 #define for_each_node_mask(node, mask) \
287 if (!nodes_empty(mask)) \
288 for ((node) = 0; (node) < 1; (node)++)
289 #endif /* MAX_NUMNODES */
292 * The following particular system nodemasks and operations
293 * on them manage all possible and online nodes.
296 extern nodemask_t node_online_map;
297 extern nodemask_t node_possible_map;
300 #define num_online_nodes() nodes_weight(node_online_map)
301 #define num_possible_nodes() nodes_weight(node_possible_map)
302 #define node_online(node) node_isset((node), node_online_map)
303 #define node_possible(node) node_isset((node), node_possible_map)
305 #define num_online_nodes() 1
306 #define num_possible_nodes() 1
307 #define node_online(node) ((node) == 0)
308 #define node_possible(node) ((node) == 0)
311 #define any_online_node(mask) \
314 for_each_node_mask(node, (mask)) \
315 if (node_online(node)) \
320 #define node_set_online(node) set_bit((node), node_online_map.bits)
321 #define node_set_offline(node) clear_bit((node), node_online_map.bits)
323 #define for_each_node(node) for_each_node_mask((node), node_possible_map)
324 #define for_each_online_node(node) for_each_node_mask((node), node_online_map)
326 #endif /* __LINUX_NODEMASK_H */