1#include <linux/slab.h>
2#include <linux/kernel.h>
3#include <linux/bitops.h>
4#include <linux/cpumask.h>
5#include <linux/module.h>
6#include <linux/bootmem.h>
7
8int __first_cpu(const cpumask_t *srcp)
9{
10 return min_t(int, NR_CPUS, find_first_bit(srcp->bits, NR_CPUS));
11}
12EXPORT_SYMBOL(__first_cpu);
13
14int __next_cpu(int n, const cpumask_t *srcp)
15{
16 return min_t(int, NR_CPUS, find_next_bit(srcp->bits, NR_CPUS, n+1));
17}
18EXPORT_SYMBOL(__next_cpu);
19
20#if NR_CPUS > 64
21int __next_cpu_nr(int n, const cpumask_t *srcp)
22{
23 return min_t(int, nr_cpu_ids,
24 find_next_bit(srcp->bits, nr_cpu_ids, n+1));
25}
26EXPORT_SYMBOL(__next_cpu_nr);
27#endif
28
29int __any_online_cpu(const cpumask_t *mask)
30{
31 int cpu;
32
33 for_each_cpu_mask(cpu, *mask) {
34 if (cpu_online(cpu))
35 break;
36 }
37 return cpu;
38}
39EXPORT_SYMBOL(__any_online_cpu);
40
41
42
43
44
45
46
47
48
49int cpumask_next_and(int n, const struct cpumask *src1p,
50 const struct cpumask *src2p)
51{
52 while ((n = cpumask_next(n, src1p)) < nr_cpu_ids)
53 if (cpumask_test_cpu(n, src2p))
54 break;
55 return n;
56}
57EXPORT_SYMBOL(cpumask_next_and);
58
59
60
61
62
63
64
65
66
67int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
68{
69 unsigned int i;
70
71 cpumask_check(cpu);
72 for_each_cpu(i, mask)
73 if (i != cpu)
74 break;
75 return i;
76}
77
78
79#ifdef CONFIG_CPUMASK_OFFSTACK
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
95{
96 *mask = kmalloc_node(cpumask_size(), flags, node);
97
98#ifdef CONFIG_DEBUG_PER_CPU_MAPS
99 if (!*mask) {
100 printk(KERN_ERR "=> alloc_cpumask_var: failed!\n");
101 dump_stack();
102 }
103#endif
104
105 if (*mask) {
106 unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
107 unsigned int tail;
108 tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
109 memset(ptr + cpumask_size() - tail, 0, tail);
110 }
111
112 return *mask != NULL;
113}
114EXPORT_SYMBOL(alloc_cpumask_var_node);
115
116bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
117{
118 return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
119}
120EXPORT_SYMBOL(zalloc_cpumask_var_node);
121
122
123
124
125
126
127
128
129
130
131
132bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
133{
134 return alloc_cpumask_var_node(mask, flags, numa_node_id());
135}
136EXPORT_SYMBOL(alloc_cpumask_var);
137
138bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
139{
140 return alloc_cpumask_var(mask, flags | __GFP_ZERO);
141}
142EXPORT_SYMBOL(zalloc_cpumask_var);
143
144
145
146
147
148
149
150
151
152
153void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask)
154{
155 *mask = alloc_bootmem(cpumask_size());
156}
157
158
159
160
161
162
163
164void free_cpumask_var(cpumask_var_t mask)
165{
166 kfree(mask);
167}
168EXPORT_SYMBOL(free_cpumask_var);
169
170
171
172
173
174void __init free_bootmem_cpumask_var(cpumask_var_t mask)
175{
176 free_bootmem((unsigned long)mask, cpumask_size());
177}
178#endif
179