* [PATCH V3 0/8] Enable SMM perf-logging
@ 2023-06-13 6:13 Ni, Ray
2023-06-13 6:13 ` [PATCH V3 1/8] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures Ni, Ray
` (7 more replies)
0 siblings, 8 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel
To avoid impacting runtime performance, the perf-logging is
disabled upon ExitBootServices.
Ray Ni (8):
UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures
UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures
MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures
MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler
MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS
MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime
UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging
MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch
MdeModulePkg/Core/PiSmmCore/Dispatcher.c | 5 +-
MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 19 +++-
MdeModulePkg/Core/PiSmmCore/Smi.c | 6 ++
.../SmmCorePerformanceLib.c | 48 ++++++++-
.../SmmCorePerformanceLib.inf | 3 +-
.../SmmPerformanceLib/SmmPerformanceLib.c | 63 ++++++++++-
.../SmmPerformanceLib/SmmPerformanceLib.inf | 4 +
UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 42 +++++++-
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 38 +++++++
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 +
.../PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 13 ++-
UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c | 100 ++++++++++++++++++
UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 83 +++++++++++++++
UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 4 +-
UefiCpuPkg/UefiCpuPkg.dec | 6 ++
16 files changed, 429 insertions(+), 11 deletions(-)
create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
--
2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH V3 1/8] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-13 6:13 ` [PATCH V3 2/8] UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures Ni, Ray
` (6 subsequent siblings)
7 siblings, 0 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Rahul Kumar, Gerd Hoffmann, Jiaxin Wu, Eric Dong
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: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
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/PiSmmCpuDxeSmm/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;
+ PERF_FUNCTION_BEGIN ();
+
DelayedCount = 0;
BlockedCount = 0;
@@ -439,7 +441,7 @@ SmmWaitForApArrival (
DEBUG ((DEBUG_INFO, "SmmWaitForApArrival: Delayed AP Count = %d, Blocked AP Count = %d\n", DelayedCount, BlockedCount));
}
- return;
+ PERF_FUNCTION_END ();
}
/**
@@ -577,6 +579,8 @@ BSPHandler (
ASSERT (CpuIndex == mSmmMpSyncData->BspIndex);
ApCount = 0;
+ PERF_FUNCTION_BEGIN ();
+
//
// Flag BSP's presence
//
@@ -792,6 +796,8 @@ BSPHandler (
*mSmmMpSyncData->Counter = 0;
*mSmmMpSyncData->AllCpusInSync = FALSE;
mSmmMpSyncData->AllApArrivedWithException = FALSE;
+
+ PERF_FUNCTION_END ();
}
/**
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index 2144d6ade8..32ca417f73 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -410,12 +410,15 @@ ExecuteFirstSmiInit (
{
UINTN Index;
+ PERF_FUNCTION_BEGIN ();
+
if (mSmmInitialized == NULL) {
mSmmInitialized = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * mMaxNumberOfCpus);
}
ASSERT (mSmmInitialized != NULL);
if (mSmmInitialized == NULL) {
+ PERF_FUNCTION_END ();
return;
}
@@ -442,6 +445,8 @@ ExecuteFirstSmiInit (
while (!(BOOLEAN)mSmmInitialized[Index]) {
}
}
+
+ PERF_FUNCTION_END ();
}
/**
@@ -463,6 +468,8 @@ SmmRelocateBases (
UINTN Index;
UINTN BspIndex;
+ PERF_FUNCTION_BEGIN ();
+
//
// Make sure the reserved size is large enough for procedure SmmInitTemplate.
//
@@ -540,6 +547,7 @@ SmmRelocateBases (
//
CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2));
CopyMem (U8Ptr, BakBuf, sizeof (BakBuf));
+ PERF_FUNCTION_END ();
}
/**
@@ -617,6 +625,8 @@ PiCpuSmmEntry (
GuidHob = NULL;
SmmBaseHobData = NULL;
+ PERF_FUNCTION_BEGIN ();
+
//
// Initialize address fixup
//
@@ -1194,6 +1204,7 @@ PiCpuSmmEntry (
DEBUG ((DEBUG_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n"));
+ PERF_FUNCTION_END ();
return EFI_SUCCESS;
}
@@ -1348,12 +1359,15 @@ ConfigSmmCodeAccessCheck (
UINTN Index;
EFI_STATUS Status;
+ PERF_FUNCTION_BEGIN ();
+
//
// Check to see if the Feature Control MSR is supported on this CPU
//
Index = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu;
if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl)) {
mSmmCodeAccessCheckEnable = FALSE;
+ PERF_FUNCTION_END ();
return;
}
@@ -1363,6 +1377,7 @@ ConfigSmmCodeAccessCheck (
//
if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) == 0) {
mSmmCodeAccessCheckEnable = FALSE;
+ PERF_FUNCTION_END ();
return;
}
@@ -1419,6 +1434,8 @@ ConfigSmmCodeAccessCheck (
ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);
}
}
+
+ PERF_FUNCTION_END ();
}
/**
@@ -1540,6 +1557,8 @@ PerformRemainingTasks (
)
{
if (mSmmReadyToLock) {
+ PERF_FUNCTION_BEGIN ();
+
//
// Check if all Aps enter SMM. In Relaxed-AP Sync Mode, BSP will not wait for
// all Aps arrive. However,PerformRemainingTasks() needs to wait all Aps arrive before calling
@@ -1587,12 +1606,20 @@ PerformRemainingTasks (
//
ConfigSmmCodeAccessCheck ();
+ //
+ // 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);
//
// Clean SMM ready to lock flag
//
mSmmReadyToLock = FALSE;
+
+ PERF_FUNCTION_END ();
}
}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/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 <Library/SmmCpuFeaturesLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/RegisterCpuFeaturesLib.h>
+#include <Library/PerformanceLib.h>
#include <AcpiCpuData.h>
#include <CpuHotPlugData.h>
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
index 158e05e264..af66a1941c 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -97,6 +97,7 @@
ReportStatusCodeLib
SmmCpuFeaturesLib
PeCoffGetEntryPointLib
+ PerformanceLib
[Protocols]
gEfiSmmAccess2ProtocolGuid ## CONSUMES
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
index 834a756061..8b21e16f1c 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
@@ -1,6 +1,6 @@
/** @file
-Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -1100,6 +1100,8 @@ SetMemMapAttributes (
return;
}
+ PERF_FUNCTION_BEGIN ();
+
DEBUG ((DEBUG_INFO, "MemoryAttributesTable:\n"));
DEBUG ((DEBUG_INFO, " Version - 0x%08x\n", MemoryAttributesTable->Version));
DEBUG ((DEBUG_INFO, " NumberOfEntries - 0x%08x\n", MemoryAttributesTable->NumberOfEntries));
@@ -1152,7 +1154,7 @@ SetMemMapAttributes (
PatchSmmSaveStateMap ();
PatchGdtIdtMap ();
- return;
+ PERF_FUNCTION_END ();
}
/**
@@ -1454,6 +1456,8 @@ SetUefiMemMapAttributes (
UINTN Index;
EFI_MEMORY_DESCRIPTOR *Entry;
+ PERF_FUNCTION_BEGIN ();
+
DEBUG ((DEBUG_INFO, "SetUefiMemMapAttributes\n"));
if (mUefiMemoryMap != NULL) {
@@ -1537,6 +1541,8 @@ SetUefiMemMapAttributes (
//
// Do not free mUefiMemoryAttributesTable, it will be checked in IsSmmCommBufferForbiddenAddress().
//
+
+ PERF_FUNCTION_END ();
}
/**
@@ -1862,6 +1868,7 @@ SetPageTableAttributes (
return;
}
+ PERF_FUNCTION_BEGIN ();
DEBUG ((DEBUG_INFO, "SetPageTableAttributes\n"));
//
@@ -1900,5 +1907,5 @@ SetPageTableAttributes (
EnableCet ();
}
- return;
+ PERF_FUNCTION_END ();
}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/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;
+ PERF_FUNCTION_BEGIN ();
+
Cr4.UintN = AsmReadCr4 ();
Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
@@ -810,7 +812,7 @@ InitPaging (
//
mXdEnabled = TRUE;
- return;
+ PERF_FUNCTION_END ();
}
/**
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 2/8] UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
2023-06-13 6:13 ` [PATCH V3 1/8] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-13 6:13 ` [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures Ni, Ray
` (5 subsequent siblings)
7 siblings, 0 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Eric Dong, Rahul Kumar, Gerd Hoffmann, Jiaxin Wu
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 <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
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 | 81 +++++++++++++++++
6 files changed, 220 insertions(+)
create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index fa666bd118..bcd90f0671 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -778,6 +778,15 @@ BSPHandler (
//
WaitForAllAPs (ApCount);
+ //
+ // At this point, all APs should have exited from APHandler().
+ // Migrate the SMM MP performance logging to standard SMM performance logging.
+ // Any SMM MP performance logging after this point will be migrated in next 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));
+ );
//
// Determine if this is a valid SMI
//
+ PERF_CODE (
+ MpPerfBegin (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (PlatformValidSmi));
+ );
ValidSmi = PlatformValidSmi ();
+ PERF_CODE (
+ MpPerfEnd (CpuIndex, SMM_MP_PERF_PROCEDURE_ID (PlatformValidSmi));
+ );
//
// Determine if BSP has been already in progress. Note this must be checked after
@@ -1904,7 +1925,20 @@ SmiRendezvous (
}
Exit:
+ //
+ // Note: SmmRendezvousExit perf-logging entry is the only one that will be
+ // migrated to standard perf-logging database in next SMI by BSPHandler().
+ // Hence, the number of SmmRendezvousEntry entries will be larger than
+ // the number of SmmRendezvousExit entries. Delta equals to the number
+ // 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));
+ );
//
// Restore Cr2
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index 32ca417f73..7a3ed3022d 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -362,6 +362,9 @@ SmmInitHandler (
for (Index = 0; Index < mNumberOfCpus; Index++) {
if (ApicId == (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId) {
+ 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]);
}
+ PERF_CODE (
+ MpPerfEnd (Index, SMM_MP_PERF_PROCEDURE_ID (SmmInitHandler));
+ );
+
return;
}
}
@@ -699,6 +706,10 @@ PiCpuSmmEntry (
gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus = mMaxNumberOfCpus;
+ 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/PiSmmCpuDxeSmm/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
#include "CpuService.h"
#include "SmmProfile.h"
+#include "SmmMpPerf.h"
//
// CET definition
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/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
[Sources.Ia32]
Ia32/Semaphore.c
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c b/UefiCpuPkg/PiSmmCpuDxeSmm/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.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "PiSmmCpuDxeSmm.h"
+
+
+#define SMM_MP_PERF_PROCEDURE_NAME(procedure) # procedure
+GLOBAL_REMOVE_IF_UNREFERENCED
+CHAR8 *gSmmMpPerfProcedureName[] = {
+ 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 = NULL;
+
+/**
+ Initialize the perf-logging feature for APs.
+
+ @param NumberofCpus Number of processors in the platform.
+**/
+VOID
+InitializeMpPerf (
+ UINTN NumberofCpus
+ )
+{
+ mSmmMpProcedurePerformance = AllocateZeroPool (NumberofCpus * sizeof (*mSmmMpProcedurePerformance));
+ ASSERT (mSmmMpProcedurePerformance != 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 = 0; CpuIndex < NumberofCpus; CpuIndex++) {
+ for (MpProcecureId = 0; MpProcecureId < SMM_MP_PERF_PROCEDURE_ID (SmmMpProcedureMax); MpProcecureId++) {
+ if (mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId] != 0) {
+ PERF_START (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId]);
+ PERF_END (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmmMpProcedurePerformance[CpuIndex].End[MpProcecureId]);
+ }
+ }
+ }
+
+ ZeroMem (mSmmMpProcedurePerformance, NumberofCpus * sizeof (*mSmmMpProcedurePerformance));
+}
+
+/**
+ 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] = GetPerformanceCounter ();
+}
+
+/**
+ 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] = GetPerformanceCounter ();
+}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
new file mode 100644
index 0000000000..eeafb242f9
--- /dev/null
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
@@ -0,0 +1,81 @@
+/** @file
+SMM MP perf-logging implementation
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+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
+
+//
+// To perf-log MP procedures, call MpPerfBegin()/MpPerfEnd() with CpuIndex
+// and SMM_MP_PERF_PROCEDURE_ID with entry name defined in the SMM_MP_PERF_PROCEDURE_LIST.
+//
+#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
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
2023-06-13 6:13 ` [PATCH V3 1/8] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures Ni, Ray
2023-06-13 6:13 ` [PATCH V3 2/8] UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-16 3:19 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler Ni, Ray
` (4 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Liming Gao, Jiaxin Wu, Eric Dong
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 <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 15 ++++++++++++++-
MdeModulePkg/Core/PiSmmCore/Smi.c | 6 ++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index 875c7c0258..68af9ab81b 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -1,7 +1,7 @@
/** @file
SMM Core Main Entry Point
- Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -305,6 +305,8 @@ SmmReadyToBootHandler (
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
+ PERF_CALLBACK_BEGIN (&gEfiEventReadyToBootGuid);
+
//
// Install SMM Ready To Boot protocol.
//
@@ -318,6 +320,7 @@ SmmReadyToBootHandler (
SmiHandlerUnRegister (DispatchHandle);
+ PERF_CALLBACK_END (&gEfiEventReadyToBootGuid);
return Status;
}
@@ -352,6 +355,8 @@ SmmReadyToLockHandler (
EFI_HANDLE SmmHandle;
VOID *Interface;
+ PERF_CALLBACK_BEGIN (&gEfiDxeSmmReadyToLockProtocolGuid);
+
//
// Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
//
@@ -408,6 +413,7 @@ SmmReadyToLockHandler (
SmramProfileReadyToLock ();
+ PERF_CALLBACK_END (&gEfiDxeSmmReadyToLockProtocolGuid);
return Status;
}
@@ -442,6 +448,8 @@ SmmEndOfDxeHandler (
DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n"));
+ PERF_CALLBACK_BEGIN (&gEfiEndOfDxeEventGroupGuid);
+
//
// Install SMM EndOfDxe protocol
//
@@ -479,6 +487,7 @@ SmmEndOfDxeHandler (
}
}
+ PERF_CALLBACK_END (&gEfiEndOfDxeEventGroupGuid);
return EFI_SUCCESS;
}
@@ -669,6 +678,8 @@ SmmEntryPoint (
VOID *CommunicationBuffer;
UINTN BufferSize;
+ PERF_FUNCTION_BEGIN ();
+
//
// Update SMST with contents of the SmmEntryContext structure
//
@@ -769,6 +780,8 @@ SmmEntryPoint (
//
gSmmCorePrivate->InSmm = FALSE;
}
+
+ PERF_FUNCTION_END ();
}
/**
diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmCore/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;
+ PERF_FUNCTION_BEGIN ();
+
Status = EFI_NOT_FOUND;
SuccessReturn = FALSE;
if (HandlerType == 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_PENDING will be returned.
//
if (HandlerType != NULL) {
+ PERF_FUNCTION_END ();
return EFI_INTERRUPT_PENDING;
}
@@ -160,6 +164,7 @@ SmiManage (
// additional handlers will be processed.
//
if (HandlerType != NULL) {
+ PERF_FUNCTION_END ();
return EFI_SUCCESS;
}
@@ -194,6 +199,7 @@ SmiManage (
Status = EFI_SUCCESS;
}
+ PERF_FUNCTION_END ();
return Status;
}
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
` (2 preceding siblings ...)
2023-06-13 6:13 ` [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-16 3:19 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS Ni, Ray
` (3 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Liming Gao, Jiaxin Wu, Eric Dong
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 <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
MdeModulePkg/Core/PiSmmCore/Dispatcher.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/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.
Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -1322,6 +1322,8 @@ SmmDriverDispatchHandler (
return EFI_NOT_FOUND;
}
+ PERF_CALLBACK_BEGIN (&gEfiEventDxeDispatchGuid);
+
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
FvHandle = HandleBuffer[HandleIndex];
@@ -1511,6 +1513,7 @@ SmmDriverDispatchHandler (
}
}
+ PERF_CALLBACK_END (&gEfiEventDxeDispatchGuid);
return EFI_SUCCESS;
}
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
` (3 preceding siblings ...)
2023-06-13 6:13 ` [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-16 3:27 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Ni, Ray
` (2 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Jiaxin Wu, Dandan Bi, Liming Gao, Jian J Wang, Eric Dong
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 <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>
---
.../SmmPerformanceLib/SmmPerformanceLib.c | 63 ++++++++++++++++++-
.../SmmPerformanceLib/SmmPerformanceLib.inf | 4 ++
2 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c b/MdeModulePkg/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 interface.
EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *mPerformanceMeasurement = NULL;
BOOLEAN mPerformanceMeasurementEnabled;
+VOID *mPerformanceLibExitBootServicesRegistration;
+
+/**
+ 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
+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 performance
+ // log is not useful.
+ //
+ mPerformanceMeasurementEnabled = FALSE;
+
+ return EFI_SUCCESS;
+}
/**
The constructor function initializes the Performance Measurement Enable flag
@@ -40,9 +70,40 @@ SmmPerformanceLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
+ EFI_STATUS Status;
+
mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
- return EFI_SUCCESS;
+ Status = 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 = gSmst->SmmRegisterProtocolNotify (
+ &gEdkiiSmmExitBootServicesProtocolGuid,
+ NULL,
+ &mPerformanceLibExitBootServicesRegistration
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
}
/**
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 = PerformanceLib|DXE_SMM_DRIVER
CONSTRUCTOR = SmmPerformanceLibConstructor
+ DESTRUCTOR = SmmPerformanceLibDestructor
#
# The following information is for reference only and not required by the build tools.
@@ -46,5 +47,8 @@
[Guids]
gEdkiiSmmPerformanceMeasurementProtocolGuid ## SOMETIMES_CONSUMES ## UNDEFINED # Locate protocol
+[Protocols]
+ gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES
+
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask ## CONSUMES
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
` (4 preceding siblings ...)
2023-06-13 6:13 ` [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-16 3:28 ` Wang, Jian J
2023-06-20 9:34 ` 回复: [edk2-devel] " gaoliming
2023-06-13 6:13 ` [PATCH V3 7/8] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging Ni, Ray
2023-06-13 6:13 ` [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch Ni, Ray
7 siblings, 2 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Jiaxin Wu, Dandan Bi, Liming Gao, Jian J Wang, Eric Dong
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
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 7/8] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
` (5 preceding siblings ...)
2023-06-13 6:13 ` [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-13 6:13 ` [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch Ni, Ray
7 siblings, 0 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Eric Dong, Rahul Kumar, Gerd Hoffmann, Jiaxin Wu
When a platform has lots of CPU cores/threads, perf-logging on every
AP produces lots of records. When this multiplies with number of SMIs
during post, the records are even more.
So, this patch adds a new PCD PcdSmmApPerfLogEnable (default TRUE)
to allow platform to turn off perf-logging on APs.
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
---
UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 2 +-
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 +
UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c | 11 ++++++++++-
UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 4 +++-
UefiCpuPkg/UefiCpuPkg.dec | 6 ++++++
5 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index bcd90f0671..8364b73242 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -784,7 +784,7 @@ BSPHandler (
// Any SMM MP performance logging after this point will be migrated in next SMI.
//
PERF_CODE (
- MigrateMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus);
+ MigrateMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus, CpuIndex);
);
//
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
index 4864532c35..d864ae9101 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -128,6 +128,7 @@
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmProfileRingBuffer ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmFeatureControlMsrLock ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES
+ gUefiCpuPkgTokenSpaceGuid.PcdSmmApPerfLogEnable ## CONSUMES
[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## SOMETIMES_CONSUMES
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
index c13556af46..92c67f31bf 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
@@ -39,16 +39,25 @@ InitializeMpPerf (
Migrate MP performance data to standardized performance database.
@param NumberofCpus Number of processors in the platform.
+ @param BspIndex The index of the BSP.
**/
VOID
MigrateMpPerf (
- UINTN NumberofCpus
+ UINTN NumberofCpus,
+ UINTN BspIndex
)
{
UINTN CpuIndex;
UINTN MpProcecureId;
for (CpuIndex = 0; CpuIndex < NumberofCpus; CpuIndex++) {
+ if ((CpuIndex != BspIndex) && !FeaturePcdGet (PcdSmmApPerfLogEnable)) {
+ //
+ // Skip migrating AP performance data if AP perf-logging is disabled.
+ //
+ continue;
+ }
+
for (MpProcecureId = 0; MpProcecureId < SMM_MP_PERF_PROCEDURE_ID (SmmMpProcedureMax); MpProcecureId++) {
if (mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId] != 0) {
PERF_START (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId]);
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
index eeafb242f9..3bd594c36f 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
@@ -48,10 +48,12 @@ InitializeMpPerf (
Migrate MP performance data to standardized performance database.
@param NumberofCpus Number of processors in the platform.
+ @param BspIndex The index of the BSP.
**/
VOID
MigrateMpPerf (
- UINTN NumberofCpus
+ UINTN NumberofCpus,
+ UINTN BspIndex
);
/**
diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index d31c3b127c..5b0ac64e33 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -175,6 +175,12 @@
# @Prompt Support SmmFeatureControl.
gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable|TRUE|BOOLEAN|0x32132110
+ ## Indicates if SMM perf logging in APs will be enabled.<BR><BR>
+ # TRUE - SMM perf logging in APs will be enabled.<BR>
+ # FALSE - SMM perf logging in APs will not be enabled.<BR>
+ # @Prompt Enable SMM perf logging in APs.
+ gUefiCpuPkgTokenSpaceGuid.PcdSmmApPerfLogEnable|TRUE|BOOLEAN|0x32132114
+
[PcdsFixedAtBuild]
## List of exception vectors which need switching stack.
# This PCD will only take into effect if PcdCpuStackGuard is enabled.
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
` (6 preceding siblings ...)
2023-06-13 6:13 ` [PATCH V3 7/8] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging Ni, Ray
@ 2023-06-13 6:13 ` Ni, Ray
2023-06-13 8:44 ` Wu, Jiaxin
2023-06-16 3:29 ` Wang, Jian J
7 siblings, 2 replies; 16+ messages in thread
From: Ni, Ray @ 2023-06-13 6:13 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Liming Gao, Jiaxin Wu
Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
---
MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index 68af9ab81b..a8537829e3 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -692,7 +692,9 @@ SmmEntryPoint (
//
// Call platform hook before Smm Dispatch
//
+ PERF_START (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0, 0);
PlatformHookBeforeSmmDispatch ();
+ PERF_END (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
//
// Call memory management hook function
@@ -769,7 +771,9 @@ SmmEntryPoint (
//
// Call platform hook after Smm Dispatch
//
+ PERF_START (NULL, "PlatformHookAfterSmmDispatch", NULL, 0, 0);
PlatformHookAfterSmmDispatch ();
+ PERF_END (NULL, "PlatformHookAfterSmmDispatch", NULL, 0)
//
// If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
--
2.39.1.windows.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch
2023-06-13 6:13 ` [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch Ni, Ray
@ 2023-06-13 8:44 ` Wu, Jiaxin
2023-06-16 3:29 ` Wang, Jian J
1 sibling, 0 replies; 16+ messages in thread
From: Wu, Jiaxin @ 2023-06-13 8:44 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io; +Cc: Wang, Jian J, Gao, Liming
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Tuesday, June 13, 2023 2:13 PM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log
> PlatformHookBefore/AfterSmmDispatch
>
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> ---
> MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> index 68af9ab81b..a8537829e3 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> @@ -692,7 +692,9 @@ SmmEntryPoint (
> //
>
> // Call platform hook before Smm Dispatch
>
> //
>
> + PERF_START (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0, 0);
>
> PlatformHookBeforeSmmDispatch ();
>
> + PERF_END (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
>
>
>
> //
>
> // Call memory management hook function
>
> @@ -769,7 +771,9 @@ SmmEntryPoint (
> //
>
> // Call platform hook after Smm Dispatch
>
> //
>
> + PERF_START (NULL, "PlatformHookAfterSmmDispatch", NULL, 0, 0);
>
> PlatformHookAfterSmmDispatch ();
>
> + PERF_END (NULL, "PlatformHookAfterSmmDispatch", NULL, 0)
>
>
>
> //
>
> // If a legacy boot has occurred, then make sure gSmmCorePrivate is not
> accessed
>
> --
> 2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures
2023-06-13 6:13 ` [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures Ni, Ray
@ 2023-06-16 3:19 ` Wang, Jian J
0 siblings, 0 replies; 16+ messages in thread
From: Wang, Jian J @ 2023-06-16 3:19 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io; +Cc: Gao, Liming, Wu, Jiaxin, Dong, Eric
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: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Jiaxin <jiaxin.wu@intel.com>; Dong, Eric
> <eric.dong@intel.com>
> Subject: [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-
> consuming procedures
>
> 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 <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Eric Dong <eric.dong@intel.com>
> ---
> MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 15 ++++++++++++++-
> MdeModulePkg/Core/PiSmmCore/Smi.c | 6 ++++++
> 2 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> index 875c7c0258..68af9ab81b 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> @@ -1,7 +1,7 @@
> /** @file
>
> SMM Core Main Entry Point
>
>
>
> - Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
>
> + Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
> **/
>
> @@ -305,6 +305,8 @@ SmmReadyToBootHandler (
> EFI_STATUS Status;
>
> EFI_HANDLE SmmHandle;
>
>
>
> + PERF_CALLBACK_BEGIN (&gEfiEventReadyToBootGuid);
>
> +
>
> //
>
> // Install SMM Ready To Boot protocol.
>
> //
>
> @@ -318,6 +320,7 @@ SmmReadyToBootHandler (
>
>
> SmiHandlerUnRegister (DispatchHandle);
>
>
>
> + PERF_CALLBACK_END (&gEfiEventReadyToBootGuid);
>
> return Status;
>
> }
>
>
>
> @@ -352,6 +355,8 @@ SmmReadyToLockHandler (
> EFI_HANDLE SmmHandle;
>
> VOID *Interface;
>
>
>
> + PERF_CALLBACK_BEGIN (&gEfiDxeSmmReadyToLockProtocolGuid);
>
> +
>
> //
>
> // Unregister SMI Handlers that are no required after the SMM driver dispatch
> is stopped
>
> //
>
> @@ -408,6 +413,7 @@ SmmReadyToLockHandler (
>
>
> SmramProfileReadyToLock ();
>
>
>
> + PERF_CALLBACK_END (&gEfiDxeSmmReadyToLockProtocolGuid);
>
> return Status;
>
> }
>
>
>
> @@ -442,6 +448,8 @@ SmmEndOfDxeHandler (
>
>
> DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n"));
>
>
>
> + PERF_CALLBACK_BEGIN (&gEfiEndOfDxeEventGroupGuid);
>
> +
>
> //
>
> // Install SMM EndOfDxe protocol
>
> //
>
> @@ -479,6 +487,7 @@ SmmEndOfDxeHandler (
> }
>
> }
>
>
>
> + PERF_CALLBACK_END (&gEfiEndOfDxeEventGroupGuid);
>
> return EFI_SUCCESS;
>
> }
>
>
>
> @@ -669,6 +678,8 @@ SmmEntryPoint (
> VOID *CommunicationBuffer;
>
> UINTN BufferSize;
>
>
>
> + PERF_FUNCTION_BEGIN ();
>
> +
>
> //
>
> // Update SMST with contents of the SmmEntryContext structure
>
> //
>
> @@ -769,6 +780,8 @@ SmmEntryPoint (
> //
>
> gSmmCorePrivate->InSmm = FALSE;
>
> }
>
> +
>
> + PERF_FUNCTION_END ();
>
> }
>
>
>
> /**
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c
> b/MdeModulePkg/Core/PiSmmCore/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;
>
>
>
> + PERF_FUNCTION_BEGIN ();
>
> +
>
> Status = EFI_NOT_FOUND;
>
> SuccessReturn = FALSE;
>
> if (HandlerType == 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_PENDING
> will be returned.
>
> //
>
> if (HandlerType != NULL) {
>
> + PERF_FUNCTION_END ();
>
> return EFI_INTERRUPT_PENDING;
>
> }
>
>
>
> @@ -160,6 +164,7 @@ SmiManage (
> // additional handlers will be processed.
>
> //
>
> if (HandlerType != NULL) {
>
> + PERF_FUNCTION_END ();
>
> return EFI_SUCCESS;
>
> }
>
>
>
> @@ -194,6 +199,7 @@ SmiManage (
> Status = EFI_SUCCESS;
>
> }
>
>
>
> + PERF_FUNCTION_END ();
>
> return Status;
>
> }
>
>
>
> --
> 2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler
2023-06-13 6:13 ` [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler Ni, Ray
@ 2023-06-16 3:19 ` Wang, Jian J
0 siblings, 0 replies; 16+ messages in thread
From: Wang, Jian J @ 2023-06-16 3:19 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io; +Cc: Gao, Liming, Wu, Jiaxin, Dong, Eric
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: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Jiaxin <jiaxin.wu@intel.com>; Dong, Eric
> <eric.dong@intel.com>
> Subject: [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for
> SmmDriverDispatchHandler
>
> 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 <ray.ni@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
> Reviewed-by: Eric Dong <eric.dong@intel.com>
> ---
> MdeModulePkg/Core/PiSmmCore/Dispatcher.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
> b/MdeModulePkg/Core/PiSmmCore/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.
>
>
>
> Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
>
> - Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>
> + Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<BR>
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
> **/
>
> @@ -1322,6 +1322,8 @@ SmmDriverDispatchHandler (
> return EFI_NOT_FOUND;
>
> }
>
>
>
> + PERF_CALLBACK_BEGIN (&gEfiEventDxeDispatchGuid);
>
> +
>
> for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
>
> FvHandle = HandleBuffer[HandleIndex];
>
>
>
> @@ -1511,6 +1513,7 @@ SmmDriverDispatchHandler (
> }
>
> }
>
>
>
> + PERF_CALLBACK_END (&gEfiEventDxeDispatchGuid);
>
> return EFI_SUCCESS;
>
> }
>
>
>
> --
> 2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS
2023-06-13 6:13 ` [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS Ni, Ray
@ 2023-06-16 3:27 ` Wang, Jian J
0 siblings, 0 replies; 16+ messages in thread
From: Wang, Jian J @ 2023-06-16 3:27 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io
Cc: Wu, Jiaxin, Bi, Dandan, Gao, Liming, Dong, Eric
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 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-
> logging after ExitBS
>
> 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 <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>
> ---
> .../SmmPerformanceLib/SmmPerformanceLib.c | 63 ++++++++++++++++++-
> .../SmmPerformanceLib/SmmPerformanceLib.inf | 4 ++
> 2 files changed, 66 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.c
> b/MdeModulePkg/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
> interface.
>
> EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL
> *mPerformanceMeasurement = NULL;
>
> BOOLEAN mPerformanceMeasurementEnabled;
>
> +VOID *mPerformanceLibExitBootServicesRegistration;
>
> +
>
> +/**
>
> + 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
>
> +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
> performance
>
> + // log is not useful.
>
> + //
>
> + mPerformanceMeasurementEnabled = FALSE;
>
> +
>
> + return EFI_SUCCESS;
>
> +}
>
>
>
> /**
>
> The constructor function initializes the Performance Measurement Enable flag
>
> @@ -40,9 +70,40 @@ SmmPerformanceLibConstructor (
> IN EFI_SYSTEM_TABLE *SystemTable
>
> )
>
> {
>
> + EFI_STATUS Status;
>
> +
>
> mPerformanceMeasurementEnabled = (BOOLEAN)((PcdGet8
> (PcdPerformanceLibraryPropertyMask) &
> PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
>
>
>
> - return EFI_SUCCESS;
>
> + Status = 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 = gSmst->SmmRegisterProtocolNotify (
>
> + &gEdkiiSmmExitBootServicesProtocolGuid,
>
> + NULL,
>
> + &mPerformanceLibExitBootServicesRegistration
>
> + );
>
> + ASSERT_EFI_ERROR (Status);
>
> +
>
> + return Status;
>
> }
>
>
>
> /**
>
> 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 = PerformanceLib|DXE_SMM_DRIVER
>
>
>
> CONSTRUCTOR = SmmPerformanceLibConstructor
>
> + DESTRUCTOR = SmmPerformanceLibDestructor
>
>
>
> #
>
> # The following information is for reference only and not required by the build
> tools.
>
> @@ -46,5 +47,8 @@
> [Guids]
>
> gEdkiiSmmPerformanceMeasurementProtocolGuid ##
> SOMETIMES_CONSUMES ## UNDEFINED # Locate protocol
>
>
>
> +[Protocols]
>
> + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES
>
> +
>
> [Pcd]
>
> gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask ##
> CONSUMES
>
> --
> 2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime
2023-06-13 6:13 ` [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Ni, Ray
@ 2023-06-16 3:28 ` Wang, Jian J
2023-06-20 9:34 ` 回复: [edk2-devel] " gaoliming
1 sibling, 0 replies; 16+ messages in thread
From: Wang, Jian J @ 2023-06-16 3:28 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io
Cc: Wu, Jiaxin, Bi, Dandan, Gao, Liming, Dong, Eric
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
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch
2023-06-13 6:13 ` [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch Ni, Ray
2023-06-13 8:44 ` Wu, Jiaxin
@ 2023-06-16 3:29 ` Wang, Jian J
1 sibling, 0 replies; 16+ messages in thread
From: Wang, Jian J @ 2023-06-16 3:29 UTC (permalink / raw)
To: Ni, Ray, devel@edk2.groups.io; +Cc: Gao, Liming, Wu, Jiaxin
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: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log
> PlatformHookBefore/AfterSmmDispatch
>
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> ---
> MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> index 68af9ab81b..a8537829e3 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> @@ -692,7 +692,9 @@ SmmEntryPoint (
> //
>
> // Call platform hook before Smm Dispatch
>
> //
>
> + PERF_START (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0, 0);
>
> PlatformHookBeforeSmmDispatch ();
>
> + PERF_END (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
>
>
>
> //
>
> // Call memory management hook function
>
> @@ -769,7 +771,9 @@ SmmEntryPoint (
> //
>
> // Call platform hook after Smm Dispatch
>
> //
>
> + PERF_START (NULL, "PlatformHookAfterSmmDispatch", NULL, 0, 0);
>
> PlatformHookAfterSmmDispatch ();
>
> + PERF_END (NULL, "PlatformHookAfterSmmDispatch", NULL, 0)
>
>
>
> //
>
> // If a legacy boot has occurred, then make sure gSmmCorePrivate is not
> accessed
>
> --
> 2.39.1.windows.1
^ permalink raw reply [flat|nested] 16+ messages in thread
* 回复: [edk2-devel] [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime
2023-06-13 6:13 ` [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Ni, Ray
2023-06-16 3:28 ` Wang, Jian J
@ 2023-06-20 9:34 ` gaoliming
1 sibling, 0 replies; 16+ messages in thread
From: gaoliming @ 2023-06-20 9:34 UTC (permalink / raw)
To: devel, ray.ni
Cc: 'Jiaxin Wu', 'Dandan Bi', 'Jian J Wang',
'Eric Dong'
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]
> -=-=-=-=-=-=
>
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2023-06-20 9:36 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13 6:13 [PATCH V3 0/8] Enable SMM perf-logging Ni, Ray
2023-06-13 6:13 ` [PATCH V3 1/8] UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures Ni, Ray
2023-06-13 6:13 ` [PATCH V3 2/8] UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures Ni, Ray
2023-06-13 6:13 ` [PATCH V3 3/8] MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures Ni, Ray
2023-06-16 3:19 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 4/8] MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler Ni, Ray
2023-06-16 3:19 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 5/8] MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS Ni, Ray
2023-06-16 3:27 ` Wang, Jian J
2023-06-13 6:13 ` [PATCH V3 6/8] MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime Ni, Ray
2023-06-16 3:28 ` Wang, Jian J
2023-06-20 9:34 ` 回复: [edk2-devel] " gaoliming
2023-06-13 6:13 ` [PATCH V3 7/8] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging Ni, Ray
2023-06-13 6:13 ` [PATCH V3 8/8] MdeModulePkg/SmmCore: Perf-log PlatformHookBefore/AfterSmmDispatch Ni, Ray
2023-06-13 8:44 ` Wu, Jiaxin
2023-06-16 3:29 ` Wang, Jian J
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox