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 <jiaxin.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
.../SmmCorePerformanceLib.c | 48 ++++++++++++++++++-
.../SmmCorePerformanceLib.inf | 3 +-
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.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 @@
SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.
-Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -48,6 +48,7 @@ SPIN_LOCK mSmmFpdtLock;
PERFORMANCE_PROPERTY mPerformanceProperty;
UINT32 mCachedLength = 0;
UINT32 mBootRecordSize = 0;
+BOOLEAN mPerformanceMeasurementEnabled;
//
// Interfaces for SMM PerformanceMeasurement Protocol.
@@ -929,6 +930,36 @@ FpdtSmiHandler (
return EFI_SUCCESS;
}
+/**
+ This is the Event call back function is triggered in SMM to notify the Library
+ 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 performance
+ // log is not useful.
+ //
+ mPerformanceMeasurementEnabled = FALSE;
+
+ return EFI_SUCCESS;
+}
+
+
/**
SmmBase2 protocol notify callback function, when SMST and SMM memory service 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;
//
// Initialize spin lock
@@ -987,6 +1019,16 @@ InitializeSmmCorePerformanceLib (
Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);
ASSERT_EFI_ERROR (Status);
}
+
+ //
+ // Register callback function for ExitBootServices event.
+ //
+ Status = gSmst->SmmRegisterProtocolNotify (
+ &gEdkiiSmmExitBootServicesProtocolGuid,
+ SmmCorePerformanceLibExitBootServicesCallback,
+ &Registration
+ );
+ ASSERT_EFI_ERROR (Status);
}
/**
@@ -1011,6 +1053,8 @@ SmmCorePerformanceLibConstructor (
EFI_EVENT Event;
VOID *Registration;
+ mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
+
if (!PerformanceMeasurementEnabled ()) {
//
// Do not initialize performance infrastructure if not required.
@@ -1383,7 +1427,7 @@ PerformanceMeasurementEnabled (
VOID
)
{
- return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
+ return mPerformanceMeasurementEnabled;
}
/**
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf
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 beginning of SMM phase.
#
-# Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -58,6 +58,7 @@
[Protocols]
gEfiSmmBase2ProtocolGuid ## CONSUMES
+ gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES
[Guids]
## PRODUCES ## SystemTable
--
2.39.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106048): https://edk2.groups.io/g/devel/message/106048
Mute This Topic: https://groups.io/mt/99500188/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Regards,
Jian
> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Tuesday, June 13, 2023 2:13 PM
> To: devel@edk2.groups.io
> Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Gao,
> Liming <gaoliming@byosoft.com.cn>; Wang, Jian J <jian.j.wang@intel.com>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable
> perf-logging at runtime
>
> 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 <jiaxin.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Eric Dong <eric.dong@intel.com>
> ---
> .../SmmCorePerformanceLib.c | 48 ++++++++++++++++++-
> .../SmmCorePerformanceLib.inf | 3 +-
> 2 files changed, 48 insertions(+), 3 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.
> 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 @@
>
>
> SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive
> untrusted input and do basic validation.
>
>
>
> -Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
>
> +Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
> **/
>
> @@ -48,6 +48,7 @@ SPIN_LOCK mSmmFpdtLock;
> PERFORMANCE_PROPERTY mPerformanceProperty;
>
> UINT32 mCachedLength = 0;
>
> UINT32 mBootRecordSize = 0;
>
> +BOOLEAN mPerformanceMeasurementEnabled;
>
>
>
> //
>
> // Interfaces for SMM PerformanceMeasurement Protocol.
>
> @@ -929,6 +930,36 @@ FpdtSmiHandler (
> return EFI_SUCCESS;
>
> }
>
>
>
> +/**
>
> + This is the Event call back function is triggered in SMM to notify the Library
>
> + 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
> performance
>
> + // log is not useful.
>
> + //
>
> + mPerformanceMeasurementEnabled = FALSE;
>
> +
>
> + return EFI_SUCCESS;
>
> +}
>
> +
>
> +
>
> /**
>
> SmmBase2 protocol notify callback function, when SMST and SMM memory
> service 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;
>
>
>
> //
>
> // Initialize spin lock
>
> @@ -987,6 +1019,16 @@ InitializeSmmCorePerformanceLib (
> Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid,
> &mPerformanceProperty);
>
> ASSERT_EFI_ERROR (Status);
>
> }
>
> +
>
> + //
>
> + // Register callback function for ExitBootServices event.
>
> + //
>
> + Status = gSmst->SmmRegisterProtocolNotify (
>
> + &gEdkiiSmmExitBootServicesProtocolGuid,
>
> + SmmCorePerformanceLibExitBootServicesCallback,
>
> + &Registration
>
> + );
>
> + ASSERT_EFI_ERROR (Status);
>
> }
>
>
>
> /**
>
> @@ -1011,6 +1053,8 @@ SmmCorePerformanceLibConstructor (
> EFI_EVENT Event;
>
> VOID *Registration;
>
>
>
> + mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8
> (PcdPerformanceLibraryPropertyMask) &
> PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
>
> +
>
> if (!PerformanceMeasurementEnabled ()) {
>
> //
>
> // Do not initialize performance infrastructure if not required.
>
> @@ -1383,7 +1427,7 @@ PerformanceMeasurementEnabled (
> VOID
>
> )
>
> {
>
> - return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) &
> PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
>
> + return mPerformanceMeasurementEnabled;
>
> }
>
>
>
> /**
>
> diff --git
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.i
> nf
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.i
> nf
> index 9eecc4b58c..9a7e14e80c 100644
> ---
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.i
> nf
> +++
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.i
> nf
> @@ -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
> beginning of SMM phase.
>
> #
>
> -# Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
>
> +# Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
>
> # SPDX-License-Identifier: BSD-2-Clause-Patent
>
> #
>
> ##
>
> @@ -58,6 +58,7 @@
>
>
> [Protocols]
>
> gEfiSmmBase2ProtocolGuid ## CONSUMES
>
> + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES
>
>
>
> [Guids]
>
> ## PRODUCES ## SystemTable
>
> --
> 2.39.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106137): https://edk2.groups.io/g/devel/message/106137
Mute This Topic: https://groups.io/mt/99500188/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Ray:
After ExitBS, you can update CreatePerformanceMeasurement() API directly
returns EFI_UNSUPPORTED. Then, no PERF record will be handled. With this
change, you don't need to update SmmPerformanceLib.
Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Ni, Ray
> 发送时间: 2023年6月13日 14:13
> 收件人: devel@edk2.groups.io
> 抄送: Jiaxin Wu <jiaxin.wu@intel.com>; Dandan Bi <dandan.bi@intel.com>;
> Liming Gao <gaoliming@byosoft.com.cn>; Jian J Wang
> <jian.j.wang@intel.com>; Eric Dong <eric.dong@intel.com>
> 主题: [edk2-devel] [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib:
> Disable perf-logging at runtime
>
> 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 <jiaxin.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Eric Dong <eric.dong@intel.com>
> ---
> .../SmmCorePerformanceLib.c | 48
> ++++++++++++++++++-
> .../SmmCorePerformanceLib.inf | 3 +-
> 2 files changed, 48 insertions(+), 3 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.c
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.c
> index 3efe56e056..c566a298dd 100644
> ---
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.c
> +++
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.c
> @@ -16,7 +16,7 @@
>
>
> SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive
> untrusted input and do basic validation.
>
>
>
> -Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
>
> +Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
> **/
>
> @@ -48,6 +48,7 @@ SPIN_LOCK mSmmFpdtLock;
> PERFORMANCE_PROPERTY mPerformanceProperty;
>
> UINT32 mCachedLength = 0;
>
> UINT32 mBootRecordSize = 0;
>
> +BOOLEAN mPerformanceMeasurementEnabled;
>
>
>
> //
>
> // Interfaces for SMM PerformanceMeasurement Protocol.
>
> @@ -929,6 +930,36 @@ FpdtSmiHandler (
> return EFI_SUCCESS;
>
> }
>
>
>
> +/**
>
> + This is the Event call back function is triggered in SMM to notify the
> Library
>
> + 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
> performance
>
> + // log is not useful.
>
> + //
>
> + mPerformanceMeasurementEnabled = FALSE;
>
> +
>
> + return EFI_SUCCESS;
>
> +}
>
> +
>
> +
>
> /**
>
> SmmBase2 protocol notify callback function, when SMST and SMM
> memory service 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;
>
>
>
> //
>
> // Initialize spin lock
>
> @@ -987,6 +1019,16 @@ InitializeSmmCorePerformanceLib (
> Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid,
> &mPerformanceProperty);
>
> ASSERT_EFI_ERROR (Status);
>
> }
>
> +
>
> + //
>
> + // Register callback function for ExitBootServices event.
>
> + //
>
> + Status = gSmst->SmmRegisterProtocolNotify (
>
> + &gEdkiiSmmExitBootServicesProtocolGuid,
>
> + SmmCorePerformanceLibExitBootServicesCallback,
>
> + &Registration
>
> + );
>
> + ASSERT_EFI_ERROR (Status);
>
> }
>
>
>
> /**
>
> @@ -1011,6 +1053,8 @@ SmmCorePerformanceLibConstructor (
> EFI_EVENT Event;
>
> VOID *Registration;
>
>
>
> + mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8
> (PcdPerformanceLibraryPropertyMask) &
> PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
>
> +
>
> if (!PerformanceMeasurementEnabled ()) {
>
> //
>
> // Do not initialize performance infrastructure if not required.
>
> @@ -1383,7 +1427,7 @@ PerformanceMeasurementEnabled (
> VOID
>
> )
>
> {
>
> - return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) &
> PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
>
> + return mPerformanceMeasurementEnabled;
>
> }
>
>
>
> /**
>
> diff --git
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.inf
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.inf
> index 9eecc4b58c..9a7e14e80c 100644
> ---
> a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.inf
> +++
> b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLi
> b.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
> beginning of SMM phase.
>
> #
>
> -# Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>
>
> +# Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
>
> # SPDX-License-Identifier: BSD-2-Clause-Patent
>
> #
>
> ##
>
> @@ -58,6 +58,7 @@
>
>
> [Protocols]
>
> gEfiSmmBase2ProtocolGuid ## CONSUMES
>
> + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES
>
>
>
> [Guids]
>
> ## PRODUCES ## SystemTable
>
> --
> 2.39.1.windows.1
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#106048):
> https://edk2.groups.io/g/devel/message/106048
> Mute This Topic: https://groups.io/mt/99500188/4905953
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe:
> https://edk2.groups.io/g/devel/leave/8761045/4905953/397992573/xyzzy
> [gaoliming@byosoft.com.cn]
> -=-=-=-=-=-=
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106200): https://edk2.groups.io/g/devel/message/106200
Mute This Topic: https://groups.io/mt/99640931/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.