From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105493+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105493+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532889; cv=none; d=zohomail.com; s=zohoarc; b=UDiVoQEJZheGn3DQOaz9+MZNaKKp9iEfylQXnXK2EFW+hyxYSLPfF2BEdJrab6P4yFIlliTFFktUkTEZjmu+GWsvZWtEAJVw30FYfpNROGdSOyljaHbprFCJRerUlqRft3r0Dg0VnjKm00hpHh/VgxVhPS+hc8fOPcEu1xkkmtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532889; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=tFhWrngxAPjq4ZPcJBeeQPP7JlppmVmHFzgeKMa2nro=; b=UzDVtOa0BiQpufEMiwcwLEy0khWn4j/rEPNmDp1eraC/19j7SMx2uhTLB8RYDx+H3Y55okA/b9klcRdw8npa3O5I1wdUJW1BL7v/iRnnv3pdfkbS1rzltMyLnBhtxD7amW6hQY2jjK7UH4eR39PwOto7ri0LeJ+2eGmkoMW0TlU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105493+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532889232293.9247900269429; Wed, 31 May 2023 04:34:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OJGIYY1788612xF1onZJxQIm; Wed, 31 May 2023 04:34:48 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11830.1685532887032383064 for ; Wed, 31 May 2023 04:34:48 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830230" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830230" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921471" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921471" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:46 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH V2 1/6] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures Date: Wed, 31 May 2023 19:34:33 +0800 Message-Id: <20230531113438.1797-2-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: t4VjURiMYnw4JQpIPjXYiGq0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532888; bh=Nvd4S7k2a5jLVs626PypLBARc344l8oiMze5Xh0539Y=; h=Cc:Date:From:Reply-To:Subject:To; b=aajd0EY+qaYcjA8bKz1VwGUA1RJ0oHEL5nTZG5ad3TIDuV2DY9lfx0X2cIxc/Otq1DC rgrLA+JE4TMpd87cU3zzlqI0lDPfvV77CelhZeumkO/cvvI/p2Qm/OZK1YdNE4W3shwRJ 5qe3O9jb90Zgb/ngVJtUTdLrMEzHd+EAdWY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532891490100007 Content-Type: text/plain; charset="utf-8" The patch adds perf-logging for the following potential time-consuming BSP procedures: * PiCpuSmmEntry - SmmRelocateBases * ExecuteFirstSmiInit * BSPHandler - SmmWaitForApArrival - PerformRemainingTasks * InitPaging * SetMemMapAttributes * SetUefiMemMapAttributes * SetPageTableAttributes * ConfigSmmCodeAccessCheck * SmmCpuFeaturesCompleteSmmReadyToLock Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Reviewed-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 8 +++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 27 +++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 1 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + .../PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 13 ++++++--- UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 4 ++- 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index baf827cf9d..fa666bd118 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -351,6 +351,8 @@ SmmWaitForApArrival ( UINT32 DelayedCount; UINT32 BlockedCount; =20 + PERF_FUNCTION_BEGIN (); + DelayedCount =3D 0; BlockedCount =3D 0; =20 @@ -439,7 +441,7 @@ SmmWaitForApArrival ( DEBUG ((DEBUG_INFO, "SmmWaitForApArrival: Delayed AP Count =3D %d, Blo= cked AP Count =3D %d\n", DelayedCount, BlockedCount)); } =20 - return; + PERF_FUNCTION_END (); } =20 /** @@ -577,6 +579,8 @@ BSPHandler ( ASSERT (CpuIndex =3D=3D mSmmMpSyncData->BspIndex); ApCount =3D 0; =20 + PERF_FUNCTION_BEGIN (); + // // Flag BSP's presence // @@ -792,6 +796,8 @@ BSPHandler ( *mSmmMpSyncData->Counter =3D 0; *mSmmMpSyncData->AllCpusInSync =3D FALSE; mSmmMpSyncData->AllApArrivedWithException =3D FALSE; + + PERF_FUNCTION_END (); } =20 /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index c0e368ea94..2fc7dda682 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -410,12 +410,15 @@ ExecuteFirstSmiInit ( { UINTN Index; =20 + PERF_FUNCTION_BEGIN (); + if (mSmmInitialized =3D=3D NULL) { mSmmInitialized =3D (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * mMaxNu= mberOfCpus); } =20 ASSERT (mSmmInitialized !=3D NULL); if (mSmmInitialized =3D=3D NULL) { + PERF_FUNCTION_END (); return; } =20 @@ -442,6 +445,8 @@ ExecuteFirstSmiInit ( while (!(BOOLEAN)mSmmInitialized[Index]) { } } + + PERF_FUNCTION_END (); } =20 /** @@ -463,6 +468,8 @@ SmmRelocateBases ( UINTN Index; UINTN BspIndex; =20 + PERF_FUNCTION_BEGIN (); + // // Make sure the reserved size is large enough for procedure SmmInitTemp= late. // @@ -540,6 +547,7 @@ SmmRelocateBases ( // CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2)); CopyMem (U8Ptr, BakBuf, sizeof (BakBuf)); + PERF_FUNCTION_END (); } =20 /** @@ -617,6 +625,8 @@ PiCpuSmmEntry ( GuidHob =3D NULL; SmmBaseHobData =3D NULL; =20 + PERF_FUNCTION_BEGIN (); + // // Initialize address fixup // @@ -1194,6 +1204,7 @@ PiCpuSmmEntry ( =20 DEBUG ((DEBUG_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n")= ); =20 + PERF_FUNCTION_END (); return EFI_SUCCESS; } =20 @@ -1348,12 +1359,15 @@ ConfigSmmCodeAccessCheck ( UINTN Index; EFI_STATUS Status; =20 + PERF_FUNCTION_BEGIN (); + // // Check to see if the Feature Control MSR is supported on this CPU // Index =3D gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu; if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl))= { mSmmCodeAccessCheckEnable =3D FALSE; + PERF_FUNCTION_END (); return; } =20 @@ -1363,6 +1377,7 @@ ConfigSmmCodeAccessCheck ( // if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) =3D= =3D 0) { mSmmCodeAccessCheckEnable =3D FALSE; + PERF_FUNCTION_END (); return; } =20 @@ -1419,6 +1434,8 @@ ConfigSmmCodeAccessCheck ( ReleaseSpinLock (mConfigSmmCodeAccessCheckLock); } } + + PERF_FUNCTION_END (); } =20 /** @@ -1540,6 +1557,8 @@ PerformRemainingTasks ( ) { if (mSmmReadyToLock) { + PERF_FUNCTION_BEGIN (); + // // Start SMM Profile feature // @@ -1574,12 +1593,20 @@ PerformRemainingTasks ( // ConfigSmmCodeAccessCheck (); =20 + // + // Measure performance of SmmCpuFeaturesCompleteSmmReadyToLock() from = caller side + // as the implementation is provided by platform. + // + PERF_START (NULL, "SmmCompleteReadyToLock", NULL, 0); SmmCpuFeaturesCompleteSmmReadyToLock (); + PERF_END (NULL, "SmmCompleteReadyToLock", NULL, 0); =20 // // Clean SMM ready to lock flag // mSmmReadyToLock =3D FALSE; + + PERF_FUNCTION_END (); } } =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index a5c2bdd971..b03f2ef882 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -50,6 +50,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 158e05e264..af66a1941c 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -97,6 +97,7 @@ ReportStatusCodeLib SmmCpuFeaturesLib PeCoffGetEntryPointLib + PerformanceLib =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPk= g/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 834a756061..8b21e16f1c 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1,6 +1,6 @@ /** @file =20 -Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
+Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -1100,6 +1100,8 @@ SetMemMapAttributes ( return; } =20 + PERF_FUNCTION_BEGIN (); + DEBUG ((DEBUG_INFO, "MemoryAttributesTable:\n")); DEBUG ((DEBUG_INFO, " Version - 0x%08x\n", MemoryAttr= ibutesTable->Version)); DEBUG ((DEBUG_INFO, " NumberOfEntries - 0x%08x\n", MemoryAttr= ibutesTable->NumberOfEntries)); @@ -1152,7 +1154,7 @@ SetMemMapAttributes ( PatchSmmSaveStateMap (); PatchGdtIdtMap (); =20 - return; + PERF_FUNCTION_END (); } =20 /** @@ -1454,6 +1456,8 @@ SetUefiMemMapAttributes ( UINTN Index; EFI_MEMORY_DESCRIPTOR *Entry; =20 + PERF_FUNCTION_BEGIN (); + DEBUG ((DEBUG_INFO, "SetUefiMemMapAttributes\n")); =20 if (mUefiMemoryMap !=3D NULL) { @@ -1537,6 +1541,8 @@ SetUefiMemMapAttributes ( // // Do not free mUefiMemoryAttributesTable, it will be checked in IsSmmCo= mmBufferForbiddenAddress(). // + + PERF_FUNCTION_END (); } =20 /** @@ -1862,6 +1868,7 @@ SetPageTableAttributes ( return; } =20 + PERF_FUNCTION_BEGIN (); DEBUG ((DEBUG_INFO, "SetPageTableAttributes\n")); =20 // @@ -1900,5 +1907,5 @@ SetPageTableAttributes ( EnableCet (); } =20 - return; + PERF_FUNCTION_END (); } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/SmmProfile.c index 1b0b6673e1..ed6e58065f 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c @@ -575,6 +575,8 @@ InitPaging ( IA32_CR4 Cr4; BOOLEAN Enable5LevelPaging; =20 + PERF_FUNCTION_BEGIN (); + Cr4.UintN =3D AsmReadCr4 (); Enable5LevelPaging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); =20 @@ -810,7 +812,7 @@ InitPaging ( // mXdEnabled =3D TRUE; =20 - return; + PERF_FUNCTION_END (); } =20 /** --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105493): https://edk2.groups.io/g/devel/message/105493 Mute This Topic: https://groups.io/mt/99240108/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105494+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105494+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532890; cv=none; d=zohomail.com; s=zohoarc; b=P3nZnLsiGL2YOchp2fxrKFolyAEMvm/9QdxJDOT5lPSDs2y1p0lBIDvQBvmPq+xpa9kBaTO4+pKr7jAc/fBX13kuzljOIpARKgU4wYy+vNcFdqHh5chOFhkCEqVLLcXC1fLW6JKyXu6Ay2+gYyS76FahTeWUBPRUt4crl+u2wfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532890; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=IxKpevF8+bQVsAYMX3TazksS5MthVgj+BWd+cUup8xI=; b=N5b4Ji8BTAzAdP0eqKvDjWIDzB0Dt6PLy1TltDXBhW2I/ZYA+rSeKZd4p0ykjo/HIfE19LSUScOhXj29HjvHH75nbejdRFpOyNld97ILZ2SONvslFmNFQ1xrXGa6bKtz7pa48RcxbTgx1QBwjaAZYn+GArkoNVIz6BomXpW5+V8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105494+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532890572536.4539405514756; Wed, 31 May 2023 04:34:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BhbMYY1788612xdhLGSqtuVP; Wed, 31 May 2023 04:34:50 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11830.1685532887032383064 for ; Wed, 31 May 2023 04:34:49 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830242" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830242" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921480" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921480" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:47 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann , Jiaxin Wu Subject: [edk2-devel] [PATCH V2 2/6] UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures Date: Wed, 31 May 2023 19:34:34 +0800 Message-Id: <20230531113438.1797-3-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: 1J0Tkpe1l2uWXHXEEr5wsA8Px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532890; bh=MV+l6UuIyyvmIWXnIgS/P64EvEfYiuWVQB5bPVjqszo=; h=Cc:Date:From:Reply-To:Subject:To; b=I/1zxSr99wzHjjdkNWhBLQC18ukaRY7xYEls7T7/fwJWBBOnPseOIWqE11gTZtDs4zw TpSkKfvEPvdO0JcmqdGC65uJp/LM7n0eCqgyafiTK3wTUkOJs71f7MtJCJ65cOraTqvbL FXzz7tf/R/htpQ4wMwLo3CODXAKzQ7kyxJc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532891492100008 Content-Type: text/plain; charset="utf-8" MP procedures are those procedures that run in every CPU thread. The EDKII perf infra is not MP safe so it doesn't support to be called from those MP procedures. The patch adds SMM MP perf-logging support in SmmMpPerf.c. The following procedures are perf-logged: * SmmInitHandler * SmmCpuFeaturesRendezvousEntry * PlatformValidSmi * SmmCpuFeaturesRendezvousExit Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Jiaxin Wu Reviewed-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 34 ++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 11 +++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 1 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 2 + UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c | 91 ++++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 77 +++++++++++++++++ 6 files changed, 216 insertions(+) create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index fa666bd118..bcd90f0671 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -778,6 +778,15 @@ BSPHandler ( // WaitForAllAPs (ApCount); =20 + // + // At this point, all APs should have exited from APHandler(). + // Migrate the SMM MP performance logging to standard SMM performance lo= gging. + // Any SMM MP performance logging after this point will be migrated in n= ext SMI. + // + PERF_CODE ( + MigrateMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus); + ); + // // Reset the tokens buffer. // @@ -1769,12 +1778,24 @@ SmiRendezvous ( // // Perform CPU specific entry hooks // + PERF_CODE ( + MpPerfBegin (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (SmmRendezvousEntry)); + ); SmmCpuFeaturesRendezvousEntry (CpuIndex); + PERF_CODE ( + MpPerfEnd (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (SmmRendezvousEntry)); + ); =20 // // Determine if this is a valid SMI // + PERF_CODE ( + MpPerfBegin (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (PlatformValidSmi)); + ); ValidSmi =3D PlatformValidSmi (); + PERF_CODE ( + MpPerfEnd (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (PlatformValidSmi)); + ); =20 // // Determine if BSP has been already in progress. Note this must be chec= ked after @@ -1904,7 +1925,20 @@ SmiRendezvous ( } =20 Exit: + // + // Note: SmmRendezvousExit perf-logging entry is the only one that will = be + // migrated to standard perf-logging database in next SMI by BSPHa= ndler(). + // Hence, the number of SmmRendezvousEntry entries will be larger = than + // the number of SmmRendezvousExit entries. Delta equals to the nu= mber + // of CPU threads. + // + PERF_CODE ( + MpPerfBegin (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (SmmRendezvousExit)); + ); SmmCpuFeaturesRendezvousExit (CpuIndex); + PERF_CODE ( + MpPerfEnd (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (SmmRendezvousExit)); + ); =20 // // Restore Cr2 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 2fc7dda682..5afab1e040 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -362,6 +362,9 @@ SmmInitHandler ( =20 for (Index =3D 0; Index < mNumberOfCpus; Index++) { if (ApicId =3D=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Process= orId) { + PERF_CODE ( + MpPerfBegin (Index, SMM_MP_PERF_PROCEDURE_ID (SmmInitHandler)); + ); // // Initialize SMM specific features on the currently executing CPU // @@ -392,6 +395,10 @@ SmmInitHandler ( SemaphoreHook (Index, &mRebased[Index]); } =20 + PERF_CODE ( + MpPerfEnd (Index, SMM_MP_PERF_PROCEDURE_ID (SmmInitHandler)); + ); + return; } } @@ -699,6 +706,10 @@ PiCpuSmmEntry ( =20 gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus =3D mMaxNumberOfCpus; =20 + PERF_CODE ( + InitializeMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus); + ); + // // The CPU save state and code for the SMI entry point are tiled within = an SMRAM // allocated buffer. The minimum size of this buffer for a uniprocessor= system diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index b03f2ef882..1876a27cae 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -60,6 +60,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "CpuService.h" #include "SmmProfile.h" +#include "SmmMpPerf.h" =20 // // CET definition diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index af66a1941c..4864532c35 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -42,6 +42,8 @@ SmmCpuMemoryManagement.c SmmMp.h SmmMp.c + SmmMpPerf.h + SmmMpPerf.c =20 [Sources.Ia32] Ia32/Semaphore.c diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/SmmMpPerf.c new file mode 100644 index 0000000000..c13556af46 --- /dev/null +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c @@ -0,0 +1,91 @@ +/** @file +SMM MP perf-logging implementation + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PiSmmCpuDxeSmm.h" + + +#define SMM_MP_PERF_PROCEDURE_NAME(procedure) # procedure +GLOBAL_REMOVE_IF_UNREFERENCED +CHAR8 *gSmmMpPerfProcedureName[] =3D { + SMM_MP_PERF_PROCEDURE_LIST (SMM_MP_PERF_PROCEDURE_NAME) +}; +// +// Each element holds the performance data for one processor. +// +GLOBAL_REMOVE_IF_UNREFERENCED +SMM_PERF_AP_PROCEDURE_PERFORMANCE *mSmmMpProcedurePerformance =3D NULL; + +/** + Initialize the perf-logging feature for APs. + + @param NumberofCpus Number of processors in the platform. +**/ +VOID +InitializeMpPerf ( + UINTN NumberofCpus + ) +{ + mSmmMpProcedurePerformance =3D AllocateZeroPool (NumberofCpus * sizeof (= *mSmmMpProcedurePerformance)); + ASSERT (mSmmMpProcedurePerformance !=3D NULL); +} + +/** + Migrate MP performance data to standardized performance database. + + @param NumberofCpus Number of processors in the platform. +**/ +VOID +MigrateMpPerf ( + UINTN NumberofCpus + ) +{ + UINTN CpuIndex; + UINTN MpProcecureId; + + for (CpuIndex =3D 0; CpuIndex < NumberofCpus; CpuIndex++) { + for (MpProcecureId =3D 0; MpProcecureId < SMM_MP_PERF_PROCEDURE_ID (Sm= mMpProcedureMax); MpProcecureId++) { + if (mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId] !=3D 0= ) { + PERF_START (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mS= mmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId]); + PERF_END (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmm= MpProcedurePerformance[CpuIndex].End[MpProcecureId]); + } + } + } + + ZeroMem (mSmmMpProcedurePerformance, NumberofCpus * sizeof (*mSmmMpProce= durePerformance)); +} + +/** + Save the performance counter value before running the MP procedure. + + @param CpuIndex The index of the CPU. + @param MpProcedureId The ID of the MP procedure. +**/ +VOID +MpPerfBegin ( + IN UINTN CpuIndex, + IN UINTN MpProcedureId + ) +{ + mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcedureId] =3D GetPerform= anceCounter (); +} + +/** + Save the performance counter value after running the MP procedure. + + @param CpuIndex The index of the CPU. + @param MpProcedureId The ID of the MP procedure. +**/ +VOID +MpPerfEnd ( + IN UINTN CpuIndex, + IN UINTN MpProcedureId + ) +{ + mSmmMpProcedurePerformance[CpuIndex].End[MpProcedureId] =3D GetPerforman= ceCounter (); +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h b/UefiCpuPkg/PiSmmCpuDxe= Smm/SmmMpPerf.h new file mode 100644 index 0000000000..b148a99e86 --- /dev/null +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h @@ -0,0 +1,77 @@ +/** @file +SMM MP perf-logging implementation + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _MP_PERF_H_ +#define _MP_PERF_H_ + +// +// The list of all MP procedures that need to be perf-logged. +// +#define SMM_MP_PERF_PROCEDURE_LIST(_) \ + _(SmmInitHandler), \ + _(SmmRendezvousEntry), \ + _(PlatformValidSmi), \ + _(SmmRendezvousExit), \ + _(SmmMpProcedureMax) // Add new entries above this line + +#define SMM_MP_PERF_PROCEDURE_ID(procedure) SmmMpProcedureId ## procedure +enum { + SMM_MP_PERF_PROCEDURE_LIST (SMM_MP_PERF_PROCEDURE_ID) +}; + +typedef struct { + UINT64 Begin[SMM_MP_PERF_PROCEDURE_ID (SmmMpProcedureMax)]; + UINT64 End[SMM_MP_PERF_PROCEDURE_ID (SmmMpProcedureMax)]; +} SMM_PERF_AP_PROCEDURE_PERFORMANCE; + +/** + Initialize the perf-logging feature for APs. + + @param NumberofCpus Number of processors in the platform. +**/ +VOID +InitializeMpPerf ( + UINTN NumberofCpus + ); + +/** + Migrate MP performance data to standardized performance database. + + @param NumberofCpus Number of processors in the platform. +**/ +VOID +MigrateMpPerf ( + UINTN NumberofCpus + ); + +/** + Save the performance counter value before running the MP procedure. + + @param CpuIndex The index of the CPU. + @param MpProcedureId The ID of the MP procedure. +**/ +VOID +MpPerfBegin ( + IN UINTN CpuIndex, + IN UINTN MpProcedureId + ); + +/** + Save the performance counter value after running the MP procedure. + + @param CpuIndex The index of the CPU. + @param MpProcedureId The ID of the MP procedure. +**/ +VOID +MpPerfEnd ( + IN UINTN CpuIndex, + IN UINTN MpProcedureId + ); + +#endif --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105494): https://edk2.groups.io/g/devel/message/105494 Mute This Topic: https://groups.io/mt/99240109/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105495+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105495+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532892; cv=none; d=zohomail.com; s=zohoarc; b=DzkIJ4K/lwJO455PDhE9l9T2PZ5TDojxzpqWVsh1VsfjixZR74oFPT9Pv8uu7EBZAHnKZU+j77QeizYcD+7j+pK4JswWYtsPra6B9W/V13jTxSb+tlskfIYvQzb9HWFUIE0HVeBgvsTUigzFGv5MijW+6CEzV81TXir8ziFlvXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532892; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YVVvX7739EYs4ZFruIkHkyGJ++FHnth6+LKIrhZXgw4=; b=dkT0JIpRehkXkgTcyPHJM6Xu3gplsALCTziGCk0x+HMOfgqqI5B7aTz8buHNMJfNoy8mLcNp/bcpFiSxGrD9r0I3kF0yWL3aQlyKmB3+Ko08C+GHpAt60dGYSMglgMR8n4X0MHwyAsQrbg5tDgmdIArA+2zD1DGctZk2vBAontg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105495+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532892250893.4096651444565; Wed, 31 May 2023 04:34:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Rw3QYY1788612xqb62odP2Ve; Wed, 31 May 2023 04:34:51 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11830.1685532887032383064 for ; Wed, 31 May 2023 04:34:51 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830246" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830246" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921489" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921489" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:49 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Jiaxin Wu Subject: [edk2-devel] [PATCH V2 3/6] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures Date: Wed, 31 May 2023 19:34:35 +0800 Message-Id: <20230531113438.1797-4-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: fu2n0yngvsj8pjOhhS6CuaQpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532891; bh=h9Ps9wxbThm1oOCWW1A4BIZY8K3VZdjc47RGRTXaOlo=; h=Cc:Date:From:Reply-To:Subject:To; b=Pk0vkP9s+0jbD0dO9aObi1OXNBvske9OaiOImEnbdOlkyma2cj2CG4HXGNkIxtNYnj5 FSbwlCl1C6IucJbYk0h83jyyA7EVOC8sVFBoc3OYlRI3EFCJAkW48YW/ElN3tCfhcHhfZ M4kCskcukH+7ZNgKmbqbyf+o6Cq6+K6Akt8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532893263100013 Content-Type: text/plain; charset="utf-8" Following procedures are perf-logged: * SmmReadyToBootHandler * SmmReadyToLockHandler * SmmEndOfDxeHandler * SmmEntryPoint (It's the main routine run in BSP when SMI happens.) * SmiManage Cc: Jian J Wang Cc: Liming Gao Cc: Jiaxin Wu Reviewed-by: Jiaxin Wu --- MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 14 +++++++++++++- MdeModulePkg/Core/PiSmmCore/Smi.c | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/Pi= SmmCore/PiSmmCore.c index 875c7c0258..a15afa8dd6 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -1,7 +1,7 @@ /** @file SMM Core Main Entry Point =20 - Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -304,6 +304,7 @@ SmmReadyToBootHandler ( { EFI_STATUS Status; EFI_HANDLE SmmHandle; + PERF_CALLBACK_BEGIN (&gEfiEventReadyToBootGuid); =20 // // Install SMM Ready To Boot protocol. @@ -318,6 +319,7 @@ SmmReadyToBootHandler ( =20 SmiHandlerUnRegister (DispatchHandle); =20 + PERF_CALLBACK_END (&gEfiEventReadyToBootGuid); return Status; } =20 @@ -352,6 +354,8 @@ SmmReadyToLockHandler ( EFI_HANDLE SmmHandle; VOID *Interface; =20 + PERF_CALLBACK_BEGIN (&gEfiDxeSmmReadyToLockProtocolGuid); + // // Unregister SMI Handlers that are no required after the SMM driver dis= patch is stopped // @@ -408,6 +412,7 @@ SmmReadyToLockHandler ( =20 SmramProfileReadyToLock (); =20 + PERF_CALLBACK_END (&gEfiDxeSmmReadyToLockProtocolGuid); return Status; } =20 @@ -442,6 +447,8 @@ SmmEndOfDxeHandler ( =20 DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n")); =20 + PERF_CALLBACK_BEGIN (&gEfiEndOfDxeEventGroupGuid); + // // Install SMM EndOfDxe protocol // @@ -479,6 +486,7 @@ SmmEndOfDxeHandler ( } } =20 + PERF_CALLBACK_END (&gEfiEndOfDxeEventGroupGuid); return EFI_SUCCESS; } =20 @@ -669,6 +677,8 @@ SmmEntryPoint ( VOID *CommunicationBuffer; UINTN BufferSize; =20 + PERF_FUNCTION_BEGIN (); + // // Update SMST with contents of the SmmEntryContext structure // @@ -769,6 +779,8 @@ SmmEntryPoint ( // gSmmCorePrivate->InSmm =3D FALSE; } + + PERF_FUNCTION_END (); } =20 /** diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmCor= e/Smi.c index 6d13969979..2985f989c3 100644 --- a/MdeModulePkg/Core/PiSmmCore/Smi.c +++ b/MdeModulePkg/Core/PiSmmCore/Smi.c @@ -109,6 +109,8 @@ SmiManage ( BOOLEAN SuccessReturn; EFI_STATUS Status; =20 + PERF_FUNCTION_BEGIN (); + Status =3D EFI_NOT_FOUND; SuccessReturn =3D FALSE; if (HandlerType =3D=3D NULL) { @@ -125,6 +127,7 @@ SmiManage ( // // There is no handler registered for this interrupt source // + PERF_FUNCTION_END (); return Status; } } @@ -148,6 +151,7 @@ SmiManage ( // no additional handlers will be processed and EFI_INTERRUPT_PEND= ING will be returned. // if (HandlerType !=3D NULL) { + PERF_FUNCTION_END (); return EFI_INTERRUPT_PENDING; } =20 @@ -160,6 +164,7 @@ SmiManage ( // additional handlers will be processed. // if (HandlerType !=3D NULL) { + PERF_FUNCTION_END (); return EFI_SUCCESS; } =20 @@ -194,6 +199,7 @@ SmiManage ( Status =3D EFI_SUCCESS; } =20 + PERF_FUNCTION_END (); return Status; } =20 --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105495): https://edk2.groups.io/g/devel/message/105495 Mute This Topic: https://groups.io/mt/99240110/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105496+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105496+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532893; cv=none; d=zohomail.com; s=zohoarc; b=JnQLA7pSuFSntHxZhYT4MpMH2Jwt2Tymv5mRRvTppKQIBgWx6/X22Jt+IvKo7TnHWUT974EgX1BkYWAsA1OWPrCaEPINHVvNo2xPg8NUmVN2KlDbhDlMhG4WLu5zmS20wZRtGKje22/fiAK8bANTlW058+zIsddbW+bx2HGDcz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532893; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WhBmkwfWxqp9qkkt3nfV96Gu4NESW4B893fyCWw3g00=; b=modzgzhleSQHiK97SkCM9DdMwVYGElPywTZtc0dy6Y0lZL4W61M+cbGWXKurbFLg3APL91rT05T97DUm2ifAE8vC4pgz1JcLXSrCEp1yAADCOL7jD0faK1db9SXi594fIs0zpHp4lfsczo2mXhgnuGpi1AWrMRpqhTZ1v+PpQC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105496+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532893591214.06393624079158; Wed, 31 May 2023 04:34:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6nVCYY1788612xGuZKG41iHq; Wed, 31 May 2023 04:34:53 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11830.1685532887032383064 for ; Wed, 31 May 2023 04:34:52 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830250" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830250" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921504" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921504" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:51 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Jiaxin Wu Subject: [edk2-devel] [PATCH V2 4/6] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler Date: Wed, 31 May 2023 19:34:36 +0800 Message-Id: <20230531113438.1797-5-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: Bt5vhqC3YYdyAg1pWL9TZXMNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532893; bh=uvA/mO+fLLhSWl8UTWg1Nqve9jVusJTRBp2s62uAb98=; h=Cc:Date:From:Reply-To:Subject:To; b=X3tS56KfpWcNYyaMqg2CbRNnrIrFT6bCbV/rUQrpDM24484JYvOXj+vzsPziMiSI13k +hGzzWXKt80kg/BBD7u0Ub8EECuE/BKHldZh3RjeLB3OcZ/UHPvGzzlNGs2KJSrN5i+Sk 7PJ+2jn233mmng+y8KNq6xBHoiB+wcJ/KE8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532895443100017 Content-Type: text/plain; charset="utf-8" SmmDriverDispatchHandler is the routine that dispatches SMM drivers from FV. It's a time-consuming routine. Add perf-logging for this routine. Signed-off-by: Ray Ni Cc: Jian J Wang Cc: Liming Gao Cc: Jiaxin Wu Reviewed-by: Jiaxin Wu --- MdeModulePkg/Core/PiSmmCore/Dispatcher.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/P= iSmmCore/Dispatcher.c index f635565dd1..bb789e5890 100644 --- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c +++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c @@ -28,7 +28,7 @@ Depex - Dependency Expression. =20 Copyright (c) 2014, Hewlett-Packard Development Company, L.P. - Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -1322,6 +1322,8 @@ SmmDriverDispatchHandler ( return EFI_NOT_FOUND; } =20 + PERF_CALLBACK_BEGIN (&gEfiEventDxeDispatchGuid); + for (HandleIndex =3D 0; HandleIndex < HandleCount; HandleIndex++) { FvHandle =3D HandleBuffer[HandleIndex]; =20 @@ -1511,6 +1513,7 @@ SmmDriverDispatchHandler ( } } =20 + PERF_CALLBACK_END (&gEfiEventDxeDispatchGuid); return EFI_SUCCESS; } =20 --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105496): https://edk2.groups.io/g/devel/message/105496 Mute This Topic: https://groups.io/mt/99240111/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105497+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105497+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532895; cv=none; d=zohomail.com; s=zohoarc; b=VYZgj/5ArJGzGje3gJq7PN91GDDyt5lmyVyD/q4RMy1fEOgsQq0KNogHdwKptSp08LnhZQQlREgrjE4TfaGMYecXhoMYXgCNwoDw0HEwF8+hRcwn2hVpLDTJ9N7h9D1g/ZICoOPXQOE9yonQpaJLwuJBN/kpa74MYhHg1m3FNJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532895; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hVKW4qNiJsoQHheWMJN2z3BG4u1LrooeR2qNSo6jQi0=; b=TOFZD0lsJORgqB3h7Hg0N+vMReWo7KybLxORaAJh7I2e8GB+T4VsdY0/QBgjo36a0k+HNYr3mA7wSaj1ghBs3hgtw/oASE26DlX9NOR7+6hAXoapyhgnKWv096E8ZqJR91I4wE7j3/tvU7g1x0rFgkatLrO1WSe7mRZvI/LQMns= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105497+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532895073370.67612811211086; Wed, 31 May 2023 04:34:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wIziYY1788612xLbcwpgQ1rM; Wed, 31 May 2023 04:34:54 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11830.1685532887032383064 for ; Wed, 31 May 2023 04:34:54 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830257" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830257" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921510" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921510" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:52 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Jiaxin Wu , Dandan Bi , Liming Gao , Jian J Wang Subject: [edk2-devel] [PATCH V2 5/6] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS Date: Wed, 31 May 2023 19:34:37 +0800 Message-Id: <20230531113438.1797-6-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: 3XhTpOa5gBaHM3n3BHMYBCbWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532894; bh=mge18eCI3L0O/CErymCQWEynWDoSkrMOOoqfqbmO+1M=; h=Cc:Date:From:Reply-To:Subject:To; b=MbqUsXljGe7KjmbVQFUNkSzkZhXNN9EHWkawQhZuV7IGLlnHudwOiJKa9ygjBaqtD+6 AXsX7LY5v7B96Vf7R7+ZQGnevOs5xHIHjjs1Sj5CArtcnmosVysaHpHPcuA3K4igMd2/3 DNg+E6Vo49yqKKqCusQ+17OBarGjZQ2DlvU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532895990100021 Content-Type: text/plain; charset="utf-8" Because SMM perf-logging is migrated to non-SMRAM at ReadyToBoot by DxeCorePerformanceLib, the perf-logging after ExitBS is useless and impact the SMI latency at runtime. Hence the SmmPerformanceLib is updated to disable perf-logging after ExitBS. Cc: Jiaxin Wu Cc: Dandan Bi Cc: Liming Gao Cc: Jian J Wang Reviewed-by: Jiaxin Wu --- .../SmmPerformanceLib/SmmPerformanceLib.c | 63 ++++++++++++++++++- .../SmmPerformanceLib/SmmPerformanceLib.inf | 4 ++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c b/M= deModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c index 623f8a978c..b9c33c0f64 100644 --- a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c +++ b/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c @@ -23,6 +23,36 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // The cached SMM Performance Protocol and SMM PerformanceEx Protocol inte= rface. EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *mPerformanceMeasurement =3D NULL; BOOLEAN mPerformanceMeasurementEnabled; +VOID *mPerformanceLibExitBootServicesRe= gistration; + +/** + This is the Event call back function is triggered in SMM to notify the L= ibrary + the system is entering runtime phase. + + @param[in] Protocol Points to the protocol's unique identifier + @param[in] Interface Points to the interface instance + @param[in] Handle The handle on which the interface was installed + + @retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully + **/ +EFI_STATUS +EFIAPI +SmmPerformanceLibExitBootServicesCallback ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + // + // Disable performance measurement after ExitBootServices because + // 1. Performance measurement might impact SMI latency at runtime; + // 2. Performance log is copied to non SMRAM at ReadyToBoot so runtime p= erformance + // log is not useful. + // + mPerformanceMeasurementEnabled =3D FALSE; + + return EFI_SUCCESS; +} =20 /** The constructor function initializes the Performance Measurement Enable = flag @@ -40,9 +70,40 @@ SmmPerformanceLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_STATUS Status; + mPerformanceMeasurementEnabled =3D (BOOLEAN)((PcdGet8 (PcdPerformanceLi= braryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) !=3D= 0); =20 - return EFI_SUCCESS; + Status =3D gSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + SmmPerformanceLibExitBootServicesCallback, + &mPerformanceLibExitBootServicesRegistration + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +EFI_STATUS +EFIAPI +SmmPerformanceLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Unregister SmmExitBootServices notification. + // + Status =3D gSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + NULL, + &mPerformanceLibExitBootServicesRegistration + ); + ASSERT_EFI_ERROR (Status); + + return Status; } =20 /** diff --git a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf b= /MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf index d79cd5c8da..002462f5ca 100644 --- a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf +++ b/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf @@ -21,6 +21,7 @@ LIBRARY_CLASS =3D PerformanceLib|DXE_SMM_DRIVER =20 CONSTRUCTOR =3D SmmPerformanceLibConstructor + DESTRUCTOR =3D SmmPerformanceLibDestructor =20 # # The following information is for reference only and not required by the = build tools. @@ -46,5 +47,8 @@ [Guids] gEdkiiSmmPerformanceMeasurementProtocolGuid ## SOMETIMES_CONSUM= ES ## UNDEFINED # Locate protocol =20 +[Protocols] + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES + [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask ## CONSUMES --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105497): https://edk2.groups.io/g/devel/message/105497 Mute This Topic: https://groups.io/mt/99240113/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 05:00:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105498+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105498+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685532921; cv=none; d=zohomail.com; s=zohoarc; b=Gg01iTx7ujnqggxcsgChxwX289EgLH+zA54L8W5nTTmngNU1EIYoPCSxsgrkVF+rSsYri1nAvmCGP0WdzijXyALlfQP3wH8a1evn5Pk09gQMNTV2LF9V/H70lT0iXA/iNeUoYE+V304p+Dy6KLkqNEzRpfCPe2DVzKkTvp4adnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685532921; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bZYaume8zQNqlKWMCz2/TwRkTTe7L98M+O0UqeF+K84=; b=Drx0CaTkJF1geOkEze4DSvNycAUoPcrlhFwXs+hpsWu/X7kHjofWp90mdXWwiDFvb2GXBoY85KhRSvomyUb+X8tb76Qrfr393BiZOW8fAsIkCt57zCnUPsY24Sc6SQBcvqse7IFwrD/g+idQ71fNui2UP5dODSYyHV4tJc0U1wA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105498+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1685532921708984.4663869403527; Wed, 31 May 2023 04:35:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aESfYY1788612xo9U2nd3VX0; Wed, 31 May 2023 04:35:21 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.11797.1685532914757563483 for ; Wed, 31 May 2023 04:35:15 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="334830269" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="334830269" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 04:34:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="739921513" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="739921513" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by orsmga001.jf.intel.com with ESMTP; 31 May 2023 04:34:54 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Jiaxin Wu , Dandan Bi , Liming Gao , Jian J Wang Subject: [edk2-devel] [PATCH V2 6/6] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Date: Wed, 31 May 2023 19:34:38 +0800 Message-Id: <20230531113438.1797-7-ray.ni@intel.com> In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: 3as099BIxPIuE3dRzzOTIjkAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685532921; bh=V0OnbCvKUvH3vwyLaqegRm+i7qPYNhYaZhGRvrFIPcA=; h=Cc:Date:From:Reply-To:Subject:To; b=V5tS22S7jfnfhztD4VtQ+U95Lwi1kUWl1/nc9qzrDPlw3Nemqfd1froC73NiiGgSoc1 rkdwJzkDiv0DvGPk1UCzkrnEsIBsQCjKpjMaqLLUFQ0l16lVd1WCHvSR/+7+c3aElLYvN XHzaq/0R+KrF0PHW8lU+tq29M9D28NGkgfg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685532923773100003 Content-Type: text/plain; charset="utf-8" Because SMM perf-logging is migrated to non-SMRAM at ReadyToBoot by DxeCorePerformanceLib, the perf-logging after ExitBS is useless and impact the SMI latency at runtime. Hence the SmmCorePerformanceLib is updated to disable perf-logging after ExitBS. Cc: Jiaxin Wu Cc: Dandan Bi Cc: Liming Gao Cc: Jian J Wang Reviewed-by: Jiaxin Wu --- .../SmmCorePerformanceLib.c | 48 ++++++++++++++++++- .../SmmCorePerformanceLib.inf | 3 +- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL= ib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c index 3efe56e056..c566a298dd 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c @@ -16,7 +16,7 @@ =20 SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted= input and do basic validation. =20 -Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -48,6 +48,7 @@ SPIN_LOCK mSmmFpdtLock; PERFORMANCE_PROPERTY mPerformanceProperty; UINT32 mCachedLength =3D 0; UINT32 mBootRecordSize =3D 0; +BOOLEAN mPerformanceMeasurementEnabled; =20 // // Interfaces for SMM PerformanceMeasurement Protocol. @@ -929,6 +930,36 @@ FpdtSmiHandler ( return EFI_SUCCESS; } =20 +/** + This is the Event call back function is triggered in SMM to notify the L= ibrary + the system is entering runtime phase. + + @param[in] Protocol Points to the protocol's unique identifier + @param[in] Interface Points to the interface instance + @param[in] Handle The handle on which the interface was installed + + @retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully + **/ +EFI_STATUS +EFIAPI +SmmCorePerformanceLibExitBootServicesCallback ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + // + // Disable performance measurement after ExitBootServices because + // 1. Performance measurement might impact SMI latency at runtime; + // 2. Performance log is copied to non SMRAM at ReadyToBoot so runtime p= erformance + // log is not useful. + // + mPerformanceMeasurementEnabled =3D FALSE; + + return EFI_SUCCESS; +} + + /** SmmBase2 protocol notify callback function, when SMST and SMM memory ser= vice get initialized this function is callbacked to initialize the Smm Performance Lib @@ -948,6 +979,7 @@ InitializeSmmCorePerformanceLib ( EFI_HANDLE SmiHandle; EFI_STATUS Status; PERFORMANCE_PROPERTY *PerformanceProperty; + VOID *Registration; =20 // // Initialize spin lock @@ -987,6 +1019,16 @@ InitializeSmmCorePerformanceLib ( Status =3D gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, = &mPerformanceProperty); ASSERT_EFI_ERROR (Status); } + + // + // Register callback function for ExitBootServices event. + // + Status =3D gSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + SmmCorePerformanceLibExitBootServicesCallback, + &Registration + ); + ASSERT_EFI_ERROR (Status); } =20 /** @@ -1011,6 +1053,8 @@ SmmCorePerformanceLibConstructor ( EFI_EVENT Event; VOID *Registration; =20 + mPerformanceMeasurementEnabled =3D (BOOLEAN)((PcdGet8 (PcdPerformanceLi= braryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) !=3D= 0); + if (!PerformanceMeasurementEnabled ()) { // // Do not initialize performance infrastructure if not required. @@ -1383,7 +1427,7 @@ PerformanceMeasurementEnabled ( VOID ) { - return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMA= NCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) !=3D 0); + return mPerformanceMeasurementEnabled; } =20 /** diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL= ib.inf b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.i= nf index 9eecc4b58c..9a7e14e80c 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf @@ -8,7 +8,7 @@ # This library is mainly used by SMM Core to start performance logging to= ensure that # SMM Performance and PerformanceEx Protocol are installed at the very be= ginning of SMM phase. # -# Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -58,6 +58,7 @@ =20 [Protocols] gEfiSmmBase2ProtocolGuid ## CONSUMES + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES =20 [Guids] ## PRODUCES ## SystemTable --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105498): https://edk2.groups.io/g/devel/message/105498 Mute This Topic: https://groups.io/mt/99240117/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-