Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm: Reduce the times of BSP and AP sync for exit
Browse files Browse the repository at this point in the history
After review, there are unnecessary steps for BSP and AP sync for exit.
This patch is to reduce one round BSP and AP sync for exit so as to
improve SMM performance:
WaitForAllAPs <- ReleaseBsp
ReleaseAllAPs -> WaitForBsp

Cc: Eric Dong <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Zeng Star <[email protected]>
Cc: Rahul Kumar <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Signed-off-by: Jiaxin Wu <[email protected]>
  • Loading branch information
jiaxinwu committed Oct 11, 2023
1 parent 3c47613 commit 055092a
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ BSPHandler (
ApCount = LockdownSemaphore (mSmmMpSyncData->Counter) - 1;

//
// Wait for all APs to get ready for programming MTRRs
// Wait for all APs:
// 1. Make sure all Aps have set the Present.
// 2. Get ready for programming MTRRs.
//
WaitForAllAPs (ApCount);

Expand Down Expand Up @@ -770,12 +772,12 @@ BSPHandler (
*mSmmMpSyncData->InsideSmm = FALSE;
ReleaseAllAPs ();

//
// Wait for all APs to complete their pending tasks
//
WaitForAllAPs (ApCount);

if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
//
// Wait for all APs to complete their pending tasks
//
WaitForAllAPs (ApCount);

//
// Signal APs to restore MTRRs
//
Expand All @@ -791,6 +793,11 @@ BSPHandler (
// Wait for all APs to complete MTRR programming
//
WaitForAllAPs (ApCount);

//
// Signal APs to Reset states/semaphore for this processor
//
ReleaseAllAPs ();
}

//
Expand All @@ -799,11 +806,6 @@ BSPHandler (
//
InitializeDebugAgent (DEBUG_AGENT_INIT_EXIT_SMI, NULL, NULL);

//
// Signal APs to Reset states/semaphore for this processor
//
ReleaseAllAPs ();

//
// Perform pending operations for hot-plug
//
Expand Down Expand Up @@ -943,6 +945,8 @@ APHandler (
if ((SyncMode == SmmCpuSyncModeTradition) || SmmCpuFeaturesNeedConfigureMtrrs ()) {
//
// Notify BSP of arrival at this point
// 1. Set the Present.
// 2. Get ready for programming MTRRs.
//
ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run);
}
Expand Down Expand Up @@ -1035,17 +1039,17 @@ APHandler (
//
SmmCpuFeaturesReenableSmrr ();
MtrrSetAllMtrrs (&Mtrrs);
}

//
// Notify BSP the readiness of this AP to Reset states/semaphore for this processor
//
ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run);
//
// Notify BSP the readiness of this AP to Reset states/semaphore for this processor
//
ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run);

//
// Wait for the signal from BSP to Reset states/semaphore for this processor
//
WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Wait for the signal from BSP to Reset states/semaphore for this processor
//
WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run);
}

//
// Reset states/semaphore for this processor
Expand Down

0 comments on commit 055092a

Please sign in to comment.