]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg
authorJiaxin Wu <jiaxin.wu@intel.com>
Tue, 6 Feb 2024 07:49:55 +0000 (15:49 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 21 Feb 2024 01:33:51 +0000 (01:33 +0000)
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 <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Kinney Michael D <michael.d.kinney@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c

index 71d6b0c6d85759896a77533bcbebac566bd00600..081f0c15013504f3f6e8409dad6fc2dc03975a68 100644 (file)
@@ -1654,11 +1654,13 @@ SmiRendezvous (
             //\r
             // Platform hook fails to determine, use default BSP election method\r
             //\r
-            InterlockedCompareExchange32 (\r
-              (UINT32 *)&mSmmMpSyncData->BspIndex,\r
-              MAX_UINT32,\r
-              (UINT32)CpuIndex\r
-              );\r
+            if (mSmmMpSyncData->BspIndex == MAX_UINT32) {\r
+              InterlockedCompareExchange32 (\r
+                (UINT32 *)&mSmmMpSyncData->BspIndex,\r
+                MAX_UINT32,\r
+                (UINT32)CpuIndex\r
+                );\r
+            }\r
           }\r
         }\r
       }\r