From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 75CA87803D7 for ; Tue, 6 Feb 2024 07:58:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=hnjM71ESW+18u79Zg2PJ8h/EtcDh4dPe/g3rmg1fqwI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1707206293; v=1; b=e13pfYqGY7upto//kdCVJ+I5xwRhEuAajjSN4L19+nyKVz6RcqYWXtdAUrboiBDOLq+vIGo1 AhWjih/fpmPALQFrB7MF9w+GDt9fnXMdRStZvZ62v66cZPHkOzVAO+BawNz41tCCS9zQy4cp/ug tH7Morgjca5ERMSaVjVh3xP8= X-Received: by 127.0.0.2 with SMTP id rbDgYY7687511xnfQf6SnX4O; Mon, 05 Feb 2024 23:58:13 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by mx.groups.io with SMTP id smtpd.web10.17030.1707206288775720019 for ; Mon, 05 Feb 2024 23:58:13 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="575558" X-IronPort-AV: E=Sophos;i="6.05,246,1701158400"; d="scan'208";a="575558" X-Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 23:58:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,246,1701158400"; d="scan'208";a="5571332" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmviesa004.fm.intel.com with ESMTP; 05 Feb 2024 23:58:11 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Ray Ni , Laszlo Ersek , Eric Dong , Zeng Star , Gerd Hoffmann , Rahul Kumar , Kinney Michael D Subject: [edk2-devel] [PATCH v3 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg Date: Tue, 6 Feb 2024 15:58:04 +0800 Message-Id: <20240206075804.15152-3-jiaxin.wu@intel.com> In-Reply-To: <20240206075804.15152-1-jiaxin.wu@intel.com> References: <20240206075804.15152-1-jiaxin.wu@intel.com> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Gy9DoPr38S63sk6GzkquzQc4x7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=e13pfYqG; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 --- 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 @@ -1652,15 +1652,17 @@ SmiRendezvous ( } } else { // // 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 + ); + } } } } // -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115151): https://edk2.groups.io/g/devel/message/115151 Mute This Topic: https://groups.io/mt/104194206/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-