diff options
author | Yuanhao Xie <yuanhao.xie@intel.com> | 2023-10-25 19:42:16 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-10-26 17:43:03 +0000 |
commit | 74c687cc2f2f29d3bdd454a416624f0ca5a86566 (patch) | |
tree | d36110ef642769651d44bc1bfd8258aeea86439b /UefiCpuPkg | |
parent | fe43b426762c31c2f1958444d3aca388ec8d4702 (diff) | |
download | edk2-74c687cc2f2f29d3bdd454a416624f0ca5a86566.tar.gz edk2-74c687cc2f2f29d3bdd454a416624f0ca5a86566.tar.bz2 edk2-74c687cc2f2f29d3bdd454a416624f0ca5a86566.zip |
UefiCpuPkg/MpInitLib: Wait for all APs to finish initialization
Aim:
- To solve the assertion that checks if CpuMpData->FinishedCount
equals (CpuMpData->CpuCount - 1). The assertion arises from a timing
discrepancy between the BSP's completion of startup signal checks and
the APs' incrementation of the FinishedCount.
- This patch also ensures that "finished" reporting from the APs is as
later as possible.
More specifially:
In the SwitchApContext() function, the BSP trigers
the startup signal and check whether the APs have received it. After
completing this check, the BSP then verifies if the FinishedCount is
equal to CpuCount-1.
On the AP side, upon receiving the startup signal, they invoke
SwitchContextPerAp() and increase the FinishedCount to indicate their
activation. However, even when all APs have received the startup signal,
they might not have finished incrementing the FinishedCount. This timing
gap results in the triggering of the assertion.
Solution:
Instead of assertion, use while loop to waits until all the APs have
incremented the FinishedCount.
Fixes: 964a4f032dcd
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <20231025114216.2824-1-yuanhao.xie@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r-- | UefiCpuPkg/Library/MpInitLib/MpLib.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 6f1456cfe1..9a6ec5db5c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -913,8 +913,8 @@ DxeApEntryPoint ( UINTN ProcessorNumber;
GetProcessorNumber (CpuMpData, &ProcessorNumber);
- InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount);
RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE);
+ InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount);
PlaceAPInMwaitLoopOrRunLoop (
CpuMpData->ApLoopMode,
CpuMpData->CpuData[ProcessorNumber].StartupApSignal,
@@ -2201,7 +2201,12 @@ MpInitLibInitialize ( // looping process there.
//
SwitchApContext (MpHandOff);
- ASSERT (CpuMpData->FinishedCount == (CpuMpData->CpuCount - 1));
+ //
+ // Wait for all APs finished initialization
+ //
+ while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
+ CpuPause ();
+ }
//
// Set Apstate as Idle, otherwise Aps cannot be waken-up again.
|