]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: take VCPU count from QEMU and configure MpInitLib
authorLaszlo Ersek <lersek@redhat.com>
Thu, 24 Nov 2016 14:18:44 +0000 (15:18 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Tue, 29 Nov 2016 09:05:54 +0000 (10:05 +0100)
These settings will allow CpuMpPei and CpuDxe to wait for the initial AP
check-ins exactly as long as necessary.

It is safe to set PcdCpuMaxLogicalProcessorNumber and
PcdCpuApInitTimeOutInMicroSeconds in OvmfPkg/PlatformPei.
OvmfPkg/PlatformPei installs the permanent PEI RAM, producing
gEfiPeiMemoryDiscoveredPpiGuid, and UefiCpuPkg/CpuMpPei has a depex on
gEfiPeiMemoryDiscoveredPpiGuid.

It is safe to read the fw_cfg item QemuFwCfgItemSmpCpuCount (0x0005). It
was added to QEMU in 2008 as key FW_CFG_NB_CPUS, in commit 905fdcb5264c
("Add common keys to firmware configuration"). Even if the key is
unavailable (or if fw_cfg is entirely unavailable, for example on Xen),
QemuFwCfgRead16() will return 0, and then we stick with the current
behavior.

Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
OvmfPkg/OvmfPkgIa32.dsc
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/PlatformPei/MemDetect.c
OvmfPkg/PlatformPei/Platform.c
OvmfPkg/PlatformPei/Platform.h
OvmfPkg/PlatformPei/PlatformPei.inf

index ed43c45144917d9e3671a41b871288328d08cf45..d913030522639cc73137cfde782ffbb2666460d8 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable|FALSE\r
 \r
+  # UefiCpuPkg PCDs related to initial AP bringup and general AP management.\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000\r
+\r
 ################################################################################\r
 #\r
 # Components Section - list of all EDK II Modules needed by this Platform.\r
index ccd156d9231a0319d5a53230f97962af31ffa992..8143ea9c28375a5f0baeaf730d34563634171ac1 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable|FALSE\r
 \r
+  # UefiCpuPkg PCDs related to initial AP bringup and general AP management.\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000\r
+\r
 ################################################################################\r
 #\r
 # Components Section - list of all EDK II Modules needed by this Platform.\r
index 012ce85462c5ac92daaedbe95a8244139d72e4a4..d48d603d33d4e09584968eaa7f8f2441760f2d87 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable|FALSE\r
 \r
+  # UefiCpuPkg PCDs related to initial AP bringup and general AP management.\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000\r
+\r
 ################################################################################\r
 #\r
 # Components Section - list of all EDK II Modules needed by this Platform.\r
index d00a570d438116320e57d2456679ad4f974b2f09..af96a04d194aae3fecb5a22534201f47ee83d79d 100644 (file)
@@ -358,7 +358,7 @@ PublishPeiMemory (
   //\r
   if (mS3Supported) {\r
     mS3AcpiReservedMemorySize = SIZE_512KB +\r
-      PcdGet32 (PcdCpuMaxLogicalProcessorNumber) *\r
+      mMaxCpuCount *\r
       PcdGet32 (PcdCpuApStackSize);\r
     mS3AcpiReservedMemoryBase = LowerMemorySize - mS3AcpiReservedMemorySize;\r
     LowerMemorySize = mS3AcpiReservedMemoryBase;\r
index c6e1106c9ed01ef790ad9947497e9192cf34dd5a..0be86722e548e0db6c1f259348f692c31faeb3d1 100644 (file)
@@ -68,6 +68,7 @@ EFI_BOOT_MODE mBootMode = BOOT_WITH_FULL_CONFIGURATION;
 \r
 BOOLEAN mS3Supported = FALSE;\r
 \r
+UINT32 mMaxCpuCount;\r
 \r
 VOID\r
 AddIoMemoryBaseSizeHob (\r
@@ -567,6 +568,47 @@ S3Verification (
 }\r
 \r
 \r
+/**\r
+  Fetch the number of boot CPUs from QEMU and expose it to UefiCpuPkg modules.\r
+  Set the mMaxCpuCount variable.\r
+**/\r
+VOID\r
+MaxCpuCountInitialization (\r
+  VOID\r
+  )\r
+{\r
+  UINT16        ProcessorCount;\r
+  RETURN_STATUS PcdStatus;\r
+\r
+  QemuFwCfgSelectItem (QemuFwCfgItemSmpCpuCount);\r
+  ProcessorCount = QemuFwCfgRead16 ();\r
+  //\r
+  // If the fw_cfg key or fw_cfg entirely is unavailable, load mMaxCpuCount\r
+  // from the PCD default. No change to PCDs.\r
+  //\r
+  if (ProcessorCount == 0) {\r
+    mMaxCpuCount = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r
+    return;\r
+  }\r
+  //\r
+  // Otherwise, set mMaxCpuCount to the value reported by QEMU.\r
+  //\r
+  mMaxCpuCount = ProcessorCount;\r
+  //\r
+  // Additionally, tell UefiCpuPkg modules (a) the exact number of VCPUs, (b)\r
+  // to wait, in the initial AP bringup, exactly as long as it takes for all of\r
+  // the APs to report in. For this, we set the longest representable timeout\r
+  // (approx. 71 minutes).\r
+  //\r
+  PcdStatus = PcdSet32S (PcdCpuMaxLogicalProcessorNumber, ProcessorCount);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (PcdCpuApInitTimeOutInMicroSeconds, MAX_UINT32);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  DEBUG ((DEBUG_INFO, "%a: QEMU reports %d processor(s)\n", __FUNCTION__,\r
+    ProcessorCount));\r
+}\r
+\r
+\r
 /**\r
   Perform Platform PEI initialization.\r
 \r
@@ -601,6 +643,7 @@ InitializePlatform (
   S3Verification ();\r
   BootModeInitialization ();\r
   AddressWidthInitialization ();\r
+  MaxCpuCountInitialization ();\r
 \r
   PublishPeiMemory ();\r
 \r
index eda765be30dee46de7d1d362456d7f5c44e15a89..18f42c3f0ea8e29b1c105bece168278255a44f03 100644 (file)
@@ -101,4 +101,6 @@ extern BOOLEAN mS3Supported;
 \r
 extern UINT8 mPhysMemAddressWidth;\r
 \r
+extern UINT32 mMaxCpuCount;\r
+\r
 #endif // _PLATFORM_PEI_H_INCLUDED_\r
index 776a4ab11f7900660d5ff032b02e7c054279354e..fbaed3182dcfce643d130c5a58b59394fd7954e5 100644 (file)
@@ -95,6 +95,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize\r
 \r
 [FixedPcd]\r