]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Add performance property configuration table
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index 0b925b3c7d6c1e583ebd82dc86249d751d058a4d..1564514518d3a5475a1812df5a24c7541831c86d 100644 (file)
@@ -1,8 +1,18 @@
 /** @file\r
-  Support for measurement of DXE performance\r
+  Performance library instance mainly used by DxeCore.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+  This library provides the performance measurement interfaces and initializes performance\r
+  logging for DXE phase. It first initializes its private global data structure for\r
+  performance logging and saves the performance GUIDed HOB passed from PEI phase. \r
+  It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,\r
+  which are consumed by DxePerformanceLib to logging performance data in DXE phase.\r
+\r
+  This library is mainly used by DxeCore to start performance logging to ensure that\r
+  Performance Protocol is installed at the very beginning of DXE phase.\r
+\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -17,23 +27,47 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
 //\r
-// Definition for global variables.\r
+// The data structure to hold global performance data.\r
 //\r
 GAUGE_DATA_HEADER    *mGaugeData;\r
+\r
+//\r
+// The current maximum number of logging entries. If current number of \r
+// entries exceeds this value, it will re-allocate a larger array and\r
+// migration the old data to the larger array.\r
+//\r
 UINT32               mMaxGaugeRecords;\r
 \r
+//\r
+// The handle to install Performance Protocol instance.\r
+//\r
 EFI_HANDLE           mHandle = NULL;\r
+\r
+//\r
+// Interfaces for Performance Protocol.\r
+//\r
 PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
   StartGauge,\r
   EndGauge,\r
   GetGauge\r
   };\r
 \r
+//\r
+// Interfaces for PerformanceEx Protocol.\r
+//\r
+PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r
+  StartGaugeEx,\r
+  EndGaugeEx,\r
+  GetGaugeEx\r
+  };\r
+\r
+PERFORMANCE_PROPERTY  mPerformanceProperty;\r
+\r
 /**\r
-  Searches in the gauge array with keyword Handle, Token and Module.\r
+  Searches in the gauge array with keyword Handle, Token, Module and Identifier.\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
+  If there is an entry that exactly matches the given keywords\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
@@ -43,6 +77,7 @@ PERFORMANCE_PROTOCOL mPerformanceInterface = {
                                   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
 \r
   @retval The index of gauge entry in the array.\r
 \r
@@ -51,12 +86,14 @@ UINT32
 InternalSearchForGaugeEntry (\r
   IN CONST VOID                 *Handle,  OPTIONAL\r
   IN CONST CHAR8                *Token,   OPTIONAL\r
-  IN CONST CHAR8                *Module   OPTIONAL\r
+  IN CONST CHAR8                *Module,   OPTIONAL\r
+  IN UINT32                     Identifier\r
   )\r
 {\r
   UINT32                    Index;\r
+  UINT32                    Index2;\r
   UINT32                    NumberOfEntries;\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
 \r
   if (Token == NULL) {\r
     Token = "";\r
@@ -66,14 +103,17 @@ InternalSearchForGaugeEntry (
   }\r
 \r
   NumberOfEntries = mGaugeData->NumberOfEntries;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+\r
+  Index2 = 0;\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
+    Index2 = NumberOfEntries - 1 - Index;\r
+    if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&\r
+        (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
+        AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+        AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, DXE_PERFORMANCE_STRING_LENGTH) == 0) {\r
+      Index = Index2;\r
       break;\r
     }\r
   }\r
@@ -86,7 +126,7 @@ InternalSearchForGaugeEntry (
   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
+  that contains the Handle, Token, Module and Identifier.\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
@@ -99,6 +139,8 @@ InternalSearchForGaugeEntry (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
+                                  is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\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
@@ -106,15 +148,17 @@ InternalSearchForGaugeEntry (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-StartGauge (\r
+StartGaugeEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
   UINTN                     GaugeDataSize;\r
+  GAUGE_DATA_HEADER         *NewGaugeData;\r
   UINTN                     OldGaugeDataSize;\r
   GAUGE_DATA_HEADER         *OldGaugeData;\r
   UINT32                    Index;\r
@@ -122,40 +166,46 @@ StartGauge (
   Index = mGaugeData->NumberOfEntries;\r
   if (Index >= mMaxGaugeRecords) {\r
     //\r
-    // Try to enlarge the scale of gauge arrary.\r
+    // Try to enlarge the scale of gauge array.\r
     //\r
     OldGaugeData      = mGaugeData;\r
-    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;\r
 \r
-    mMaxGaugeRecords *= 2;\r
-    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;\r
 \r
-    mGaugeData = AllocateZeroPool (GaugeDataSize);\r
-    if (mGaugeData == NULL) {\r
+    NewGaugeData = AllocateZeroPool (GaugeDataSize);\r
+    if (NewGaugeData == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
+    mGaugeData = NewGaugeData;\r
+    mMaxGaugeRecords *= 2;\r
+\r
     //\r
-    // Initialize new data arry and migrate old data one.\r
+    // Initialize new data array 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
+  GaugeEntryExArray               = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+  GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
 \r
   if (Token != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (GaugeEntryExArray[Index].Token, DXE_PERFORMANCE_STRING_SIZE, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
   }\r
   if (Module != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
   }\r
 \r
+  GaugeEntryExArray[Index].EndTimeStamp = 0;\r
+  GaugeEntryExArray[Index].Identifier = Identifier;\r
+\r
   if (TimeStamp == 0) {\r
     TimeStamp = GetPerformanceCounter ();\r
   }\r
-  GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r
+  GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;\r
 \r
   mGaugeData->NumberOfEntries++;\r
 \r
@@ -167,7 +217,7 @@ StartGauge (
   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
+  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
@@ -181,6 +231,8 @@ StartGauge (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
+                                  is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.\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
@@ -188,57 +240,60 @@ StartGauge (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-EndGauge (\r
+EndGaugeEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY  *GaugeEntryArray;\r
-  UINT32            Index;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
+  UINT32              Index;\r
 \r
   if (TimeStamp == 0) {\r
     TimeStamp = GetPerformanceCounter ();\r
   }\r
 \r
-  Index = InternalSearchForGaugeEntry (Handle, Token, Module);\r
+  Index = InternalSearchForGaugeEntry (Handle, Token, Module, Identifier);\r
   if (Index >= mGaugeData->NumberOfEntries) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY  *) (mGaugeData + 1);\r
-  GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+  GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Retrieves a previously logged performance measurement.\r
+  It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r
+  and then assign the Identifier with 0.\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
+  GaugeDataEntryEx 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
+  @param  GaugeDataEntryEx        The indirect pointer to the extended 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_SUCCESS             The GuageDataEntryEx is successfully 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
+  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntryEx is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-GetGauge (\r
-  IN  UINTN               LogEntryKey,\r
-  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
+GetGaugeEx (\r
+  IN  UINTN                 LogEntryKey,\r
+  OUT GAUGE_DATA_ENTRY_EX   **GaugeDataEntryEx\r
   )\r
 {\r
   UINTN               NumberOfEntries;\r
-  GAUGE_DATA_ENTRY    *LogEntryArray;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
 \r
   NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
   if (LogEntryKey > NumberOfEntries) {\r
@@ -248,12 +303,129 @@ GetGauge (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  LogEntryArray   = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+\r
+  if (GaugeDataEntryEx == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *GaugeDataEntryEx = &GaugeEntryExArray[LogEntryKey];\r
+\r
+  return EFI_SUCCESS;\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
+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
+  return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\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
+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
+  return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
+\r
+/**\r
+  Retrieves a previously logged performance measurement.\r
+  It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,\r
+  and then eliminate the Identifier.\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 successfully 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
+EFI_STATUS\r
+EFIAPI\r
+GetGauge (\r
+  IN  UINTN               LogEntryKey,\r
+  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryEx;\r
+\r
+  GaugeEntryEx = NULL;\r
+\r
+  Status = GetGaugeEx (LogEntryKey, &GaugeEntryEx);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   if (GaugeDataEntry == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r
+\r
+  *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -274,29 +446,38 @@ InternalGetPeiPerformance (
   EFI_HOB_GUID_TYPE                 *GuidHob;\r
   PEI_PERFORMANCE_LOG_HEADER        *LogHob;\r
   PEI_PERFORMANCE_LOG_ENTRY         *LogEntryArray;\r
-  GAUGE_DATA_ENTRY                  *GaugeEntryArray;\r
+  UINT32                            *LogIdArray;\r
+  GAUGE_DATA_ENTRY_EX               *GaugeEntryExArray;\r
   UINT32                            Index;\r
   UINT32                            NumberOfEntries;\r
 \r
   NumberOfEntries = 0;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
 \r
   //\r
   // Dump PEI Log Entries to DXE Guage Data structure.\r
   //\r
-  GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid);\r
+  GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\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
+      GaugeEntryExArray[Index].Handle         = LogEntryArray[Index].Handle;\r
+      AsciiStrCpyS (GaugeEntryExArray[Index].Token,  DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Token);\r
+      AsciiStrCpyS (GaugeEntryExArray[Index].Module, DXE_PERFORMANCE_STRING_SIZE, LogEntryArray[Index].Module);\r
+      GaugeEntryExArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r
+      GaugeEntryExArray[Index].EndTimeStamp   = LogEntryArray[Index].EndTimeStamp;\r
+      GaugeEntryExArray[Index].Identifier     = 0;\r
+    }\r
+\r
+    GuidHob = GetFirstGuidHob (&gPerformanceExProtocolGuid);\r
+    if (GuidHob != NULL) {\r
+      LogIdArray    = GET_GUID_HOB_DATA (GuidHob);\r
+      for (Index = 0; Index < NumberOfEntries; Index++) {\r
+        GaugeEntryExArray[Index].Identifier   = LogIdArray[Index];\r
+      }\r
     }\r
   }\r
   mGaugeData->NumberOfEntries = NumberOfEntries;\r
@@ -305,7 +486,7 @@ InternalGetPeiPerformance (
 /**\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
+  The constructor function publishes Performance and PerformanceEx 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
@@ -323,6 +504,8 @@ DxeCorePerformanceLibConstructor (
   )\r
 {\r
   EFI_STATUS                Status;\r
+  PERFORMANCE_PROPERTY      *PerformanceProperty;\r
+\r
 \r
   if (!PerformanceMeasurementEnabled ()) {\r
     //\r
@@ -333,22 +516,41 @@ DxeCorePerformanceLibConstructor (
   //\r
   // Install the protocol interfaces.\r
   //\r
-  Status = gBS->InstallProtocolInterface (\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mHandle,\r
                   &gPerformanceProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &mPerformanceInterface\r
+                  &mPerformanceInterface,\r
+                  &gPerformanceExProtocolGuid,\r
+                  &mPerformanceExInterface,\r
+                  NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
+  mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
+                                                             PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
+                                                             PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
 \r
-  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
+  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r
   ASSERT (mGaugeData != NULL);\r
 \r
   InternalGetPeiPerformance ();\r
 \r
-  return Status;\r
+  Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, &PerformanceProperty);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Install configuration table for performance property.\r
+    //\r
+    mPerformanceProperty.Revision  = PERFORMANCE_PROPERTY_REVISION;\r
+    mPerformanceProperty.Reserved  = 0;\r
+    mPerformanceProperty.Frequency = GetPerformanceCounterProperties (\r
+                                       &mPerformanceProperty.TimerStartValue,\r
+                                       &mPerformanceProperty.TimerEndValue\r
+                                       );\r
+    Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -356,7 +558,7 @@ DxeCorePerformanceLibConstructor (
   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
+  that contains the Handle, Token, Module and Identifier.\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
@@ -369,6 +571,8 @@ DxeCorePerformanceLibConstructor (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
+                                  is same as the one created by StartPerformanceMeasurement.\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
@@ -376,17 +580,15 @@ DxeCorePerformanceLibConstructor (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-StartPerformanceMeasurement (\r
+StartPerformanceMeasurementEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = StartGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -394,7 +596,7 @@ StartPerformanceMeasurement (
   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
+  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
@@ -408,6 +610,8 @@ StartPerformanceMeasurement (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
+                                  is same as the one found by EndPerformanceMeasurement.\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
@@ -415,21 +619,21 @@ StartPerformanceMeasurement (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-EndPerformanceMeasurement (\r
+EndPerformanceMeasurementEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EndGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
   Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
+  and then assign the Identifier with 0.\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
@@ -440,17 +644,18 @@ EndPerformanceMeasurement (
   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
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\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
+  If Identifier 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
+                                  On exit, the key of the next performance log 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
@@ -461,23 +666,25 @@ EndPerformanceMeasurement (
                                   was started.\r
   @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
                                   was ended.\r
+  @param  Identifier              Pointer to the 32-bit identifier that was recorded.\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
+GetPerformanceMeasurementEx (\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
+  OUT UINT64      *EndTimeStamp,\r
+  OUT UINT32      *Identifier\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  GAUGE_DATA_ENTRY  *GaugeData;\r
+  EFI_STATUS           Status;\r
+  GAUGE_DATA_ENTRY_EX  *GaugeData;\r
 \r
   GaugeData = NULL;\r
   \r
@@ -486,8 +693,9 @@ GetPerformanceMeasurement (
   ASSERT (Module != NULL);\r
   ASSERT (StartTimeStamp != NULL);\r
   ASSERT (EndTimeStamp != NULL);\r
+  ASSERT (Identifier != NULL);\r
 \r
-  Status = GetGauge (LogEntryKey++, &GaugeData);\r
+  Status = GetGaugeEx (LogEntryKey++, &GaugeData);\r
 \r
   //\r
   // Make sure that LogEntryKey is a valid log entry key,\r
@@ -508,10 +716,136 @@ GetPerformanceMeasurement (
   *Module         = GaugeData->Module;\r
   *StartTimeStamp = GaugeData->StartTimeStamp;\r
   *EndTimeStamp   = GaugeData->EndTimeStamp;\r
+  *Identifier     = GaugeData->Identifier;\r
 \r
   return LogEntryKey;\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
+  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\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
+  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
+\r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
+  and then eliminate the Identifier.\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 log 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
+  UINT32 Identifier;\r
+  return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
+}\r
+\r
 /**\r
   Returns TRUE if the performance measurement macros are enabled.\r
 \r