+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+\r
+Module Name:\r
+\r
+ DxeCorePerformance.c\r
+\r
+Abstract:\r
+\r
+ Support for measurement of DXE performance \r
+\r
+--*/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/Performance.h>\r
+#include <Guid/PeiPerformanceHob.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PerformanceLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+//\r
+// Interface declarations for Performance Protocol.\r
+//\r
+/**\r
+ Adds a record at the end of the performance measurement log\r
+ that records the start time of a performance measurement.\r
+\r
+ Adds a record to the end of the performance measurement log\r
+ that contains the Handle, Token, and Module.\r
+ The end time of the new record must be set to zero.\r
+ If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+ If TimeStamp is zero, the start time in the record is filled in with the value\r
+ read from the current time stamp.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval EFI_SUCCESS The data was read correctly from the device.\r
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+StartGauge (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ );\r
+\r
+/**\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first matching record that contains a zero end time and fills in a valid end time.\r
+\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+ If the record can not be found then return EFI_NOT_FOUND.\r
+ If the record is found and TimeStamp is not zero,\r
+ then the end time in the record is filled in with the value specified by TimeStamp.\r
+ If the record is found and TimeStamp is zero, then the end time in the matching record\r
+ is filled in with the current time stamp value.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval EFI_SUCCESS The end of the measurement was recorded.\r
+ @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+EndGauge (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ );\r
+\r
+/**\r
+ Retrieves a previously logged performance measurement.\r
+\r
+ Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
+ If it stands for a valid entry, then EFI_SUCCESS is returned and\r
+ GaugeDataEntry stores the pointer to that entry.\r
+\r
+ @param LogEntryKey The key for the previous performance measurement log entry.\r
+ If 0, then the first performance measurement log entry is retrieved.\r
+ @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r
+ if the retrieval is successful.\r
+\r
+ @retval EFI_SUCCESS The GuageDataEntry is successfuly found based on LogEntryKey.\r
+ @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
+ @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
+ @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+GetGauge (\r
+ IN UINTN LogEntryKey,\r
+ OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r
+ );\r
+\r
+//\r
+// Definition for global variables.\r
+//\r
+STATIC GAUGE_DATA_HEADER *mGaugeData;\r
+STATIC UINT32 mMaxGaugeRecords;\r
+\r
+EFI_HANDLE mHandle = NULL;\r
+PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
+ StartGauge,\r
+ EndGauge,\r
+ GetGauge\r
+ };\r
+\r
+\r
+/**\r
+ Searches in the gauge array with keyword Handle, Token and Module.\r
+\r
+ This internal function searches for the gauge entry in the gauge array.\r
+ If there is an entry that exactly matches the given key word triple\r
+ and its end time stamp is zero, then the index of that gauge entry is returned;\r
+ otherwise, the the number of gauge entries in the array is returned.\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
+ that identifies the component being measured.\r
+ @param Module Pointer to a Null-terminated ASCII string\r
+ that identifies the module being measured.\r
+\r
+ @retval The index of gauge entry in the array.\r
+\r
+**/\r
+STATIC\r
+UINT32\r
+InternalSearchForGaugeEntry (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module OPTIONAL\r
+ )\r
+{\r
+ UINT32 Index;\r
+ UINT32 NumberOfEntries;\r
+ GAUGE_DATA_ENTRY *GaugeEntryArray;\r
+\r
+ if (Token == NULL) {\r
+ Token = "";\r
+ }\r
+ if (Module == NULL) {\r
+ Module = "";\r
+ }\r
+\r
+ NumberOfEntries = mGaugeData->NumberOfEntries;\r
+ GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+\r
+ for (Index = 0; Index < NumberOfEntries; Index++) {\r
+ if ((GaugeEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
+ AsciiStrnCmp (GaugeEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+ AsciiStrnCmp (GaugeEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+ GaugeEntryArray[Index].EndTimeStamp == 0\r
+ ) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ return Index;\r
+}\r
+\r
+/**\r
+ Adds a record at the end of the performance measurement log\r
+ that records the start time of a performance measurement.\r
+\r
+ Adds a record to the end of the performance measurement log\r
+ that contains the Handle, Token, and Module.\r
+ The end time of the new record must be set to zero.\r
+ If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+ If TimeStamp is zero, the start time in the record is filled in with the value\r
+ read from the current time stamp.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval EFI_SUCCESS The data was read correctly from the device.\r
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+StartGauge (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ )\r
+{\r
+ GAUGE_DATA_ENTRY *GaugeEntryArray;\r
+ UINTN GaugeDataSize;\r
+ UINTN OldGaugeDataSize;\r
+ GAUGE_DATA_HEADER *OldGaugeData;\r
+ UINT32 Index;\r
+\r
+ Index = mGaugeData->NumberOfEntries;\r
+ if (Index >= mMaxGaugeRecords) {\r
+ //\r
+ // Try to enlarge the scale of gauge arrary.\r
+ //\r
+ OldGaugeData = mGaugeData;\r
+ OldGaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+\r
+ mMaxGaugeRecords *= 2;\r
+ GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+\r
+ mGaugeData = AllocateZeroPool (GaugeDataSize);\r
+ if (mGaugeData == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ //\r
+ // Initialize new data arry and migrate old data one.\r
+ //\r
+ mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
+\r
+ FreePool (OldGaugeData);\r
+ }\r
+\r
+ GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+ GaugeEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+\r
+ if (Token != NULL) {\r
+ AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
+ }\r
+ if (Module != NULL) {\r
+ AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
+ }\r
+\r
+ if (TimeStamp == 0) {\r
+ TimeStamp = GetPerformanceCounter ();\r
+ }\r
+ GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r
+\r
+ mGaugeData->NumberOfEntries++;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first matching record that contains a zero end time and fills in a valid end time.\r
+\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+ If the record can not be found then return EFI_NOT_FOUND.\r
+ If the record is found and TimeStamp is not zero,\r
+ then the end time in the record is filled in with the value specified by TimeStamp.\r
+ If the record is found and TimeStamp is zero, then the end time in the matching record\r
+ is filled in with the current time stamp value.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval EFI_SUCCESS The end of the measurement was recorded.\r
+ @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+EndGauge (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ )\r
+{\r
+ GAUGE_DATA_ENTRY *GaugeEntryArray;\r
+ UINT32 Index;\r
+\r
+ if (TimeStamp == 0) {\r
+ TimeStamp = GetPerformanceCounter ();\r
+ }\r
+\r
+ Index = InternalSearchForGaugeEntry (Handle, Token, Module);\r
+ if (Index >= mGaugeData->NumberOfEntries) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+ GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrieves a previously logged performance measurement.\r
+\r
+ Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
+ If it stands for a valid entry, then EFI_SUCCESS is returned and\r
+ GaugeDataEntry stores the pointer to that entry.\r
+\r
+ @param LogEntryKey The key for the previous performance measurement log entry.\r
+ If 0, then the first performance measurement log entry is retrieved.\r
+ @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r
+ if the retrieval is successful.\r
+\r
+ @retval EFI_SUCCESS The GuageDataEntry is successfuly found based on LogEntryKey.\r
+ @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
+ @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
+ @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+GetGauge (\r
+ IN UINTN LogEntryKey,\r
+ OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r
+ )\r
+{\r
+ UINTN NumberOfEntries;\r
+ GAUGE_DATA_ENTRY *LogEntryArray;\r
+\r
+ NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
+ if (LogEntryKey > NumberOfEntries) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ if (LogEntryKey == NumberOfEntries) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ LogEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+\r
+ if (GaugeDataEntry == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Dumps all the PEI performance log to DXE performance gauge array.\r
+\r
+ This internal function dumps all the PEI performance log to the DXE performance gauge array.\r
+ It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r
+ to DXE performance data structures.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+InternalGetPeiPerformance (\r
+ VOID\r
+ )\r
+{\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ PEI_PERFORMANCE_LOG_HEADER *LogHob;\r
+ PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
+ GAUGE_DATA_ENTRY *GaugeEntryArray;\r
+ UINT32 Index;\r
+ UINT32 NumberOfEntries;\r
+\r
+ NumberOfEntries = 0;\r
+ GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+\r
+ //\r
+ // Dump PEI Log Entries to DXE Guage Data structure.\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid);\r
+ if (GuidHob != NULL) {\r
+ LogHob = GET_GUID_HOB_DATA (GuidHob);\r
+ LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);\r
+ GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+\r
+ NumberOfEntries = LogHob->NumberOfEntries;\r
+ for (Index = 0; Index < NumberOfEntries; Index++) {\r
+ GaugeEntryArray[Index].Handle = LogEntryArray[Index].Handle;\r
+ AsciiStrnCpy (GaugeEntryArray[Index].Token, LogEntryArray[Index].Token, DXE_PERFORMANCE_STRING_LENGTH);\r
+ AsciiStrnCpy (GaugeEntryArray[Index].Module, LogEntryArray[Index].Module, DXE_PERFORMANCE_STRING_LENGTH);\r
+ GaugeEntryArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r
+ GaugeEntryArray[Index].EndTimeStamp = LogEntryArray[Index].EndTimeStamp;\r
+ }\r
+ }\r
+ mGaugeData->NumberOfEntries = NumberOfEntries;\r
+}\r
+\r
+/**\r
+ The constructor function initializes Performance infrastructure for DXE phase.\r
+\r
+ The constructor function publishes Performance protocol, allocates memory to log DXE performance\r
+ and merges PEI performance data to DXE performance log.\r
+ It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeCorePerformanceLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (!PerformanceMeasurementEnabled ()) {\r
+ //\r
+ // Do not initialize performance infrastructure if not required.\r
+ //\r
+ return EFI_SUCCESS;\r
+ }\r
+ //\r
+ // Install the protocol interfaces.\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &mHandle,\r
+ &gPerformanceProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &mPerformanceInterface\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
+\r
+ mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
+ ASSERT (mGaugeData != NULL);\r
+\r
+ InternalGetPeiPerformance ();\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Adds a record at the end of the performance measurement log\r
+ that records the start time of a performance measurement.\r
+\r
+ Adds a record to the end of the performance measurement log\r
+ that contains the Handle, Token, and Module.\r
+ The end time of the new record must be set to zero.\r
+ If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+ If TimeStamp is zero, the start time in the record is filled in with the value\r
+ read from the current time stamp.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval RETURN_SUCCESS The start of the measurement was recorded.\r
+ @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StartPerformanceMeasurement (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = StartGauge (Handle, Token, Module, TimeStamp);\r
+ return (RETURN_STATUS) Status;\r
+}\r
+\r
+/**\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first matching record that contains a zero end time and fills in a valid end time.\r
+\r
+ Searches the performance measurement log from the beginning of the log\r
+ for the first record that matches Handle, Token, and Module and has an end time value of zero.\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 the end time in the record is filled in with the value specified by TimeStamp.\r
+ If the record is found and TimeStamp is zero, then the end time in the matching record\r
+ is filled in with the current time stamp value.\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
+ 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 TimeStamp 64-bit time stamp.\r
+\r
+ @retval RETURN_SUCCESS The end of the measurement was recorded.\r
+ @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+EndPerformanceMeasurement (\r
+ IN CONST VOID *Handle, OPTIONAL\r
+ IN CONST CHAR8 *Token, OPTIONAL\r
+ IN CONST CHAR8 *Module, OPTIONAL\r
+ IN UINT64 TimeStamp\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = EndGauge (Handle, Token, Module, TimeStamp);\r
+ return (RETURN_STATUS) Status;\r
+}\r
+\r
+/**\r
+ Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+\r
+ Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
+ zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+ and the key for the second entry in the log is returned. If the performance log is empty,\r
+ then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
+ log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+ returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+ retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+ log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+ is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
+ the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+ If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+ If Handle is NULL, then ASSERT().\r
+ If Token is NULL, then ASSERT().\r
+ If Module is NULL, then ASSERT().\r
+ If StartTimeStamp is NULL, then ASSERT().\r
+ If EndTimeStamp is NULL, then ASSERT().\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 lof entry entry.\r
+ @param Handle Pointer to environment specific context used to identify the component\r
+ being measured.\r
+ @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
+ being measured.\r
+ @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
+ being measured.\r
+ @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
+ was started.\r
+ @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
+ was ended.\r
+\r
+ @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetPerformanceMeasurement (\r
+ IN UINTN LogEntryKey,\r
+ OUT CONST VOID **Handle,\r
+ OUT CONST CHAR8 **Token,\r
+ OUT CONST CHAR8 **Module,\r
+ OUT UINT64 *StartTimeStamp,\r
+ OUT UINT64 *EndTimeStamp\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ GAUGE_DATA_ENTRY *GaugeData;\r
+\r
+ ASSERT (Handle != NULL);\r
+ ASSERT (Token != NULL);\r
+ ASSERT (Module != NULL);\r
+ ASSERT (StartTimeStamp != NULL);\r
+ ASSERT (EndTimeStamp != NULL);\r
+\r
+ Status = GetGauge (LogEntryKey++, &GaugeData);\r
+\r
+ //\r
+ // Make sure that LogEntryKey is a valid log entry key,\r
+ //\r
+ ASSERT (Status != EFI_INVALID_PARAMETER);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // The LogEntryKey is the last entry (equals to the total entry number).\r
+ //\r
+ return 0;\r
+ }\r
+\r
+ ASSERT (GaugeData != NULL);\r
+\r
+ *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
+ *Token = GaugeData->Token;\r
+ *Module = GaugeData->Module;\r
+ *StartTimeStamp = GaugeData->StartTimeStamp;\r
+ *EndTimeStamp = GaugeData->EndTimeStamp;\r
+\r
+ return LogEntryKey;\r
+}\r
+\r
+/**\r
+ Returns TRUE if the performance measurement macros are enabled.\r
+\r
+ This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+ PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
+\r
+ @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+ PcdPerformanceLibraryPropertyMask is set.\r
+ @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+ PcdPerformanceLibraryPropertyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PerformanceMeasurementEnabled (\r
+ VOID\r
+ )\r
+{\r
+ return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
+}\r