Skip to content

Commit d81056b

Browse files
lukaszanrafaeljw
authored andcommitted
x86, ACPI: Handle apic/x2apic entries in MADT in correct order
ACPI specifies the following rules when listing APIC IDs: (1) Boot processor is listed first (2) For multi-threaded processors, BIOS should list the first logical processor of each of the individual multi-threaded processors in MADT before listing any of the second logical processors. (3) APIC IDs < 0xFF should be listed in APIC subtable, APIC IDs >= 0xFF should be listed in X2APIC subtable Because of above, when there's more than 0xFF logical CPUs, BIOS interleaves APIC/X2APIC subtables. Assuming, there's 72 cores, 72 hyper-threads each, 288 CPUs total, listing is like this: APIC (0,4,8, .., 252) X2APIC (258,260,264, .. 284) APIC (1,5,9,...,253) X2APIC (259,261,265,...,285) APIC (2,6,10,...,254) X2APIC (260,262,266,..,286) APIC (3,7,11,...,251) X2APIC (255,261,262,266,..,287) Now, before this patch, due to how ACPI MADT subtables were parsed (BSP then X2APIC then APIC), kernel enumerated CPUs in reverted order (i.e. high APIC IDs were getting low logical IDs, and low APIC IDs were getting high logical IDs). This is wrong for the following reasons: () it's hard to predict how cores and threads are enumerated () when it's hard to predict, s/w threads cannot be properly affinitized causing significant performance impact due to e.g. inproper cache sharing () enumeration is inconsistent with how threads are enumerated on other Intel Xeon processors So, order in which MADT APIC/X2APIC handlers are passed is reverse and both handlers are passed to be called during same MADT table to walk to achieve correct CPU enumeration. In scenario when someone boots kernel with options 'maxcpus=72 nox2apic', in result less cores may be booted, since some of the CPUs the kernel will try to use will have APIC ID >= 0xFF. In such case, one should not pass 'nox2apic'. Disclimer: code parsing MADT APIC/X2APIC has not been touched since 2009, when X2APIC support was initially added. I do not know why MADT parsing code was added in the reversed order in the first place. I guess it didn't matter at that time since nobody cared about cores with APIC IDs >= 0xFF, right? This patch is based on work of "Yinghai Lu <[email protected]>" previously published at https://lkml.org/lkml/2013/1/21/563 Here's the explanation why parsing interface needs to be changed and why simpler approach will not work https://lkml.org/lkml/2015/9/7/285 Signed-off-by: Lukasz Anaczkowski <[email protected]> Acked-by: Thomas Gleixner <[email protected]> (commit message) Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 9b3fedd commit d81056b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

arch/x86/kernel/acpi/boot.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ static int __init acpi_parse_madt_lapic_entries(void)
976976
{
977977
int count;
978978
int x2count = 0;
979+
int ret;
980+
struct acpi_subtable_proc madt_proc[2];
979981

980982
if (!cpu_has_apic)
981983
return -ENODEV;
@@ -999,10 +1001,22 @@ static int __init acpi_parse_madt_lapic_entries(void)
9991001
acpi_parse_sapic, MAX_LOCAL_APIC);
10001002

10011003
if (!count) {
1002-
x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
1003-
acpi_parse_x2apic, MAX_LOCAL_APIC);
1004-
count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
1005-
acpi_parse_lapic, MAX_LOCAL_APIC);
1004+
memset(madt_proc, 0, sizeof(madt_proc));
1005+
madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
1006+
madt_proc[0].handler = acpi_parse_lapic;
1007+
madt_proc[1].id = ACPI_MADT_TYPE_LOCAL_X2APIC;
1008+
madt_proc[1].handler = acpi_parse_x2apic;
1009+
ret = acpi_table_parse_entries_array(ACPI_SIG_MADT,
1010+
sizeof(struct acpi_table_madt),
1011+
madt_proc, ARRAY_SIZE(madt_proc), MAX_LOCAL_APIC);
1012+
if (ret < 0) {
1013+
printk(KERN_ERR PREFIX
1014+
"Error parsing LAPIC/X2APIC entries\n");
1015+
return ret;
1016+
}
1017+
1018+
x2count = madt_proc[0].count;
1019+
count = madt_proc[1].count;
10061020
}
10071021
if (!count && !x2count) {
10081022
printk(KERN_ERR PREFIX "No LAPIC entries present\n");

0 commit comments

Comments
 (0)