public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules
@ 2024-04-01  6:04 duntan
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: duntan @ 2024-04-01  6:04 UTC (permalink / raw)
  To: devel

This patch set is to sort ApicIdOrderTable by following special rules:
1. Make sure BSP is the first entry.
2. For APs, big core first, then small core.

With this implementation, BIOS can present cores in order of relative performance in MADT.
Linux OS would schedule cores by the order that they are presented in the MADT LocalX2ApicStruct entries. Then Linux OS would think of this as relative performance order.
This implementation can benefit the linux os usage case.

Dun Tan (3):
  MinPlatformPkg: Remove the global variable mForceX2ApicId
  MinPlatformPkg: Get CoreType for all cores
  MinPlatformPkg: Sort ApicIdOrderTable by special rules

 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 109 insertions(+), 14 deletions(-)

-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117278): https://edk2.groups.io/g/devel/message/117278
Mute This Topic: https://groups.io/mt/105259122/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId
  2024-04-01  6:04 [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
@ 2024-04-01  6:04 ` duntan
  2024-04-01  7:45   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
  2 siblings, 2 replies; 10+ messages in thread
From: duntan @ 2024-04-01  6:04 UTC (permalink / raw)
  To: devel
  Cc: Ray Ni, Jason Lou, Chasel Chiu, Nate DeSimone, Liming Gao, Eric Dong

This global variable mForceX2ApicId is not assigned
to any value in code and will be initialized to 0 when
the driver is loaded. So remove the global variable
and related code that will not be executed.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 2a833ec99c..62a7da290a 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -53,7 +53,6 @@ VOID  *mLocalTable[] = {
 EFI_ACPI_TABLE_PROTOCOL     *mAcpiTable;
 
 UINT32                      mNumOfBitShift = 6;
-BOOLEAN                     mForceX2ApicId;
 BOOLEAN                     mX2ApicEnabled;
 
 EFI_MP_SERVICES_PROTOCOL    *mMpService;
@@ -163,14 +162,6 @@ CreateCpuLocalApicInTable (
       CpuIdMapPtr->Thread  = ProcessorInfoBuffer.Location.Thread;
       CpuIdMapPtr->Flags   = ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0);
       CpuIdMapPtr->SocketNum = ProcessorInfoBuffer.Location.Package;
-
-      //update processorbitMask
-      if (CpuIdMapPtr->Flags == 1) {
-        if (mForceX2ApicId) {
-          CpuIdMapPtr->SocketNum        &= 0x7;
-          CpuIdMapPtr->AcpiProcessorUid &= 0xFF; //keep lower 8bit due to use Proc obj in dsdt
-        }
-      }
     } else {  //not enabled
       CpuIdMapPtr->ApicId     = (UINT32)-1;
       CpuIdMapPtr->Thread     = (UINT32)-1;
@@ -1537,7 +1528,6 @@ InstallAcpiPlatform (
   }
 
   DEBUG ((DEBUG_INFO, "mX2ApicEnabled - 0x%x\n", mX2ApicEnabled));
-  DEBUG ((DEBUG_INFO, "mForceX2ApicId - 0x%x\n", mForceX2ApicId));
 
   // support up to 64 threads/socket
   AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 1, &mNumOfBitShift, NULL, NULL, NULL);
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117279): https://edk2.groups.io/g/devel/message/117279
Mute This Topic: https://groups.io/mt/105259123/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores
  2024-04-01  6:04 [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
@ 2024-04-01  6:04 ` duntan
  2024-04-01  7:45   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
  2 siblings, 2 replies; 10+ messages in thread
From: duntan @ 2024-04-01  6:04 UTC (permalink / raw)
  To: devel
  Cc: Ray Ni, Jason Lou, Chasel Chiu, Nate DeSimone, Liming Gao, Eric Dong

Add a new field CoreType in EFI_CPU_ID_ORDER_MAP
and get CoreType for all cores.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 62a7da290a..1fa70e3df9 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -18,6 +18,7 @@ typedef struct {
   UINT32   Flags;
   UINT32   SocketNum;
   UINT32   Thread;
+  UINT8    CoreType;
 } EFI_CPU_ID_ORDER_MAP;
 
 //
@@ -71,15 +72,16 @@ DebugDisplayReOrderTable (
 {
   UINT32 Index;
 
-  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt\n"));
+  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt  CoreType\n"));
   for (Index = 0; Index < mNumberOfCpus; Index++) {
-    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d\n",
+    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d      0x%x\n",
                            Index,
                            CpuApicIdOrderTable[Index].AcpiProcessorUid,
                            CpuApicIdOrderTable[Index].ApicId,
                            CpuApicIdOrderTable[Index].Thread,
                            CpuApicIdOrderTable[Index].Flags,
-                           CpuApicIdOrderTable[Index].SocketNum));
+                           CpuApicIdOrderTable[Index].SocketNum,
+                           CpuApicIdOrderTable[Index].CoreType));
   }
 }
 
