This source file includes following definitions.
- cpumask_next
- cpumask_next_and
- cpumask_any_but
- cpumask_next_wrap
- alloc_cpumask_var_node
- zalloc_cpumask_var_node
- alloc_cpumask_var
- zalloc_cpumask_var
- alloc_bootmem_cpumask_var
- free_cpumask_var
- free_bootmem_cpumask_var
- cpumask_local_spread
1
2 #include <linux/slab.h>
3 #include <linux/kernel.h>
4 #include <linux/bitops.h>
5 #include <linux/cpumask.h>
6 #include <linux/export.h>
7 #include <linux/memblock.h>
8 #include <linux/numa.h>
9
10
11
12
13
14
15
16
17 unsigned int cpumask_next(int n, const struct cpumask *srcp)
18 {
19
20 if (n != -1)
21 cpumask_check(n);
22 return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
23 }
24 EXPORT_SYMBOL(cpumask_next);
25
26
27
28
29
30
31
32
33
34 int cpumask_next_and(int n, const struct cpumask *src1p,
35 const struct cpumask *src2p)
36 {
37
38 if (n != -1)
39 cpumask_check(n);
40 return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
41 nr_cpumask_bits, n + 1);
42 }
43 EXPORT_SYMBOL(cpumask_next_and);
44
45
46
47
48
49
50
51
52
53 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
54 {
55 unsigned int i;
56
57 cpumask_check(cpu);
58 for_each_cpu(i, mask)
59 if (i != cpu)
60 break;
61 return i;
62 }
63 EXPORT_SYMBOL(cpumask_any_but);
64
65
66
67
68
69
70
71
72
73
74
75
76
77 int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
78 {
79 int next;
80
81 again:
82 next = cpumask_next(n, mask);
83
84 if (wrap && n < start && next >= start) {
85 return nr_cpumask_bits;
86
87 } else if (next >= nr_cpumask_bits) {
88 wrap = true;
89 n = -1;
90 goto again;
91 }
92
93 return next;
94 }
95 EXPORT_SYMBOL(cpumask_next_wrap);
96
97
98 #ifdef CONFIG_CPUMASK_OFFSTACK
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
114 {
115 *mask = kmalloc_node(cpumask_size(), flags, node);
116
117 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
118 if (!*mask) {
119 printk(KERN_ERR "=> alloc_cpumask_var: failed!\n");
120 dump_stack();
121 }
122 #endif
123
124 return *mask != NULL;
125 }
126 EXPORT_SYMBOL(alloc_cpumask_var_node);
127
128 bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
129 {
130 return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
131 }
132 EXPORT_SYMBOL(zalloc_cpumask_var_node);
133
134
135
136
137
138
139
140
141
142
143
144 bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
145 {
146 return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE);
147 }
148 EXPORT_SYMBOL(alloc_cpumask_var);
149
150 bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
151 {
152 return alloc_cpumask_var(mask, flags | __GFP_ZERO);
153 }
154 EXPORT_SYMBOL(zalloc_cpumask_var);
155
156
157
158
159
160
161
162
163
164
165 void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask)
166 {
167 *mask = memblock_alloc(cpumask_size(), SMP_CACHE_BYTES);
168 if (!*mask)
169 panic("%s: Failed to allocate %u bytes\n", __func__,
170 cpumask_size());
171 }
172
173
174
175
176
177
178
179 void free_cpumask_var(cpumask_var_t mask)
180 {
181 kfree(mask);
182 }
183 EXPORT_SYMBOL(free_cpumask_var);
184
185
186
187
188
189 void __init free_bootmem_cpumask_var(cpumask_var_t mask)
190 {
191 memblock_free_early(__pa(mask), cpumask_size());
192 }
193 #endif
194
195
196
197
198
199
200
201
202
203
204
205
206 unsigned int cpumask_local_spread(unsigned int i, int node)
207 {
208 int cpu;
209
210
211 i %= num_online_cpus();
212
213 if (node == NUMA_NO_NODE) {
214 for_each_cpu(cpu, cpu_online_mask)
215 if (i-- == 0)
216 return cpu;
217 } else {
218
219 for_each_cpu_and(cpu, cpumask_of_node(node), cpu_online_mask)
220 if (i-- == 0)
221 return cpu;
222
223 for_each_cpu(cpu, cpu_online_mask) {
224
225 if (cpumask_test_cpu(cpu, cpumask_of_node(node)))
226 continue;
227
228 if (i-- == 0)
229 return cpu;
230 }
231 }
232 BUG();
233 }
234 EXPORT_SYMBOL(cpumask_local_spread);