[PATCH] x86_64: Early initialization of cpu_to_node

Patch enables early intialization of cpu_to_node.
apicid_to_node is built by reading the SRAT table, from acpi_numa_init with
ACPI_NUMA and k8_scan_nodes with K8_NUMA.
x86_cpu_to_apicid is built by parsing the ACPI MADT table, from acpi_boot_init.
We combine these two tables and setup cpu_to_node.

Early intialization helps the static per_cpu_areas in getting pages from
correct node.

Change since last release:
Do not initialize early init_cpu_to_node for faking node cases.

Patch tested on TYAN dual core 4P board with K8 only, ACPI_NUMA.
Tested on EM64T NUMA. Also tested with numa=off, numa=fake, and running
a kernel compiled with NUMA on a regular EM64 2 way SMP.

Signed-off-by: Alok N Kataria <alokk@calsoftinc.com>
Signed-off-by: Ravikiran Thirumalai <kiran@scalex86.org>
Signed-off-by: Shai Fultheim <shai@scalex86.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Ravikiran Thirumalai and committed by
Linus Torvalds
05b3cbd8 0b91317e

+32
+2
arch/x86_64/kernel/setup.c
··· 713 713 acpi_boot_init(); 714 714 #endif 715 715 716 + init_cpu_to_node(); 717 + 716 718 #ifdef CONFIG_X86_LOCAL_APIC 717 719 /* 718 720 * get boot-time SMP configuration:
+25
arch/x86_64/mm/numa.c
··· 330 330 return 1; 331 331 } 332 332 333 + /* 334 + * Setup early cpu_to_node. 335 + * 336 + * Populate cpu_to_node[] only if x86_cpu_to_apicid[], 337 + * and apicid_to_node[] tables have valid entries for a CPU. 338 + * This means we skip cpu_to_node[] initialisation for NUMA 339 + * emulation and faking node case (when running a kernel compiled 340 + * for NUMA on a non NUMA box), which is OK as cpu_to_node[] 341 + * is already initialized in a round robin manner at numa_init_array, 342 + * prior to this call, and this initialization is good enough 343 + * for the fake NUMA cases. 344 + */ 345 + void __init init_cpu_to_node(void) 346 + { 347 + int i; 348 + for (i = 0; i < NR_CPUS; i++) { 349 + u8 apicid = x86_cpu_to_apicid[i]; 350 + if (apicid == BAD_APICID) 351 + continue; 352 + if (apicid_to_node[apicid] == NUMA_NO_NODE) 353 + continue; 354 + cpu_to_node[i] = apicid_to_node[apicid]; 355 + } 356 + } 357 + 333 358 EXPORT_SYMBOL(cpu_to_node); 334 359 EXPORT_SYMBOL(node_to_cpumask); 335 360 EXPORT_SYMBOL(memnode_shift);
+5
include/asm-x86_64/numa.h
··· 20 20 extern void numa_set_node(int cpu, int node); 21 21 22 22 extern unsigned char apicid_to_node[256]; 23 + #ifdef CONFIG_NUMA 24 + extern void __init init_cpu_to_node(void); 25 + #else 26 + #define init_cpu_to_node() do {} while (0) 27 + #endif 23 28 24 29 #define NUMA_NO_NODE 0xff 25 30