MdeModulePkg: Add Standalone MM perf library support

Adds a new library instance to support logging performance data in
Standalone MM.

- Add StandaloneMmPerformanceLib instance
- Move common MM logic to a new file `SmmPerformanceLibInternal.c`
- Since the library largely defers most logic to the performance
  measurement protocol a large degree of code can be shared between
  Standalone MM and Traditional MM.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
This commit is contained in:
Michael Kubacki
2025-03-21 15:23:11 +00:00
committed by mergify[bot]
parent 11b44c5cd1
commit 1c51a268b7
8 changed files with 725 additions and 488 deletions
File diff suppressed because it is too large Load Diff
@@ -7,6 +7,7 @@
# it does not log any performance information.
#
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -30,6 +31,8 @@
#
[Sources]
SmmPerformanceLibInternal.h
SmmPerformanceLibInternal.c
SmmPerformanceLib.c
@@ -40,7 +43,7 @@
[LibraryClasses]
PcdLib
SmmServicesTableLib
MmServicesTableLib
DebugLib
BaseMemoryLib
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,56 @@
/** @file
Internal library header.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef SMM_CORE_PERFORMANCE_LIB_INTERNAL_H_
#define SMM_CORE_PERFORMANCE_LIB_INTERNAL_H_
/**
Registers a callback to perform library actions needed at exit boot services.
@param[in] ExitBootServicesProtocolGuid The protocol GUID to register the callback for.
@retval EFI_SUCCESS The callback was registered successfully.
@retval Others An error occurred registering the callback.
**/
EFI_STATUS
RegisterExitBootServicesCallback (
IN CONST EFI_GUID *ExitBootServicesProtocolGuid
);
/**
Unregisters a callback to perform library actions needed at exit boot services.
@param[in] ExitBootServicesProtocolGuid The protocol GUID to unregister the callback for.
@retval EFI_SUCCESS The callback was unregistered successfully.
@retval Others An error occurred unregistering the callback.
**/
EFI_STATUS
UnregisterExitBootServicesCallback (
IN CONST EFI_GUID *ExitBootServicesProtocolGuid
);
/**
This is the Event call back function is triggered in MM 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
SmmPerformanceLibExitBootServicesCallback (
IN CONST EFI_GUID *Protocol,
IN VOID *Interface,
IN EFI_HANDLE Handle
);
#endif // SMM_CORE_PERFORMANCE_LIB_INTERNAL_H_
@@ -0,0 +1,55 @@
/** @file
Performance Library used in Standalone MM phase.
This library instance provides infrastructure for Standalone MM drivers to log performance
data. It consumes the MM PerformanceEx or Performance Protocol to log performance data. If
both MM PerformanceEx and Performance Protocol are not available, it does not log any
performance information.
Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiMm.h>
#include <Guid/EventGroup.h>
#include "SmmPerformanceLibInternal.h"
/**
The constructor function initializes the Performance Measurement Enable flag.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] MmSystemTable A pointer to the MM System Table.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
StandaloneMmPerformanceLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
return RegisterExitBootServicesCallback (&gEfiEventExitBootServicesGuid);
}
/**
The destructor function frees resources allocated by constructor.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] MmSystemTable A pointer to the MM System Table.
@retval EFI_SUCCESS The destructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
StandaloneMmPerformanceLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
return UnregisterExitBootServicesCallback (&gEfiEventExitBootServicesGuid);
}
@@ -0,0 +1,48 @@
## @file
# Performance library instance used in Standalone MM phase.
#
# This library instance provides infrastructure for Standalone MM drivers to log performance
# data. It consumes the MM PerformanceEx or Performance Protocol to log performance data. If
# both MM PerformanceEx and Performance Protocol are not available, it does not log any
# performance information.
#
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
# Copyright Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x0001001B
BASE_NAME = StandaloneMmPerformanceLib
MODULE_UNI_FILE = StandaloneMmPerformanceLib.uni
FILE_GUID = 7E7415FC-0BFB-47B4-B1C8-66149CC9050C
MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
PI_SPECIFICATION_VERSION = 0x00010032
LIBRARY_CLASS = PerformanceLib|MM_STANDALONE
CONSTRUCTOR = StandaloneMmPerformanceLibConstructor
DESTRUCTOR = StandaloneMmPerformanceLibDestructor
[Sources]
SmmPerformanceLibInternal.h
SmmPerformanceLibInternal.c
StandaloneMmPerformanceLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
PcdLib
MmServicesTableLib
DebugLib
BaseMemoryLib
[Guids]
gEdkiiSmmPerformanceMeasurementProtocolGuid ## SOMETIMES_CONSUMES ## UNDEFINED # Locate protocol
gEfiEventExitBootServicesGuid ## CONSUMES
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask ## CONSUMES
@@ -0,0 +1,20 @@
// /** @file
// Performance library instance used in Standalone MM phase.
//
// This library instance provides infrastructure for Standalone MM drivers to log performance
// data. It consumes the MM PerformanceEx or Performance Protocol to log performance data. If
// both MM PerformanceEx and Performance Protocol are not available, it does not log any
// performance information.
//
// Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
// Copyright Microsoft Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Performance library instance used in the Standalone MM phase"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides infrastructure for Standalone MM drivers to log performance data. It consumes the Standalone MM PerformanceEx or Performance Protocol to log performance data. If both Standalone MM PerformanceEx and Performance Protocol are not available, it does not log any performance information."
+1
View File
@@ -505,6 +505,7 @@
MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf
MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.inf
MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf
MdeModulePkg/Library/SmmPerformanceLib/StandaloneMmPerformanceLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf