Skip to content

Commit

Permalink
UefiCpuPkg/MpInitLib: Wait for all APs to finish initialization
Browse files Browse the repository at this point in the history
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: 964a4f0

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>
  • Loading branch information
xieyuanh authored and mergify[bot] committed Oct 26, 2023
1 parent fe43b42 commit 74c687c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions UefiCpuPkg/Library/MpInitLib/MpLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 74c687c

Please sign in to comment.