From 58d94639390803e375a7d16c94a5a527ec158474 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Fri, 15 Dec 2023 16:56:31 +0800 Subject: UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync After BSP returned from SmmCoreEntry, there are several rounds BSP and AP sync in BSP handler: 1 .ReleaseAllAPs(); /// Notify all APs to exit. if (SmmCpuFeaturesNeedConfigureMtrrs()) { 2. SmmCpuSyncWaitForAPs(); /// Wait for all APs to program MTRRs. 3. ReleaseAllAPs(); /// Signal APs to restore MTRRs. } 4. SmmCpuSyncWaitForAPs(); /// Wait for all APs to complete pending tasks including MTRR. 5. ReleaseAllAPs(); /// Signal APs to Reset states. 6. SmmCpuSyncWaitForAPs(); /// Gather APs to exit SMM synchronously. Before step 6 and after step 5, BSP performs below items: A. InitializeDebugAgent() /// Stop source level debug. B. SmmCpuUpdate() /// Perform pending operations for hot-plug. C. Present = FALSE; /// Clear the Present flag of BSP. For InitializeDebugAgent(), BSP needs to wait all APs complete pending tasks and then notify all APs to stop source level debug. So, above step 4 & step 5 are required for InitializeDebugAgent(). For SmmCpuUpdate(), it's to perform pending operations for hot-plug CPUs take effect in next SMI. Existing APs in SMI do not reply on the CPU switch & hot-add & hot-remove operations. So, no need step 4 and step 5 for additional one round BSP & AP sync. Step 6 can make sure all APs are ready to exit SMM, then hot-plug operation can take effect in next SMI. For BSP "Present" flag, AP does not reply on it. No need step 4 and step 5 for additional one round BSP & AP sync. Based on above analysis, step 4 and step 5 are only required if need configure MTRR and support SMM source level debug. So, we can reduce one round BSP and AP sync if both are unsupported. With this change, SMI performance can be improved. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 9aa9908863..e988ce0542 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -645,15 +645,17 @@ BSPHandler ( MtrrSetAllMtrrs (&Mtrrs); } - // - // Wait for all APs to complete their pending tasks including MTRR programming if needed. - // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + if (SmmCpuFeaturesNeedConfigureMtrrs () || mSmmDebugAgentSupport) { + // + // Wait for all APs to complete their pending tasks including MTRR programming if needed. + // + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); - // - // Signal APs to Reset states/semaphore for this processor - // - ReleaseAllAPs (); + // + // Signal APs to Reset states/semaphore for this processor + // + ReleaseAllAPs (); + } if (mSmmDebugAgentSupport) { // @@ -896,15 +898,17 @@ APHandler ( MtrrSetAllMtrrs (&Mtrrs); } - // - // Notify BSP the readiness of this AP to Reset states/semaphore for this processor - // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + if (SmmCpuFeaturesNeedConfigureMtrrs () || mSmmDebugAgentSupport) { + // + // Notify BSP the readiness of this AP to Reset states/semaphore for this processor + // + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); - // - // Wait for the signal from BSP to Reset states/semaphore for this processor - // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + // + // Wait for the signal from BSP to Reset states/semaphore for this processor + // + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + } // // Reset states/semaphore for this processor -- cgit v1.2.3