Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 1 | /* Common code for 32 and 64-bit NUMA */ |
| 2 | #include <linux/topology.h> |
| 3 | #include <linux/module.h> |
| 4 | #include <linux/bootmem.h> |
Jan Beulich | 9032160 | 2011-01-19 08:57:21 +0000 | [diff] [blame] | 5 | #include <asm/numa.h> |
| 6 | #include <asm/acpi.h> |
| 7 | |
| 8 | int __initdata numa_off; |
| 9 | |
| 10 | static __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 | } |
| 26 | early_param("numa", numa_setup); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 27 | |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 28 | /* |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 29 | * apicid, cpu, node mappings |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 30 | */ |
Tejun Heo | bbc9e2f | 2011-01-23 14:37:39 +0100 | [diff] [blame] | 31 | s16 __apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = { |
| 32 | [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE |
| 33 | }; |
| 34 | |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 35 | cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 36 | EXPORT_SYMBOL(node_to_cpumask_map); |
| 37 | |
| 38 | /* |
Tejun Heo | 645a791 | 2011-01-23 14:37:40 +0100 | [diff] [blame^] | 39 | * Map cpu index to node index |
| 40 | */ |
| 41 | #ifdef CONFIG_X86_32 |
| 42 | DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, 0); |
| 43 | #else |
| 44 | DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE); |
| 45 | #endif |
| 46 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map); |
| 47 | |
| 48 | void __cpuinit numa_set_node(int cpu, int node) |
| 49 | { |
| 50 | int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map); |
| 51 | |
| 52 | /* early setting, no percpu area yet */ |
| 53 | if (cpu_to_node_map) { |
| 54 | cpu_to_node_map[cpu] = node; |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
| 59 | if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) { |
| 60 | printk(KERN_ERR "numa_set_node: invalid cpu# (%d)\n", cpu); |
| 61 | dump_stack(); |
| 62 | return; |
| 63 | } |
| 64 | #endif |
| 65 | per_cpu(x86_cpu_to_node_map, cpu) = node; |
| 66 | |
| 67 | if (node != NUMA_NO_NODE) |
| 68 | set_cpu_numa_node(cpu, node); |
| 69 | } |
| 70 | |
| 71 | void __cpuinit numa_clear_node(int cpu) |
| 72 | { |
| 73 | numa_set_node(cpu, NUMA_NO_NODE); |
| 74 | } |
| 75 | |
| 76 | /* |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 77 | * Allocate node_to_cpumask_map based on number of available nodes |
| 78 | * Requires node_possible_map to be valid. |
| 79 | * |
| 80 | * Note: node_to_cpumask() is not valid until after this is done. |
| 81 | * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) |
| 82 | */ |
| 83 | void __init setup_node_to_cpumask_map(void) |
| 84 | { |
| 85 | unsigned int node, num = 0; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 86 | |
| 87 | /* setup nr_node_ids if not done yet */ |
| 88 | if (nr_node_ids == MAX_NUMNODES) { |
| 89 | for_each_node_mask(node, node_possible_map) |
| 90 | num = node; |
| 91 | nr_node_ids = num + 1; |
| 92 | } |
| 93 | |
| 94 | /* allocate the map */ |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 95 | for (node = 0; node < nr_node_ids; node++) |
| 96 | alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 97 | |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 98 | /* cpumask_of_node() will now work */ |
| 99 | pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids); |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
Tejun Heo | 645a791 | 2011-01-23 14:37:40 +0100 | [diff] [blame^] | 103 | |
| 104 | int __cpu_to_node(int cpu) |
| 105 | { |
| 106 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) { |
| 107 | printk(KERN_WARNING |
| 108 | "cpu_to_node(%d): usage too early!\n", cpu); |
| 109 | dump_stack(); |
| 110 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 111 | } |
| 112 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 113 | } |
| 114 | EXPORT_SYMBOL(__cpu_to_node); |
| 115 | |
| 116 | /* |
| 117 | * Same function as cpu_to_node() but used if called before the |
| 118 | * per_cpu areas are setup. |
| 119 | */ |
| 120 | int early_cpu_to_node(int cpu) |
| 121 | { |
| 122 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) |
| 123 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 124 | |
| 125 | if (!cpu_possible(cpu)) { |
| 126 | printk(KERN_WARNING |
| 127 | "early_cpu_to_node(%d): no per_cpu area!\n", cpu); |
| 128 | dump_stack(); |
| 129 | return NUMA_NO_NODE; |
| 130 | } |
| 131 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 132 | } |
| 133 | |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 134 | /* |
| 135 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
| 136 | */ |
Rusty Russell | 73e907d | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 137 | const struct cpumask *cpumask_of_node(int node) |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 138 | { |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 139 | if (node >= nr_node_ids) { |
| 140 | printk(KERN_WARNING |
| 141 | "cpumask_of_node(%d): node > nr_node_ids(%d)\n", |
| 142 | node, nr_node_ids); |
| 143 | dump_stack(); |
| 144 | return cpu_none_mask; |
| 145 | } |
Rusty Russell | c032ef60 | 2009-03-13 14:49:53 +1030 | [diff] [blame] | 146 | if (node_to_cpumask_map[node] == NULL) { |
| 147 | printk(KERN_WARNING |
| 148 | "cpumask_of_node(%d): no node_to_cpumask_map!\n", |
| 149 | node); |
| 150 | dump_stack(); |
| 151 | return cpu_online_mask; |
| 152 | } |
Rusty Russell | 0b96625 | 2009-03-13 23:42:42 +1030 | [diff] [blame] | 153 | return node_to_cpumask_map[node]; |
Rusty Russell | 71ee73e | 2009-03-13 14:49:52 +1030 | [diff] [blame] | 154 | } |
| 155 | EXPORT_SYMBOL(cpumask_of_node); |
Tejun Heo | 645a791 | 2011-01-23 14:37:40 +0100 | [diff] [blame^] | 156 | |
| 157 | #endif /* CONFIG_DEBUG_PER_CPU_MAPS */ |