From 2ca8d559744319025592df10ada0f714fc3b8e15 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Tue, 6 Feb 2024 15:49:55 +0800 Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg This patch is to check BspIndex first before lock cmpxchg operation. If BspIndex has not been set, then do the lock cmpxchg, otherwise, the APs don't need to lock cmpxchg the BspIndex value since the BSP election has been done. It's the optimization to lower the resource contention caused by the atomic compare exchange operation, so as to improve the SMI performance for BSP election. Cc: Ray Ni Cc: Laszlo Ersek Cc: Eric Dong Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Cc: Kinney Michael D Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 71d6b0c6d8..081f0c1501 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1654,11 +1654,13 @@ SmiRendezvous ( // // Platform hook fails to determine, use default BSP election method // - InterlockedCompareExchange32 ( - (UINT32 *)&mSmmMpSyncData->BspIndex, - MAX_UINT32, - (UINT32)CpuIndex - ); + if (mSmmMpSyncData->BspIndex == MAX_UINT32) { + InterlockedCompareExchange32 ( + (UINT32 *)&mSmmMpSyncData->BspIndex, + MAX_UINT32, + (UINT32)CpuIndex + ); + } } } }