ia64/xen-unstable

annotate xen/arch/x86/srat.c @ 19835:edfdeb150f27

Fix buildsystem to detect udev > version 124

udev removed the udevinfo symlink from versions higher than 123 and
xen's build-system could not detect if udev is in place and has the
required version.

Signed-off-by: Marc-A. Dahlhaus <mad@wol.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:02:37 2009 +0100 (2009-06-25)
parents 89e50c449307
children
rev   line source
kfraser@11971 1 /*
kfraser@11971 2 * ACPI 3.0 based NUMA setup
kfraser@11971 3 * Copyright 2004 Andi Kleen, SuSE Labs.
kfraser@11971 4 *
kfraser@11971 5 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
kfraser@11971 6 *
kfraser@11971 7 * Called from acpi_numa_init while reading the SRAT and SLIT tables.
kfraser@11971 8 * Assumes all memory regions belonging to a single proximity domain
kfraser@11971 9 * are in one chunk. Holes between them will be included in the node.
kfraser@11971 10 *
kfraser@11971 11 * Adapted for Xen: Ryan Harper <ryanh@us.ibm.com>
kfraser@11971 12 */
kfraser@11971 13
kfraser@11971 14 #include <xen/init.h>
kfraser@11971 15 #include <xen/mm.h>
kfraser@11971 16 #include <xen/inttypes.h>
kfraser@11971 17 #include <xen/nodemask.h>
kfraser@11971 18 #include <xen/acpi.h>
kfraser@11998 19 #include <xen/numa.h>
kfraser@11971 20 #include <asm/page.h>
kfraser@11971 21
kfraser@11971 22 static struct acpi_table_slit *acpi_slit;
kfraser@11971 23
kfraser@11971 24 static nodemask_t nodes_parsed __initdata;
kfraser@11971 25 static nodemask_t nodes_found __initdata;
kfraser@11971 26 static struct node nodes[MAX_NUMNODES] __initdata;
kfraser@11971 27 static u8 pxm2node[256] = { [0 ... 255] = 0xff };
kfraser@11971 28
kfraser@11971 29 /* Too small nodes confuse the VM badly. Usually they result
kfraser@11971 30 from BIOS bugs. */
kfraser@11971 31 #define NODE_MIN_SIZE (4*1024*1024)
kfraser@11971 32
kfraser@11971 33 static int node_to_pxm(int n);
kfraser@11971 34
kfraser@11971 35 int pxm_to_node(int pxm)
kfraser@11971 36 {
kfraser@11971 37 if ((unsigned)pxm >= 256)
kfraser@11971 38 return -1;
kfraser@11971 39 /* Extend 0xff to (int)-1 */
kfraser@11971 40 return (signed char)pxm2node[pxm];
kfraser@11971 41 }
kfraser@11971 42
kfraser@11971 43 static __init int setup_node(int pxm)
kfraser@11971 44 {
kfraser@11971 45 unsigned node = pxm2node[pxm];
kfraser@11971 46 if (node == 0xff) {
kfraser@11971 47 if (nodes_weight(nodes_found) >= MAX_NUMNODES)
kfraser@11971 48 return -1;
kfraser@11971 49 node = first_unset_node(nodes_found);
kfraser@11971 50 node_set(node, nodes_found);
kfraser@11971 51 pxm2node[pxm] = node;
kfraser@11971 52 }
kfraser@11971 53 return pxm2node[pxm];
kfraser@11971 54 }
kfraser@11971 55
kfraser@11971 56 static __init int conflicting_nodes(u64 start, u64 end)
kfraser@11971 57 {
kfraser@11971 58 int i;
kfraser@11971 59 for_each_node_mask(i, nodes_parsed) {
kfraser@11971 60 struct node *nd = &nodes[i];
kfraser@11971 61 if (nd->start == nd->end)
kfraser@11971 62 continue;
kfraser@11971 63 if (nd->end > start && nd->start < end)
kfraser@11971 64 return i;
kfraser@11971 65 if (nd->end == end && nd->start == start)
kfraser@11971 66 return i;
kfraser@11971 67 }
kfraser@11971 68 return -1;
kfraser@11971 69 }
kfraser@11971 70
kfraser@11971 71 static __init void cutoff_node(int i, u64 start, u64 end)
kfraser@11971 72 {
kfraser@11971 73 struct node *nd = &nodes[i];
kfraser@11971 74 if (nd->start < start) {
kfraser@11971 75 nd->start = start;
kfraser@11971 76 if (nd->end < nd->start)
kfraser@11971 77 nd->start = nd->end;
kfraser@11971 78 }
kfraser@11971 79 if (nd->end > end) {
kfraser@11971 80 nd->end = end;
kfraser@11971 81 if (nd->start > nd->end)
kfraser@11971 82 nd->start = nd->end;
kfraser@11971 83 }
kfraser@11971 84 }
kfraser@11971 85
kfraser@11971 86 static __init void bad_srat(void)
kfraser@11971 87 {
kfraser@11971 88 int i;
kfraser@11971 89 printk(KERN_ERR "SRAT: SRAT not used.\n");
kfraser@11971 90 acpi_numa = -1;
kfraser@11971 91 for (i = 0; i < MAX_LOCAL_APIC; i++)
kfraser@11971 92 apicid_to_node[i] = NUMA_NO_NODE;
kfraser@11971 93 }
kfraser@11971 94
kfraser@11971 95 static __init inline int srat_disabled(void)
kfraser@11971 96 {
kfraser@11971 97 return numa_off || acpi_numa < 0;
kfraser@11971 98 }
kfraser@11971 99
kfraser@11971 100 /*
kfraser@11971 101 * A lot of BIOS fill in 10 (= no distance) everywhere. This messes
kfraser@11971 102 * up the NUMA heuristics which wants the local node to have a smaller
kfraser@11971 103 * distance than the others.
kfraser@11971 104 * Do some quick checks here and only use the SLIT if it passes.
kfraser@11971 105 */
kfraser@11971 106 static __init int slit_valid(struct acpi_table_slit *slit)
kfraser@11971 107 {
kfraser@11971 108 int i, j;
keir@17248 109 int d = slit->locality_count;
kfraser@11971 110 for (i = 0; i < d; i++) {
kfraser@11971 111 for (j = 0; j < d; j++) {
kfraser@11971 112 u8 val = slit->entry[d*i + j];
kfraser@11971 113 if (i == j) {
kfraser@11971 114 if (val != 10)
kfraser@11971 115 return 0;
kfraser@11971 116 } else if (val <= 10)
kfraser@11971 117 return 0;
kfraser@11971 118 }
kfraser@11971 119 }
kfraser@11971 120 return 1;
kfraser@11971 121 }
kfraser@11971 122
kfraser@11971 123 /* Callback for SLIT parsing */
kfraser@11971 124 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
kfraser@11971 125 {
kfraser@11971 126 if (!slit_valid(slit)) {
kfraser@11971 127 printk(KERN_INFO "ACPI: SLIT table looks invalid. Not used.\n");
kfraser@11971 128 return;
kfraser@11971 129 }
kfraser@11971 130 acpi_slit = slit;
kfraser@11971 131 }
kfraser@11971 132
kfraser@11971 133 /* Callback for Proximity Domain -> LAPIC mapping */
kfraser@11971 134 void __init
keir@19633 135 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
kfraser@11971 136 {
kfraser@11971 137 int pxm, node;
kfraser@11971 138 if (srat_disabled())
kfraser@11971 139 return;
keir@19633 140 if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
keir@19633 141 bad_srat();
kfraser@11971 142 return;
kfraser@11971 143 }
keir@19633 144 if (!(pa->flags & ACPI_SRAT_CPU_ENABLED))
kfraser@11971 145 return;
keir@19633 146 pxm = pa->proximity_domain_lo;
keir@19633 147 if (srat_rev >= 2) {
keir@19633 148 pxm |= pa->proximity_domain_hi[0] << 8;
keir@19633 149 pxm |= pa->proximity_domain_hi[1] << 16;
keir@19633 150 pxm |= pa->proximity_domain_hi[2] << 24;
keir@19633 151 }
kfraser@11971 152 node = setup_node(pxm);
kfraser@11971 153 if (node < 0) {
kfraser@11971 154 printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
kfraser@11971 155 bad_srat();
kfraser@11971 156 return;
kfraser@11971 157 }
kfraser@11971 158 apicid_to_node[pa->apic_id] = node;
kfraser@11971 159 acpi_numa = 1;
kfraser@11971 160 printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n",
kfraser@11971 161 pxm, pa->apic_id, node);
kfraser@11971 162 }
kfraser@11971 163
kfraser@11971 164 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
kfraser@11971 165 void __init
keir@19633 166 acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
kfraser@11971 167 {
kfraser@11971 168 struct node *nd;
kfraser@11971 169 u64 start, end;
kfraser@11971 170 int node, pxm;
kfraser@11971 171 int i;
kfraser@11971 172
kfraser@11971 173 if (srat_disabled())
kfraser@11971 174 return;
keir@19633 175 if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
kfraser@11971 176 bad_srat();
kfraser@11971 177 return;
kfraser@11971 178 }
keir@19633 179 if (!(ma->flags & ACPI_SRAT_MEM_ENABLED))
kfraser@11971 180 return;
keir@19633 181 start = ma->base_address;
keir@19633 182 end = start + ma->length;
kfraser@11971 183 pxm = ma->proximity_domain;
keir@19633 184 if (srat_rev < 2)
keir@19633 185 pxm &= 0xff;
kfraser@11971 186 node = setup_node(pxm);
kfraser@11971 187 if (node < 0) {
kfraser@11971 188 printk(KERN_ERR "SRAT: Too many proximity domains.\n");
kfraser@11971 189 bad_srat();
kfraser@11971 190 return;
kfraser@11971 191 }
kfraser@11971 192 /* It is fine to add this area to the nodes data it will be used later*/
keir@19633 193 if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)
kfraser@11971 194 printk(KERN_INFO "SRAT: hot plug zone found %"PRIx64" - %"PRIx64" \n",
kfraser@11971 195 start, end);
kfraser@11971 196 i = conflicting_nodes(start, end);
kfraser@11971 197 if (i == node) {
kfraser@11971 198 printk(KERN_WARNING
kfraser@11971 199 "SRAT: Warning: PXM %d (%"PRIx64"-%"PRIx64") overlaps with itself (%"
kfraser@11971 200 PRIx64"-%"PRIx64")\n", pxm, start, end, nodes[i].start, nodes[i].end);
kfraser@11971 201 } else if (i >= 0) {
kfraser@11971 202 printk(KERN_ERR
kfraser@11971 203 "SRAT: PXM %d (%"PRIx64"-%"PRIx64") overlaps with PXM %d (%"
kfraser@11971 204 PRIx64"-%"PRIx64")\n", pxm, start, end, node_to_pxm(i),
kfraser@11971 205 nodes[i].start, nodes[i].end);
kfraser@11971 206 bad_srat();
kfraser@11971 207 return;
kfraser@11971 208 }
kfraser@11971 209 nd = &nodes[node];
kfraser@11971 210 if (!node_test_and_set(node, nodes_parsed)) {
kfraser@11971 211 nd->start = start;
kfraser@11971 212 nd->end = end;
kfraser@11971 213 } else {
kfraser@11971 214 if (start < nd->start)
kfraser@11971 215 nd->start = start;
kfraser@11971 216 if (nd->end < end)
kfraser@11971 217 nd->end = end;
kfraser@11971 218 }
kfraser@11971 219 printk(KERN_INFO "SRAT: Node %u PXM %u %"PRIx64"-%"PRIx64"\n", node, pxm,
kfraser@11971 220 nd->start, nd->end);
kfraser@11971 221 }
kfraser@11971 222
kfraser@11971 223 /* Sanity check to catch more bad SRATs (they are amazingly common).
kfraser@11971 224 Make sure the PXMs cover all memory. */
kfraser@11971 225 static int nodes_cover_memory(void)
kfraser@11971 226 {
kfraser@11971 227 int i;
kfraser@11971 228 u64 pxmram, e820ram;
kfraser@11971 229
kfraser@11971 230 pxmram = 0;
kfraser@11971 231 for_each_node_mask(i, nodes_parsed) {
kfraser@11971 232 u64 s = nodes[i].start >> PAGE_SHIFT;
kfraser@11971 233 u64 e = nodes[i].end >> PAGE_SHIFT;
kfraser@11971 234 pxmram += e - s;
kfraser@11971 235 }
kfraser@11971 236
kfraser@11971 237 e820ram = max_page;
kfraser@11971 238 /* We seem to lose 3 pages somewhere. Allow a bit of slack. */
kfraser@11971 239 if ((long)(e820ram - pxmram) >= 1*1024*1024) {
kfraser@11971 240 printk(KERN_ERR "SRAT: PXMs only cover %"PRIu64"MB of your %"
kfraser@11971 241 PRIu64"MB e820 RAM. Not used.\n",
kfraser@11971 242 (pxmram << PAGE_SHIFT) >> 20,
kfraser@11971 243 (e820ram << PAGE_SHIFT) >> 20);
kfraser@11971 244 return 0;
kfraser@11971 245 }
kfraser@11971 246 return 1;
kfraser@11971 247 }
kfraser@11971 248
kfraser@11971 249 static void unparse_node(int node)
kfraser@11971 250 {
kfraser@11971 251 int i;
kfraser@11971 252 node_clear(node, nodes_parsed);
kfraser@11971 253 for (i = 0; i < MAX_LOCAL_APIC; i++) {
kfraser@11971 254 if (apicid_to_node[i] == node)
kfraser@11971 255 apicid_to_node[i] = NUMA_NO_NODE;
kfraser@11971 256 }
kfraser@11971 257 }
kfraser@11971 258
kfraser@11971 259 void __init acpi_numa_arch_fixup(void) {}
kfraser@11971 260
kfraser@11971 261 /* Use the information discovered above to actually set up the nodes. */
kfraser@11971 262 int __init acpi_scan_nodes(u64 start, u64 end)
kfraser@11971 263 {
kfraser@11971 264 int i;
kfraser@11971 265
kfraser@11971 266 /* First clean up the node list */
kfraser@11971 267 for (i = 0; i < MAX_NUMNODES; i++) {
kfraser@11971 268 cutoff_node(i, start, end);
kfraser@11971 269 if ((nodes[i].end - nodes[i].start) < NODE_MIN_SIZE)
kfraser@11971 270 unparse_node(i);
kfraser@11971 271 }
kfraser@11971 272
kfraser@11971 273 if (acpi_numa <= 0)
kfraser@11971 274 return -1;
kfraser@11971 275
kfraser@11971 276 if (!nodes_cover_memory()) {
kfraser@11971 277 bad_srat();
kfraser@11971 278 return -1;
kfraser@11971 279 }
kfraser@11971 280
kfraser@11971 281 memnode_shift = compute_hash_shift(nodes, MAX_NUMNODES);
kfraser@11971 282 if (memnode_shift < 0) {
kfraser@11971 283 printk(KERN_ERR
kfraser@11971 284 "SRAT: No NUMA node hash function found. Contact maintainer\n");
kfraser@11971 285 bad_srat();
kfraser@11971 286 return -1;
kfraser@11971 287 }
kfraser@11971 288
kfraser@11971 289 /* Finally register nodes */
kfraser@11971 290 for_each_node_mask(i, nodes_parsed)
kfraser@11971 291 setup_node_bootmem(i, nodes[i].start, nodes[i].end);
kfraser@11971 292 for (i = 0; i < NR_CPUS; i++) {
kfraser@11971 293 if (cpu_to_node[i] == NUMA_NO_NODE)
kfraser@11971 294 continue;
kfraser@11971 295 if (!node_isset(cpu_to_node[i], nodes_parsed))
kfraser@11971 296 numa_set_node(i, NUMA_NO_NODE);
kfraser@11971 297 }
kfraser@11971 298 numa_init_array();
kfraser@11971 299 return 0;
kfraser@11971 300 }
kfraser@11971 301
kfraser@11971 302 static int node_to_pxm(int n)
kfraser@11971 303 {
kfraser@11971 304 int i;
kfraser@11971 305 if (pxm2node[n] == n)
kfraser@11971 306 return n;
kfraser@11971 307 for (i = 0; i < 256; i++)
kfraser@11971 308 if (pxm2node[i] == n)
kfraser@11971 309 return i;
kfraser@11971 310 return 0;
kfraser@11971 311 }
kfraser@11971 312
kfraser@11971 313 int __node_distance(int a, int b)
kfraser@11971 314 {
kfraser@11971 315 int index;
kfraser@11971 316
kfraser@11971 317 if (!acpi_slit)
kfraser@11971 318 return a == b ? 10 : 20;
keir@17248 319 index = acpi_slit->locality_count * node_to_pxm(a);
kfraser@11971 320 return acpi_slit->entry[index + node_to_pxm(b)];
kfraser@11971 321 }
kfraser@11971 322
kfraser@11971 323 EXPORT_SYMBOL(__node_distance);