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 3A74A941394 for ; Sun, 4 Feb 2024 08:47:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=L8AQWAMXQk3wWkFmYMya+zo7oLL0U7EU9pg3AyA9BIo=; 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=1707036471; v=1; b=WIyOKLbN3oo5GB/oWzJtXPF3gMQpIlSr2dRpWXEbWk3PucqqFcGIEywlVJp5sT7ITwgmdKWG ObbD/1j8GTGAlwsB+kvUclbtkF6lLaI5jvUq5IGvVPhT24U+VAaO7HxDUGngCbr79lUpnhayMyR qYDhFqFklzo6uxWV3wprjp9g= X-Received: by 127.0.0.2 with SMTP id DbF1YY7687511xmXJtUbQVBC; Sun, 04 Feb 2024 00:47:51 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by mx.groups.io with SMTP id smtpd.web11.35053.1707036467322819380 for ; Sun, 04 Feb 2024 00:47:51 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10973"; a="11022053" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="11022053" X-Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 00:47:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="5080715" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmviesa003.fm.intel.com with ESMTP; 04 Feb 2024 00:47:49 -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 v2 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg Date: Sun, 4 Feb 2024 16:47:44 +0800 Message-Id: <20240204084744.16464-3-jiaxin.wu@intel.com> In-Reply-To: <20240204084744.16464-1-jiaxin.wu@intel.com> References: <20240204084744.16464-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: MIZIzzsKM1Il39riimkpHU8Ux7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=WIyOKLbN; 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 e988ce0542..085aa91286 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, - (UINT32)-1, - (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 (#115081): https://edk2.groups.io/g/devel/message/115081 Mute This Topic: https://groups.io/mt/104153489/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-