]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuFeature: Introduce First to indicate 1st unit.
authorRay Ni <ray.ni@intel.com>
Fri, 5 Jul 2019 03:49:15 +0000 (11:49 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 14 Feb 2020 03:15:00 +0000 (03:15 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1584

The flow of CPU feature initialization logic is:
1. BSP calls GetConfigDataFunc() for each thread/AP;
2. Each thread/AP calls SupportFunc() to detect its own capability;
3. BSP calls InitializeFunc() for each thread/AP.

There is a design gap in step #3. For a package scope feature that only
requires one thread of each package does the initialization operation,
what InitializeFunc() currently does is to do the initialization
operation only CPU physical location Core# is 0.
But in certain platform, Core#0 might be disabled in hardware level
which results the certain package scope feature isn't initialized at
all.

The patch adds a new field First to indicate the CPU's location in
its parent scope.
First.Package is set for all APs/threads under first package;
First.Core is set for all APs/threads under first core of each
package;
First.Thread is set for the AP/thread of each core.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c

index be14a92b352d3ed220589337f02de9f36c488dc0..27bd2f6b48dc4b47d75733ea6a092bd8cd1fc48d 100644 (file)
 #define CPU_FEATURE_END                             MAX_UINT32\r
 /// @}\r
 \r
+///\r
+/// The bit field to indicate whether the processor is the first in its parent scope.\r
+///\r
+typedef struct {\r
+  //\r
+  // Set to 1 when current processor is the first thread in the core it resides in.\r
+  //\r
+  UINT32 Thread   : 1;\r
+  //\r
+  // Set to 1 when current processor is a thread of the first core in the module it resides in.\r
+  //\r
+  UINT32 Core     : 1;\r
+  //\r
+  // Set to 1 when current processor is a thread of the first module in the tile it resides in.\r
+  //\r
+  UINT32 Module   : 1;\r
+  //\r
+  // Set to 1 when current processor is a thread of the first tile in the die it resides in.\r
+  //\r
+  UINT32 Tile     : 1;\r
+  //\r
+  // Set to 1 when current processor is a thread of the first die in the package it resides in.\r
+  //\r
+  UINT32 Die      : 1;\r
+  //\r
+  // Set to 1 when current processor is a thread of the first package in the system.\r
+  //\r
+  UINT32 Package  : 1;\r
+  UINT32 Reserved : 26;\r
+} REGISTER_CPU_FEATURE_FIRST_PROCESSOR;\r
+\r
 ///\r
 /// CPU Information passed into the SupportFunc and InitializeFunc of the\r
 /// RegisterCpuFeature() library function.  This structure contains information\r
@@ -88,6 +119,11 @@ typedef struct {
   /// The package that the CPU resides\r
   ///\r
   EFI_PROCESSOR_INFORMATION            ProcessorInfo;\r
+\r
+  ///\r
+  /// The bit flag indicating whether the CPU is the first Thread/Core/Module/Tile/Die/Package in its parent scope.\r
+  ///\r
+  REGISTER_CPU_FEATURE_FIRST_PROCESSOR First;\r
   ///\r
   /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO\r
   ///\r
index 0a4fcff033a3cb30641cb061321b3c776ba512c1..cdee6d92abe7af996d09632649e1657c614025fd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU Features Initialize functions.\r
 \r
-  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -105,6 +105,9 @@ CpuInitDataInitialize (
   EFI_CPU_PHYSICAL_LOCATION            *Location;\r
   BOOLEAN                              *CoresVisited;\r
   UINTN                                Index;\r
+  UINT32                               PackageIndex;\r
+  UINT32                               CoreIndex;\r
+  UINT32                               First;\r
   ACPI_CPU_DATA                        *AcpiCpuData;\r
   CPU_STATUS_INFORMATION               *CpuStatus;\r
   UINT32                               *ValidCoreCountPerPackage;\r
@@ -234,6 +237,77 @@ CpuInitDataInitialize (
   ASSERT (CpuFeaturesData->CpuFlags.CoreSemaphoreCount != NULL);\r
   CpuFeaturesData->CpuFlags.PackageSemaphoreCount = AllocateZeroPool (sizeof (UINT32) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount);\r
   ASSERT (CpuFeaturesData->CpuFlags.PackageSemaphoreCount != NULL);\r
+\r
+  //\r
+  // Initialize CpuFeaturesData->InitOrder[].CpuInfo.First\r
+  //\r
+\r
+  //\r
+  // Set First.Package for each thread belonging to the first package.\r
+  //\r
+  First = MAX_UINT32;\r
+  for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+    Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+    First = MIN (Location->Package, First);\r
+  }\r
+  for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+    Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+    if (Location->Package == First) {\r
+      CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Package = 1;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Set First.Die/Tile/Module for each thread assuming:\r
+  //  single Die under each package, single Tile under each Die, single Module under each Tile\r
+  //\r
+  for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Die = 1;\r
+    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Tile = 1;\r
+    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Module = 1;\r
+  }\r
+\r
+  for (PackageIndex = 0; PackageIndex < CpuStatus->PackageCount; PackageIndex++) {\r
+    //\r
+    // Set First.Core for each thread in the first core of each package.\r
+    //\r
+    First = MAX_UINT32;\r
+    for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+      Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+      if (Location->Package == PackageIndex) {\r
+        First = MIN (Location->Core, First);\r
+      }\r
+    }\r
+\r
+    for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+      Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+      if (Location->Package == PackageIndex && Location->Core == First) {\r
+        CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Core = 1;\r
+      }\r
+    }\r
+  }\r
+\r
+  for (PackageIndex = 0; PackageIndex < CpuStatus->PackageCount; PackageIndex++) {\r
+    for (CoreIndex = 0; CoreIndex < CpuStatus->MaxCoreCount; CoreIndex++) {\r
+      //\r
+      // Set First.Thread for the first thread of each core.\r
+      //\r
+      First = MAX_UINT32;\r
+      for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+        Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+        if (Location->Package == PackageIndex && Location->Core == CoreIndex) {\r
+          First = MIN (Location->Thread, First);\r
+        }\r
+      }\r
+\r
+      for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
+        Location = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.ProcessorInfo.Location;\r
+        if (Location->Package == PackageIndex && Location->Core == CoreIndex && Location->Thread == First) {\r
+          CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Thread = 1;\r
+        }\r
+      }\r
+    }\r
+  }\r
 }\r
 \r
 /**\r