blob: ebf6d7887a38fa54481b6b7645e42bb7c59499a7 [file] [log] [blame]
Rusty Russell71ee73e2009-03-13 14:49:52 +10301/* Common code for 32 and 64-bit NUMA */
2#include <linux/topology.h>
3#include <linux/module.h>
4#include <linux/bootmem.h>
Jan Beulich90321602011-01-19 08:57:21 +00005#include <asm/numa.h>
6#include <asm/acpi.h>
7
8int __initdata numa_off;
9
10static __init int numa_setup(char *opt)
11{
12 if (!opt)
13 return -EINVAL;
14 if (!strncmp(opt, "off", 3))
15 numa_off = 1;
16#ifdef CONFIG_NUMA_EMU
17 if (!strncmp(opt, "fake=", 5))
18 numa_emu_cmdline(opt + 5);
19#endif
20#ifdef CONFIG_ACPI_NUMA
21 if (!strncmp(opt, "noacpi", 6))
22 acpi_numa = -1;
23#endif
24 return 0;
25}
26early_param("numa", numa_setup);
Rusty Russell71ee73e2009-03-13 14:49:52 +103027
Rusty Russell71ee73e2009-03-13 14:49:52 +103028/*
29 * Which logical CPUs are on which nodes
30 */
Rusty Russellc032ef602009-03-13 14:49:53 +103031cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
Rusty Russell71ee73e2009-03-13 14:49:52 +103032EXPORT_SYMBOL(node_to_cpumask_map);
33
34/*
35 * Allocate node_to_cpumask_map based on number of available nodes
36 * Requires node_possible_map to be valid.
37 *
38 * Note: node_to_cpumask() is not valid until after this is done.
39 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
40 */
41void __init setup_node_to_cpumask_map(void)
42{
43 unsigned int node, num = 0;
Rusty Russell71ee73e2009-03-13 14:49:52 +103044
45 /* setup nr_node_ids if not done yet */
46 if (nr_node_ids == MAX_NUMNODES) {
47 for_each_node_mask(node, node_possible_map)
48 num = node;
49 nr_node_ids = num + 1;
50 }
51
52 /* allocate the map */
Rusty Russellc032ef602009-03-13 14:49:53 +103053 for (node = 0; node < nr_node_ids; node++)
54 alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
Rusty Russell71ee73e2009-03-13 14:49:52 +103055
Rusty Russellc032ef602009-03-13 14:49:53 +103056 /* cpumask_of_node() will now work */
57 pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
Rusty Russell71ee73e2009-03-13 14:49:52 +103058}
59
60#ifdef CONFIG_DEBUG_PER_CPU_MAPS
61/*
62 * Returns a pointer to the bitmask of CPUs on Node 'node'.
63 */
Rusty Russell73e907d2009-03-13 14:49:57 +103064const struct cpumask *cpumask_of_node(int node)
Rusty Russell71ee73e2009-03-13 14:49:52 +103065{
Rusty Russell71ee73e2009-03-13 14:49:52 +103066 if (node >= nr_node_ids) {
67 printk(KERN_WARNING
68 "cpumask_of_node(%d): node > nr_node_ids(%d)\n",
69 node, nr_node_ids);
70 dump_stack();
71 return cpu_none_mask;
72 }
Rusty Russellc032ef602009-03-13 14:49:53 +103073 if (node_to_cpumask_map[node] == NULL) {
74 printk(KERN_WARNING
75 "cpumask_of_node(%d): no node_to_cpumask_map!\n",
76 node);
77 dump_stack();
78 return cpu_online_mask;
79 }
Rusty Russell0b966252009-03-13 23:42:42 +103080 return node_to_cpumask_map[node];
Rusty Russell71ee73e2009-03-13 14:49:52 +103081}
82EXPORT_SYMBOL(cpumask_of_node);
83#endif