linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukasz Anaczkowski <lukasz.anaczkowski@intel.com>
To: marc.zyngier@arm.com, lorenzo.pieralisi@arm.com,
	tomasz.nowicki@linaro.org, tglx@linutronix.de, mingo@redhat.com,
	hpa@zytor.com, x86@kernel.org, jason@lakedaemon.net
Cc: rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org,
	Lukasz Anaczkowski <lukasz.anaczkowski@intel.com>
Subject: [PATCH v4 2/2] x86, acpi: Handle apic/x2apic entries in MADT in correct order
Date: Wed,  9 Sep 2015 15:47:29 +0200	[thread overview]
Message-ID: <1441806449-27481-4-git-send-email-lukasz.anaczkowski@intel.com> (raw)
In-Reply-To: <1441806449-27481-3-git-send-email-lukasz.anaczkowski@intel.com>

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 <yinghai@kernel.org>"
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 <lukasz.anaczkowski@intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de> (commit message)
---
 arch/x86/kernel/acpi/boot.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index e49ee24..116e911 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -981,6 +981,8 @@ static int __init acpi_parse_madt_lapic_entries(void)
 {
 	int count;
 	int x2count = 0;
+	int ret;
+	struct acpi_subtable_proc madt_proc[2];
 
 	if (!cpu_has_apic)
 		return -ENODEV;
@@ -1004,10 +1006,22 @@ static int __init acpi_parse_madt_lapic_entries(void)
 				      acpi_parse_sapic, MAX_LOCAL_APIC);
 
 	if (!count) {
-		x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
-					acpi_parse_x2apic, MAX_LOCAL_APIC);
-		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
-					acpi_parse_lapic, MAX_LOCAL_APIC);
+		memset(madt_proc, 0, sizeof(madt_proc));
+		madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
+		madt_proc[0].handler = acpi_parse_lapic;
+		madt_proc[1].id = ACPI_MADT_TYPE_LOCAL_X2APIC;
+		madt_proc[1].handler = acpi_parse_x2apic;
+		ret = acpi_table_parse_entries_array(ACPI_SIG_MADT,
+				sizeof(struct acpi_table_madt),
+				madt_proc, ARRAY_SIZE(madt_proc), MAX_LOCAL_APIC);
+		if (ret < 0) {
+			printk(KERN_ERR PREFIX
+					"Error parsing LAPIC/X2APIC entries\n");
+			return ret;
+		}
+
+		x2count = madt_proc[0].count;
+		count = madt_proc[1].count;
 	}
 	if (!count && !x2count) {
 		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
-- 
1.8.3.1


  reply	other threads:[~2015-09-09 13:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.DEB.2.11.1507211017590.18576 () nanos>
2015-07-30 17:43 ` [PATCH] x86, acpi: Handle xapic/x2apic entries in MADT Lukasz Anaczkowski
2015-07-30 17:43   ` [PATCH] x86, acpi: Handle lapic/x2apic " Lukasz Anaczkowski
2015-08-02  9:57     ` Thomas Gleixner
2015-08-02 12:40     ` Marc Zyngier
2015-08-03 18:26       ` Lukasz Anaczkowski
2015-08-03 18:26         ` Lukasz Anaczkowski
2015-08-26  7:04           ` Anaczkowski, Lukasz
2015-08-26 10:43             ` Marc Zyngier
2015-08-26 11:42               ` Lorenzo Pieralisi
2015-08-26 12:43                 ` Marc Zyngier
2015-08-26 17:49                   ` Lukasz Anaczkowski
2015-08-26 17:49                     ` [PATCH] x86, arm64, " Lukasz Anaczkowski
2015-08-27  9:37                       ` Lorenzo Pieralisi
2015-09-08 11:07                         ` Lukasz Anaczkowski
2015-09-08 11:07                           ` [PATCH 0/4] Fix how CPUs are enumerated when there's more than 255 CPUs Lukasz Anaczkowski
2015-09-08 11:07                             ` [PATCH 1/4] acpi: rename acpi_table_parse_entries Lukasz Anaczkowski
2015-09-08 11:07                               ` [PATCH 2/4] x86, arm64, acpi: Added acpi_subtable_proc Lukasz Anaczkowski
2015-09-08 11:07                                 ` [PATCH 3/4] acpi: multi proc support Lukasz Anaczkowski
2015-09-08 11:08                                   ` [PATCH 4/4] x86, acpi: Handle apic/x2apic entries in MADT in correct order Lukasz Anaczkowski
2015-09-08 15:22                                     ` Marc Zyngier
2015-09-08 16:27                             ` [PATCH 0/4] Fix how CPUs are enumerated when there's more than 255 CPUs Marc Zyngier
2015-09-08 22:45                               ` Al Stone
2015-09-09  7:01                               ` Anaczkowski, Lukasz
2015-09-09  9:30                               ` [PATCH 0/2] " Lukasz Anaczkowski
2015-09-09  9:30                                 ` [PATCH 1/2] acpi: Added acpi_subtable_proc to ACPI table parsers Lukasz Anaczkowski
2015-09-09  9:30                                   ` [PATCH 2/2] x86, acpi: Handle apic/x2apic entries in MADT in correct order Lukasz Anaczkowski
2015-09-09 13:56                                     ` Lorenzo Pieralisi
2015-09-09 14:27                                       ` Anaczkowski, Lukasz
2015-09-09 15:43                                         ` Lorenzo Pieralisi
2015-09-09 10:47                                   ` [PATCH 1/2] acpi: Added acpi_subtable_proc to ACPI table parsers Marc Zyngier
2015-09-09 13:47                                     ` Lukasz Anaczkowski
2015-09-09 13:47                                       ` [PATCH v4 0/2] Fix how CPUs are enumerated when there's more than 255 CPUs Lukasz Anaczkowski
2015-09-09 13:47                                         ` [PATCH v4 1/2] acpi: Added acpi_subtable_proc to ACPI table parsers Lukasz Anaczkowski
2015-09-09 13:47                                           ` Lukasz Anaczkowski [this message]
2015-09-09 20:45                                         ` [PATCH v4 0/2] Fix how CPUs are enumerated when there's more than 255 CPUs Rafael J. Wysocki
2015-09-18 22:38                                           ` Rafael J. Wysocki
2015-08-28  8:30                       ` [PATCH] x86, arm64, acpi: Handle lapic/x2apic entries in MADT Ingo Molnar
2015-09-01  8:02                       ` Tomasz Nowicki
2015-09-01 12:07                         ` Anaczkowski, Lukasz
2015-09-01 13:36                           ` Tomasz Nowicki
2015-09-07 14:04                             ` Anaczkowski, Lukasz
2015-09-08 14:44                               ` Tomasz Nowicki
2015-08-26 11:03           ` [PATCH] x86, " Marc Zyngier
2015-08-26 12:56           ` Tomasz Nowicki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441806449-27481-4-git-send-email-lukasz.anaczkowski@intel.com \
    --to=lukasz.anaczkowski@intel.com \
    --cc=hpa@zytor.com \
    --cc=jason@lakedaemon.net \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=marc.zyngier@arm.com \
    --cc=mingo@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=tomasz.nowicki@linaro.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).