]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg/DxeCorePerformanceLib: use AllocatePeiAccessiblePages
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index 1cf4fb1da34f8f0c294895b9d8bf770f9d7cd984..68b29ac5a9e291493060ec913bb9468f8652342a 100644 (file)
@@ -4,13 +4,14 @@
   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 Protocol,\r
-  which is consumed by DxePerformanceLib to logging performance data in DXE 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 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -24,40 +25,1093 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "DxeCorePerformanceLibInternal.h"\r
 \r
+//\r
+// Data for FPDT performance records.\r
+//\r
+#define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))\r
+#define STRING_SIZE             (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
+#define FIRMWARE_RECORD_BUFFER  0x10000\r
+#define CACHE_HANDLE_GUID_COUNT 0x800\r
+\r
+BOOT_PERFORMANCE_TABLE          *mAcpiBootPerformanceTable = NULL;\r
+BOOT_PERFORMANCE_TABLE          mBootPerformanceTableTemplate = {\r
+  {\r
+    EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,\r
+    sizeof (BOOT_PERFORMANCE_TABLE)\r
+  },\r
+  {\r
+    {\r
+      EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT,    // Type\r
+      sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD),        // Length\r
+      EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT // Revision\r
+    },\r
+    0,  // Reserved\r
+    //\r
+    // These values will be updated at runtime.\r
+    //\r
+    0,  // ResetEnd\r
+    0,  // OsLoaderLoadImageStart\r
+    0,  // OsLoaderStartImageStart\r
+    0,  // ExitBootServicesEntry\r
+    0   // ExitBootServicesExit\r
+  }\r
+};\r
+\r
+typedef struct {\r
+  EFI_HANDLE    Handle;\r
+  CHAR8         NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
+  EFI_GUID      ModuleGuid;\r
+} HANDLE_GUID_MAP;\r
+\r
+HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];\r
+UINTN           mCachePairCount = 0;\r
+\r
+UINT32  mLoadImageCount       = 0;\r
+UINT32  mPerformanceLength    = 0;\r
+UINT32  mMaxPerformanceLength = 0;\r
+UINT32  mBootRecordSize       = 0;\r
+UINT32  mBootRecordMaxSize    = 0;\r
+\r
+BOOLEAN mFpdtBufferIsReported = FALSE;\r
+BOOLEAN mLackSpaceIsReported  = FALSE;\r
+CHAR8   *mPlatformLanguage    = NULL;\r
+UINT8   *mPerformancePointer  = NULL;\r
+UINT8   *mBootRecordBuffer    = NULL;\r
+BOOLEAN  mLockInsertRecord    = FALSE;\r
+\r
+EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;\r
 \r
 //\r
-// The data structure to hold global performance data.\r
+// Interfaces for Performance Protocol.\r
 //\r
-GAUGE_DATA_HEADER    *mGaugeData;\r
+PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
+  StartGauge,\r
+  EndGauge,\r
+  GetGauge\r
+  };\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
+// Interfaces for PerformanceEx Protocol.\r
 //\r
