UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures

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

Signed-off-by: Ray Ni <ray.ni@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>
This commit is contained in:
Ray Ni 2023-05-26 20:57:29 +08:00 committed by mergify[bot]
parent 4a0642ad27
commit 0da3df78ff
6 changed files with 49 additions and 5 deletions

View File

@ -351,6 +351,8 @@ SmmWaitForApArrival (
UINT32 DelayedCount; UINT32 DelayedCount;
UINT32 BlockedCount; UINT32 BlockedCount;
PERF_FUNCTION_BEGIN ();
DelayedCount = 0; DelayedCount = 0;
BlockedCount = 0; BlockedCount = 0;
@ -439,7 +441,7 @@ SmmWaitForApArrival (
DEBUG ((DEBUG_INFO, "SmmWaitForApArrival: Delayed AP Count = %d, Blocked AP Count = %d\n", DelayedCount, BlockedCount)); 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); ASSERT (CpuIndex == mSmmMpSyncData->BspIndex);
ApCount = 0; ApCount = 0;
PERF_FUNCTION_BEGIN ();
// //
// Flag BSP's presence // Flag BSP's presence
// //
@ -792,6 +796,8 @@ BSPHandler (
*mSmmMpSyncData->Counter = 0; *mSmmMpSyncData->Counter = 0;
*mSmmMpSyncData->AllCpusInSync = FALSE; *mSmmMpSyncData->AllCpusInSync = FALSE;
mSmmMpSyncData->AllApArrivedWithException = FALSE; mSmmMpSyncData->AllApArrivedWithException = FALSE;
PERF_FUNCTION_END ();
} }
/** /**

View File

@ -410,12 +410,15 @@ ExecuteFirstSmiInit (
{ {
UINTN Index; UINTN Index;
PERF_FUNCTION_BEGIN ();
if (mSmmInitialized == NULL) { if (mSmmInitialized == NULL) {
mSmmInitialized = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * mMaxNumberOfCpus); mSmmInitialized = (BOOLEAN *)AllocatePool (sizeof (BOOLEAN) * mMaxNumberOfCpus);
} }
ASSERT (mSmmInitialized != NULL); ASSERT (mSmmInitialized != NULL);
if (mSmmInitialized == NULL) { if (mSmmInitialized == NULL) {
PERF_FUNCTION_END ();
return; return;
} }
@ -442,6 +445,8 @@ ExecuteFirstSmiInit (
while (!(BOOLEAN)mSmmInitialized[Index]) { while (!(BOOLEAN)mSmmInitialized[Index]) {
} }
} }
PERF_FUNCTION_END ();
} }
/** /**
@ -463,6 +468,8 @@ SmmRelocateBases (
UINTN Index; UINTN Index;
UINTN BspIndex; UINTN BspIndex;
PERF_FUNCTION_BEGIN ();
// //
// Make sure the reserved size is large enough for procedure SmmInitTemplate. // Make sure the reserved size is large enough for procedure SmmInitTemplate.
// //
@ -540,6 +547,7 @@ SmmRelocateBases (
// //
CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2)); CopyMem (CpuStatePtr, &BakBuf2, sizeof (BakBuf2));
CopyMem (U8Ptr, BakBuf, sizeof (BakBuf)); CopyMem (U8Ptr, BakBuf, sizeof (BakBuf));
PERF_FUNCTION_END ();
} }
/** /**
@ -617,6 +625,8 @@ PiCpuSmmEntry (
GuidHob = NULL; GuidHob = NULL;
SmmBaseHobData = NULL; SmmBaseHobData = NULL;
PERF_FUNCTION_BEGIN ();
// //
// Initialize address fixup // Initialize address fixup
// //
@ -1194,6 +1204,7 @@ PiCpuSmmEntry (
DEBUG ((DEBUG_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n")); DEBUG ((DEBUG_INFO, "SMM CPU Module exit from SMRAM with EFI_SUCCESS\n"));
PERF_FUNCTION_END ();
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1348,12 +1359,15 @@ ConfigSmmCodeAccessCheck (
UINTN Index; UINTN Index;
EFI_STATUS Status; EFI_STATUS Status;
PERF_FUNCTION_BEGIN ();
// //
// Check to see if the Feature Control MSR is supported on this CPU // Check to see if the Feature Control MSR is supported on this CPU
// //
Index = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu; Index = gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu;
if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl)) { if (!SmmCpuFeaturesIsSmmRegisterSupported (Index, SmmRegFeatureControl)) {
mSmmCodeAccessCheckEnable = FALSE; mSmmCodeAccessCheckEnable = FALSE;
PERF_FUNCTION_END ();
return; return;
} }
@ -1363,6 +1377,7 @@ ConfigSmmCodeAccessCheck (
// //
if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) == 0) { if ((AsmReadMsr64 (EFI_MSR_SMM_MCA_CAP) & SMM_CODE_ACCESS_CHK_BIT) == 0) {
mSmmCodeAccessCheckEnable = FALSE; mSmmCodeAccessCheckEnable = FALSE;
PERF_FUNCTION_END ();
return; return;
} }
@ -1419,6 +1434,8 @@ ConfigSmmCodeAccessCheck (
ReleaseSpinLock (mConfigSmmCodeAccessCheckLock); ReleaseSpinLock (mConfigSmmCodeAccessCheckLock);
} }
} }
PERF_FUNCTION_END ();
} }
/** /**
@ -1540,6 +1557,8 @@ PerformRemainingTasks (
) )
{ {
if (mSmmReadyToLock) { if (mSmmReadyToLock) {
PERF_FUNCTION_BEGIN ();
// //
// Check if all Aps enter SMM. In Relaxed-AP Sync Mode, BSP will not wait for // 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 // all Aps arrive. However,PerformRemainingTasks() needs to wait all Aps arrive before calling
@ -1587,12 +1606,20 @@ PerformRemainingTasks (
// //
ConfigSmmCodeAccessCheck (); ConfigSmmCodeAccessCheck ();
//
// Measure performance of SmmCpuFeaturesCompleteSmmReadyToLock() from caller side
// as the implementation is provided by platform.
//
PERF_START (NULL, "SmmCompleteReadyToLock", NULL, 0);
SmmCpuFeaturesCompleteSmmReadyToLock (); SmmCpuFeaturesCompleteSmmReadyToLock ();
PERF_END (NULL, "SmmCompleteReadyToLock", NULL, 0);
// //
// Clean SMM ready to lock flag // Clean SMM ready to lock flag
// //
mSmmReadyToLock = FALSE; mSmmReadyToLock = FALSE;
PERF_FUNCTION_END ();
} }
} }

View File

@ -50,6 +50,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/SmmCpuFeaturesLib.h> #include <Library/SmmCpuFeaturesLib.h>
#include <Library/PeCoffGetEntryPointLib.h> #include <Library/PeCoffGetEntryPointLib.h>
#include <Library/RegisterCpuFeaturesLib.h> #include <Library/RegisterCpuFeaturesLib.h>
#include <Library/PerformanceLib.h>
#include <AcpiCpuData.h> #include <AcpiCpuData.h>
#include <CpuHotPlugData.h> #include <CpuHotPlugData.h>

View File

@ -97,6 +97,7 @@
ReportStatusCodeLib ReportStatusCodeLib
SmmCpuFeaturesLib SmmCpuFeaturesLib
PeCoffGetEntryPointLib PeCoffGetEntryPointLib
PerformanceLib
[Protocols] [Protocols]
gEfiSmmAccess2ProtocolGuid ## CONSUMES gEfiSmmAccess2ProtocolGuid ## CONSUMES

View File

@ -1,6 +1,6 @@
/** @file /** @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 SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -1100,6 +1100,8 @@ SetMemMapAttributes (
return; return;
} }
PERF_FUNCTION_BEGIN ();
DEBUG ((DEBUG_INFO, "MemoryAttributesTable:\n")); DEBUG ((DEBUG_INFO, "MemoryAttributesTable:\n"));
DEBUG ((DEBUG_INFO, " Version - 0x%08x\n", MemoryAttributesTable->Version)); DEBUG ((DEBUG_INFO, " Version - 0x%08x\n", MemoryAttributesTable->Version));
DEBUG ((DEBUG_INFO, " NumberOfEntries - 0x%08x\n", MemoryAttributesTable->NumberOfEntries)); DEBUG ((DEBUG_INFO, " NumberOfEntries - 0x%08x\n", MemoryAttributesTable->NumberOfEntries));
@ -1152,7 +1154,7 @@ SetMemMapAttributes (
PatchSmmSaveStateMap (); PatchSmmSaveStateMap ();
PatchGdtIdtMap (); PatchGdtIdtMap ();
return; PERF_FUNCTION_END ();
} }
/** /**
@ -1454,6 +1456,8 @@ SetUefiMemMapAttributes (
UINTN Index; UINTN Index;
EFI_MEMORY_DESCRIPTOR *Entry; EFI_MEMORY_DESCRIPTOR *Entry;
PERF_FUNCTION_BEGIN ();
DEBUG ((DEBUG_INFO, "SetUefiMemMapAttributes\n")); DEBUG ((DEBUG_INFO, "SetUefiMemMapAttributes\n"));
if (mUefiMemoryMap != NULL) { if (mUefiMemoryMap != NULL) {
@ -1537,6 +1541,8 @@ SetUefiMemMapAttributes (
// //
// Do not free mUefiMemoryAttributesTable, it will be checked in IsSmmCommBufferForbiddenAddress(). // Do not free mUefiMemoryAttributesTable, it will be checked in IsSmmCommBufferForbiddenAddress().
// //
PERF_FUNCTION_END ();
} }
/** /**
@ -1862,6 +1868,7 @@ SetPageTableAttributes (
return; return;
} }
PERF_FUNCTION_BEGIN ();
DEBUG ((DEBUG_INFO, "SetPageTableAttributes\n")); DEBUG ((DEBUG_INFO, "SetPageTableAttributes\n"));
// //
@ -1900,5 +1907,5 @@ SetPageTableAttributes (
EnableCet (); EnableCet ();
} }
return; PERF_FUNCTION_END ();
} }

View File

@ -575,6 +575,8 @@ InitPaging (
IA32_CR4 Cr4; IA32_CR4 Cr4;
BOOLEAN Enable5LevelPaging; BOOLEAN Enable5LevelPaging;
PERF_FUNCTION_BEGIN ();
Cr4.UintN = AsmReadCr4 (); Cr4.UintN = AsmReadCr4 ();
Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1); Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
@ -810,7 +812,7 @@ InitPaging (
// //
mXdEnabled = TRUE; mXdEnabled = TRUE;
return; PERF_FUNCTION_END ();
} }
/** /**