[CONNECTOR]: Update documentation to match reality.
[linux-2.6/verdex.git] / include / linux / nodemask.h
blobe96fe90625003b64556d1c30a17496cee54124d7
1 #ifndef __LINUX_NODEMASK_H
2 #define __LINUX_NODEMASK_H
4 /*
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.
13 * For details of nodelist_scnprintf() and nodelist_parse(), see
14 * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c.
16 * The available nodemask operations are:
18 * void node_set(node, mask) turn on bit 'node' in mask
19 * void node_clear(node, mask) turn off bit 'node' in mask
20 * void nodes_setall(mask) set all bits
21 * void nodes_clear(mask) clear all bits
22 * int node_isset(node, mask) true iff bit 'node' set in mask
23 * int node_test_and_set(node, mask) test and set bit 'node' in mask
25 * void nodes_and(dst, src1, src2) dst = src1 & src2 [intersection]
26 * void nodes_or(dst, src1, src2) dst = src1 | src2 [union]
27 * void nodes_xor(dst, src1, src2) dst = src1 ^ src2
28 * void nodes_andnot(dst, src1, src2) dst = src1 & ~src2
29 * void nodes_complement(dst, src) dst = ~src
31 * int nodes_equal(mask1, mask2) Does mask1 == mask2?
32 * int nodes_intersects(mask1, mask2) Do mask1 and mask2 intersect?
33 * int nodes_subset(mask1, mask2) Is mask1 a subset of mask2?
34 * int nodes_empty(mask) Is mask empty (no bits sets)?
35 * int nodes_full(mask) Is mask full (all bits sets)?
36 * int nodes_weight(mask) Hamming weight - number of set bits
38 * void nodes_shift_right(dst, src, n) Shift right
39 * void nodes_shift_left(dst, src, n) Shift left
41 * int first_node(mask) Number lowest set bit, or MAX_NUMNODES
42 * int next_node(node, mask) Next node past 'node', or MAX_NUMNODES
43 * int first_unset_node(mask) First node not set in mask, or
44 * MAX_NUMNODES.
46 * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set
47 * NODE_MASK_ALL Initializer - all bits set
48 * NODE_MASK_NONE Initializer - no bits set
49 * unsigned long *nodes_addr(mask) Array of unsigned long's in mask
51 * int nodemask_scnprintf(buf, len, mask) Format nodemask for printing
52 * int nodemask_parse(ubuf, ulen, mask) Parse ascii string as nodemask
53 * int nodelist_scnprintf(buf, len, mask) Format nodemask as list for printing
54 * int nodelist_parse(buf, map) Parse ascii string as nodelist
56 * for_each_node_mask(node, mask) for-loop node over mask
58 * int num_online_nodes() Number of online Nodes
59 * int num_possible_nodes() Number of all possible Nodes
61 * int node_online(node) Is some node online?
62 * int node_possible(node) Is some node possible?
64 * int any_online_node(mask) First online node in mask
66 * node_set_online(node) set bit 'node' in node_online_map
67 * node_set_offline(node) clear bit 'node' in node_online_map
69 * for_each_node(node) for-loop node over node_possible_map
70 * for_each_online_node(node) for-loop node over node_online_map
72 * Subtlety:
73 * 1) The 'type-checked' form of node_isset() causes gcc (3.3.2, anyway)
74 * to generate slightly worse code. So use a simple one-line #define
75 * for node_isset(), instead of wrapping an inline inside a macro, the
76 * way we do the other calls.
79 #include <linux/kernel.h>
80 #include <linux/threads.h>
81 #include <linux/bitmap.h>
82 #include <linux/numa.h>
83 #include <asm/bug.h>
85 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
86 extern nodemask_t _unused_nodemask_arg_;
88 #define node_set(node, dst) __node_set((node), &(dst))
89 static inline void __node_set(int node, volatile nodemask_t *dstp)
91 set_bit(node, dstp->bits);
94 #define node_clear(node, dst) __node_clear((node), &(dst))
95 static inline void __node_clear(int node, volatile nodemask_t *dstp)
97 clear_bit(node, dstp->bits);
100 #define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES)
101 static inline void __nodes_setall(nodemask_t *dstp, int nbits)
103 bitmap_fill(dstp->bits, nbits);
106 #define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES)
107 static inline void __nodes_clear(nodemask_t *dstp, int nbits)
109 bitmap_zero(dstp->bits, nbits);
112 /* No static inline type checking - see Subtlety (1) above. */
113 #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
115 #define node_test_and_set(node, nodemask) \
116 __node_test_and_set((node), &(nodemask))
117 static inline int __node_test_and_set(int node, nodemask_t *addr)
119 return test_and_set_bit(node, addr->bits);
122 #define nodes_and(dst, src1, src2) \
123 __nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES)
124 static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,
125 const nodemask_t *src2p, int nbits)
127 bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
130 #define nodes_or(dst, src1, src2) \
131 __nodes_or(&(dst), &(src1), &(src2), MAX_NUMNODES)
132 static inline void __nodes_or(nodemask_t *dstp, const nodemask_t *src1p,
133 const nodemask_t *src2p, int nbits)
135 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
138 #define nodes_xor(dst, src1, src2) \
139 __nodes_xor(&(dst), &(src1), &(src2), MAX_NUMNODES)
140 static inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1p,
141 const nodemask_t *src2p, int nbits)
143 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
146 #define nodes_andnot(dst, src1, src2) \
147 __nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES)
148 static inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,
149 const nodemask_t *src2p, int nbits)
151 bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
154 #define nodes_complement(dst, src) \
155 __nodes_complement(&(dst), &(src), MAX_NUMNODES)
156 static inline void __nodes_complement(nodemask_t *dstp,
157 const nodemask_t *srcp, int nbits)
159 bitmap_complement(dstp->bits, srcp->bits, nbits);
162 #define nodes_equal(src1, src2) \
163 __nodes_equal(&(src1), &(src2), MAX_NUMNODES)
164 static inline int __nodes_equal(const nodemask_t *src1p,
165 const nodemask_t *src2p, int nbits)
167 return bitmap_equal(src1p->bits, src2p->bits, nbits);
170 #define nodes_intersects(src1, src2) \
171 __nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
172 static inline int __nodes_intersects(const nodemask_t *src1p,
173 const nodemask_t *src2p, int nbits)
175 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
178 #define nodes_subset(src1, src2) \
179 __nodes_subset(&(src1), &(src2), MAX_NUMNODES)
180 static inline int __nodes_subset(const nodemask_t *src1p,
181 const nodemask_t *src2p, int nbits)
183 return bitmap_subset(src1p->bits, src2p->bits, nbits);
186 #define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
187 static inline int __nodes_empty(const nodemask_t *srcp, int nbits)
189 return bitmap_empty(srcp->bits, nbits);
192 #define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
193 static inline int __nodes_full(const nodemask_t *srcp, int nbits)
195 return bitmap_full(srcp->bits, nbits);
198 #define nodes_weight(nodemask) __nodes_weight(&(nodemask), MAX_NUMNODES)
199 static inline int __nodes_weight(const nodemask_t *srcp, int nbits)
201 return bitmap_weight(srcp->bits, nbits);
204 #define nodes_shift_right(dst, src, n) \
205 __nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES)
206 static inline void __nodes_shift_right(nodemask_t *dstp,
207 const nodemask_t *srcp, int n, int nbits)
209 bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
212 #define nodes_shift_left(dst, src, n) \
213 __nodes_shift_left(&(dst), &(src), (n), MAX_NUMNODES)
214 static inline void __nodes_shift_left(nodemask_t *dstp,
215 const nodemask_t *srcp, int n, int nbits)
217 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
220 /* FIXME: better would be to fix all architectures to never return
221 > MAX_NUMNODES, then the silly min_ts could be dropped. */
223 #define first_node(src) __first_node(&(src))
224 static inline int __first_node(const nodemask_t *srcp)
226 return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
229 #define next_node(n, src) __next_node((n), &(src))
230 static inline int __next_node(int n, const nodemask_t *srcp)
232 return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
235 #define nodemask_of_node(node) \
236 ({ \
237 typeof(_unused_nodemask_arg_) m; \
238 if (sizeof(m) == sizeof(unsigned long)) { \
239 m.bits[0] = 1UL<<(node); \
240 } else { \
241 nodes_clear(m); \
242 node_set((node), m); \
244 m; \
247 #define first_unset_node(mask) __first_unset_node(&(mask))
248 static inline int __first_unset_node(const nodemask_t *maskp)
250 return min_t(int,MAX_NUMNODES,
251 find_first_zero_bit(maskp->bits, MAX_NUMNODES));
254 #define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES)
256 #if MAX_NUMNODES <= BITS_PER_LONG
258 #define NODE_MASK_ALL \
259 ((nodemask_t) { { \
260 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
261 } })
263 #else
265 #define NODE_MASK_ALL \
266 ((nodemask_t) { { \
267 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL, \
268 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
269 } })
271 #endif
273 #define NODE_MASK_NONE \
274 ((nodemask_t) { { \
275 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] = 0UL \
276 } })
278 #define nodes_addr(src) ((src).bits)
280 #define nodemask_scnprintf(buf, len, src) \
281 __nodemask_scnprintf((buf), (len), &(src), MAX_NUMNODES)
282 static inline int __nodemask_scnprintf(char *buf, int len,
283 const nodemask_t *srcp, int nbits)
285 return bitmap_scnprintf(buf, len, srcp->bits, nbits);
288 #define nodemask_parse(ubuf, ulen, dst) \
289 __nodemask_parse((ubuf), (ulen), &(dst), MAX_NUMNODES)
290 static inline int __nodemask_parse(const char __user *buf, int len,
291 nodemask_t *dstp, int nbits)
293 return bitmap_parse(buf, len, dstp->bits, nbits);
296 #define nodelist_scnprintf(buf, len, src) \
297 __nodelist_scnprintf((buf), (len), &(src), MAX_NUMNODES)
298 static inline int __nodelist_scnprintf(char *buf, int len,
299 const nodemask_t *srcp, int nbits)
301 return bitmap_scnlistprintf(buf, len, srcp->bits, nbits);
304 #define nodelist_parse(buf, dst) __nodelist_parse((buf), &(dst), MAX_NUMNODES)
305 static inline int __nodelist_parse(const char *buf, nodemask_t *dstp, int nbits)
307 return bitmap_parselist(buf, dstp->bits, nbits);
310 #if MAX_NUMNODES > 1
311 #define for_each_node_mask(node, mask) \
312 for ((node) = first_node(mask); \
313 (node) < MAX_NUMNODES; \
314 (node) = next_node((node), (mask)))
315 #else /* MAX_NUMNODES == 1 */
316 #define for_each_node_mask(node, mask) \
317 if (!nodes_empty(mask)) \
318 for ((node) = 0; (node) < 1; (node)++)
319 #endif /* MAX_NUMNODES */
322 * The following particular system nodemasks and operations
323 * on them manage all possible and online nodes.
326 extern nodemask_t node_online_map;
327 extern nodemask_t node_possible_map;
329 #if MAX_NUMNODES > 1
330 #define num_online_nodes() nodes_weight(node_online_map)
331 #define num_possible_nodes() nodes_weight(node_possible_map)
332 #define node_online(node) node_isset((node), node_online_map)
333 #define node_possible(node) node_isset((node), node_possible_map)
334 #else
335 #define num_online_nodes() 1
336 #define num_possible_nodes() 1
337 #define node_online(node) ((node) == 0)
338 #define node_possible(node) ((node) == 0)
339 #endif
341 #define any_online_node(mask) \
342 ({ \
343 int node; \
344 for_each_node_mask(node, (mask)) \
345 if (node_online(node)) \
346 break; \
347 node; \
350 #define node_set_online(node) set_bit((node), node_online_map.bits)
351 #define node_set_offline(node) clear_bit((node), node_online_map.bits)
353 #define for_each_node(node) for_each_node_mask((node), node_possible_map)
354 #define for_each_online_node(node) for_each_node_mask((node), node_online_map)
356 #endif /* __LINUX_NODEMASK_H */