aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cpumask.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cpumask.c')
-rw-r--r--lib/cpumask.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/lib/cpumask.c b/lib/cpumask.c
index 8d03f22c6ced..3389e2440da0 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -76,15 +76,28 @@ int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
76 76
77/* These are not inline because of header tangles. */ 77/* These are not inline because of header tangles. */
78#ifdef CONFIG_CPUMASK_OFFSTACK 78#ifdef CONFIG_CPUMASK_OFFSTACK
79bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 79/**
80 * alloc_cpumask_var_node - allocate a struct cpumask on a given node
81 * @mask: pointer to cpumask_var_t where the cpumask is returned
82 * @flags: GFP_ flags
83 *
84 * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
85 * a nop returning a constant 1 (in <linux/cpumask.h>)
86 * Returns TRUE if memory allocation succeeded, FALSE otherwise.
87 *
88 * In addition, mask will be NULL if this fails. Note that gcc is
89 * usually smart enough to know that mask can never be NULL if
90 * CONFIG_CPUMASK_OFFSTACK=n, so does code elimination in that case
91 * too.
92 */
93bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
80{ 94{
81 if (likely(slab_is_available())) 95 if (likely(slab_is_available()))
82 *mask = kmalloc(cpumask_size(), flags); 96 *mask = kmalloc_node(cpumask_size(), flags, node);
83 else { 97 else {
84#ifdef CONFIG_DEBUG_PER_CPU_MAPS 98#ifdef CONFIG_DEBUG_PER_CPU_MAPS
85 printk(KERN_ERR 99 printk(KERN_ERR
86 "=> alloc_cpumask_var: kmalloc not available!\n"); 100 "=> alloc_cpumask_var: kmalloc not available!\n");
87 dump_stack();
88#endif 101#endif
89 *mask = NULL; 102 *mask = NULL;
90 } 103 }
@@ -94,21 +107,64 @@ bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
94 dump_stack(); 107 dump_stack();
95 } 108 }
96#endif 109#endif
110 /* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
111 if (*mask) {
112 unsigned int tail;
113 tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
114 memset(cpumask_bits(*mask) + cpumask_size() - tail,
115 0, tail);
116 }
117
97 return *mask != NULL; 118 return *mask != NULL;
98} 119}
120EXPORT_SYMBOL(alloc_cpumask_var_node);
121
122/**
123 * alloc_cpumask_var - allocate a struct cpumask
124 * @mask: pointer to cpumask_var_t where the cpumask is returned
125 * @flags: GFP_ flags
126 *
127 * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
128 * a nop returning a constant 1 (in <linux/cpumask.h>).
129 *
130 * See alloc_cpumask_var_node.
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}
99EXPORT_SYMBOL(alloc_cpumask_var); 136EXPORT_SYMBOL(alloc_cpumask_var);
100 137
138/**
139 * alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena.
140 * @mask: pointer to cpumask_var_t where the cpumask is returned
141 *
142 * Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
143 * a nop (in <linux/cpumask.h>).
144 * Either returns an allocated (zero-filled) cpumask, or causes the
145 * system to panic.
146 */
101void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask) 147void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask)
102{ 148{
103 *mask = alloc_bootmem(cpumask_size()); 149 *mask = alloc_bootmem(cpumask_size());
104} 150}
105 151
152/**
153 * free_cpumask_var - frees memory allocated for a struct cpumask.
154 * @mask: cpumask to free
155 *
156 * This is safe on a NULL mask.
157 */
106void free_cpumask_var(cpumask_var_t mask) 158void free_cpumask_var(cpumask_var_t mask)
107{ 159{
108 kfree(mask); 160 kfree(mask);
109} 161}
110EXPORT_SYMBOL(free_cpumask_var); 162EXPORT_SYMBOL(free_cpumask_var);
111 163
164/**
165 * free_bootmem_cpumask_var - frees result of alloc_bootmem_cpumask_var
166 * @mask: cpumask to free
167 */
112void __init free_bootmem_cpumask_var(cpumask_var_t mask) 168void __init free_bootmem_cpumask_var(cpumask_var_t mask)
113{ 169{
114 free_bootmem((unsigned long)mask, cpumask_size()); 170 free_bootmem((unsigned long)mask, cpumask_size());