This file implements all APIs in Performance Library class in MdePkg. It creates\r
performance logging GUIDed HOB on the first performance logging and then logs the\r
performance data to the GUIDed HOB. Due to the limitation of temporary RAM, the maximum\r
- number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries. \r
+ number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries or\r
+ PcdMaxPeiPerformanceLogEntries16.\r
\r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
\r
#include <PiPei.h>\r
\r
-#include <Guid/Performance.h>\r
+#include <Guid/ExtendedFirmwarePerformance.h>\r
+#include <Guid/PerformanceMeasurement.h>\r
\r
#include <Library/PerformanceLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/PcdLib.h>\r
#include <Library/BaseMemoryLib.h>\r
\r
+#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
+#define PEI_MAX_RECORD_SIZE (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)\r
\r
-/**\r
- Gets the GUID HOB for PEI performance.\r
\r
- This internal function searches for the GUID HOB for PEI performance.\r
- If that GUID HOB is not found, it will build a new one.\r
- It outputs the data area of that GUID HOB to record performance log.\r
+/**\r
+ Return the pointer to the FPDT record in the allocated memory.\r
\r
- @param PeiPerformanceLog Pointer to Pointer to PEI performance log header.\r
- @param PeiPerformanceIdArray Pointer to Pointer to PEI performance identifier array.\r
+ @param RecordSize The size of FPDT record.\r
+ @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.\r
+ @param PeiPerformanceLogHeader Pointer to the header of the PEI Performance records in the GUID Hob.\r
\r
+ @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.\r
+ @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.\r
**/\r
-VOID\r
-InternalGetPerformanceHobLog (\r
- OUT PEI_PERFORMANCE_LOG_HEADER **PeiPerformanceLog,\r
- OUT UINT32 **PeiPerformanceIdArray\r
- )\r
+EFI_STATUS\r
+GetFpdtRecordPtr (\r
+ IN UINT8 RecordSize,\r
+ IN OUT FPDT_RECORD_PTR *FpdtRecordPtr,\r
+ IN OUT FPDT_PEI_EXT_PERF_HEADER **PeiPerformanceLogHeader\r
+)\r
{\r
- EFI_HOB_GUID_TYPE *GuidHob;\r
- UINTN PeiPerformanceSize;\r
-\r
- ASSERT (PeiPerformanceLog != NULL);\r
- ASSERT (PeiPerformanceIdArray != NULL);\r
+ UINT16 PeiPerformanceLogEntries;\r
+ UINTN PeiPerformanceSize;\r
+ UINT8 *PeiFirmwarePerformance;\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
\r
- GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\r
+ //\r
+ // Get the number of PeiPerformanceLogEntries form PCD.\r
+ //\r
+ PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
+ PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
+ PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
\r
- if (GuidHob != NULL) {\r
+ //\r
+ // Create GUID HOB Data.\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);\r
+ PeiFirmwarePerformance = NULL;\r
+ while (GuidHob != NULL) {\r
//\r
// PEI Performance HOB was found, then return the existing one.\r
//\r
- *PeiPerformanceLog = GET_GUID_HOB_DATA (GuidHob);\r
+ PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob);\r
+ *PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
+ if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {\r
+ (*PeiPerformanceLogHeader)->HobIsFull = TRUE;\r
+ }\r
+ if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {\r
+ FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + (*PeiPerformanceLogHeader)->SizeOfAllEntries);\r
+ break;\r
+ }\r
+ //\r
+ // Previous HOB is used, then find next one.\r
+ //\r
+ GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
+ }\r
\r
- GuidHob = GetFirstGuidHob (&gPerformanceExProtocolGuid);\r
- ASSERT (GuidHob != NULL);\r
- *PeiPerformanceIdArray = GET_GUID_HOB_DATA (GuidHob);\r
- } else {\r
+ if (GuidHob == NULL) {\r
//\r
// PEI Performance HOB was not found, then build one.\r
//\r
- PeiPerformanceSize = sizeof (PEI_PERFORMANCE_LOG_HEADER) +\r
- sizeof (PEI_PERFORMANCE_LOG_ENTRY) * PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
- *PeiPerformanceLog = BuildGuidHob (&gPerformanceProtocolGuid, PeiPerformanceSize);\r
- *PeiPerformanceLog = ZeroMem (*PeiPerformanceLog, PeiPerformanceSize);\r
-\r
- PeiPerformanceSize = sizeof (UINT32) * PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
- *PeiPerformanceIdArray = BuildGuidHob (&gPerformanceExProtocolGuid, PeiPerformanceSize);\r
- *PeiPerformanceIdArray = ZeroMem (*PeiPerformanceIdArray, PeiPerformanceSize);\r
+ PeiPerformanceSize = sizeof (FPDT_PEI_EXT_PERF_HEADER) +\r
+ PEI_MAX_RECORD_SIZE * PeiPerformanceLogEntries;\r
+ PeiFirmwarePerformance = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);\r
+ if (PeiFirmwarePerformance != NULL) {\r
+ ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);\r
+ (*PeiPerformanceLogHeader) = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
+ FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));\r
+ }\r
}\r
+\r
+ if (PeiFirmwarePerformance == NULL) {\r
+ //\r
+ // there is no enough resource to store performance data\r
+ //\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
}\r
\r
/**\r
- Searches in the log array with keyword Handle, Token, Module and Identifier.\r
+Check whether the Token is a known one which is uesed by core.\r
\r
- This internal function searches for the log entry in the log array.\r
- If there is an entry that exactly matches the given keywords\r
- and its end time stamp is zero, then the index of that log entry is returned;\r
- otherwise, the the number of log entries in the array is returned.\r
+@param Token Pointer to a Null-terminated ASCII string\r
\r
- @param PeiPerformanceLog Pointer to the data structure containing PEI \r
- performance data.\r
- @param Handle Pointer to environment specific context used\r
- to identify the component being measured.\r
- @param Token Pointer to a Null-terminated ASCII string\r
- that identifies the component being measured.\r
- @param Module Pointer to a Null-terminated ASCII string\r
- that identifies the module being measured.\r
- @param Identifier 32-bit identifier.\r
+@retval TRUE Is a known one used by core.\r
+@retval FALSE Not a known one.\r
\r
- @retval The index of log entry in the array.\r
+**/\r
+BOOLEAN\r
+IsKnownTokens (\r
+ IN CONST CHAR8 *Token\r
+ )\r
+{\r
+ if (Token == NULL) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
+ AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
+ AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
+ AsciiStrCmp (Token, BDS_TOK) == 0 ||\r
+ AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||\r
+ AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||\r
+ AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||\r
+ AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||\r
+ AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||\r
+ AsciiStrCmp (Token, PEIM_TOK) == 0) {\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+/**\r
+Check whether the ID is a known one which map to the known Token.\r
+\r
+@param Identifier 32-bit identifier.\r
+\r
+@retval TRUE Is a known one used by core.\r
+@retval FALSE Not a known one.\r
\r
**/\r
-UINT32\r
-InternalSearchForLogEntry (\r
- IN PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog,\r
- IN UINT32 *PeiPerformanceIdArray,\r
- IN CONST VOID *Handle, OPTIONAL\r
- IN CONST CHAR8 *Token, OPTIONAL\r
- IN CONST CHAR8 *Module, OPTIONAL\r
- IN UINT32 Identifier\r
+BOOLEAN\r
+IsKnownID (\r
+ IN UINT32 Identifier\r
)\r
{\r
- UINT32 Index;\r
- UINT32 NumberOfEntries;\r
- PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
+ if (Identifier == MODULE_START_ID ||\r
+ Identifier == MODULE_END_ID ||\r
+ Identifier == MODULE_LOADIMAGE_START_ID ||\r
+ Identifier == MODULE_LOADIMAGE_END_ID ||\r
+ Identifier == MODULE_DB_START_ID ||\r
+ Identifier == MODULE_DB_END_ID ||\r
+ Identifier == MODULE_DB_SUPPORT_START_ID ||\r
+ Identifier == MODULE_DB_SUPPORT_END_ID ||\r
+ Identifier == MODULE_DB_STOP_START_ID ||\r
+ Identifier == MODULE_DB_STOP_END_ID) {\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+/**\r
+ Get the FPDT record identifier.\r
\r
+ @param Attribute The attribute of the Record.\r
+ PerfStartEntry: Start Record.\r
+ PerfEndEntry: End Record.\r
+ @param Handle Pointer to environment specific context used to identify the component being measured.\r
+ @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.\r
+ @param ProgressID On return, pointer to the ProgressID.\r
\r
- if (Token == NULL) {\r
- Token = "";\r
+ @retval EFI_SUCCESS Get record info successfully.\r
+ @retval EFI_INVALID_PARAMETER No matched FPDT record.\r
+\r
+**/\r
+EFI_STATUS\r
+GetFpdtRecordId (\r
+ IN BOOLEAN Attribute,\r
+ IN CONST VOID *Handle,\r
+ IN CONST CHAR8 *String,\r
+ OUT UINT16 *ProgressID\r
+ )\r
+{\r
+ //\r
+ // Get the ProgressID based on the Token.\r
+ // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.\r
+ //\r
+ if (String != NULL) {\r
+ if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"\r
+ if (Attribute == PerfStartEntry) {\r
+ *ProgressID = MODULE_LOADIMAGE_START_ID;\r
+ } else {\r
+ *ProgressID = MODULE_LOADIMAGE_END_ID;\r
+ }\r
+ } else if (AsciiStrCmp (String, SEC_TOK) == 0 || // "SEC"\r
+ AsciiStrCmp (String, PEI_TOK) == 0) { // "PEI"\r
+ if (Attribute == PerfStartEntry) {\r
+ *ProgressID = PERF_CROSSMODULE_START_ID;\r
+ } else {\r
+ *ProgressID = PERF_CROSSMODULE_END_ID;\r
+ }\r
+ } else if (AsciiStrCmp (String, PEIM_TOK) == 0) { // "PEIM"\r
+ if (Attribute == PerfStartEntry) {\r
+ *ProgressID = MODULE_START_ID;\r
+ } else {\r
+ *ProgressID = MODULE_END_ID;\r
+ }\r
+ } else { //Pref used in Modules.\r
+ if (Attribute == PerfStartEntry) {\r
+ *ProgressID = PERF_INMODULE_START_ID;\r
+ } else {\r
+ *ProgressID = PERF_INMODULE_END_ID;\r
+ }\r
+ }\r
+ } else if (Handle != NULL) { //Pref used in Modules.\r
+ if (Attribute == PerfStartEntry) {\r
+ *ProgressID = PERF_INMODULE_START_ID;\r
+ } else {\r
+ *ProgressID = PERF_INMODULE_END_ID;\r
+ }\r
+ } else {\r
+ return EFI_INVALID_PARAMETER;\r
}\r
- if (Module == NULL) {\r
- Module = "";\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Copies the string from Source into Destination and updates Length with the\r
+ size of the string.\r
+\r
+ @param Destination - destination of the string copy\r
+ @param Source - pointer to the source string which will get copied\r
+ @param Length - pointer to a length variable to be updated\r
+\r
+**/\r
+VOID\r
+CopyStringIntoPerfRecordAndUpdateLength (\r
+ IN OUT CHAR8 *Destination,\r
+ IN CONST CHAR8 *Source,\r
+ IN OUT UINT8 *Length\r
+ )\r
+{\r
+ UINTN StringLen;\r
+ UINTN DestMax;\r
+\r
+ ASSERT (Source != NULL);\r
+\r
+ if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ DestMax = STRING_SIZE;\r
+ } else {\r
+ DestMax = AsciiStrSize (Source);\r
+ if (DestMax > STRING_SIZE) {\r
+ DestMax = STRING_SIZE;\r
+ }\r
}\r
- NumberOfEntries = PeiPerformanceLog->NumberOfEntries;\r
- LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
-\r
- for (Index = 0; Index < NumberOfEntries; Index++) {\r
- if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
- AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
- AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
- (PeiPerformanceIdArray[Index] == Identifier) &&\r
- LogEntryArray[Index].EndTimeStamp == 0\r
- ) {\r
- break;\r
+ StringLen = AsciiStrLen (Source);\r
+ if (StringLen >= DestMax) {\r
+ StringLen = DestMax -1;\r
+ }\r
+\r
+ AsciiStrnCpyS(Destination, DestMax, Source, StringLen);\r
+ *Length += (UINT8)DestMax;\r
+\r
+ return;\r
+}\r
+\r
+\r
+/**\r
+ Convert PEI performance log to FPDT String boot record.\r
+\r
+ @param CallerIdentifier - Image handle or pointer to caller ID GUID.\r
+ @param Guid - Pointer to a GUID.\r
+ @param String - Pointer to a string describing the measurement.\r
+ @param Ticker - 64-bit time stamp.\r
+ @param Address - Pointer to a location in memory relevant to the measurement.\r
+ @param PerfId - Performance identifier describing the type of measurement.\r
+ @param Attribute - The attribute of the measurement. According to attribute can create a start\r
+ record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
+ or a general record for other Perf macros.\r
+\r
+ @retval EFI_SUCCESS - Successfully created performance record.\r
+ @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.\r
+ @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+ pointer or invalid PerfId.\r
+\r
+**/\r
+EFI_STATUS\r
+InsertFpdtRecord (\r
+ IN CONST VOID *CallerIdentifier, OPTIONAL\r
+ IN CONST VOID *Guid, OPTIONAL\r
+ IN CONST CHAR8 *String, OPTIONAL\r
+ IN UINT64 Ticker,\r
+ IN UINT64 Address, OPTIONAL\r
+ IN UINT16 PerfId,\r
+ IN PERF_MEASUREMENT_ATTRIBUTE Attribute\r
+ )\r
+{\r
+ FPDT_RECORD_PTR FpdtRecordPtr;\r
+ CONST VOID *ModuleGuid;\r
+ CONST CHAR8 *StringPtr;\r
+ EFI_STATUS Status;\r
+ UINT64 TimeStamp;\r
+ FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;\r
+\r
+ StringPtr = NULL;\r
+ FpdtRecordPtr.RecordHeader = NULL;\r
+ PeiPerformanceLogHeader = NULL;\r
+\r
+ //\r
+ // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.\r
+ // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.\r
+ //\r
+ if (Attribute != PerfEntry) {\r
+ //\r
+ // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.\r
+ // !!! Note: If the Perf is not the known Token used in the core but have same\r
+ // ID with the core Token, this case will not be supported.\r
+ // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
+ // If it is start pref: the lower 4 bits of the ID should be 0.\r
+ // If it is end pref: the lower 4 bits of the ID should not be 0.\r
+ // If input ID doesn't follow the rule, we will adjust it.\r
+ //\r
+ if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
+ return EFI_UNSUPPORTED;\r
+ } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
+ if (Attribute == PerfStartEntry && ((PerfId & 0x000F) != 0)) {\r
+ PerfId &= 0xFFF0;\r
+ } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {\r
+ PerfId += 1;\r
+ }\r
+ } else if (PerfId == 0) {\r
+ Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &PerfId);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // 2. Get the buffer to store the FPDT record.\r
+ //\r
+ Status = GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE, &FpdtRecordPtr, &PeiPerformanceLogHeader);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // 3 Get the TimeStamp.\r
+ //\r
+ if (Ticker == 0) {\r
+ Ticker = GetPerformanceCounter ();\r
+ TimeStamp = GetTimeInNanoSecond (Ticker);\r
+ } else if (Ticker == 1) {\r
+ TimeStamp = 0;\r
+ } else {\r
+ TimeStamp = GetTimeInNanoSecond (Ticker);\r
+ }\r
+\r
+ //\r
+ // 4.Get the ModuleGuid.\r
+ //\r
+ if (CallerIdentifier != NULL) {\r
+ ModuleGuid = CallerIdentifier;\r
+ } else {\r
+ ModuleGuid = &gEfiCallerIdGuid;\r
+ }\r
+\r
+ //\r
+ // 5. Fill in the FPDT record according to different Performance Identifier.\r
+ //\r
+ switch (PerfId) {\r
+ case MODULE_START_ID:\r
+ case MODULE_END_ID:\r
+ StringPtr = PEIM_TOK;\r
+ if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;\r
+ FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);\r
+ FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.GuidEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;\r
+ CopyMem (&FpdtRecordPtr.GuidEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
+ }\r
+ break;\r
+\r
+ case MODULE_LOADIMAGE_START_ID:\r
+ case MODULE_LOADIMAGE_END_ID:\r
+ StringPtr = LOAD_IMAGE_TOK;\r
+ if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;\r
+ FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
+ FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;\r
+ if (PerfId == MODULE_LOADIMAGE_START_ID) {\r
+ PeiPerformanceLogHeader->LoadImageCount++;\r
+ }\r
+ FpdtRecordPtr.GuidQwordEvent->Qword = PeiPerformanceLogHeader->LoadImageCount;\r
+ CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
+ }\r
+ break;\r
+\r
+ case PERF_EVENTSIGNAL_START_ID:\r
+ case PERF_EVENTSIGNAL_END_ID:\r
+ case PERF_CALLBACK_START_ID:\r
+ case PERF_CALLBACK_END_ID:\r
+ if (String == NULL || Guid == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ StringPtr = String;\r
+ if (AsciiStrLen (String) == 0) {\r
+ StringPtr = "unknown name";\r
}\r
+ if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;\r
+ FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);\r
+ FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;\r
+ CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, ModuleGuid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));\r
+ CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));\r
+ CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);\r
+ }\r
+ break;\r
+\r
+ case PERF_EVENT_ID:\r
+ case PERF_FUNCTION_START_ID:\r
+ case PERF_FUNCTION_END_ID:\r
+ case PERF_INMODULE_START_ID:\r
+ case PERF_INMODULE_END_ID:\r
+ case PERF_CROSSMODULE_START_ID:\r
+ case PERF_CROSSMODULE_END_ID:\r
+ if (String != NULL && AsciiStrLen (String) != 0) {\r
+ StringPtr = String;\r
+ } else {\r
+ StringPtr = "unknown name";\r
+ }\r
+ if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
+ CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
+ CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
+ }\r
+ break;\r
+\r
+ default:\r
+ if (Attribute != PerfEntry) {\r
+ if (String != NULL && AsciiStrLen (String) != 0) {\r
+ StringPtr = String;\r
+ } else {\r
+ StringPtr = "unknown name";\r
+ }\r
+ if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
+ CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+ CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
+ }\r
+ } else {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ break;\r
+ }\r
+\r
+ //\r
+ // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.\r
+ //\r
+ if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+ FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+ FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
+ FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
+ if (Guid != NULL) {\r
+ //\r
+ // Cache the event guid in string event record.\r
+ //\r
+ CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (EFI_GUID));\r
+ } else {\r
+ CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
+ }\r
+ CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
}\r
- return Index;\r
+\r
+ //\r
+ // 6. Update the length of the used buffer after fill in the record.\r
+ //\r
+ PeiPerformanceLogHeader->SizeOfAllEntries += FpdtRecordPtr.RecordHeader->Length;\r
+\r
+ return EFI_SUCCESS;\r
}\r
\r
/**\r
Creates a record for the beginning of a performance measurement.\r
\r
- Creates a record that contains the Handle, Token, Module and Identifier.\r
- If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
If TimeStamp is zero, then this function reads the current time stamp\r
and adds that time stamp value to the record as the start time.\r
\r
+ If TimeStamp is one, then this function reads 0 as the start time.\r
+\r
+ If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
+\r
@param Handle Pointer to environment specific context used\r
to identify the component being measured.\r
@param Token Pointer to a Null-terminated ASCII string\r
IN UINT32 Identifier\r
)\r
{\r
- PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r
- UINT32 *PeiPerformanceIdArray;\r
- PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
- UINT32 Index;\r
-\r
- InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
-\r
- if (PeiPerformanceLog->NumberOfEntries >= PcdGet8 (PcdMaxPeiPerformanceLogEntries)) {\r
- return RETURN_OUT_OF_RESOURCES;\r
- }\r
- Index = PeiPerformanceLog->NumberOfEntries++;\r
- LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
- LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+ CONST CHAR8 *String;\r
\r
if (Token != NULL) {\r
- AsciiStrnCpy (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH);\r
- }\r
- if (Module != NULL) {\r
- AsciiStrnCpy (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH);\r
+ String = Token;\r
+ } else if (Module != NULL) {\r
+ String = Module;\r
+ } else {\r
+ String = NULL;\r
}\r
\r
- LogEntryArray[Index].EndTimeStamp = 0;\r
- PeiPerformanceIdArray[Index] = Identifier;\r
-\r
- if (TimeStamp == 0) {\r
- TimeStamp = GetPerformanceCounter ();\r
- }\r
- LogEntryArray[Index].StartTimeStamp = TimeStamp;\r
+ return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfStartEntry);\r
\r
- return RETURN_SUCCESS;\r
}\r
\r
/**\r
- Fills in the end time of a performance measurement.\r
\r
- Looks up the record that matches Handle, Token, Module and Identifier.\r
- If the record can not be found then return RETURN_NOT_FOUND.\r
- If the record is found and TimeStamp is not zero,\r
- then TimeStamp is added to the record as the end time.\r
- If the record is found and TimeStamp is zero, then this function reads\r
- the current time stamp and adds that time stamp value to the record as the end time.\r
+ Creates a record for the end of a performance measurement.\r
+\r
+ If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
+ If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
+ If the TimeStamp is one, then this function reads 0 as the end time.\r
\r
@param Handle Pointer to environment specific context used\r
to identify the component being measured.\r
IN UINT32 Identifier\r
)\r
{\r
- PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r
- UINT32 *PeiPerformanceIdArray;\r
- PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
- UINT32 Index;\r
-\r
- if (TimeStamp == 0) {\r
- TimeStamp = GetPerformanceCounter ();\r
- }\r
+ CONST CHAR8 *String;\r
\r
- InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
- Index = InternalSearchForLogEntry (PeiPerformanceLog, PeiPerformanceIdArray, Handle, Token, Module, Identifier);\r
- if (Index >= PeiPerformanceLog->NumberOfEntries) {\r
- return RETURN_NOT_FOUND;\r
+ if (Token != NULL) {\r
+ String = Token;\r
+ } else if (Module != NULL) {\r
+ String = Module;\r
+ } else {\r
+ String = NULL;\r
}\r
- LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
- LogEntryArray[Index].EndTimeStamp = TimeStamp;\r
\r
- return RETURN_SUCCESS;\r
+ return (RETURN_STATUS)InsertFpdtRecord (Handle, NULL, String, TimeStamp, 0, (UINT16)Identifier, PerfEndEntry);\r
}\r
\r
/**\r
If EndTimeStamp is NULL, then ASSERT().\r
If Identifier is NULL, then ASSERT().\r
\r
+ !!!NOT Support yet!!!\r
+\r
@param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
0, then the first performance measurement log entry is retrieved.\r
On exit, the key of the next performance of entry entry.\r
OUT UINT32 *Identifier\r
)\r
{\r
- PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog;\r
- UINT32 *PeiPerformanceIdArray;\r
- PEI_PERFORMANCE_LOG_ENTRY *CurrentLogEntry;\r
- PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
- UINTN NumberOfEntries;\r
-\r
- ASSERT (Handle != NULL);\r
- ASSERT (Token != NULL);\r
- ASSERT (Module != NULL);\r
- ASSERT (StartTimeStamp != NULL);\r
- ASSERT (EndTimeStamp != NULL);\r
- ASSERT (Identifier != NULL);\r
-\r
- InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
-\r
- NumberOfEntries = (UINTN) (PeiPerformanceLog->NumberOfEntries);\r
- LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
- //\r
- // Make sure that LogEntryKey is a valid log entry key.\r
- //\r
- ASSERT (LogEntryKey <= NumberOfEntries);\r
-\r
- if (LogEntryKey == NumberOfEntries) {\r
- return 0;\r
- }\r
-\r
- CurrentLogEntry = &(LogEntryArray[LogEntryKey]);\r
-\r
- *Handle = (VOID *) (UINTN) (CurrentLogEntry->Handle);\r
- *Token = CurrentLogEntry->Token;\r
- *Module = CurrentLogEntry->Module;\r
- *StartTimeStamp = CurrentLogEntry->StartTimeStamp;\r
- *EndTimeStamp = CurrentLogEntry->EndTimeStamp;\r
- *Identifier = PeiPerformanceIdArray[LogEntryKey++];\r
-\r
- return LogEntryKey;\r
+ return 0;\r
}\r
\r
/**\r
Creates a record for the beginning of a performance measurement.\r
\r
- Creates a record that contains the Handle, Token, and Module.\r
- If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
If TimeStamp is zero, then this function reads the current time stamp\r
and adds that time stamp value to the record as the start time.\r
\r
+ If TimeStamp is one, then this function reads 0 as the start time.\r
+\r
+ If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
+\r
+\r
@param Handle Pointer to environment specific context used\r
to identify the component being measured.\r
@param Token Pointer to a Null-terminated ASCII string\r
}\r
\r
/**\r
- Fills in the end time of a performance measurement.\r
\r
- Looks up the record that matches Handle, Token, and Module.\r
- If the record can not be found then return RETURN_NOT_FOUND.\r
- If the record is found and TimeStamp is not zero,\r
- then TimeStamp is added to the record as the end time.\r
- If the record is found and TimeStamp is zero, then this function reads\r
- the current time stamp and adds that time stamp value to the record as the end time.\r
+ Creates a record for the end of a performance measurement.\r
+\r
+ If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
+ If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
+ If the TimeStamp is one, then this function reads 0 as the end time.\r
\r
@param Handle Pointer to environment specific context used\r
to identify the component being measured.\r
If StartTimeStamp is NULL, then ASSERT().\r
If EndTimeStamp is NULL, then ASSERT().\r
\r
+ NOT Support yet.\r
+\r
@param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
0, then the first performance measurement log entry is retrieved.\r
On exit, the key of the next performance of entry entry.\r
OUT UINT64 *EndTimeStamp\r
)\r
{\r
- UINT32 Identifier;\r
- return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
+ return 0;\r
}\r
\r
/**\r
{\r
return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
}\r
+\r
+/**\r
+ Create performance record with event description and a timestamp.\r
+\r
+ @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
+ @param Guid - Pointer to a GUID\r
+ @param String - Pointer to a string describing the measurement\r
+ @param Address - Pointer to a location in memory relevant to the measurement\r
+ @param Identifier - Performance identifier describing the type of measurement\r
+\r
+ @retval RETURN_SUCCESS - Successfully created performance record\r
+ @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
+ @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+ pointer or invalid PerfId\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LogPerformanceMeasurement (\r
+ IN CONST VOID *CallerIdentifier,\r
+ IN CONST VOID *Guid, OPTIONAL\r
+ IN CONST CHAR8 *String, OPTIONAL\r
+ IN UINT64 Address, OPTIONAL\r
+ IN UINT32 Identifier\r
+ )\r
+{\r
+ return (RETURN_STATUS)InsertFpdtRecord (CallerIdentifier, Guid, String, 0, Address, (UINT16)Identifier, PerfEntry);\r
+}\r
+\r
+/**\r
+ Check whether the specified performance measurement can be logged.\r
+\r
+ This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
+ and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
+\r
+ @param Type - Type of the performance measurement entry.\r
+\r
+ @retval TRUE The performance measurement can be logged.\r
+ @retval FALSE The performance measurement can NOT be logged.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LogPerformanceMeasurementEnabled (\r
+ IN CONST UINTN Type\r
+ )\r
+{\r
+ //\r
+ // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
+ //\r
+ if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
+ return TRUE;\r
+ }\r
+ return FALSE;\r
+}\r