blob: efbafbbff584050742444a40245738e19dc19ee5 [file] [log] [blame]
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -03001#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/init.h>
4#include <linux/bootmem.h>
5#include <linux/percpu.h>
Bernhard Walle1ecd2762008-06-20 15:38:22 +02006#include <linux/kexec.h>
Yinghai Lu17b4cce2008-06-21 21:02:20 -07007#include <linux/crash_dump.h>
Jaswinder Singh Rajput8a87dd92009-01-04 17:04:26 +05308#include <linux/smp.h>
9#include <linux/topology.h>
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030010#include <asm/sections.h>
11#include <asm/processor.h>
12#include <asm/setup.h>
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040013#include <asm/mpspec.h>
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040014#include <asm/apicdef.h>
Bernhard Walle1ecd2762008-06-20 15:38:22 +020015#include <asm/highmem.h>
Tejun Heo1a51e3a2009-01-13 20:41:35 +090016#include <asm/proto.h>
Jaswinder Singh Rajput06879032009-01-10 12:17:37 +053017#include <asm/cpumask.h>
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040018
Mike Travisc90aa892009-01-13 20:41:34 +090019#ifdef CONFIG_DEBUG_PER_CPU_MAPS
20# define DBG(x...) printk(KERN_DEBUG x)
21#else
22# define DBG(x...)
23#endif
24
Brian Gerstea927902009-01-19 00:38:58 +090025/*
26 * Could be inside CONFIG_HAVE_SETUP_PER_CPU_AREA with other stuff but
27 * voyager wants cpu_number too.
28 */
29#ifdef CONFIG_SMP
30DEFINE_PER_CPU(int, cpu_number);
31EXPORT_PER_CPU_SYMBOL(cpu_number);
32#endif
33
James Bottomleyf8955eb2008-05-10 09:01:48 -050034#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040035unsigned int num_processors;
36unsigned disabled_cpus __cpuinitdata;
37/* Processor that is doing the boot up */
38unsigned int boot_cpu_physical_apicid = -1U;
39EXPORT_SYMBOL(boot_cpu_physical_apicid);
Jaswinder Singh Rajput8a87dd92009-01-04 17:04:26 +053040unsigned int max_physical_apicid;
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040041
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040042/* Bitmask of physically existing CPUs */
43physid_mask_t phys_cpu_present_map;
James Bottomleyf8955eb2008-05-10 09:01:48 -050044#endif
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040045
Mike Travisc90aa892009-01-13 20:41:34 +090046/*
47 * Map cpu index to physical APIC ID
48 */
Mike Travis23ca4bb2008-05-12 21:21:12 +020049DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID);
50DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID);
51EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
52EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
53
54#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
Mike Travisc90aa892009-01-13 20:41:34 +090055#define X86_64_NUMA 1 /* (used later) */
Brian Gerste7a22c12009-01-19 00:38:59 +090056DEFINE_PER_CPU(int, node_number) = 0;
57EXPORT_PER_CPU_SYMBOL(node_number);
Mike Travis23ca4bb2008-05-12 21:21:12 +020058
Mike Travisc90aa892009-01-13 20:41:34 +090059/*
60 * Map cpu index to node index
61 */
Mike Travis23ca4bb2008-05-12 21:21:12 +020062DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE);
63EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map);
Mike Travis9f248bd2008-05-12 21:21:12 +020064
Mike Travisc90aa892009-01-13 20:41:34 +090065/*
66 * Which logical CPUs are on which nodes
67 */
Mike Travis9f248bd2008-05-12 21:21:12 +020068cpumask_t *node_to_cpumask_map;
69EXPORT_SYMBOL(node_to_cpumask_map);
70
Mike Travisc90aa892009-01-13 20:41:34 +090071/*
72 * Setup node_to_cpumask_map
73 */
Mike Travis9f248bd2008-05-12 21:21:12 +020074static void __init setup_node_to_cpumask_map(void);
75
76#else
77static inline void setup_node_to_cpumask_map(void) { }
Mike Travis23ca4bb2008-05-12 21:21:12 +020078#endif
79
Tejun Heob12d8db2009-01-13 20:41:35 +090080/*
81 * Define load_pda_offset() and per-cpu __pda for x86_64.
82 * load_pda_offset() is responsible for loading the offset of pda into
83 * %gs.
84 *
85 * On SMP, pda offset also duals as percpu base address and thus it
86 * should be at the start of per-cpu area. To achieve this, it's
87 * preallocated in vmlinux_64.lds.S directly instead of using
88 * DEFINE_PER_CPU().
89 */
Tejun Heo1a51e3a2009-01-13 20:41:35 +090090#ifdef CONFIG_X86_64
91void __cpuinit load_pda_offset(int cpu)
92{
93 /* Memory clobbers used to order pda/percpu accesses */
94 mb();
95 wrmsrl(MSR_GS_BASE, cpu_pda(cpu));
96 mb();
97}
Tejun Heob12d8db2009-01-13 20:41:35 +090098#ifndef CONFIG_SMP
99DEFINE_PER_CPU(struct x8664_pda, __pda);
Tejun Heob12d8db2009-01-13 20:41:35 +0900100#endif
Tejun Heoa338af22009-01-16 11:19:03 +0900101EXPORT_PER_CPU_SYMBOL(__pda);
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900102#endif /* CONFIG_SMP && CONFIG_X86_64 */
103
104#ifdef CONFIG_X86_64
105
106/* correctly size the local cpu masks */
107static void setup_cpu_local_masks(void)
108{
109 alloc_bootmem_cpumask_var(&cpu_initialized_mask);
110 alloc_bootmem_cpumask_var(&cpu_callin_mask);
111 alloc_bootmem_cpumask_var(&cpu_callout_mask);
112 alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
113}
114
115#else /* CONFIG_X86_32 */
116
117static inline void setup_cpu_local_masks(void)
118{
119}
120
121#endif /* CONFIG_X86_32 */
122
Mike Travisc90aa892009-01-13 20:41:34 +0900123#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300124/*
125 * Copy data used in early init routines from the initial arrays to the
126 * per cpu data areas. These arrays then become expendable and the
127 * *_early_ptr's are zeroed indicating that the static arrays are gone.
128 */
129static void __init setup_per_cpu_maps(void)
130{
131 int cpu;
132
133 for_each_possible_cpu(cpu) {
Mike Travis23ca4bb2008-05-12 21:21:12 +0200134 per_cpu(x86_cpu_to_apicid, cpu) =
135 early_per_cpu_map(x86_cpu_to_apicid, cpu);
Mike Travisb447a462008-03-25 15:06:51 -0700136 per_cpu(x86_bios_cpu_apicid, cpu) =
Mike Travis23ca4bb2008-05-12 21:21:12 +0200137 early_per_cpu_map(x86_bios_cpu_apicid, cpu);
138#ifdef X86_64_NUMA
Mike Travisb447a462008-03-25 15:06:51 -0700139 per_cpu(x86_cpu_to_node_map, cpu) =
Mike Travis23ca4bb2008-05-12 21:21:12 +0200140 early_per_cpu_map(x86_cpu_to_node_map, cpu);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300141#endif
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300142 }
143
144 /* indicate the early static arrays will soon be gone */
Mike Travis23ca4bb2008-05-12 21:21:12 +0200145 early_per_cpu_ptr(x86_cpu_to_apicid) = NULL;
146 early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL;
147#ifdef X86_64_NUMA
148 early_per_cpu_ptr(x86_cpu_to_node_map) = NULL;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300149#endif
150}
151
Tejun Heo9939dda2009-01-13 20:41:35 +0900152#ifdef CONFIG_X86_64
153unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
154 [0] = (unsigned long)__per_cpu_load,
155};
156#else
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300157unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900158#endif
Tejun Heo9939dda2009-01-13 20:41:35 +0900159EXPORT_SYMBOL(__per_cpu_offset);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300160
161/*
162 * Great future plan:
163 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
164 * Always point %gs to its beginning
165 */
166void __init setup_per_cpu_areas(void)
167{
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200168 ssize_t size, old_size;
Mike Travis3461b0a2008-05-12 21:21:13 +0200169 char *ptr;
170 int cpu;
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700171 unsigned long align = 1;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300172
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300173 /* Copy section for each CPU (we discard the original) */
Yinghai Lu1f3fcd42008-08-19 20:49:44 -0700174 old_size = PERCPU_ENOUGH_ROOM;
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700175 align = max_t(unsigned long, PAGE_SIZE, align);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200176 size = roundup(old_size, align);
Mike Travisa1681962008-12-16 17:33:53 -0800177
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300178 pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n",
Mike Travisa1681962008-12-16 17:33:53 -0800179 NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids);
180
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300181 pr_info("PERCPU: Allocating %zd bytes of per cpu data\n", size);
Mike Travisb447a462008-03-25 15:06:51 -0700182
Mike Travis3461b0a2008-05-12 21:21:13 +0200183 for_each_possible_cpu(cpu) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300184#ifndef CONFIG_NEED_MULTIPLE_NODES
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700185 ptr = __alloc_bootmem(size, align,
186 __pa(MAX_DMA_ADDRESS));
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300187#else
Mike Travis3461b0a2008-05-12 21:21:13 +0200188 int node = early_cpu_to_node(cpu);
Mike Travisb447a462008-03-25 15:06:51 -0700189 if (!node_online(node) || !NODE_DATA(node)) {
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700190 ptr = __alloc_bootmem(size, align,
191 __pa(MAX_DMA_ADDRESS));
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300192 pr_info("cpu %d has no node %d or node-local memory\n",
Mike Travis3461b0a2008-05-12 21:21:13 +0200193 cpu, node);
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300194 pr_debug("per cpu data for cpu%d at %016lx\n",
195 cpu, __pa(ptr));
196 } else {
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700197 ptr = __alloc_bootmem_node(NODE_DATA(node), size, align,
198 __pa(MAX_DMA_ADDRESS));
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300199 pr_debug("per cpu data for cpu%d on node%d at %016lx\n",
200 cpu, node, __pa(ptr));
Yinghai Lua677f582008-07-29 00:37:10 -0700201 }
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300202#endif
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900203
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900204 memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start);
Tejun Heo9939dda2009-01-13 20:41:35 +0900205 per_cpu_offset(cpu) = ptr - __per_cpu_start;
Brian Gerst26f80bd2009-01-19 00:38:58 +0900206 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
Brian Gerstea927902009-01-19 00:38:58 +0900207 per_cpu(cpu_number, cpu) = cpu;
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900208#ifdef CONFIG_X86_64
Brian Gerst26f80bd2009-01-19 00:38:58 +0900209 per_cpu(irq_stack_ptr, cpu) =
210 (char *)per_cpu(irq_stack, cpu) + IRQ_STACK_SIZE - 64;
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900211 /*
212 * CPU0 modified pda in the init data area, reload pda
213 * offset for CPU0 and clear the area for others.
214 */
215 if (cpu == 0)
216 load_pda_offset(0);
217 else
218 memset(cpu_pda(cpu), 0, sizeof(*cpu_pda(cpu)));
219#endif
Mike Travisc90aa892009-01-13 20:41:34 +0900220
221 DBG("PERCPU: cpu %4d %p\n", cpu, ptr);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300222 }
223
Mike Travisb447a462008-03-25 15:06:51 -0700224 /* Setup percpu data maps */
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300225 setup_per_cpu_maps();
Mike Travis9f0e8d02008-04-04 18:11:01 -0700226
Mike Travis9f248bd2008-05-12 21:21:12 +0200227 /* Setup node to cpumask map */
228 setup_node_to_cpumask_map();
Mike Travisc2d1cec2009-01-04 05:18:03 -0800229
230 /* Setup cpu initialized, callin, callout masks */
231 setup_cpu_local_masks();
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300232}
233
234#endif
Huang, Yingc45a7072008-06-02 14:26:25 +0800235
Mike Travis23ca4bb2008-05-12 21:21:12 +0200236#ifdef X86_64_NUMA
Mike Travis9f248bd2008-05-12 21:21:12 +0200237
238/*
239 * Allocate node_to_cpumask_map based on number of available nodes
240 * Requires node_possible_map to be valid.
241 *
242 * Note: node_to_cpumask() is not valid until after this is done.
Mike Travisc90aa892009-01-13 20:41:34 +0900243 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
Mike Travis9f248bd2008-05-12 21:21:12 +0200244 */
245static void __init setup_node_to_cpumask_map(void)
246{
247 unsigned int node, num = 0;
248 cpumask_t *map;
249
250 /* setup nr_node_ids if not done yet */
251 if (nr_node_ids == MAX_NUMNODES) {
252 for_each_node_mask(node, node_possible_map)
253 num = node;
254 nr_node_ids = num + 1;
255 }
256
257 /* allocate the map */
258 map = alloc_bootmem_low(nr_node_ids * sizeof(cpumask_t));
Mike Travisc90aa892009-01-13 20:41:34 +0900259 DBG("node_to_cpumask_map at %p for %d nodes\n", map, nr_node_ids);
Mike Travis9f248bd2008-05-12 21:21:12 +0200260
Gustavo F. Padovan55410792008-10-15 10:37:04 -0300261 pr_debug("Node to cpumask map at %p for %d nodes\n",
Thomas Gleixnercfc1b9a2008-07-21 21:35:38 +0200262 map, nr_node_ids);
Mike Travis9f248bd2008-05-12 21:21:12 +0200263
264 /* node_to_cpumask() will now work */
265 node_to_cpumask_map = map;
266}
267
Mike Travis23ca4bb2008-05-12 21:21:12 +0200268void __cpuinit numa_set_node(int cpu, int node)
269{
270 int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
271
Mike Travisc90aa892009-01-13 20:41:34 +0900272 /* early setting, no percpu area yet */
273 if (cpu_to_node_map) {
Mike Travis23ca4bb2008-05-12 21:21:12 +0200274 cpu_to_node_map[cpu] = node;
Mike Travisc90aa892009-01-13 20:41:34 +0900275 return;
276 }
Mike Travis23ca4bb2008-05-12 21:21:12 +0200277
Mike Travisc90aa892009-01-13 20:41:34 +0900278#ifdef CONFIG_DEBUG_PER_CPU_MAPS
279 if (cpu >= nr_cpu_ids || !per_cpu_offset(cpu)) {
280 printk(KERN_ERR "numa_set_node: invalid cpu# (%d)\n", cpu);
281 dump_stack();
282 return;
283 }
284#endif
285 per_cpu(x86_cpu_to_node_map, cpu) = node;
Mike Travis23ca4bb2008-05-12 21:21:12 +0200286
Mike Travisc90aa892009-01-13 20:41:34 +0900287 if (node != NUMA_NO_NODE)
Brian Gerste7a22c12009-01-19 00:38:59 +0900288 per_cpu(node_number, cpu) = node;
Mike Travis23ca4bb2008-05-12 21:21:12 +0200289}
290
291void __cpuinit numa_clear_node(int cpu)
292{
293 numa_set_node(cpu, NUMA_NO_NODE);
294}
295
Mike Travis9f248bd2008-05-12 21:21:12 +0200296#ifndef CONFIG_DEBUG_PER_CPU_MAPS
297
Mike Travis23ca4bb2008-05-12 21:21:12 +0200298void __cpuinit numa_add_cpu(int cpu)
299{
300 cpu_set(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
301}
302
303void __cpuinit numa_remove_cpu(int cpu)
304{
Mike Travisc90aa892009-01-13 20:41:34 +0900305 cpu_clear(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
Mike Travis23ca4bb2008-05-12 21:21:12 +0200306}
Mike Travis23ca4bb2008-05-12 21:21:12 +0200307
Mike Travis9f248bd2008-05-12 21:21:12 +0200308#else /* CONFIG_DEBUG_PER_CPU_MAPS */
309
310/*
311 * --------- debug versions of the numa functions ---------
312 */
313static void __cpuinit numa_set_cpumask(int cpu, int enable)
314{
Mike Travisc90aa892009-01-13 20:41:34 +0900315 int node = early_cpu_to_node(cpu);
Mike Travis9f248bd2008-05-12 21:21:12 +0200316 cpumask_t *mask;
317 char buf[64];
318
319 if (node_to_cpumask_map == NULL) {
320 printk(KERN_ERR "node_to_cpumask_map NULL\n");
321 dump_stack();
322 return;
323 }
324
325 mask = &node_to_cpumask_map[node];
326 if (enable)
327 cpu_set(cpu, *mask);
328 else
329 cpu_clear(cpu, *mask);
330
Rusty Russell29c01772008-12-13 21:20:25 +1030331 cpulist_scnprintf(buf, sizeof(buf), mask);
Mike Travis9f248bd2008-05-12 21:21:12 +0200332 printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
Jaswinder Singh Rajput8a87dd92009-01-04 17:04:26 +0530333 enable ? "numa_add_cpu" : "numa_remove_cpu", cpu, node, buf);
334}
Mike Travis9f248bd2008-05-12 21:21:12 +0200335
336void __cpuinit numa_add_cpu(int cpu)
337{
338 numa_set_cpumask(cpu, 1);
339}
340
341void __cpuinit numa_remove_cpu(int cpu)
342{
343 numa_set_cpumask(cpu, 0);
344}
Mike Travis23ca4bb2008-05-12 21:21:12 +0200345
346int cpu_to_node(int cpu)
347{
348 if (early_per_cpu_ptr(x86_cpu_to_node_map)) {
349 printk(KERN_WARNING
350 "cpu_to_node(%d): usage too early!\n", cpu);
351 dump_stack();
352 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
353 }
354 return per_cpu(x86_cpu_to_node_map, cpu);
355}
356EXPORT_SYMBOL(cpu_to_node);
357
Mike Travis9f248bd2008-05-12 21:21:12 +0200358/*
359 * Same function as cpu_to_node() but used if called before the
360 * per_cpu areas are setup.
361 */
Mike Travis23ca4bb2008-05-12 21:21:12 +0200362int early_cpu_to_node(int cpu)
363{
364 if (early_per_cpu_ptr(x86_cpu_to_node_map))
365 return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
366
367 if (!per_cpu_offset(cpu)) {
368 printk(KERN_WARNING
369 "early_cpu_to_node(%d): no per_cpu area!\n", cpu);
Mike Travis9f248bd2008-05-12 21:21:12 +0200370 dump_stack();
Mike Travis23ca4bb2008-05-12 21:21:12 +0200371 return NUMA_NO_NODE;
372 }
373 return per_cpu(x86_cpu_to_node_map, cpu);
374}
Mike Travis9f248bd2008-05-12 21:21:12 +0200375
Mike Travis6a2f47c2008-06-27 10:10:13 -0700376
377/* empty cpumask */
378static const cpumask_t cpu_mask_none;
379
Mike Travis9f248bd2008-05-12 21:21:12 +0200380/*
381 * Returns a pointer to the bitmask of CPUs on Node 'node'.
382 */
Rusty Russell393d68f2008-12-26 22:23:38 +1030383const cpumask_t *cpumask_of_node(int node)
Mike Travis9f248bd2008-05-12 21:21:12 +0200384{
385 if (node_to_cpumask_map == NULL) {
386 printk(KERN_WARNING
Rusty Russell393d68f2008-12-26 22:23:38 +1030387 "cpumask_of_node(%d): no node_to_cpumask_map!\n",
Mike Travis9f248bd2008-05-12 21:21:12 +0200388 node);
389 dump_stack();
Mike Travis11369f352008-07-08 14:35:21 -0700390 return (const cpumask_t *)&cpu_online_map;
Mike Travis9f248bd2008-05-12 21:21:12 +0200391 }
Mike Travis6a2f47c2008-06-27 10:10:13 -0700392 if (node >= nr_node_ids) {
393 printk(KERN_WARNING
Rusty Russell393d68f2008-12-26 22:23:38 +1030394 "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
Mike Travis6a2f47c2008-06-27 10:10:13 -0700395 node, nr_node_ids);
396 dump_stack();
Mike Travis11369f352008-07-08 14:35:21 -0700397 return &cpu_mask_none;
Mike Travis6a2f47c2008-06-27 10:10:13 -0700398 }
Mike Travis11369f352008-07-08 14:35:21 -0700399 return &node_to_cpumask_map[node];
Mike Travis9f248bd2008-05-12 21:21:12 +0200400}
Rusty Russell393d68f2008-12-26 22:23:38 +1030401EXPORT_SYMBOL(cpumask_of_node);
Mike Travis9f248bd2008-05-12 21:21:12 +0200402
403/*
404 * Returns a bitmask of CPUs on Node 'node'.
Mike Travis6a2f47c2008-06-27 10:10:13 -0700405 *
406 * Side note: this function creates the returned cpumask on the stack
407 * so with a high NR_CPUS count, excessive stack space is used. The
408 * node_to_cpumask_ptr function should be used whenever possible.
Mike Travis9f248bd2008-05-12 21:21:12 +0200409 */
410cpumask_t node_to_cpumask(int node)
411{
412 if (node_to_cpumask_map == NULL) {
413 printk(KERN_WARNING
414 "node_to_cpumask(%d): no node_to_cpumask_map!\n", node);
415 dump_stack();
416 return cpu_online_map;
417 }
Mike Travis6a2f47c2008-06-27 10:10:13 -0700418 if (node >= nr_node_ids) {
419 printk(KERN_WARNING
420 "node_to_cpumask(%d): node > nr_node_ids(%d)\n",
421 node, nr_node_ids);
422 dump_stack();
423 return cpu_mask_none;
424 }
Mike Travis9f248bd2008-05-12 21:21:12 +0200425 return node_to_cpumask_map[node];
426}
427EXPORT_SYMBOL(node_to_cpumask);
428
429/*
430 * --------- end of debug versions of the numa functions ---------
431 */
432
433#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
434
435#endif /* X86_64_NUMA */
Bernhard Walle1ecd2762008-06-20 15:38:22 +0200436