]> 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 08d295ca5a6b956588638a4159305fb3036a09c5..68b29ac5a9e291493060ec913bb9468f8652342a 100644 (file)
@@ -10,7 +10,8 @@
   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 - 2012, 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,23 +25,61 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "DxeCorePerformanceLibInternal.h"\r
 \r
-\r
 //\r
-// The data structure to hold global performance data.\r
+// Data for FPDT performance records.\r
 //\r
-GAUGE_DATA_HEADER    *mGaugeData;\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
-//\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
+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
-//\r
-// The handle to install Performance Protocol instance.\r
-//\r
-EFI_HANDLE           mHandle = NULL;\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
 // Interfaces for Performance Protocol.\r
@@ -60,150 +99,1006 @@ PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {
   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
-  Searches in the gauge array with keyword Handle, Token, Module and Identifier.\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
-  This internal function searches for the gauge entry in the gauge array.\r
-  If there is an entry that exactly matches the given keywords\r
-  and its end time stamp is zero, then the index of that gauge entry is returned;\r
-  otherwise, the the number of gauge entries in the array is returned.\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  Identifier              32-bit identifier.\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 The index of gauge entry in the array.\r
+  @retval EFI_SUCCESS          Get record info successfully.\r
+  @retval EFI_UNSUPPORTED      No matched FPDT record.\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
-  IN UINT32                     Identifier\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
-  UINT32                    Index;\r
-  UINT32                    NumberOfEntries;\r
-  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
+  UINT16              RecordType;\r
+  UINTN               StringSize;\r
 \r
-  if (Token == NULL) {\r
-    Token = "";\r
-  }\r
-  if (Module == NULL) {\r
-    Module = "";\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
-  NumberOfEntries = mGaugeData->NumberOfEntries;\r
-  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\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
-  for (Index = 0; Index < NumberOfEntries; Index++) {\r
-    if ((GaugeEntryExArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
-         AsciiStrnCmp (GaugeEntryExArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         AsciiStrnCmp (GaugeEntryExArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         (GaugeEntryExArray[Index].Identifier == Identifier) &&\r
-         GaugeEntryExArray[Index].EndTimeStamp == 0\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
-  return Index;\r
+  RecordInfo->Type = RecordType;\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
+  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  TimeStamp               64-bit time stamp.\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             The data was read correctly from the device.\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
-EFIAPI\r
-StartGaugeEx (\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       TimeStamp,\r
+  IN UINT64       Ticker,\r
   IN UINT32       Identifier\r
   )\r
 {\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
+  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
-  Index = mGaugeData->NumberOfEntries;\r
-  if (Index >= mMaxGaugeRecords) {\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
-    // Try to enlarge the scale of gauge array.\r
+    // Covert buffer to FPDT Ptr Union type.\r
     //\r
-    OldGaugeData      = mGaugeData;\r
-    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;\r
+    FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);\r
+    mPerformanceLength += RecordInfo.RecordSize;\r
+  }\r
 \r
-    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;\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
-    NewGaugeData = AllocateZeroPool (GaugeDataSize);\r
-    if (NewGaugeData == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\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
-    mGaugeData = NewGaugeData;\r
-    mMaxGaugeRecords *= 2;\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
-    // Initialize new data array and migrate old data one.\r
+    // Update the used buffer size.\r
     //\r
-    mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
+    mPerformanceLength += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);\r
+    mLoadImageCount    += PeiPerformanceLogHeader->LoadImageCount;\r
 \r
-    FreePool (OldGaugeData);\r
+    //\r
+    // Get next performance guid hob\r
+    //\r
+    GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
   }\r
+}\r
 \r
-  GaugeEntryExArray               = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
-  GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+/**\r
+  Report Boot Perforamnce table address as report status code.\r
 \r
-  if (Token != NULL) {\r
-    AsciiStrnCpy (GaugeEntryExArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
-  }\r
-  if (Module != NULL) {\r
-    AsciiStrnCpy (GaugeEntryExArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\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
-  GaugeEntryExArray[Index].EndTimeStamp = 0;\r
-  GaugeEntryExArray[Index].Identifier = Identifier;\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
-  if (TimeStamp == 0) {\r
-    TimeStamp = GetPerformanceCounter ();\r
-  }\r
-  GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;\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
-  mGaugeData->NumberOfEntries++;\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
-  return EFI_SUCCESS;\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
@@ -242,21 +1137,7 @@ EndGaugeEx (
   IN UINT32       Identifier\r
   )\r
 {\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, Identifier);\r
-  if (Index >= mGaugeData->NumberOfEntries) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
-  GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;\r
-\r
-  return EFI_SUCCESS;\r
+  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -264,6 +1145,8 @@ EndGaugeEx (
   It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r
   and then assign the Identifier with 0.\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
   GaugeDataEntryEx stores the pointer to that entry.\r
@@ -286,25 +1169,7 @@ GetGaugeEx (
   OUT GAUGE_DATA_ENTRY_EX   **GaugeDataEntryEx\r
   )\r
 {\r
-  UINTN               NumberOfEntries;\r
-  GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\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
-  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
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 /**\r
@@ -383,6 +1248,8 @@ EndGauge (
   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
   GaugeDataEntry stores the pointer to that entry.\r
@@ -405,75 +1272,9 @@ GetGauge (
   OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  GAUGE_DATA_ENTRY_EX *GaugeEntryEx;\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
-\r
-  *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;\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
-  UINT32                            *LogIdArray;\r
-  GAUGE_DATA_ENTRY_EX               *GaugeEntryExArray;\r
-  UINT32                            Index;\r
-  UINT32                            NumberOfEntries;\r
-\r
-  NumberOfEntries = 0;\r
-  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (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
-\r
-    NumberOfEntries = LogHob->NumberOfEntries;\r
-    for (Index = 0; Index < NumberOfEntries; Index++) {\r
-      GaugeEntryExArray[Index].Handle         = LogEntryArray[Index].Handle;\r
-      AsciiStrnCpy (GaugeEntryExArray[Index].Token,  LogEntryArray[Index].Token,  DXE_PERFORMANCE_STRING_LENGTH);\r
-      AsciiStrnCpy (GaugeEntryExArray[Index].Module, LogEntryArray[Index].Module, DXE_PERFORMANCE_STRING_LENGTH);\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
-}\r
 \r
 /**\r
   The constructor function initializes Performance infrastructure for DXE phase.\r
@@ -496,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
@@ -503,11 +1307,18 @@ 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
+  Handle = NULL;\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &mHandle,\r
+                  &Handle,\r
                   &gPerformanceProtocolGuid,\r
                   &mPerformanceInterface,\r
                   &gPerformanceExProtocolGuid,\r
@@ -516,14 +1327,36 @@ DxeCorePerformanceLibConstructor (
                   );\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_EX) * 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
@@ -561,7 +1394,7 @@ StartPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
+  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -600,7 +1433,7 @@ EndPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
+  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -608,6 +1441,8 @@ EndPerformanceMeasurementEx (
   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
@@ -639,7 +1474,8 @@ EndPerformanceMeasurementEx (
                                   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
+  @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
@@ -647,7 +1483,7 @@ EndPerformanceMeasurementEx (
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurementEx (\r
-  IN  UINTN       LogEntryKey, \r
+  IN  UINTN       LogEntryKey,\r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r
@@ -656,42 +1492,7 @@ GetPerformanceMeasurementEx (
   OUT UINT32      *Identifier\r
   )\r
 {\r
-  EFI_STATUS           Status;\r
-  GAUGE_DATA_ENTRY_EX  *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
-  ASSERT (Identifier != NULL);\r
-\r
-  Status = GetGaugeEx (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
-  *Identifier     = GaugeData->Identifier;\r
-\r
-  return LogEntryKey;\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -726,7 +1527,7 @@ StartPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -762,7 +1563,7 @@ EndPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -770,6 +1571,8 @@ EndPerformanceMeasurement (
   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
   and the key for the second entry in the log is returned.  If the performance log is empty,\r
@@ -815,8 +1618,7 @@ GetPerformanceMeasurement (
   OUT UINT64      *EndTimeStamp\r
   )\r
 {\r
-  UINT32 Identifier;\r
-  return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
+  return 0;\r
 }\r
 \r
 /**\r