public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [PATCH 2/4] UefiCpuPkg/MpInitLib: Sync BSP's APIC mode to APs in InitConfig path
Date: Fri,  7 Jul 2023 13:28:59 +0800	[thread overview]
Message-ID: <20230707052901.869-3-ray.ni@intel.com> (raw)
In-Reply-To: <20230707052901.869-1-ray.ni@intel.com>

The change saves the BSP's initial APIC mode and syncs to all APs
in first time wakeup. It allows certain platforms to switch to X2 APIC
as early as possible and also independent on CpuFeaturePei/Dxe.
The platform should switch BSP to X2 APIC mode first before the
CpuMpPeim runs.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 +++++++++++
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index bf80455965..2372475a04 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -694,6 +694,12 @@ ApWakeupFunction (
       ApStackData  = (AP_STACK_DATA *)((UINTN)ApTopOfStack - sizeof (AP_STACK_DATA));
       BistData     = (UINT32)ApStackData->Bist;
 
+      //
+      // Synchronize APIC mode with BSP in the first time AP wakeup ONLY.
+      //
+      SetApicMode (CpuMpData->InitialBspApicMode);
+      CurrentApicMode = CpuMpData->InitialBspApicMode;
+
       //
       // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP environment,
       //   to initialize AP in InitConfig path.
@@ -1977,6 +1983,11 @@ MpInitLibInitialize (
   //
   ProgramVirtualWireMode ();
 
+  //
+  // Save APIC mode for AP to sync
+  //
+  CpuMpData->InitialBspApicMode = GetApicMode ();
+
   if (OldCpuMpData == NULL) {
     if (MaxLogicalProcessorNumber > 1) {
       //
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index b694c7b40f..1ede253334 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -243,6 +243,17 @@ struct _CPU_MP_DATA {
   //
   SPIN_LOCK                        MpLock;
   UINTN                            Buffer;
+  //
+  // InitialBspApicMode stores the initial BSP APIC mode.
+  // It is used to synchroneize the BSP APIC mode with APs
+  // in the first time APs wake up.
+  // Its value doesn't reflect the current APIC mode since there are
+  // two cases the APIC mode is changed:
+  // 1. MpLib explicitly switches to X2 APIC mode because number of threads is greater than 255,
+  //    or there are any logical processors reporting an initial APIC ID of 255 or greater.
+  // 2. Some code switches to X2 APIC mode in all threads through MP services PPI/Protocol.
+  //
+  UINTN                            InitialBspApicMode;
   UINTN                            CpuApStackSize;
   MP_ASSEMBLY_ADDRESS_MAP          AddressMap;
   UINTN                            WakeupBuffer;
-- 
2.39.1.windows.1


  parent reply	other threads:[~2023-07-07  5:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07  5:28 [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow Ni, Ray
2023-07-07  5:28 ` [PATCH 1/4] UefiCpuPkg/MpInitLib: Separate X2APIC enabling to subfunction Ni, Ray
2023-07-07  5:28 ` Ni, Ray [this message]
2023-07-07  5:29 ` [PATCH 3/4] UefiCpuPkg/MpInitLib: Skip X2APIC enabling when BSP in X2APIC already Ni, Ray
2023-07-07  5:29 ` [PATCH 4/4] UefiCpuPkg/CpuFeatures: Deprecate CPU_FEATURE_X2APIC Ni, Ray
2023-07-07  8:55 ` [edk2-devel] [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow Gerd Hoffmann
2023-07-07  9:25   ` Ni, Ray
2023-07-07 11:26     ` Gerd Hoffmann
2023-11-09 16:29       ` Aaron Young via groups.io
2023-11-09 18:08         ` Michael D Kinney
2023-11-13 12:32           ` Laszlo Ersek

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-list 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=20230707052901.869-3-ray.ni@intel.com \
    --to=devel@edk2.groups.io \
    /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