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 2EB5BD8004D for ; Fri, 2 Feb 2024 07:13:39 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lTAt3yiQ2bhQ/1zHqdyqzQ97WlYBRla1yH3IXWE4MmI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1706858018; v=1; b=Lu/p2Y+wZ4qWbHijMDW7eQGMyQ6ux6VEUBkNUllhJqJXJZazTsPHGxxJQUHCcelk75UFtfPz YpJmPFuuq1crlqog35vGyVSWlm1EGAmQaVJFfgv09Lh4Eo33xfg+iLZPJ3eYucQwi4LoG83YEpR aShZnZukMoDI+BGz0TGvIPO0= X-Received: by 127.0.0.2 with SMTP id 8YnGYY7687511xp8cXTsziqb; Thu, 01 Feb 2024 23:13:38 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by mx.groups.io with SMTP id smtpd.web10.18021.1706858017807593817 for ; Thu, 01 Feb 2024 23:13:38 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="10750559" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="10750559" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 23:13:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912356494" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912356494" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 01 Feb 2024 23:13:34 -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: Fri, 2 Feb 2024 15:13:31 +0800 Message-Id: <20240202071331.6548-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: PWqmruicOC1MZhhV73vMQA2Jx7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="Lu/p2Y+w"; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) This patch is to check BspIndex first before lock cmpxchg operation. 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 (#115026): https://edk2.groups.io/g/devel/message/115026 Mute This Topic: https://groups.io/mt/104115335/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-