Cc: Jiewen Yao <jiewen....@intel.com> Cc: Liming Gao <liming....@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.z...@intel.com> --- MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c | 82 +++++++++++++----------- 1 file changed, 46 insertions(+), 36 deletions(-)
diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index 25deab6..653b894 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -730,8 +730,7 @@ UnregisterSmramProfileImage ( /** Return if this memory type needs to be recorded into memory profile. - If BIOS memory type (0 ~ EfiMaxMemoryType), it checks bit (1 << MemoryType). - If OS memory type (0x80000000 ~ 0xFFFFFFFF), it checks bit63 - 0x8000000000000000. + Only need to record EfiRuntimeServicesCode and EfiRuntimeServicesData for SMRAM profile. @param MemoryType Memory type. @@ -746,12 +745,13 @@ SmmCoreNeedRecordProfile ( { UINT64 TestBit; - if ((UINT32) MemoryType >= 0x80000000) { - TestBit = BIT63; - } else { - TestBit = LShiftU64 (1, MemoryType); + if (MemoryType != EfiRuntimeServicesCode && + MemoryType != EfiRuntimeServicesData) { + return FALSE; } + TestBit = LShiftU64 (1, MemoryType); + if ((PcdGet64 (PcdMemoryProfileMemoryType) & TestBit) != 0) { return TRUE; } else { @@ -761,8 +761,9 @@ SmmCoreNeedRecordProfile ( /** Convert EFI memory type to profile memory index. The rule is: - If BIOS memory type (0 ~ EfiMaxMemoryType), ProfileMemoryIndex = MemoryType. - If OS memory type (0x80000000 ~ 0xFFFFFFFF), ProfileMemoryIndex = EfiMaxMemoryType. + If BIOS memory type (0 ~ EfiMaxMemoryType - 1), ProfileMemoryIndex = MemoryType. + As SMRAM profile is only to record EfiRuntimeServicesCode and EfiRuntimeServicesData, + so return input memory type directly. @param MemoryType Memory type. @@ -774,11 +775,7 @@ GetProfileMemoryIndex ( IN EFI_MEMORY_TYPE MemoryType ) { - if ((UINT32) MemoryType >= 0x80000000) { - return EfiMaxMemoryType; - } else { - return MemoryType; - } + return MemoryType; } /** @@ -1798,25 +1795,38 @@ GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mActionString[] = { L"FreePool", }; -GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mMemoryTypeString[] = { - L"EfiReservedMemoryType", - L"EfiLoaderCode", - L"EfiLoaderData", - L"EfiBootServicesCode", - L"EfiBootServicesData", - L"EfiRuntimeServicesCode", - L"EfiRuntimeServicesData", - L"EfiConventionalMemory", - L"EfiUnusableMemory", - L"EfiACPIReclaimMemory", - L"EfiACPIMemoryNVS", - L"EfiMemoryMappedIO", - L"EfiMemoryMappedIOPortSpace", - L"EfiPalCode", - L"EfiPersistentMemory", - L"EfiOSReserved", +typedef struct { + EFI_MEMORY_TYPE MemoryType; + CHAR16 *MemoryTypeStr; +} PROFILE_MEMORY_TYPE_STRING; + +GLOBAL_REMOVE_IF_UNREFERENCED PROFILE_MEMORY_TYPE_STRING mMemoryTypeString[] = { + {EfiRuntimeServicesCode, L"EfiRuntimeServicesCode"}, + {EfiRuntimeServicesData, L"EfiRuntimeServicesData"} }; +/** + Memory type to string. + + @param[in] MemoryType Memory type. + + @return Pointer to string. + +**/ +CHAR16 * +ProfileMemoryTypeToStr ( + IN EFI_MEMORY_TYPE MemoryType + ) +{ + UINTN Index; + for (Index = 0; Index < sizeof (mMemoryTypeString) / sizeof (mMemoryTypeString[0]); Index++) { + if (mMemoryTypeString[Index].MemoryType == MemoryType) { + return mMemoryTypeString[Index].MemoryTypeStr; + } + } + + return L"UnexpectedMemoryType"; +} /** Dump SMRAM profile. @@ -1856,11 +1866,11 @@ DumpSmramProfile ( DEBUG ((EFI_D_INFO, " CurrentTotalUsage - 0x%016lx\n", Context->CurrentTotalUsage)); DEBUG ((EFI_D_INFO, " PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage)); - for (TypeIndex = 0; TypeIndex <= EfiMaxMemoryType; TypeIndex++) { + for (TypeIndex = 0; TypeIndex < sizeof (Context->CurrentTotalUsageByType) / sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) { if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) || (Context->PeakTotalUsageByType[TypeIndex] != 0)) { - DEBUG ((EFI_D_INFO, " CurrentTotalUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex])); - DEBUG ((EFI_D_INFO, " PeakTotalUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex])); + DEBUG ((EFI_D_INFO, " CurrentTotalUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex))); + DEBUG ((EFI_D_INFO, " PeakTotalUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex))); } } DEBUG ((EFI_D_INFO, " TotalImageSize - 0x%016lx\n", Context->TotalImageSize)); @@ -1887,11 +1897,11 @@ DumpSmramProfile ( DEBUG ((EFI_D_INFO, " FileType - 0x%02x\n", DriverInfo->FileType)); DEBUG ((EFI_D_INFO, " CurrentUsage - 0x%016lx\n", DriverInfo->CurrentUsage)); DEBUG ((EFI_D_INFO, " PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage)); - for (TypeIndex = 0; TypeIndex <= EfiMaxMemoryType; TypeIndex++) { + for (TypeIndex = 0; TypeIndex < sizeof (DriverInfo->CurrentUsageByType) / sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) { if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) || (DriverInfo->PeakUsageByType[TypeIndex] != 0)) { - DEBUG ((EFI_D_INFO, " CurrentUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], mMemoryTypeString[TypeIndex])); - DEBUG ((EFI_D_INFO, " PeakUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], mMemoryTypeString[TypeIndex])); + DEBUG ((EFI_D_INFO, " CurrentUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex))); + DEBUG ((EFI_D_INFO, " PeakUsage[0x%02x] - 0x%016lx (%s)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], ProfileMemoryTypeToStr (TypeIndex))); } } DEBUG ((EFI_D_INFO, " AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount)); -- 1.9.5.msysgit.0 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel