Skip to contentSkip to conversation

x86_64: get boot_cpu_id as early for k8_scan_nodes

PATCH In review Yinghai Lu 1 participant 1 message Jul 23, 2007 ACPI

lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 9/10 x86_64: get boot_cpu_id as early for k8_scan_nodes

[PATCH 9/10] x86_64: get boot_cpu_id as early for k8_scan_nodes

When acpi=off or there is no SRAT defined, apicid_to_node is got from K8 Northbridge PCI configuration space in k8_scan_nodes() in arch/x86_64/mm/k8toplogy.c.
The problem is that it assumes bsp apic id is 0 at that point. For four socket system with Quad core cpus installed, all cpus apic id is offset by 4, and bsp apic id is 4.
For eight socket system with dual core cpus installed, all cpus apic id is offset by 2, and bsp apic id is 2.

We need get boot_cpu_id --- bsp apic id, before k8_scan_nodes by called.

So create early_acpi_boot_init and early_get_smp_config for get boot_cpu_id.

 arch/x86_64/mm/k8topology.c    |    8 +++
 b/arch/i386/kernel/acpi/boot.c |   70 ++++++++++++++++++++++++++++++++
 b/arch/x86_64/kernel/apic.c    |   29 +++++++++++--
 b/arch/x86_64/kernel/mpparse.c |   89 ++++++++++++++++++++++++++++++-----------
 b/arch/x86_64/kernel/setup.c   |   21 +++++++++
 b/include/asm-x86_64/apic.h    |    2
 b/include/asm-x86_64/mpspec.h  |    2
 b/include/linux/acpi.h         |    5 ++
 8 files changed, 198 insertions(+), 28 deletions(-)
arch/x86_64/mm/k8topology.c +7 -1
@@ -52,6 +52,7 @@
 	unsigned cores;
 	unsigned bits;
 	int j;
+	unsigned apicid_base;
 
 	if (!early_pci_allowed())
 		return -1;
@@ -170,11 +171,16 @@
 	/* use the coreid bits from early_identify_cpu */
 	bits = boot_cpu_data.x86_coreid_bits;
 	cores = (1<<bits);
+	apicid_base = 0;
+	if (boot_cpu_id > 0) {
+		printk(KERN_INFO "BSP APIC ID: %02x\n", boot_cpu_id);
+		apicid_base = boot_cpu_id;
+	}
 
 	for (i = 0; i < 8; i++) {
 		if (nodes[i].start != nodes[i].end) { 
 			nodeid = nodeids[i];
-			for (j = 0; j < cores; j++)
+			for (j = apicid_base; j < cores + apicid_base; j++)
 				apicid_to_node[(nodeid << bits) + j] = i;
 			setup_node_bootmem(i, nodes[i].start, nodes[i].end); 
 		} 
arch/i386/kernel/acpi/boot.c +70 -0

88 lines not on this page · raw message

arch/x86_64/kernel/apic.c +24 -0
index 900ff38..70b9e2b 100644
@@ -690,6 +689,30 @@ static int __init ioapic_insert_resources(void)
 late_initcall(ioapic_insert_resources);
 #endif
 
+void __init early_init_lapic_mapping(void)
+{
+	unsigned long apic_phys;
+
+	/*
+	 * If no local APIC can be found then go out
+	 * : it means there is no mpatable and MADT
+	 */
+	if (!smp_found_config)
+		return;
+
+	apic_phys = mp_lapic_addr;
+
+	set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
+	apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
+				 APIC_BASE, apic_phys);
+
+	/*
+	 * Fetch the APIC ID of the BSP in case we have a
+	 * default configuration (or the MP table is broken).
+	 */
+	boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
+}
+
 void __init init_apic_mappings(void)
 {
 	unsigned long apic_phys;
arch/x86_64/kernel/mpparse.c +66 -23

171 lines not on this page · raw message

arch/x86_64/kernel/setup.c +21 -0
index af838f6..c07b314 100644
@@ -299,6 +299,27 @@ void __init setup_arch(char **cmdline_p)
 	acpi_numa_init();
 #endif
 
+	/*
+	 * Find possible boot-time SMP configuration:
+	 */
+	early_find_smp_config();
+#ifdef CONFIG_ACPI
+	/*
+	 * Read APIC information from ACPI tables.
+	 */
+	early_acpi_boot_init();
+#endif
+	/*
+	 * get boot-time SMP configuration:
+	 */
+	if (smp_found_config)
+		early_get_smp_config();
+	/*
+	 * need to get boot_cpu_id so can use that to create apicid_to_node
+	 * in k8_scan_nodes() called by numa_initmem_init
+	 */
+	early_init_lapic_mapping();
+
 #ifdef CONFIG_NUMA
 	numa_initmem_init(0, end_pfn); 
 #else
include/asm-x86_64/apic.h +1 -0
index 85125ef..b9315f8 100644
@@ -74,6 +73,7 @@ extern void cache_APIC_registers (void);
 extern void sync_Arb_IDs (void);
 extern void init_bsp_APIC (void);
 extern void setup_local_APIC (void);
+extern void early_init_lapic_mapping(void);
 extern void init_apic_mappings (void);
 extern void smp_local_timer_interrupt (void);
 extern void setup_boot_APIC_clock (void);
include/asm-x86_64/mpspec.h +2 -0
index 017fddb..f253cb7 100644
@@ -164,6 +164,8 @@ extern int mp_bus_id_to_pci_bus [MAX_MP_BUSSES];
 
 extern unsigned int boot_cpu_physical_apicid;
 extern int smp_found_config;
+extern void early_find_smp_config(void);
+extern void early_get_smp_config(void);
 extern void find_smp_config (void);
 extern void get_smp_config (void);
 extern int nr_ioapics;
include/linux/acpi.h +5 -0
index d5680cd..e879aad 100644
@@ -79,6 +79,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co
 
 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
 unsigned long acpi_find_rsdp (void);
+int early_acpi_boot_init(void);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
 int acpi_numa_init (void);
@@ -236,6 +237,10 @@ extern int pnpacpi_disabled;
 
 #else	/* CONFIG_ACPI */
 
+static inline int early_acpi_boot_init(void)
+{
+	return 0;
+}
 static inline int acpi_boot_init(void)
 {
 	return 0;