-UINT32               mMaxGaugeRecords;\r
+PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r
+  StartGaugeEx,\r
+  EndGaugeEx,\r
+  GetGaugeEx\r
+  };\r
+\r
+PERFORMANCE_PROPERTY  mPerformanceProperty;\r
+\r
+/**\r
+Check whether the Token is a known one which is uesed by core.\r
+\r
+@param  Token      Pointer to a Null-terminated ASCII string\r
+\r
+@retval TRUE       Is a known one used by core.\r
+@retval FALSE      Not a known one.\r
+\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
+BOOLEAN\r
+IsKnownID (\r
+  IN UINT32       Identifier\r
+  )\r
+{\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
+  Allocate buffer for Boot Performance table.\r
+\r
+  @return Status code.\r
+\r
+**/\r
+EFI_STATUS\r
+AllocateBootPerformanceTable (\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  UINTN                                   Size;\r
+  UINT8                                   *SmmBootRecordCommBuffer;\r
+  EFI_SMM_COMMUNICATE_HEADER              *SmmCommBufferHeader;\r
+  SMM_BOOT_RECORD_COMMUNICATE             *SmmCommData;\r
+  UINTN                                   CommSize;\r
+  UINTN                                   BootPerformanceDataSize;\r
+  UINT8                                   *BootPerformanceData;\r
+  EFI_SMM_COMMUNICATION_PROTOCOL          *Communication;\r
+  FIRMWARE_PERFORMANCE_VARIABLE           PerformanceVariable;\r
+  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;\r
+  EFI_MEMORY_DESCRIPTOR                   *SmmCommMemRegion;\r
+  UINTN                                   Index;\r
+  VOID                                    *SmmBootRecordData;\r
+  UINTN                                   SmmBootRecordDataSize;\r
+  UINTN                                   ReservedMemSize;\r
+\r
+  //\r
+  // Collect boot records from SMM drivers.\r
+  //\r
+  SmmBootRecordCommBuffer = NULL;\r
+  SmmCommData             = NULL;\r
+  SmmBootRecordData       = NULL;\r
+  SmmBootRecordDataSize   = 0;\r
+  ReservedMemSize         = 0;\r
+  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initialize communicate buffer\r
+    // Get the prepared Reserved Memory Range\r
+    //\r
+    Status = EfiGetSystemConfigurationTable (\r
+              &gEdkiiPiSmmCommunicationRegionTableGuid,\r
+              (VOID **) &SmmCommRegionTable\r
+              );\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (SmmCommRegionTable != NULL);\r
+      SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);\r
+      for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index ++) {\r
+        if (SmmCommMemRegion->Type == EfiConventionalMemory) {\r
+          break;\r
+        }\r
+        SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);\r
+      }\r
+      ASSERT (Index < SmmCommRegionTable->NumberOfEntries);\r
+      ASSERT (SmmCommMemRegion->PhysicalStart > 0);\r
+      ASSERT (SmmCommMemRegion->NumberOfPages > 0);\r
+      ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;\r
+\r
+      //\r
+      // Check enough reserved memory space\r
+      //\r
+      if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {\r
+        SmmBootRecordCommBuffer = (VOID *) (UINTN) SmmCommMemRegion->PhysicalStart;\r
+        SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;\r
+        SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;\r
+        ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));\r
+\r
+        CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);\r
+        SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);\r
+        CommSize = SMM_BOOT_RECORD_COMM_SIZE;\r
+\r
+        //\r
+        // Get the size of boot records.\r
+        //\r
+        SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;\r
+        SmmCommData->BootRecordData = NULL;\r
+        Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+\r
+        if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
+          //\r
+          // Get all boot records\r
+          //\r
+          SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;\r
+          SmmBootRecordDataSize       = SmmCommData->BootRecordSize;\r
+          SmmBootRecordData           = AllocateZeroPool(SmmBootRecordDataSize);\r
+          ASSERT (SmmBootRecordData  != NULL);\r
+          SmmCommData->BootRecordOffset = 0;\r
+          SmmCommData->BootRecordData   = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);\r
+          SmmCommData->BootRecordSize   = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;\r
+          while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {\r
+            Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+            ASSERT_EFI_ERROR (Status);\r
+            ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
+            if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {\r
+              CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);\r
+            } else {\r
+              CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
+            }\r
+            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Prepare memory for Boot Performance table.\r
+  // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.\r
+  //\r
+  BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+    BootPerformanceDataSize += SmmBootRecordDataSize;\r
+  }\r
+\r
+  //\r
+  // Try to allocate the same runtime buffer as last time boot.\r
+  //\r
+  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  Size = sizeof (PerformanceVariable);\r
+  Status = gRT->GetVariable (\r
+                  EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
+                  &gEfiFirmwarePerformanceGuid,\r
+                  NULL,\r
+                  &Size,\r
+                  &PerformanceVariable\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->AllocatePages (\r
+                    AllocateAddress,\r
+                    EfiReservedMemoryType,\r
+                    EFI_SIZE_TO_PAGES (BootPerformanceDataSize),\r
+                    &PerformanceVariable.BootPerformanceTablePointer\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
+    }\r
+  }\r
+\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
+    //\r
+    // Fail to allocate at specified address, continue to allocate at any address.\r
+    //\r
+    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
+                                                             EfiReservedMemoryType,\r
+                                                             EFI_SIZE_TO_PAGES (BootPerformanceDataSize)\r
+                                                             );\r
+    if (mAcpiBootPerformanceTable != NULL) {\r
+      ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);\r
+    }\r
+  }\r
+  DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
+\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
+    if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+      FreePool (SmmBootRecordData);\r
+    }\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Prepare Boot Performance Table.\r
+  //\r
+  BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;\r
+  //\r
+  // Fill Basic Boot record to Boot Performance Table.\r
+  //\r
+  CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
+  BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;\r
+  //\r
+  // Fill Boot records from boot drivers.\r
+  //\r
+  if (mPerformancePointer != NULL) {\r
+    CopyMem (BootPerformanceData, mPerformancePointer, mPerformanceLength);\r
+    mAcpiBootPerformanceTable->Header.Length += mPerformanceLength;\r
+    BootPerformanceData = BootPerformanceData + mPerformanceLength;\r
+    FreePool (mPerformancePointer);\r
+    mPerformancePointer   = NULL;\r
+    mPerformanceLength    = 0;\r
+    mMaxPerformanceLength = 0;\r
+  }\r
+  if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+    //\r
+    // Fill Boot records from SMM drivers.\r
+    //\r
+    CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);\r
+    FreePool (SmmBootRecordData);\r
+    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);\r
+    BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;\r
+  }\r
+\r
+  mBootRecordBuffer  = (UINT8 *) mAcpiBootPerformanceTable;\r
+  mBootRecordSize    = mAcpiBootPerformanceTable->Header.Length;\r
+  mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get a human readable module name and module guid for the given image handle.\r
+  If module name can't be found, "" string will return.\r
+  If module guid can't be found, Zero Guid will return.\r
+\r
+  @param    Handle        Image handle or Controller handle.\r
+  @param    NameString    The ascii string will be filled into it. If not found, null string will return.\r
+  @param    BufferSize    Size of the input NameString buffer.\r
+  @param    ModuleGuid    Point to the guid buffer to store the got module guid value.\r
+\r
+  @retval EFI_SUCCESS     Successfully get module name and guid.\r
+  @retval EFI_INVALID_PARAMETER  The input parameter NameString is NULL.\r
+  @retval other value  Module Name can't be got.\r
+**/\r
+EFI_STATUS\r
+GetModuleInfoFromHandle (\r
+  IN EFI_HANDLE  Handle,\r
+  OUT CHAR8            *NameString,\r
+  IN UINTN             BufferSize,\r
+  OUT EFI_GUID         *ModuleGuid OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage;\r
+  EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;\r
+  CHAR8                       *PdbFileName;\r
+  EFI_GUID                    *TempGuid;\r
+  UINTN                       StartIndex;\r
+  UINTN                       Index;\r
+  INTN                        Count;\r
+  BOOLEAN                     ModuleGuidIsGet;\r
+  UINTN                       StringSize;\r
+  CHAR16                      *StringPtr;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r
+\r
+  if (NameString == NULL || BufferSize == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Try to get the ModuleGuid and name string form the caached array.\r
+  //\r
+  if (mCachePairCount > 0) {\r
+    for (Count = mCachePairCount -1; Count >= 0; Count--) {\r
+      if (Handle == mCacheHandleGuidTable[Count].Handle) {\r
+        CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);\r
+        AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
+  Status = EFI_INVALID_PARAMETER;\r
+  LoadedImage     = NULL;\r
+  ModuleGuidIsGet = FALSE;\r
+\r
+  //\r
+  // Initialize GUID as zero value.\r
+  //\r
+  TempGuid    = &gZeroGuid;\r
+  //\r
+  // Initialize it as "" string.\r
+  //\r
+  NameString[0] = 0;\r
+\r
+  if (Handle != NULL) {\r
+    //\r
+    // Try Handle as ImageHandle.\r
+    //\r
+    Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID**) &LoadedImage\r
+                  );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Try Handle as Controller Handle\r
+      //\r
+      Status = gBS->OpenProtocol (\r
+                    Handle,\r
+                    &gEfiDriverBindingProtocolGuid,\r
+                    (VOID **) &DriverBinding,\r
+                    NULL,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // Get Image protocol from ImageHandle\r
+        //\r
+        Status = gBS->HandleProtocol (\r
+                      DriverBinding->ImageHandle,\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID**) &LoadedImage\r
+                      );\r
+      }\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status) && LoadedImage != NULL) {\r
+    //\r
+    // Get Module Guid from DevicePath.\r
+    //\r
+    if (LoadedImage->FilePath != NULL &&\r
+        LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&\r
+        LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP\r
+       ) {\r
+      //\r
+      // Determine GUID associated with module logging performance\r
+      //\r
+      ModuleGuidIsGet = TRUE;\r
+      FvFilePath      = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;\r
+      TempGuid        = &FvFilePath->FvFileName;\r
+    }\r
+\r
+    //\r
+    // Method 1 Get Module Name from PDB string.\r
+    //\r
+    PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);\r
+    if (PdbFileName != NULL && BufferSize > 0) {\r
+      StartIndex = 0;\r
+      for (Index = 0; PdbFileName[Index] != 0; Index++) {\r
+        if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {\r
+          StartIndex = Index + 1;\r
+        }\r
+      }\r
+      //\r
+      // Copy the PDB file name to our temporary string.\r
+      // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.\r
+      //\r
+      for (Index = 0; Index < BufferSize - 1; Index++) {\r
+        NameString[Index] = PdbFileName[Index + StartIndex];\r
+        if (NameString[Index] == 0 || NameString[Index] == '.') {\r
+          NameString[Index] = 0;\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (Index == BufferSize - 1) {\r
+        NameString[Index] = 0;\r
+      }\r
+      //\r
+      // Module Name is got.\r
+      //\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Method 2: Get the name string from ComponentName2 protocol\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the current platform language setting\r
+    //\r
+    if (mPlatformLanguage == NULL) {\r
+      GetEfiGlobalVariable2 (L"PlatformLang", (VOID **) &mPlatformLanguage, NULL);\r
+    }\r
+    if (mPlatformLanguage != NULL) {\r
+      Status = ComponentName2->GetDriverName (\r
+                                 ComponentName2,\r
+                                 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",\r
+                                 &StringPtr\r
+                                 );\r
+      if (!EFI_ERROR (Status)) {\r
+        for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
+          NameString[Index] = (CHAR8) StringPtr[Index];\r
+        }\r
+        NameString[Index] = 0;\r
+        //\r
+        // Module Name is got.\r
+        //\r
+        goto Done;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (ModuleGuidIsGet) {\r
+    //\r
+    // Method 3 Try to get the image's FFS UI section by image GUID\r
+    //\r
+    StringPtr  = NULL;\r
+    StringSize = 0;\r
+    Status = GetSectionFromAnyFv (\r
+              TempGuid,\r
+              EFI_SECTION_USER_INTERFACE,\r
+              0,\r
+              (VOID **) &StringPtr,\r
+              &StringSize\r
+              );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Method 3. Get the name string from FFS UI section\r
+      //\r
+      for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
+        NameString[Index] = (CHAR8) StringPtr[Index];\r
+      }\r
+      NameString[Index] = 0;\r
+      FreePool (StringPtr);\r
+    }\r
+  }\r
+\r
+Done:\r
+  //\r
+  // Copy Module Guid\r
+  //\r
+  if (ModuleGuid != NULL) {\r
+    CopyGuid (ModuleGuid, TempGuid);\r
+    if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {\r
+        // Handle is GUID\r
+      CopyGuid (ModuleGuid, (EFI_GUID *) Handle);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Cache the Handle and Guid pairs.\r
+  //\r
+  if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {\r
+    mCacheHandleGuidTable[mCachePairCount].Handle = Handle;\r
+    CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);\r
+    AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);\r
+    mCachePairCount ++;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Get the FPDT record info.\r
+\r
+  @param  IsStart                 TRUE if the performance log is start log.\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  RecordInfo              On return, pointer to the info of the record.\r
+  @param  UseModuleName           Only useful for FPDT_DYNAMIC_STRING_EVENT_TYPE, indicate that whether need use\r
+                                  Module name to fill the string field in the FPDT_DYNAMIC_STRING_EVENT_RECORD.\r
+\r
+  @retval EFI_SUCCESS          Get record info successfully.\r
+  @retval EFI_UNSUPPORTED      No matched FPDT record.\r
+\r
+**/\r
+EFI_STATUS\r
+GetFpdtRecordInfo (\r
+  IN BOOLEAN                  IsStart,\r
+  IN CONST VOID               *Handle,\r
+  IN CONST CHAR8              *Token,\r
+  IN CONST CHAR8              *Module,\r
+  OUT FPDT_BASIC_RECORD_INFO  *RecordInfo,\r
+  IN OUT BOOLEAN              *UseModuleName\r
+  )\r
+{\r
+  UINT16              RecordType;\r
+  UINTN               StringSize;\r
+\r
+  RecordType    = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+\r
+  //\r
+  // Token to Type and Id.\r
+  //\r
+  if (Token != NULL) {\r
+    if (AsciiStrCmp (Token, START_IMAGE_TOK) == 0) {                // "StartImage:"\r
+      *UseModuleName = TRUE;\r
+      RecordType     = FPDT_GUID_EVENT_TYPE;\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = MODULE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = MODULE_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) {          // "LoadImage:"\r
+      *UseModuleName = TRUE;\r
+      RecordType = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = MODULE_LOADIMAGE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = MODULE_LOADIMAGE_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0) {  // "DB:Start:"\r
+      *UseModuleName = TRUE;\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = MODULE_DB_START_ID;\r
+        RecordType   = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      } else {\r
+        RecordInfo->ProgressID  = MODULE_DB_END_ID;\r
+        RecordType   = FPDT_GUID_QWORD_STRING_EVENT_TYPE;\r
+      }\r
+    } else if (AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0) { // "DB:Support:"\r
+      *UseModuleName = TRUE;\r
+      if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+      RecordType     = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = MODULE_DB_SUPPORT_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = MODULE_DB_SUPPORT_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0) {    // "DB:Stop:"\r
+      *UseModuleName = TRUE;\r
+      if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+         return RETURN_UNSUPPORTED;\r
+      }\r
+      RecordType     = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = MODULE_DB_STOP_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = MODULE_DB_STOP_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (Token, PEI_TOK) == 0 ||                   // "PEI"\r
+               AsciiStrCmp (Token, DXE_TOK) == 0 ||                   // "DXE"\r
+               AsciiStrCmp (Token, BDS_TOK) == 0) {                   // "BDS"\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = PERF_CROSSMODULE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = PERF_CROSSMODULE_END_ID;\r
+      }\r
+    } else {                                                          // Pref used in Modules.\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID  = PERF_INMODULE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID  = PERF_INMODULE_END_ID;\r
+      }\r
+    }\r
+  } else if (Handle!= NULL || Module != NULL) {                       // Pref used in Modules.\r
+    if (IsStart) {\r
+      RecordInfo->ProgressID    = PERF_INMODULE_START_ID;\r
+    } else {\r
+      RecordInfo->ProgressID    = PERF_INMODULE_END_ID;\r
+    }\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Get Record size baesed on the record type.\r
+  // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.\r
+  //\r
+  if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+    RecordType               = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+    RecordInfo->RecordSize   = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE;\r
+  } else {\r
+    switch (RecordType) {\r
+    case FPDT_GUID_EVENT_TYPE:\r
+      RecordInfo->RecordSize = sizeof (FPDT_GUID_EVENT_RECORD);\r
+      break;\r
+\r
+    case FPDT_DYNAMIC_STRING_EVENT_TYPE:\r
+      if (*UseModuleName) {\r
+        StringSize  = STRING_SIZE;\r
+      } else if (Token  != NULL) {\r
+        StringSize  = AsciiStrSize (Token);\r
+      } else if (Module != NULL) {\r
+        StringSize  = AsciiStrSize (Module);\r
+      } else {\r
+        StringSize  = STRING_SIZE;\r
+      }\r
+      if (StringSize > STRING_SIZE) {\r
+        StringSize   = STRING_SIZE;\r
+      }\r
+      RecordInfo->RecordSize = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + StringSize);\r
+      break;\r
+\r
+    case FPDT_GUID_QWORD_EVENT_TYPE:\r
+      RecordInfo->RecordSize = (UINT8)sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
+      break;\r
+\r
+    case FPDT_GUID_QWORD_STRING_EVENT_TYPE:\r
+      RecordInfo->RecordSize = (UINT8)sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD);\r
+      break;\r
+\r
+    default:\r
+      //\r
+      // Record is unsupported yet, return EFI_UNSUPPORTED\r
+      //\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  RecordInfo->Type = RecordType;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Add performance log to FPDT boot record table.\r
+\r
+  @param  IsStart                 TRUE if the performance log is start log.\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  Ticker                  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             Add FPDT boot record.\r
+  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
+  @retval EFI_UNSUPPORTED         No matched FPDT record.\r
+\r
+**/\r
+EFI_STATUS\r
+InsertFpdtMeasurement (\r
+  IN BOOLEAN      IsStart,\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       Ticker,\r
+  IN UINT32       Identifier\r
+  )\r
+{\r
+  EFI_GUID                     ModuleGuid;\r
+  CHAR8                        ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
+  EFI_STATUS                   Status;\r
+  FPDT_RECORD_PTR              FpdtRecordPtr;\r
+  FPDT_BASIC_RECORD_INFO       RecordInfo;\r
+  UINT64                       TimeStamp;\r
+  UINTN                        DestMax;\r
+  UINTN                        StrLength;\r
+  CONST CHAR8                  *StringPtr;\r
+  BOOLEAN                      UseModuleName;\r
+\r
+  StringPtr     = NULL;\r
+  UseModuleName = FALSE;\r
+  ZeroMem (ModuleName, sizeof (ModuleName));\r
+\r
+  if (mLockInsertRecord) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  mLockInsertRecord = TRUE;\r
+\r
+  //\r
+  // Get record info (type, size, ProgressID and Module Guid).\r
+  //\r
+  Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo, &UseModuleName);\r
+  if (EFI_ERROR (Status)) {\r
+    mLockInsertRecord = FALSE;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If PERF_START()/PERF_END() 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 ((Identifier != 0) && (IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {\r
+    mLockInsertRecord = FALSE;\r
+    return EFI_UNSUPPORTED;\r
+  } else if ((Identifier != 0) && (!IsKnownID (Identifier)) && (!IsKnownTokens (Token))) {\r
+    if (IsStart && ((Identifier & 0x000F) != 0)) {\r
+      Identifier &= 0xFFF0;\r
+    } else if ((!IsStart) && ((Identifier & 0x000F) == 0)) {\r
+      Identifier += 1;\r
+    }\r
+    RecordInfo.ProgressID = (UINT16)Identifier;\r
+  }\r
+\r
+  if (mFpdtBufferIsReported) {\r
+    //\r
+    // Append Boot records to the boot performance table.\r
+    //\r
+    if (mBootRecordSize + RecordInfo.RecordSize > mBootRecordMaxSize) {\r
+      if (!mLackSpaceIsReported) {\r
+        DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save boot records\n"));\r
+        mLackSpaceIsReported = TRUE;\r
+      }\r
+      mLockInsertRecord = FALSE;\r
+      return EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      //\r
+      // Save boot record into BootPerformance table\r
+      //\r
+      FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mBootRecordSize);\r
+      mBootRecordSize += RecordInfo.RecordSize;\r
+      mAcpiBootPerformanceTable->Header.Length += RecordInfo.RecordSize;\r
+    }\r
+  } else {\r
+    //\r
+    // Check if pre-allocated buffer is full\r
+    //\r
+    if (mPerformanceLength + RecordInfo.RecordSize > mMaxPerformanceLength) {\r
+      mPerformancePointer = ReallocatePool (\r
+                              mPerformanceLength,\r
+                              mPerformanceLength + RecordInfo.RecordSize + FIRMWARE_RECORD_BUFFER,\r
+                              mPerformancePointer\r
+                              );\r
+\r
+      if (mPerformancePointer == NULL) {\r
+        mLockInsertRecord = FALSE;\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      mMaxPerformanceLength = mPerformanceLength + RecordInfo.RecordSize + FIRMWARE_RECORD_BUFFER;\r
+    }\r
+    //\r
+    // Covert buffer to FPDT Ptr Union type.\r
+    //\r
+    FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);\r
+    mPerformanceLength += RecordInfo.RecordSize;\r
+  }\r
+\r
+  //\r
+  // 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
+  // Get the ModuleName and ModuleGuid form the handle.\r
+  //\r
+  GetModuleInfoFromHandle ((EFI_HANDLE *)Handle, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+\r
+  //\r
+  // Fill in the record information.\r
+  //\r
+  switch (RecordInfo.Type) {\r
+  case FPDT_GUID_EVENT_TYPE:\r
+    FpdtRecordPtr.GuidEvent->Header.Type                = FPDT_GUID_EVENT_TYPE;\r
+    FpdtRecordPtr.GuidEvent->Header.Length              = RecordInfo.RecordSize;\r
+    FpdtRecordPtr.GuidEvent->Header.Revision            = FPDT_RECORD_REVISION_1;\r
+    FpdtRecordPtr.GuidEvent->ProgressID                 = RecordInfo.ProgressID;\r
+    FpdtRecordPtr.GuidEvent->Timestamp                  = TimeStamp;\r
+    CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));\r
+    break;\r
+\r
+  case FPDT_DYNAMIC_STRING_EVENT_TYPE:\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Length     = RecordInfo.RecordSize;\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;\r
+    FpdtRecordPtr.DynamicStringEvent->ProgressID        = RecordInfo.ProgressID;\r
+    FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;\r
+    CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+\r
+    if (UseModuleName) {\r
+      StringPtr     = ModuleName;\r
+    } else if (Token != NULL) {\r
+      StringPtr     = Token;\r
+    } else if (Module != NULL) {\r
+      StringPtr     = Module;\r
+    } else if (ModuleName != NULL) {\r
+      StringPtr     = ModuleName;\r
+    }\r
+    if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) {\r
+      StrLength     = AsciiStrLen (StringPtr);\r
+      DestMax       = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8);\r
+      if (StrLength >= DestMax) {\r
+        StrLength   = DestMax -1;\r
+      }\r
+      AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StrLength);\r
+    } else {\r
+      AsciiStrCpyS (FpdtRecordPtr.DynamicStringEvent->String, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, "unknown name");\r
+    }\r
+    break;\r
+\r
+  case FPDT_GUID_QWORD_EVENT_TYPE:\r
+    FpdtRecordPtr.GuidQwordEvent->Header.Type           = FPDT_GUID_QWORD_EVENT_TYPE;\r
+    FpdtRecordPtr.GuidQwordEvent->Header.Length         = RecordInfo.RecordSize;\r
+    FpdtRecordPtr.GuidQwordEvent->Header.Revision       = FPDT_RECORD_REVISION_1;\r
+    FpdtRecordPtr.GuidQwordEvent->ProgressID            = RecordInfo.ProgressID;\r
+    FpdtRecordPtr.GuidQwordEvent->Timestamp             = TimeStamp;\r
+    CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));\r
+    if ((MODULE_LOADIMAGE_START_ID == RecordInfo.ProgressID) && AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) {\r
+      mLoadImageCount++;\r
+      FpdtRecordPtr.GuidQwordEvent->Qword               = mLoadImageCount;\r
+    }\r
+    break;\r
+\r
+  case FPDT_GUID_QWORD_STRING_EVENT_TYPE:\r
+    FpdtRecordPtr.GuidQwordStringEvent->Header.Type     = FPDT_GUID_QWORD_STRING_EVENT_TYPE;\r
+    FpdtRecordPtr.GuidQwordStringEvent->Header.Length   = RecordInfo.RecordSize;\r
+    FpdtRecordPtr.GuidQwordStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+    FpdtRecordPtr.GuidQwordStringEvent->ProgressID      = RecordInfo.ProgressID;\r
+    FpdtRecordPtr.GuidQwordStringEvent->Timestamp       = TimeStamp;\r
+    CopyMem (&FpdtRecordPtr.GuidQwordStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordStringEvent->Guid));\r
+    break;\r
+\r
+  default:\r
+    //\r
+    // Record is not supported in current DXE phase, return EFI_ABORTED\r
+    //\r
+    mLockInsertRecord = FALSE;\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  mLockInsertRecord = FALSE;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Dumps all the PEI performance.\r
+\r
+  @param  HobStart      A pointer to a Guid.\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
+VOID\r
+InternalGetPeiPerformance (\r
+  VOID  *HobStart\r
+  )\r
+{\r
+  UINT8                                *FirmwarePerformanceHob;\r
+  FPDT_PEI_EXT_PERF_HEADER             *PeiPerformanceLogHeader;\r
+  UINT8                                *EventRec;\r
+  EFI_HOB_GUID_TYPE                    *GuidHob;\r
+\r
+  GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, HobStart);\r
+  while (GuidHob != NULL) {\r
+    FirmwarePerformanceHob  = GET_GUID_HOB_DATA (GuidHob);\r
+    PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)FirmwarePerformanceHob;\r
+\r
+    if (mPerformanceLength + PeiPerformanceLogHeader->SizeOfAllEntries > mMaxPerformanceLength) {\r
+      mPerformancePointer = ReallocatePool (\r
+                              mPerformanceLength,\r
+                              mPerformanceLength +\r
+                              (UINTN)PeiPerformanceLogHeader->SizeOfAllEntries +\r
+                              FIRMWARE_RECORD_BUFFER,\r
+                              mPerformancePointer\r
+                              );\r
+      ASSERT (mPerformancePointer != NULL);\r
+      mMaxPerformanceLength = mPerformanceLength +\r
+                              (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries) +\r
+                              FIRMWARE_RECORD_BUFFER;\r
+    }\r
+\r
+    EventRec = mPerformancePointer + mPerformanceLength;\r
+    CopyMem (EventRec, FirmwarePerformanceHob + sizeof (FPDT_PEI_EXT_PERF_HEADER), (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries));\r
+    //\r
+    // Update the used buffer size.\r
+    //\r
+    mPerformanceLength += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);\r
+    mLoadImageCount    += PeiPerformanceLogHeader->LoadImageCount;\r
+\r
+    //\r
+    // Get next performance guid hob\r
+    //\r
+    GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
+  }\r
+}\r
+\r
+/**\r
+  Report Boot Perforamnce table address as report status code.\r
+\r
+  @param  Event    The event of notify protocol.\r
+  @param  Context  Notify event context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ReportFpdtRecordBuffer (\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UINT64          BPDTAddr;\r
+\r
+  if (!mFpdtBufferIsReported) {\r
+    Status = AllocateBootPerformanceTable ();\r
+    if (!EFI_ERROR(Status)) {\r
+      BPDTAddr = (UINT64)(UINTN)mAcpiBootPerformanceTable;\r
+      REPORT_STATUS_CODE_EX (\r
+          EFI_PROGRESS_CODE,\r
+          EFI_SOFTWARE_DXE_BS_DRIVER,\r
+          0,\r
+          NULL,\r
+          &gEdkiiFpdtExtendedFirmwarePerformanceGuid,\r
+          &BPDTAddr,\r
+          sizeof (UINT64)\r
+          );\r
+    }\r
+    //\r
+    // Set FPDT report state to TRUE.\r
+    //\r
+    mFpdtBufferIsReported = TRUE;\r
+  }\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, 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
+  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
+  @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
-//\r
-// The handle to install Performance Protocol instance.\r
-//\r
-EFI_HANDLE           mHandle = NULL;\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
-// Interfaces for performance protocol.\r
-//\r
-PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
-  StartGauge,\r
-  EndGauge,\r
-  GetGauge\r
-  };\r
+**/\r
+EFI_STATUS\r
+EFIAPI\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 UINT32       Identifier\r
+  )\r
+{\r
+  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
+}\r
 \r
 /**\r
-  Searches in the gauge array with keyword Handle, Token and Module.\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
-  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
+  Searches the performance measurement log from the beginning of the log\r
+  for the first record that matches Handle, Token, Module and Identifier 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
@@ -65,42 +1119,57 @@ 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  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 The index of gauge entry in the array.\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
-UINT32\r
-InternalSearchForGaugeEntry (\r
-  IN CONST VOID                 *Handle,  OPTIONAL\r
-  IN CONST CHAR8                *Token,   OPTIONAL\r
-  IN CONST CHAR8                *Module   OPTIONAL\r
+EFI_STATUS\r
+EFIAPI\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 UINT32       Identifier\r
   )\r
 {\r
-  UINT32                    Index;\r
-  UINT32                    NumberOfEntries;\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
+  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
+}\r
 \r
-  if (Token == NULL) {\r
-    Token = "";\r
-  }\r
-  if (Module == NULL) {\r
-    Module = "";\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
-  NumberOfEntries = mGaugeData->NumberOfEntries;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+    !!! Not support!!!\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
+  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
+  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  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 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  GaugeDataEntryEx is NULL.\r
 \r
-  return Index;\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetGaugeEx (\r
+  IN  UINTN                 LogEntryKey,\r
+  OUT GAUGE_DATA_ENTRY_EX   **GaugeDataEntryEx\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 /**\r
@@ -135,53 +1204,7 @@ StartGauge (
   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 array.\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 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
-\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
+  return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -217,25 +1240,15 @@ EndGauge (
   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
+  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
+    !!! Not support!!!\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
@@ -259,75 +1272,14 @@ GetGauge (
   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
+  return EFI_UNSUPPORTED;\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
-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 (&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
-    }\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
+  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
@@ -345,6 +1297,9 @@ DxeCorePerformanceLibConstructor (
   )\r
 {\r
   EFI_STATUS                Status;\r
+  EFI_HANDLE                Handle;\r
+  EFI_EVENT                 ReadyToBootEvent;\r
+  PERFORMANCE_PROPERTY      *PerformanceProperty;\r
 \r
   if (!PerformanceMeasurementEnabled ()) {\r
     //\r
@@ -352,25 +1307,192 @@ DxeCorePerformanceLibConstructor (
     //\r
     return EFI_SUCCESS;\r
   }\r
+\r
+  //\r
+  // Dump normal PEI performance records\r
   //\r
-  // Install the protocol interfaces.\r
+  InternalGetPeiPerformance (GetHobList());\r
+\r
+  //\r
+  // Install the protocol interfaces for DXE performance library instance.\r
   //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &mHandle,\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\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
+  //\r
+  // Register ReadyToBoot event to report StatusCode data\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  ReportFpdtRecordBuffer,\r
+                  NULL,\r
+                  &gEfiEventReadyToBootGuid,\r
+                  &ReadyToBootEvent\r
+                  );\r
 \r
-  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
-  ASSERT (mGaugeData != NULL);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
-  InternalGetPeiPerformance ();\r
+  Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &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 Status;\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, 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
+  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
+  @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
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\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 UINT32       Identifier\r
+  )\r
+{\r
+  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\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, Module and Identifier 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
+  @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
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\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 UINT32       Identifier\r
+  )\r
+{\r
+  return InsertFpdtMeasurement (FALSE, 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
+    !!! Not support!!!\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, 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 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
+  @param  Identifier              Pointer to the 32-bit identifier 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
+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 UINT32      *Identifier\r
+  )\r
+{\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -405,10 +1527,7 @@ StartPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = StartGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -444,14 +1563,15 @@ EndPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EndGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return InsertFpdtMeasurement (FALSE, 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
+  !!! Not support!!!\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
@@ -498,40 +1618,7 @@ GetPerformanceMeasurement (
   OUT UINT64      *EndTimeStamp\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  GAUGE_DATA_ENTRY  *GaugeData;\r
-\r
-  GaugeData = NULL;\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
+  return 0;\r
 }\r
 \r
 /**\r