@@ -130,6 +132,31 @@ AppendCpuMapTableEntry (
 
 }
 
+/**
+  Get CPU core type.
+
+  @param[in] CpuApicIdOrderTable         Point to a buffer which will be filled in Core type information.
+**/
+VOID
+EFIAPI
+CollectCpuCoreType (
+  IN EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable
+  )
+{
+  UINTN                                    ApNumber;
+  EFI_STATUS                               Status;
+  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX  NativeModelIdAndCoreTypeEax;
+
+  Status = mMpService->WhoAmI (
+                         mMpService,
+                         &ApNumber
+                         );
+  ASSERT_EFI_ERROR (Status);
+
+  AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+  CpuApicIdOrderTable[ApNumber].CoreType = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
 /**
   Collect all processors information and create a Cpu Apic Id table.
 
@@ -146,8 +173,23 @@ CreateCpuLocalApicInTable (
   UINT32                                    CurrProcessor;
   EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
   UINT32                                    Socket;
+  UINT32                                    CpuidMaxInput;
 
-  Status     = EFI_SUCCESS;
+  Status = EFI_SUCCESS;
+
+  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);
+  if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
+    CollectCpuCoreType (CpuApicIdOrderTable);
+    mMpService->StartupAllAPs (
+                  mMpService,                               // This
+                  (EFI_AP_PROCEDURE) CollectCpuCoreType,    // Procedure
+                  TRUE,                                     // SingleThread
+                  NULL,                                     // WaitEvent
+                  0,                                        // TimeoutInMicrosecsond
+                  CpuApicIdOrderTable,                      // ProcedureArgument
+                  NULL                                      // FailedCpuList
+                  );
+  }
 
   for (CurrProcessor = 0, Index = 0; CurrProcessor < mNumberOfCpus; CurrProcessor++, Index++) {
     Status = mMpService->GetProcessorInfo (
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117280): https://edk2.groups.io/g/devel/message/117280
Mute This Topic: https://groups.io/mt/105259124/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules
  2024-04-01  6:04 [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
@ 2024-04-01  6:04 ` duntan
  2024-04-01  7:46   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  2 siblings, 2 replies; 10+ messages in thread
From: duntan @ 2024-04-01  6:04 UTC (permalink / raw)
  To: devel
  Cc: Ray Ni, Jason Lou, Chasel Chiu, Nate DeSimone, Liming Gao, Eric Dong

Sort ApicIdOrderTable by following special rules:
1. Make sure BSP is the first entry.
2. For APs, big core first, then small core.

With this implementation, BIOS can present cores in order
of relative performance in MADT. Linux OS would schedule
cores by the order that they are presented in the MADT
LocalX2ApicStruct entries.Then Linux OS would think of
this as relative performance order. This implementation
can benefit the linux os usage case.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 1fa70e3df9..389df48824 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -132,6 +132,62 @@ AppendCpuMapTableEntry (
 
 }
 
+/**
+  Sort CpuApicIdOrderTable based on the following rules:
+  1.Make sure BSP is the first entry.
+  2.Big core first, then small core.
+
+  @param[in] CpuApicIdOrderTable      Pointer to EFI_CPU_ID_ORDER_MAP
+  @param[in] Count                    Number to EFI_CPU_ID_ORDER_MAP
+  @param[in] BspIndex                 BSP index
+**/
+VOID
+SortApicIdOrderTable (
+  IN  EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable,
+  IN  UINTN                 Count,
+  IN  UINTN                 BspIndex
+  )
+{
+  UINTN                 Index;
+  UINTN                 SubIndex;
+  EFI_CPU_ID_ORDER_MAP  SortBuffer;
+
+  //
+  // Put BSP at the first entry.
+  //
+  if (BspIndex != 0) {
+    CopyMem (&SortBuffer, &CpuApicIdOrderTable[BspIndex], sizeof (EFI_CPU_ID_ORDER_MAP));
+    CopyMem (&CpuApicIdOrderTable[1], CpuApicIdOrderTable, (BspIndex) * sizeof (EFI_CPU_ID_ORDER_MAP));
+    CopyMem (CpuApicIdOrderTable, &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP));
+  }
+
+  //
+  // If there are more than 2 cores, perform insertion sort for rest cores except the bsp in first entry
+  // to move big cores in front of small cores.
+  // Also the original order based on the MpService index inside big cores and small cores are retained.
+  //
+  for (Index = 2; Index < Count; Index++) {
+    if (CpuApicIdOrderTable[Index].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) {
+      continue;
+    }
+
+    CopyMem (&SortBuffer, &CpuApicIdOrderTable[Index], sizeof (EFI_CPU_ID_ORDER_MAP));
+
+    for (SubIndex = Index - 1; SubIndex >= 1; SubIndex--) {
+      if (CpuApicIdOrderTable[SubIndex].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) {
+        CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &CpuApicIdOrderTable[SubIndex], sizeof (EFI_CPU_ID_ORDER_MAP));
+      } else {
+        //
+        // Except the BSP, all cores in front of SubIndex must be big cores.
+        //
+        break;
+      }
+    }
+
+    CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP));
+  }
+}
+
 /**
   Get CPU core type.
 
@@ -174,6 +230,7 @@ CreateCpuLocalApicInTable (
   EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
   UINT32                                    Socket;
   UINT32                                    CpuidMaxInput;
+  UINTN                                     BspIndex;
 
   Status = EFI_SUCCESS;
 
@@ -198,6 +255,10 @@ CreateCpuLocalApicInTable (
                            &ProcessorInfoBuffer
                            );
 
+    if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {
+      BspIndex = Index;
+    }
+
     CpuIdMapPtr = (EFI_CPU_ID_ORDER_MAP *) &CpuApicIdOrderTable[Index];
     if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0) {
       CpuIdMapPtr->ApicId  = (UINT32)ProcessorInfoBuffer.ProcessorId;
@@ -230,6 +291,8 @@ CreateCpuLocalApicInTable (
     }
   }
 
+  SortApicIdOrderTable (CpuApicIdOrderTable, mNumberOfCpus, BspIndex);
+
   DEBUG ((DEBUG_INFO, "::ACPI::  APIC ID Order Table Init.   mNumOfBitShift = %x\n", mNumOfBitShift));
   DebugDisplayReOrderTable (CpuApicIdOrderTable);
 
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117281): https://edk2.groups.io/g/devel/message/117281
Mute This Topic: https://groups.io/mt/105259125/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
@ 2024-04-01  7:45   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Ni, Ray @ 2024-04-01  7:45 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Lou, Yun, Chiu, Chasel, Desimone, Nathaniel L, Liming Gao, Dong, Eric

[-- Attachment #1: Type: text/plain, Size: 3122 bytes --]

Reviewed-by: Ray Ni <ray.ni@intel.com>



Thanks,
Ray
________________________________
From: Tan, Dun <dun.tan@intel.com>
Sent: Monday, April 1, 2024 14:04
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId

This global variable mForceX2ApicId is not assigned
to any value in code and will be initialized to 0 when
the driver is loaded. So remove the global variable
and related code that will not be executed.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 2a833ec99c..62a7da290a 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -53,7 +53,6 @@ VOID  *mLocalTable[] = {
 EFI_ACPI_TABLE_PROTOCOL     *mAcpiTable;

 UINT32                      mNumOfBitShift = 6;
-BOOLEAN                     mForceX2ApicId;
 BOOLEAN                     mX2ApicEnabled;

 EFI_MP_SERVICES_PROTOCOL    *mMpService;
@@ -163,14 +162,6 @@ CreateCpuLocalApicInTable (
       CpuIdMapPtr->Thread  = ProcessorInfoBuffer.Location.Thread;
       CpuIdMapPtr->Flags   = ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0);
       CpuIdMapPtr->SocketNum = ProcessorInfoBuffer.Location.Package;
-
-      //update processorbitMask
-      if (CpuIdMapPtr->Flags == 1) {
-        if (mForceX2ApicId) {
-          CpuIdMapPtr->SocketNum        &= 0x7;
-          CpuIdMapPtr->AcpiProcessorUid &= 0xFF; //keep lower 8bit due to use Proc obj in dsdt
-        }
-      }
     } else {  //not enabled
       CpuIdMapPtr->ApicId     = (UINT32)-1;
       CpuIdMapPtr->Thread     = (UINT32)-1;
@@ -1537,7 +1528,6 @@ InstallAcpiPlatform (
   }

   DEBUG ((DEBUG_INFO, "mX2ApicEnabled - 0x%x\n", mX2ApicEnabled));
-  DEBUG ((DEBUG_INFO, "mForceX2ApicId - 0x%x\n", mForceX2ApicId));

   // support up to 64 threads/socket
   AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 1, &mNumOfBitShift, NULL, NULL, NULL);
--
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117282): https://edk2.groups.io/g/devel/message/117282
Mute This Topic: https://groups.io/mt/105259123/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 6310 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
@ 2024-04-01  7:45   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Ni, Ray @ 2024-04-01  7:45 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Lou, Yun, Chiu, Chasel, Desimone, Nathaniel L, Liming Gao, Dong, Eric

[-- Attachment #1: Type: text/plain, Size: 5164 bytes --]

Reviewed-by: Ray Ni <ray.ni@intel.com>



Thanks,
Ray
________________________________
From: Tan, Dun <dun.tan@intel.com>
Sent: Monday, April 1, 2024 14:04
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores

Add a new field CoreType in EFI_CPU_ID_ORDER_MAP
and get CoreType for all cores.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 62a7da290a..1fa70e3df9 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -18,6 +18,7 @@ typedef struct {
   UINT32   Flags;
   UINT32   SocketNum;
   UINT32   Thread;
+  UINT8    CoreType;
 } EFI_CPU_ID_ORDER_MAP;

 //
@@ -71,15 +72,16 @@ DebugDisplayReOrderTable (
 {
   UINT32 Index;

-  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt\n"));
+  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt  CoreType\n"));
   for (Index = 0; Index < mNumberOfCpus; Index++) {
-    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d\n",
+    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d      0x%x\n",
                            Index,
                            CpuApicIdOrderTable[Index].AcpiProcessorUid,
                            CpuApicIdOrderTable[Index].ApicId,
                            CpuApicIdOrderTable[Index].Thread,
                            CpuApicIdOrderTable[Index].Flags,
-                           CpuApicIdOrderTable[Index].SocketNum));
+                           CpuApicIdOrderTable[Index].SocketNum,
+                           CpuApicIdOrderTable[Index].CoreType));
   }
 }

@@ -130,6 +132,31 @@ AppendCpuMapTableEntry (

 }

+/**
+  Get CPU core type.
+
+  @param[in] CpuApicIdOrderTable         Point to a buffer which will be filled in Core type information.
+**/
+VOID
+EFIAPI
+CollectCpuCoreType (
+  IN EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable
+  )
+{
+  UINTN                                    ApNumber;
+  EFI_STATUS                               Status;
+  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX  NativeModelIdAndCoreTypeEax;
+
+  Status = mMpService->WhoAmI (
+                         mMpService,
+                         &ApNumber
+                         );
+  ASSERT_EFI_ERROR (Status);
+
+  AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+  CpuApicIdOrderTable[ApNumber].CoreType = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
 /**
   Collect all processors information and create a Cpu Apic Id table.

@@ -146,8 +173,23 @@ CreateCpuLocalApicInTable (
   UINT32                                    CurrProcessor;
   EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
   UINT32                                    Socket;
+  UINT32                                    CpuidMaxInput;

-  Status     = EFI_SUCCESS;
+  Status = EFI_SUCCESS;
+
+  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);
+  if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
+    CollectCpuCoreType (CpuApicIdOrderTable);
+    mMpService->StartupAllAPs (
+                  mMpService,                               // This
+                  (EFI_AP_PROCEDURE) CollectCpuCoreType,    // Procedure
+                  TRUE,                                     // SingleThread
+                  NULL,                                     // WaitEvent
+                  0,                                        // TimeoutInMicrosecsond
+                  CpuApicIdOrderTable,                      // ProcedureArgument
+                  NULL                                      // FailedCpuList
+                  );
+  }

   for (CurrProcessor = 0, Index = 0; CurrProcessor < mNumberOfCpus; CurrProcessor++, Index++) {
     Status = mMpService->GetProcessorInfo (
--
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117284): https://edk2.groups.io/g/devel/message/117284
Mute This Topic: https://groups.io/mt/105259124/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 12559 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
@ 2024-04-01  7:46   ` Ni, Ray
  2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Ni, Ray @ 2024-04-01  7:46 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Lou, Yun, Chiu, Chasel, Desimone, Nathaniel L, Liming Gao, Dong, Eric

[-- Attachment #1: Type: text/plain, Size: 5363 bytes --]

Reviewed-by: Ray Ni <ray.ni@intel.com>



Thanks,
Ray
________________________________
From: Tan, Dun <dun.tan@intel.com>
Sent: Monday, April 1, 2024 14:04
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules

Sort ApicIdOrderTable by following special rules:
1. Make sure BSP is the first entry.
2. For APs, big core first, then small core.

With this implementation, BIOS can present cores in order
of relative performance in MADT. Linux OS would schedule
cores by the order that they are presented in the MADT
LocalX2ApicStruct entries.Then Linux OS would think of
this as relative performance order. This implementation
can benefit the linux os usage case.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jason Lou <yun.lou@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 1fa70e3df9..389df48824 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -132,6 +132,62 @@ AppendCpuMapTableEntry (

 }

+/**
+  Sort CpuApicIdOrderTable based on the following rules:
+  1.Make sure BSP is the first entry.
+  2.Big core first, then small core.
+
+  @param[in] CpuApicIdOrderTable      Pointer to EFI_CPU_ID_ORDER_MAP
+  @param[in] Count                    Number to EFI_CPU_ID_ORDER_MAP
+  @param[in] BspIndex                 BSP index
+**/
+VOID
+SortApicIdOrderTable (
+  IN  EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable,
+  IN  UINTN                 Count,
+  IN  UINTN                 BspIndex
+  )
+{
+  UINTN                 Index;
+  UINTN                 SubIndex;
+  EFI_CPU_ID_ORDER_MAP  SortBuffer;
+
+  //
+  // Put BSP at the first entry.
+  //
+  if (BspIndex != 0) {
+    CopyMem (&SortBuffer, &CpuApicIdOrderTable[BspIndex], sizeof (EFI_CPU_ID_ORDER_MAP));
+    CopyMem (&CpuApicIdOrderTable[1], CpuApicIdOrderTable, (BspIndex) * sizeof (EFI_CPU_ID_ORDER_MAP));
+    CopyMem (CpuApicIdOrderTable, &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP));
+  }
+
+  //
+  // If there are more than 2 cores, perform insertion sort for rest cores except the bsp in first entry
+  // to move big cores in front of small cores.
+  // Also the original order based on the MpService index inside big cores and small cores are retained.
+  //
+  for (Index = 2; Index < Count; Index++) {
+    if (CpuApicIdOrderTable[Index].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) {
+      continue;
+    }
+
+    CopyMem (&SortBuffer, &CpuApicIdOrderTable[Index], sizeof (EFI_CPU_ID_ORDER_MAP));
+
+    for (SubIndex = Index - 1; SubIndex >= 1; SubIndex--) {
+      if (CpuApicIdOrderTable[SubIndex].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) {
+        CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &CpuApicIdOrderTable[SubIndex], sizeof (EFI_CPU_ID_ORDER_MAP));
+      } else {
+        //
+        // Except the BSP, all cores in front of SubIndex must be big cores.
+        //
+        break;
+      }
+    }
+
+    CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP));
+  }
+}
+
 /**
   Get CPU core type.

@@ -174,6 +230,7 @@ CreateCpuLocalApicInTable (
   EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
   UINT32                                    Socket;
   UINT32                                    CpuidMaxInput;
+  UINTN                                     BspIndex;

   Status = EFI_SUCCESS;

@@ -198,6 +255,10 @@ CreateCpuLocalApicInTable (
                            &ProcessorInfoBuffer
                            );

+    if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {
+      BspIndex = Index;
+    }
+
     CpuIdMapPtr = (EFI_CPU_ID_ORDER_MAP *) &CpuApicIdOrderTable[Index];
     if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0) {
       CpuIdMapPtr->ApicId  = (UINT32)ProcessorInfoBuffer.ProcessorId;
@@ -230,6 +291,8 @@ CreateCpuLocalApicInTable (
     }
   }

+  SortApicIdOrderTable (CpuApicIdOrderTable, mNumberOfCpus, BspIndex);
+
   DEBUG ((DEBUG_INFO, "::ACPI::  APIC ID Order Table Init.   mNumOfBitShift = %x\n", mNumOfBitShift));
   DebugDisplayReOrderTable (CpuApicIdOrderTable);

--
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117285): https://edk2.groups.io/g/devel/message/117285
Mute This Topic: https://groups.io/mt/105259125/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 10217 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
  2024-04-01  7:45   ` Ni, Ray
@ 2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Chiu, Chasel @ 2024-04-02  6:49 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Ni, Ray, Lou, Yun, Desimone, Nathaniel L, Liming Gao, Dong, Eric


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Thanks,
Chasel


> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Sunday, March 31, 2024 11:04 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable
> mForceX2ApicId
> 
> This global variable mForceX2ApicId is not assigned to any value in code and will
> be initialized to 0 when the driver is loaded. So remove the global variable and
> related code that will not be executed.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Jason Lou <yun.lou@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> ---
>  Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 10 ----------
>  1 file changed, 10 deletions(-)
> 
> diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> index 2a833ec99c..62a7da290a 100644
> --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> @@ -53,7 +53,6 @@ VOID  *mLocalTable[] = {
>  EFI_ACPI_TABLE_PROTOCOL     *mAcpiTable;
> 
>  UINT32                      mNumOfBitShift = 6;
> -BOOLEAN                     mForceX2ApicId;
>  BOOLEAN                     mX2ApicEnabled;
> 
>  EFI_MP_SERVICES_PROTOCOL    *mMpService;
> @@ -163,14 +162,6 @@ CreateCpuLocalApicInTable (
>        CpuIdMapPtr->Thread  = ProcessorInfoBuffer.Location.Thread;
>        CpuIdMapPtr->Flags   = ((ProcessorInfoBuffer.StatusFlag &
> PROCESSOR_ENABLED_BIT) != 0);
>        CpuIdMapPtr->SocketNum = ProcessorInfoBuffer.Location.Package;
> -
> -      //update processorbitMask
> -      if (CpuIdMapPtr->Flags == 1) {
> -        if (mForceX2ApicId) {
> -          CpuIdMapPtr->SocketNum        &= 0x7;
> -          CpuIdMapPtr->AcpiProcessorUid &= 0xFF; //keep lower 8bit due to use
> Proc obj in dsdt
> -        }
> -      }
>      } else {  //not enabled
>        CpuIdMapPtr->ApicId     = (UINT32)-1;
>        CpuIdMapPtr->Thread     = (UINT32)-1;
> @@ -1537,7 +1528,6 @@ InstallAcpiPlatform (
>    }
> 
>    DEBUG ((DEBUG_INFO, "mX2ApicEnabled - 0x%x\n", mX2ApicEnabled));
> -  DEBUG ((DEBUG_INFO, "mForceX2ApicId - 0x%x\n", mForceX2ApicId));
> 
>    // support up to 64 threads/socket
>    AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 1, &mNumOfBitShift, NULL, NULL,
> NULL);
> --
> 2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117327): https://edk2.groups.io/g/devel/message/117327
Mute This Topic: https://groups.io/mt/105259123/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
  2024-04-01  7:45   ` Ni, Ray
@ 2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Chiu, Chasel @ 2024-04-02  6:49 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Ni, Ray, Lou, Yun, Desimone, Nathaniel L, Liming Gao, Dong, Eric

Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Thanks,
Chasel


> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Sunday, March 31, 2024 11:04 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores
> 
> Add a new field CoreType in EFI_CPU_ID_ORDER_MAP and get CoreType for all
> cores.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Jason Lou <yun.lou@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> ---
>  Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 50
> ++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 46 insertions(+), 4 deletions(-)
> 
> diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> index 62a7da290a..1fa70e3df9 100644
> --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> @@ -18,6 +18,7 @@ typedef struct {
>    UINT32   Flags;
>    UINT32   SocketNum;
>    UINT32   Thread;
> +  UINT8    CoreType;
>  } EFI_CPU_ID_ORDER_MAP;
> 
>  //
> @@ -71,15 +72,16 @@ DebugDisplayReOrderTable (  {
>    UINT32 Index;
> 
> -  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt\n"));
> +  DEBUG ((DEBUG_INFO, "Index  AcpiProcId  ApicId   Thread  Flags   Skt
> CoreType\n"));
>    for (Index = 0; Index < mNumberOfCpus; Index++) {
> -    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d\n",
> +    DEBUG ((DEBUG_INFO, " %02d       0x%02X      0x%02X       %d      %d      %d
> 0x%x\n",
>                             Index,
>                             CpuApicIdOrderTable[Index].AcpiProcessorUid,
>                             CpuApicIdOrderTable[Index].ApicId,
>                             CpuApicIdOrderTable[Index].Thread,
>                             CpuApicIdOrderTable[Index].Flags,
> -                           CpuApicIdOrderTable[Index].SocketNum));
> +                           CpuApicIdOrderTable[Index].SocketNum,
> +                           CpuApicIdOrderTable[Index].CoreType));
>    }
>  }
> 
> @@ -130,6 +132,31 @@ AppendCpuMapTableEntry (
> 
>  }
> 
> +/**
> +  Get CPU core type.
> +
> +  @param[in] CpuApicIdOrderTable         Point to a buffer which will be filled in
> Core type information.
> +**/
> +VOID
> +EFIAPI
> +CollectCpuCoreType (
> +  IN EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable
> +  )
> +{
> +  UINTN                                    ApNumber;
> +  EFI_STATUS                               Status;
> +  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX
> NativeModelIdAndCoreTypeEax;
> +
> +  Status = mMpService->WhoAmI (
> +                         mMpService,
> +                         &ApNumber
> +                         );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  AsmCpuidEx (CPUID_HYBRID_INFORMATION,
> +CPUID_HYBRID_INFORMATION_MAIN_LEAF,
> +&NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
> +  CpuApicIdOrderTable[ApNumber].CoreType =
> +(UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
> +}
> +
>  /**
>    Collect all processors information and create a Cpu Apic Id table.
> 
> @@ -146,8 +173,23 @@ CreateCpuLocalApicInTable (
>    UINT32                                    CurrProcessor;
>    EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
>    UINT32                                    Socket;
> +  UINT32                                    CpuidMaxInput;
> 
> -  Status     = EFI_SUCCESS;
> +  Status = EFI_SUCCESS;
> +
> +  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);  if
> + (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
> +    CollectCpuCoreType (CpuApicIdOrderTable);
> +    mMpService->StartupAllAPs (
> +                  mMpService,                               // This
> +                  (EFI_AP_PROCEDURE) CollectCpuCoreType,    // Procedure
> +                  TRUE,                                     // SingleThread
> +                  NULL,                                     // WaitEvent
> +                  0,                                        // TimeoutInMicrosecsond
> +                  CpuApicIdOrderTable,                      // ProcedureArgument
> +                  NULL                                      // FailedCpuList
> +                  );
> +  }
> 
>    for (CurrProcessor = 0, Index = 0; CurrProcessor < mNumberOfCpus;
> CurrProcessor++, Index++) {
>      Status = mMpService->GetProcessorInfo (
> --
> 2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117328): https://edk2.groups.io/g/devel/message/117328
Mute This Topic: https://groups.io/mt/105259124/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules
  2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
  2024-04-01  7:46   ` Ni, Ray
@ 2024-04-02  6:49   ` Chiu, Chasel
  1 sibling, 0 replies; 10+ messages in thread
From: Chiu, Chasel @ 2024-04-02  6:49 UTC (permalink / raw)
  To: Tan, Dun, devel
  Cc: Ni, Ray, Lou, Yun, Desimone, Nathaniel L, Liming Gao, Dong, Eric


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Thanks,
Chasel


> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Sunday, March 31, 2024 11:04 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by
> special rules
> 
> Sort ApicIdOrderTable by following special rules:
> 1. Make sure BSP is the first entry.
> 2. For APs, big core first, then small core.
> 
> With this implementation, BIOS can present cores in order of relative
> performance in MADT. Linux OS would schedule cores by the order that they are
> presented in the MADT LocalX2ApicStruct entries.Then Linux OS would think of
> this as relative performance order. This implementation can benefit the linux os
> usage case.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Jason Lou <yun.lou@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> ---
>  Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 63
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 63 insertions(+)
> 
> diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> index 1fa70e3df9..389df48824 100644
> --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
> @@ -132,6 +132,62 @@ AppendCpuMapTableEntry (
> 
>  }
> 
> +/**
> +  Sort CpuApicIdOrderTable based on the following rules:
> +  1.Make sure BSP is the first entry.
> +  2.Big core first, then small core.
> +
> +  @param[in] CpuApicIdOrderTable      Pointer to EFI_CPU_ID_ORDER_MAP
> +  @param[in] Count                    Number to EFI_CPU_ID_ORDER_MAP
> +  @param[in] BspIndex                 BSP index
> +**/
> +VOID
> +SortApicIdOrderTable (
> +  IN  EFI_CPU_ID_ORDER_MAP  *CpuApicIdOrderTable,
> +  IN  UINTN                 Count,
> +  IN  UINTN                 BspIndex
> +  )
> +{
> +  UINTN                 Index;
> +  UINTN                 SubIndex;
> +  EFI_CPU_ID_ORDER_MAP  SortBuffer;
> +
> +  //
> +  // Put BSP at the first entry.
> +  //
> +  if (BspIndex != 0) {
> +    CopyMem (&SortBuffer, &CpuApicIdOrderTable[BspIndex], sizeof
> (EFI_CPU_ID_ORDER_MAP));
> +    CopyMem (&CpuApicIdOrderTable[1], CpuApicIdOrderTable, (BspIndex) *
> sizeof (EFI_CPU_ID_ORDER_MAP));
> +    CopyMem (CpuApicIdOrderTable, &SortBuffer, sizeof
> + (EFI_CPU_ID_ORDER_MAP));  }
> +
> +  //
> +  // If there are more than 2 cores, perform insertion sort for rest
> + cores except the bsp in first entry  // to move big cores in front of small cores.
> +  // Also the original order based on the MpService index inside big cores and
> small cores are retained.
> +  //
> +  for (Index = 2; Index < Count; Index++) {
> +    if (CpuApicIdOrderTable[Index].CoreType ==
> CPUID_CORE_TYPE_INTEL_ATOM) {
> +      continue;
> +    }
> +
> +    CopyMem (&SortBuffer, &CpuApicIdOrderTable[Index], sizeof
> + (EFI_CPU_ID_ORDER_MAP));
> +
> +    for (SubIndex = Index - 1; SubIndex >= 1; SubIndex--) {
> +      if (CpuApicIdOrderTable[SubIndex].CoreType ==
> CPUID_CORE_TYPE_INTEL_ATOM) {
> +        CopyMem (&CpuApicIdOrderTable[SubIndex + 1],
> &CpuApicIdOrderTable[SubIndex], sizeof (EFI_CPU_ID_ORDER_MAP));
> +      } else {
> +        //
> +        // Except the BSP, all cores in front of SubIndex must be big cores.
> +        //
> +        break;
> +      }
> +    }
> +
> +    CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &SortBuffer, sizeof
> +(EFI_CPU_ID_ORDER_MAP));
> +  }
> +}
> +
>  /**
>    Get CPU core type.
> 
> @@ -174,6 +230,7 @@ CreateCpuLocalApicInTable (
>    EFI_CPU_ID_ORDER_MAP                      *CpuIdMapPtr;
>    UINT32                                    Socket;
>    UINT32                                    CpuidMaxInput;
> +  UINTN                                     BspIndex;
> 
>    Status = EFI_SUCCESS;
> 
> @@ -198,6 +255,10 @@ CreateCpuLocalApicInTable (
>                             &ProcessorInfoBuffer
>                             );
> 
> +    if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) {
> +      BspIndex = Index;
> +    }
> +
>      CpuIdMapPtr = (EFI_CPU_ID_ORDER_MAP *) &CpuApicIdOrderTable[Index];
>      if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0) {
>        CpuIdMapPtr->ApicId  = (UINT32)ProcessorInfoBuffer.ProcessorId;
> @@ -230,6 +291,8 @@ CreateCpuLocalApicInTable (
>      }
>    }
> 
> +  SortApicIdOrderTable (CpuApicIdOrderTable, mNumberOfCpus, BspIndex);
> +
>    DEBUG ((DEBUG_INFO, "::ACPI::  APIC ID Order Table Init.   mNumOfBitShift =
> %x\n", mNumOfBitShift));
>    DebugDisplayReOrderTable (CpuApicIdOrderTable);
> 
> --
> 2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117329): https://edk2.groups.io/g/devel/message/117329
Mute This Topic: https://groups.io/mt/105259125/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-02  6:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01  6:04 [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
2024-04-01  7:45   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
2024-04-01  7:45   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
2024-04-01  7:46   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox