From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=mowjU1RH; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685532914; x=1717068914; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AOsfrW5noIY1P5VYHBCGHn3le3jLUjr9XDjSbsREDYo=; b=mowjU1RHj7ek6NQqDk3bvm9sOYq7pAdmnUmnean0AleZklTWno8hjFK4 l19C6/cBovtGa1SQd77W199qqX4OcD5G6oIz3FrGWAH0c2KjJoyQ5FaIL jZiYS7GiVXQ2mT9kfZnRWewRR5GYtgs8lItinAik/sSnwXjq/v4E79sNF 2D65kJClsZIbnl6svJBDZcGNR3LwucGXDXIC+Xq3wqDxENjhD6lnToxQF k3lcIX0u+Uxek7h9i/rjIF4MyCiyyZRnwgXlX7IpX4nL3mZM1xk5mMete 9sraGzQFHg+vkXpZJD9a/KmUll+oz7/DfMKOILAWKslvW2zcrz7Qz+zxu g==; 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" 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" 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: [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> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230531113438.1797-1-ray.ni@intel.com> References: <20230531113438.1797-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- .../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 @@ =0D SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted= input and do basic validation.=0D =0D -Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -48,6 +48,7 @@ SPIN_LOCK mSmmFpdtLock; PERFORMANCE_PROPERTY mPerformanceProperty;=0D UINT32 mCachedLength =3D 0;=0D UINT32 mBootRecordSize =3D 0;=0D +BOOLEAN mPerformanceMeasurementEnabled;=0D =0D //=0D // Interfaces for SMM PerformanceMeasurement Protocol.=0D @@ -929,6 +930,36 @@ FpdtSmiHandler ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D + This is the Event call back function is triggered in SMM to notify the L= ibrary=0D + the system is entering runtime phase.=0D +=0D + @param[in] Protocol Points to the protocol's unique identifier=0D + @param[in] Interface Points to the interface instance=0D + @param[in] Handle The handle on which the interface was installed=0D +=0D + @retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully=0D + **/=0D +EFI_STATUS=0D +EFIAPI=0D +SmmCorePerformanceLibExitBootServicesCallback (=0D + IN CONST EFI_GUID *Protocol,=0D + IN VOID *Interface,=0D + IN EFI_HANDLE Handle=0D + )=0D +{=0D + //=0D + // Disable performance measurement after ExitBootServices because=0D + // 1. Performance measurement might impact SMI latency at runtime;=0D + // 2. Performance log is copied to non SMRAM at ReadyToBoot so runtime p= erformance=0D + // log is not useful.=0D + //=0D + mPerformanceMeasurementEnabled =3D FALSE;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D /**=0D SmmBase2 protocol notify callback function, when SMST and SMM memory ser= vice get initialized=0D this function is callbacked to initialize the Smm Performance Lib=0D @@ -948,6 +979,7 @@ InitializeSmmCorePerformanceLib ( EFI_HANDLE SmiHandle;=0D EFI_STATUS Status;=0D PERFORMANCE_PROPERTY *PerformanceProperty;=0D + VOID *Registration;=0D =0D //=0D // Initialize spin lock=0D @@ -987,6 +1019,16 @@ InitializeSmmCorePerformanceLib ( Status =3D gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, = &mPerformanceProperty);=0D ASSERT_EFI_ERROR (Status);=0D }=0D +=0D + //=0D + // Register callback function for ExitBootServices event.=0D + //=0D + Status =3D gSmst->SmmRegisterProtocolNotify (=0D + &gEdkiiSmmExitBootServicesProtocolGuid,=0D + SmmCorePerformanceLibExitBootServicesCallback,=0D + &Registration=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D }=0D =0D /**=0D @@ -1011,6 +1053,8 @@ SmmCorePerformanceLibConstructor ( EFI_EVENT Event;=0D VOID *Registration;=0D =0D + mPerformanceMeasurementEnabled =3D (BOOLEAN)((PcdGet8 (PcdPerformanceLi= braryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) !=3D= 0);=0D +=0D if (!PerformanceMeasurementEnabled ()) {=0D //=0D // Do not initialize performance infrastructure if not required.=0D @@ -1383,7 +1427,7 @@ PerformanceMeasurementEnabled ( VOID=0D )=0D {=0D - return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMA= NCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) !=3D 0);=0D + return mPerformanceMeasurementEnabled;=0D }=0D =0D /**=0D 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=0D # SMM Performance and PerformanceEx Protocol are installed at the very be= ginning of SMM phase.=0D #=0D -# Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.
= =0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D ##=0D @@ -58,6 +58,7 @@ =0D [Protocols]=0D gEfiSmmBase2ProtocolGuid ## CONSUMES=0D + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES=0D =0D [Guids]=0D ## PRODUCES ## SystemTable=0D --=20 2.39.1.windows.1