From: "Andi Kleen" Last round hopefully of cpu_core_id changes hopefully fow now: - Always initialize cpu_core_id for all CPUs, even when no dual core setup is detected. This prevents funny /proc/cpuinfo output - Do the same with phys_proc_id[] even when no HyperThreading - dito. - Use the CPU APIC-ID from CPUID 1 instead of the linux virtual CPU number to identify the core for AMD dual core setups. Patch for i386/x86-64. Signed-off-by: Andi Kleen Signed-off-by: Andrew Morton --- arch/i386/kernel/cpu/amd.c | 7 +++---- arch/i386/kernel/cpu/common.c | 7 +++++++ arch/x86_64/kernel/setup.c | 11 ++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff -puN arch/i386/kernel/cpu/amd.c~x86_64-fix-defaults-for-physical-core-id-in arch/i386/kernel/cpu/amd.c --- 25/arch/i386/kernel/cpu/amd.c~x86_64-fix-defaults-for-physical-core-id-in 2005-05-13 22:54:37.000000000 -0700 +++ 25-akpm/arch/i386/kernel/cpu/amd.c 2005-05-13 22:54:37.000000000 -0700 @@ -24,9 +24,6 @@ __asm__(".align 4\nvide: ret"); static void __init init_amd(struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_SMP - int cpu = c == &boot_cpu_data ? 0 : c - cpu_data; -#endif u32 l, h; int mbytes = num_physpages >> (20-PAGE_SHIFT); int r; @@ -205,7 +202,9 @@ static void __init init_amd(struct cpuin * of two. */ if (c->x86_num_cores > 1) { - cpu_core_id[cpu] = cpu >> hweight32(c->x86_num_cores - 1); + int cpu = smp_processor_id(); + /* Fix up the APIC ID following AMD specifications. */ + cpu_core_id[cpu] >>= hweight32(c->x86_num_cores - 1); printk(KERN_INFO "CPU %d(%d) -> Core %d\n", cpu, c->x86_num_cores, cpu_core_id[cpu]); } diff -puN arch/i386/kernel/cpu/common.c~x86_64-fix-defaults-for-physical-core-id-in arch/i386/kernel/cpu/common.c --- 25/arch/i386/kernel/cpu/common.c~x86_64-fix-defaults-for-physical-core-id-in 2005-05-13 22:54:37.000000000 -0700 +++ 25-akpm/arch/i386/kernel/cpu/common.c 2005-05-13 22:54:37.000000000 -0700 @@ -243,6 +243,13 @@ static void __init early_cpu_detect(void } early_intel_workaround(c); + +#ifdef CONFIG_SMP +#ifdef CONFIG_X86_HT + phys_proc_id[smp_processor_id()] = +#endif + cpu_core_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff; +#endif } void __init generic_identify(struct cpuinfo_x86 * c) diff -puN arch/x86_64/kernel/setup.c~x86_64-fix-defaults-for-physical-core-id-in arch/x86_64/kernel/setup.c --- 25/arch/x86_64/kernel/setup.c~x86_64-fix-defaults-for-physical-core-id-in 2005-05-13 22:54:37.000000000 -0700 +++ 25-akpm/arch/x86_64/kernel/setup.c 2005-05-13 22:54:37.000000000 -0700 @@ -731,7 +731,8 @@ static void __init amd_detect_cmp(struct int node = 0; if (c->x86_num_cores == 1) return; - cpu_core_id[cpu] = cpu >> hweight32(c->x86_num_cores - 1); + /* Fix up the APIC ID following the AMD specification. */ + cpu_core_id[cpu] >>= hweight32(c->x86_num_cores - 1); #ifdef CONFIG_NUMA /* When an ACPI SRAT table is available use the mappings from SRAT @@ -745,6 +746,9 @@ static void __init amd_detect_cmp(struct node = cpu_to_node[cpu]; } #endif + /* For now: - better than BAD_APIC_ID at least*/ + phys_proc_id[cpu] = cpu_core_id[cpu]; + printk(KERN_INFO "CPU %d(%d) -> Node %d -> Core %d\n", cpu, c->x86_num_cores, node, cpu_core_id[cpu]); #endif @@ -959,6 +963,11 @@ void __init early_identify_cpu(struct cp /* Have CPUID level 0 only - unheard of */ c->x86 = 4; } + +#ifdef CONFIG_SMP + phys_proc_id[smp_processor_id()] = + cpu_core_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff; +#endif } /* _