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 EAAF97803D2 for ; Mon, 25 Dec 2023 16:20:51 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=am0QexpYziAqneckhhMOdMV2P67zaAW7mzEazgz3YLw=; 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=1703521250; v=1; b=jR9UJnj78473Az9tp3bnj5B7Ob4ed5gg90exs0QUb5vXMj5glP38O1V4iWW4Ih1n8lw+HxnV 7ejxfsZhLSv3cZMNPmEH/LKnU7YCW2aMGpFS0l5BsMmmMdtNirTONL2tuoDF7JXUbU2W+/hh4Uh Iv5d2pRkUr9UiXxbiL1AQd/8= X-Received: by 127.0.0.2 with SMTP id vL3IYY7687511x7RevnHDWAc; Mon, 25 Dec 2023 08:20:50 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.61867.1703521238683254667 for ; Mon, 25 Dec 2023 08:20:50 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10934"; a="375789620" X-IronPort-AV: E=Sophos;i="6.04,303,1695711600"; d="scan'208";a="375789620" X-Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Dec 2023 08:20:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,303,1695711600"; d="scan'208";a="26085443" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orviesa001.jf.intel.com with ESMTP; 25 Dec 2023 08:20:48 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v2 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync Date: Tue, 26 Dec 2023 00:20:34 +0800 Message-Id: <20231225162034.2052-7-jiaxin.wu@intel.com> In-Reply-To: <20231225162034.2052-1-jiaxin.wu@intel.com> References: <20231225162034.2052-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: eF8hSZhuMjXtIP5yaoxnkTnax7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=jR9UJnj7; 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 After BSP returned from SmmCoreEntry, there are several rounds BSP and AP sync in BSP handler: 1 .ReleaseAllAPs(); /// Notify all APs to exit. if (SmmCpuFeaturesNeedConfigureMtrrs()) { 2. SmmCpuSyncWaitForAPs(); /// Wait for all APs to program MTRRs. 3. ReleaseAllAPs(); /// Signal APs to restore MTRRs. } 4. SmmCpuSyncWaitForAPs(); /// Wait for all APs to complete pending tasks including MTRR. 5. ReleaseAllAPs(); /// Signal APs to Reset states. 6. SmmCpuSyncWaitForAPs(); /// Gather APs to exit SMM synchronously. Before step 6 and after step 5, BSP performs below items: A. InitializeDebugAgent() /// Stop source level debug. B. SmmCpuUpdate() /// Perform pending operations for hot-plug. C. Present = FALSE; /// Clear the Present flag of BSP. For InitializeDebugAgent(), BSP needs to wait all APs complete pending tasks and then notify all APs to stop source level debug. So, above step 4 & step 5 are required for InitializeDebugAgent(). For SmmCpuUpdate(), it's to perform pending operations for hot-plug CPUs take effect in next SMI. Existing APs in SMI do not reply on the CPU switch & hot-add & hot-remove operations. So, no need step 4 and step 5 for additional one round BSP & AP sync. Step 6 can make sure all APs are ready to exit SMM, then hot-plug operation can take effect in next SMI. For BSP "Present" flag, AP does not reply on it. No need step 4 and step 5 for additional one round BSP & AP sync. Based on above analysis, step 4 and step 5 are only required if need configure MTRR and support SMM source level debug. So, we can reduce one round BSP and AP sync if both are unsupported. With this change, SMI performance can be improved. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 9aa9908863..e988ce0542 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -643,19 +643,21 @@ BSPHandler ( // SmmCpuFeaturesReenableSmrr (); MtrrSetAllMtrrs (&Mtrrs); } - // - // Wait for all APs to complete their pending tasks including MTRR programming if needed. - // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + if (SmmCpuFeaturesNeedConfigureMtrrs () || mSmmDebugAgentSupport) { + // + // Wait for all APs to complete their pending tasks including MTRR programming if needed. + // + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); - // - // Signal APs to Reset states/semaphore for this processor - // - ReleaseAllAPs (); + // + // Signal APs to Reset states/semaphore for this processor + // + ReleaseAllAPs (); + } if (mSmmDebugAgentSupport) { // // Stop source level debug in BSP handler, the code below will not be // debugged. @@ -894,19 +896,21 @@ APHandler ( // SmmCpuFeaturesReenableSmrr (); MtrrSetAllMtrrs (&Mtrrs); } - // - // Notify BSP the readiness of this AP to Reset states/semaphore for this processor - // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + if (SmmCpuFeaturesNeedConfigureMtrrs () || mSmmDebugAgentSupport) { + // + // Notify BSP the readiness of this AP to Reset states/semaphore for this processor + // + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); - // - // Wait for the signal from BSP to Reset states/semaphore for this processor - // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + // + // Wait for the signal from BSP to Reset states/semaphore for this processor + // + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + } // // Reset states/semaphore for this processor // *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE; -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112891): https://edk2.groups.io/g/devel/message/112891 Mute This Topic: https://groups.io/mt/103360807/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-