]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PeiPerformance:Updated to track FPDT record in PEI phase
authorDandan Bi <dandan.bi@intel.com>
Fri, 19 Jan 2018 04:46:02 +0000 (12:46 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 8 Feb 2018 04:50:17 +0000 (12:50 +0800)
V3:Handle the case when string is empty in String Record.

Updated to convert Pref entry to FPDT record in PEI phase and then
report the records to DxeCorePerfLib through GUID hob.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

index 62527b2c34d1c598beb1d992ed510542a1f623a3..79b67e850610b0690b358ba087be0900c36fda09 100644 (file)
@@ -7,7 +7,7 @@
   number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries or \r
   PcdMaxPeiPerformanceLogEntries16.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015-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
@@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <PiPei.h>\r
 \r
-#include <Guid/Performance.h>\r
+#include <Guid/ExtendedFirmwarePerformance.h>\r
 \r
 #include <Library/PerformanceLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -32,201 +32,434 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/PcdLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 \r
+#define  STRING_SIZE            (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
+#define  MAX_RECORD_SIZE        (sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + STRING_SIZE)\r
 \r
 /**\r
-  Gets the GUID HOB for PEI performance.\r
+Check whether the Token is a known one which is uesed by core.\r
 \r
-  This internal function searches for the GUID HOB for PEI performance.\r
-  If that GUID HOB is not found, it will build a new one.\r
-  It outputs the data area of that GUID HOB to record performance log.\r
+@param  Token      Pointer to a Null-terminated ASCII string\r
 \r
-  @param    PeiPerformanceLog           Pointer to Pointer to PEI performance log header.\r
-  @param    PeiPerformanceIdArray       Pointer to Pointer to PEI performance identifier array.\r
+@retval TRUE       Is a known one used by core.\r
+@retval FALSE      Not a known one.\r
 \r
 **/\r
-VOID\r
-InternalGetPerformanceHobLog (\r
-  OUT PEI_PERFORMANCE_LOG_HEADER    **PeiPerformanceLog,\r
-  OUT UINT32                        **PeiPerformanceIdArray\r
+BOOLEAN\r
+IsKnownTokens (\r
+  IN CONST CHAR8  *Token\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE           *GuidHob;\r
-  UINTN                       PeiPerformanceSize;\r
-  UINT16                      PeiPerformanceLogEntries;\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
-  ASSERT (PeiPerformanceLog != NULL);\r
-  ASSERT (PeiPerformanceIdArray != NULL);\r
+/**\r
+Check whether the ID is a known one which map to the known Token.\r
 \r
-  PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
-                                       PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
-                                       PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
-  GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\r
+@param  Identifier  32-bit identifier.\r
 \r
-  if (GuidHob != NULL) {\r
-    //\r
-    // PEI Performance HOB was found, then return the existing one.\r
-    //\r
-    *PeiPerformanceLog = GET_GUID_HOB_DATA (GuidHob);\r
+@retval TRUE        Is a known one used by core.\r
+@retval FALSE       Not a known one.\r
 \r
-    GuidHob = GetFirstGuidHob (&gPerformanceExProtocolGuid);\r
-    ASSERT (GuidHob != NULL);\r
-    *PeiPerformanceIdArray = GET_GUID_HOB_DATA (GuidHob);\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
-    //\r
-    // PEI Performance HOB was not found, then build one.\r
-    //\r
-    PeiPerformanceSize     = sizeof (PEI_PERFORMANCE_LOG_HEADER) +\r
-                             sizeof (PEI_PERFORMANCE_LOG_ENTRY) * PeiPerformanceLogEntries;\r
-    *PeiPerformanceLog     = BuildGuidHob (&gPerformanceProtocolGuid, PeiPerformanceSize);\r
-    *PeiPerformanceLog     = ZeroMem (*PeiPerformanceLog, PeiPerformanceSize);\r
-\r
-    PeiPerformanceSize     = sizeof (UINT32) * PeiPerformanceLogEntries;\r
-    *PeiPerformanceIdArray = BuildGuidHob (&gPerformanceExProtocolGuid, PeiPerformanceSize);\r
-    *PeiPerformanceIdArray = ZeroMem (*PeiPerformanceIdArray, PeiPerformanceSize);\r
+    return FALSE;\r
   }\r
 }\r
 \r
 /**\r
-  Searches in the log array with keyword Handle, Token, Module and Identifier.\r
-\r
-  This internal function searches for the log entry in the log array.\r
-  If there is an entry that exactly matches the given keywords\r
-  and its end time stamp is zero, then the index of that log entry is returned;\r
-  otherwise, the the number of log entries in the array is returned.\r
+  Get the FPDT record info.\r
 \r
-  @param  PeiPerformanceLog       Pointer to the data structure containing PEI \r
-                                  performance data.\r
-  @param  PeiPerformanceIdArray   Pointer to PEI performance identifier array.\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
 \r
-  @retval The index of log 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
-InternalSearchForLogEntry (\r
-  IN PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog,\r
-  IN UINT32                     *PeiPerformanceIdArray,\r
-  IN CONST VOID                 *Handle,  OPTIONAL\r
-  IN CONST CHAR8                *Token,   OPTIONAL\r
-  IN CONST CHAR8                *Module,   OPTIONAL\r
-  IN UINT32                     Identifier\r
+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
   )\r
 {\r
-  UINT32                    Index;\r
-  UINT32                    Index2;\r
-  UINT32                    NumberOfEntries;\r
-  PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
+  UINTN     StringSize;\r
+  UINT16    RecordType;\r
 \r
+  RecordType = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
 \r
-  if (Token == NULL) {\r
-    Token = "";\r
-  }\r
-  if (Module == NULL) {\r
-    Module = "";\r
+  //\r
+  // Get the ProgressID based on the Token.\r
+  // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.\r
+  //\r
+  if (Token != NULL) {\r
+    if (AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0) {               // "LoadImage:"\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID = MODULE_LOADIMAGE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID = MODULE_LOADIMAGE_END_ID;\r
+      }\r
+      if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+        RecordType = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      }\r
+    } else if (AsciiStrCmp (Token, SEC_TOK) == 0 ||               // "SEC"\r
+               AsciiStrCmp (Token, PEI_TOK) == 0) {               // "PEI"\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID = PERF_CROSSMODULE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID = PERF_CROSSMODULE_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (Token, PEIM_TOK) == 0) {              // "PEIM"\r
+      if (IsStart) {\r
+        RecordInfo->ProgressID = MODULE_START_ID;\r
+      } else {\r
+        RecordInfo->ProgressID = MODULE_END_ID;\r
+      }\r
+      if(!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+        RecordType = FPDT_GUID_EVENT_TYPE;\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 (Module != NULL || Handle != 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
-  NumberOfEntries = PeiPerformanceLog->NumberOfEntries;\r
-  LogEntryArray   = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
-\r
-  Index2 = 0;\r
-\r
-  for (Index = 0; Index < NumberOfEntries; Index++) {\r
-    Index2 = NumberOfEntries - 1 - Index;\r
-    if (LogEntryArray[Index2].EndTimeStamp == 0 &&\r
-        (LogEntryArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
-        AsciiStrnCmp (LogEntryArray[Index2].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-        AsciiStrnCmp (LogEntryArray[Index2].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0) {\r
-      Index = Index2;\r
+\r
+  //\r
+  // Get the Guid and string.\r
+  //\r
+  if(PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\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_GUID_QWORD_EVENT_TYPE:\r
+      RecordInfo->RecordSize = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
+      break;\r
+\r
+    case FPDT_DYNAMIC_STRING_EVENT_TYPE:\r
+      if (Token != NULL) {\r
+        StringSize = AsciiStrSize (Token);\r
+      } else if (Module != NULL) {\r
+        StringSize = AsciiStrSize (Module);\r
+      } else {\r
+        StringSize = STRING_SIZE;\r
+      }\r
+      RecordInfo->RecordSize  = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD) + StringSize);\r
+      break;\r
+\r
+    default:\r
+      //\r
+      // Other type is unsupported in PEI phase yet, return EFI_UNSUPPORTED\r
+      //\r
+      return EFI_UNSUPPORTED;\r
     }\r
   }\r
-  return Index;\r
+  RecordInfo->Type = RecordType;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Creates a record for the beginning of a performance measurement.\r
-\r
-  Creates a record that contains the Handle, Token, Module and Identifier.\r
-  If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
-  If TimeStamp is zero, then this function reads the current time stamp\r
-  and adds that time stamp value to the record as the start time.\r
+  Convert PEI performance log to FPDT String boot record.\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 StartPerformanceMeasurement.\r
+                                  is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\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
+  @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
-RETURN_STATUS\r
-EFIAPI\r
-StartPerformanceMeasurementEx (\r
+EFI_STATUS\r
+InsertPeiFpdtMeasurement (\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
-  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
-  UINT32                      *PeiPerformanceIdArray;\r
-  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
-  UINT32                      Index;\r
-  UINT16                      PeiPerformanceLogEntries;\r
+  EFI_HOB_GUID_TYPE                     *GuidHob;\r
+  UINTN                                 PeiPerformanceSize;\r
+  UINT8                                 *PeiFirmwarePerformance;\r
+  FPDT_PEI_EXT_PERF_HEADER              *PeiPerformanceLogHeader;\r
+  FPDT_RECORD_PTR                       FpdtRecordPtr;\r
+  FPDT_BASIC_RECORD_INFO                RecordInfo;\r
+  CONST VOID                            *ModuleGuid;\r
+  UINTN                                 DestMax;\r
+  UINTN                                 StrLength;\r
+  CONST CHAR8                           *StringPtr;\r
+  EFI_STATUS                            Status;\r
+  UINT16                                PeiPerformanceLogEntries;\r
+  UINT64                                TimeStamp;\r
+\r
+  StringPtr = NULL;\r
+  FpdtRecordPtr.RecordHeader = NULL;\r
+  PeiPerformanceLogHeader = NULL;\r
+\r
+  //\r
+  // Get record info (type, size, ProgressID and Module Guid).\r
+  //\r
+  Status = GetFpdtRecordInfo (IsStart, Handle, Token, Module, &RecordInfo);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.\r
+  // !!! Note: If the Pref 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
+    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
+  //\r
+  // Get the number of PeiPerformanceLogEntries form PCD.\r
+  //\r
   PeiPerformanceLogEntries = (UINT16) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16) != 0 ?\r
                                        PcdGet16 (PcdMaxPeiPerformanceLogEntries16) :\r
                                        PcdGet8 (PcdMaxPeiPerformanceLogEntries));\r
 \r
-  InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
+  //\r
+  // Create GUID HOB Data.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);\r
+  PeiFirmwarePerformance = NULL;\r
+  while (GuidHob != NULL) {\r
+    //\r
+    // PEI Performance HOB was found, then return the existing one.\r
+    //\r
+    PeiFirmwarePerformance  = (UINT8*)GET_GUID_HOB_DATA (GuidHob);\r
+    PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
+    if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize > PeiPerformanceLogEntries * MAX_RECORD_SIZE) {\r
+      PeiPerformanceLogHeader->HobIsFull = TRUE;\r
+    }\r
+    if (!PeiPerformanceLogHeader->HobIsFull && PeiPerformanceLogHeader->SizeOfAllEntries + RecordInfo.RecordSize <= PeiPerformanceLogEntries * MAX_RECORD_SIZE) {\r
+      FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + PeiPerformanceLogHeader->SizeOfAllEntries);\r
+      break;\r
+    }\r
+    //\r
+    // Previous HOB is used, then find next one.\r
+    //\r
+    GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
+  }\r
 \r
-  if (PeiPerformanceLog->NumberOfEntries >= PeiPerformanceLogEntries) {\r
-    DEBUG ((DEBUG_ERROR, "PEI performance log array out of resources\n"));\r
-    return RETURN_OUT_OF_RESOURCES;\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // PEI Performance HOB was not found, then build one.\r
+    //\r
+    PeiPerformanceSize      = sizeof (FPDT_PEI_EXT_PERF_HEADER) +\r
+                              MAX_RECORD_SIZE * PeiPerformanceLogEntries;\r
+    PeiFirmwarePerformance  = (UINT8*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, PeiPerformanceSize);\r
+    if (PeiFirmwarePerformance != NULL) {\r
+      ZeroMem (PeiFirmwarePerformance, PeiPerformanceSize);\r
+    }\r
+    PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;\r
+    FpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER));\r
   }\r
-  Index                       = PeiPerformanceLog->NumberOfEntries++;\r
-  LogEntryArray               = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
-  LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
 \r
-  if (Token != NULL) {\r
-    AsciiStrnCpyS (LogEntryArray[Index].Token, PEI_PERFORMANCE_STRING_SIZE, Token, PEI_PERFORMANCE_STRING_LENGTH);\r
+  if (PeiFirmwarePerformance == NULL) {\r
+    //\r
+    // there is no enough resource to store performance data\r
+    //\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\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
-  if (Module != NULL) {\r
-    AsciiStrnCpyS (LogEntryArray[Index].Module, PEI_PERFORMANCE_STRING_SIZE, Module, PEI_PERFORMANCE_STRING_LENGTH);\r
+\r
+  //\r
+  // Get the ModuleGuid.\r
+  //\r
+  if (Handle != NULL) {\r
+    ModuleGuid = Handle;\r
+  } else {\r
+    ModuleGuid = &gEfiCallerIdGuid;\r
   }\r
 \r
-  LogEntryArray[Index].EndTimeStamp = 0;\r
-  PeiPerformanceIdArray[Index] = Identifier;\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 (EFI_GUID));\r
+    PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\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
+    PeiPerformanceLogHeader->LoadImageCount++;\r
+    FpdtRecordPtr.GuidQwordEvent->Qword           = PeiPerformanceLogHeader->LoadImageCount;\r
+    CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, ModuleGuid, sizeof (EFI_GUID));\r
+    PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\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 (EFI_GUID));\r
+    PeiPerformanceLogHeader->SizeOfAllEntries += RecordInfo.RecordSize;\r
+\r
+    if (Token != NULL) {\r
+      StringPtr                     = Token;\r
+    } else if (Module != NULL) {\r
+      StringPtr                     = Module;\r
+    }\r
+    if (StringPtr != NULL && AsciiStrLen (StringPtr) != 0) {\r
+      DestMax                       = (RecordInfo.RecordSize - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)) / sizeof (CHAR8);\r
+      StrLength                     = AsciiStrLen (StringPtr);\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
-  if (TimeStamp == 0) {\r
-    TimeStamp = GetPerformanceCounter ();\r
+  default:\r
+    //\r
+    // Record is not supported in current PEI phase, return EFI_ABORTED\r
+    //\r
+    return EFI_UNSUPPORTED;\r
   }\r
-  LogEntryArray[Index].StartTimeStamp = TimeStamp;\r
 \r
-  return RETURN_SUCCESS;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Fills in the end time of a performance measurement.\r
+  Creates a record for the beginning of a performance measurement.\r
+\r
+  If TimeStamp is zero, then this function reads the current time stamp\r
+  and adds that time stamp value to the record as the start time.\r
+\r
+  If TimeStamp is one, then this function reads 0 as the start time.\r
 \r
-  Looks up the record that matches Handle, Token and Module.\r
-  If the record can not be found then return RETURN_NOT_FOUND.\r
-  If the record is found and TimeStamp is not zero,\r
-  then TimeStamp is added to the record as the end time.\r
-  If the record is found and TimeStamp is zero, then this function reads\r
-  the current time stamp and adds that time stamp value to the record as the end time.\r
+  If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  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 InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
+}\r
+\r
+/**\r
+\r
+  Creates a record for the end of a performance measurement.\r
+\r
+  If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
+  If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
+  If the TimeStamp is one, then this function reads 0 as the end time.\r
 \r
   @param  Handle                  Pointer to environment specific context used\r
                                   to identify the component being measured.\r
@@ -252,24 +485,7 @@ EndPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
-  UINT32                      *PeiPerformanceIdArray;\r
-  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
-  UINT32                      Index;\r
-\r
-  if (TimeStamp == 0) {\r
-    TimeStamp = GetPerformanceCounter ();\r
-  }\r
-\r
-  InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
-  Index             = InternalSearchForLogEntry (PeiPerformanceLog, PeiPerformanceIdArray, Handle, Token, Module, Identifier);\r
-  if (Index >= PeiPerformanceLog->NumberOfEntries) {\r
-    return RETURN_NOT_FOUND;\r
-  }\r
-  LogEntryArray     = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
-  LogEntryArray[Index].EndTimeStamp = TimeStamp;\r
-\r
-  return RETURN_SUCCESS;\r
+  return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -295,6 +511,8 @@ EndPerformanceMeasurementEx (
   If EndTimeStamp is NULL, then ASSERT().\r
   If Identifier is NULL, then ASSERT().\r
 \r
+  !!!NOT Support yet!!!\r
+\r
   @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
                                   0, then the first performance measurement log entry is retrieved.\r
                                   On exit, the key of the next performance of entry entry.\r
@@ -325,52 +543,20 @@ GetPerformanceMeasurementEx (
   OUT UINT32      *Identifier\r
   )\r
 {\r
-  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
-  UINT32                      *PeiPerformanceIdArray;\r
-  PEI_PERFORMANCE_LOG_ENTRY   *CurrentLogEntry;\r
-  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
-  UINTN                       NumberOfEntries;\r
-\r
-  ASSERT (Handle != NULL);\r
-  ASSERT (Token != NULL);\r
-  ASSERT (Module != NULL);\r
-  ASSERT (StartTimeStamp != NULL);\r
-  ASSERT (EndTimeStamp != NULL);\r
-  ASSERT (Identifier != NULL);\r
-\r
-  InternalGetPerformanceHobLog (&PeiPerformanceLog, &PeiPerformanceIdArray);\r
-\r
-  NumberOfEntries   = (UINTN) (PeiPerformanceLog->NumberOfEntries);\r
-  LogEntryArray     = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
-  //\r
-  // Make sure that LogEntryKey is a valid log entry key.\r
-  //\r
-  ASSERT (LogEntryKey <= NumberOfEntries);\r
-\r
-  if (LogEntryKey == NumberOfEntries) {\r
-    return 0;\r
-  }\r
-\r
-  CurrentLogEntry = &(LogEntryArray[LogEntryKey]);\r
-\r
-  *Handle         = (VOID *) (UINTN) (CurrentLogEntry->Handle);\r
-  *Token          = CurrentLogEntry->Token;\r
-  *Module         = CurrentLogEntry->Module;\r
-  *StartTimeStamp = CurrentLogEntry->StartTimeStamp;\r
-  *EndTimeStamp   = CurrentLogEntry->EndTimeStamp;\r
-  *Identifier     = PeiPerformanceIdArray[LogEntryKey++];\r
-\r
-  return LogEntryKey;\r
+  return 0;\r
 }\r
 \r
 /**\r
   Creates a record for the beginning of a performance measurement.\r
 \r
-  Creates a record that contains the Handle, Token, and Module.\r
-  If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
   If TimeStamp is zero, then this function reads the current time stamp\r
   and adds that time stamp value to the record as the start time.\r
 \r
+  If TimeStamp is one, then this function reads 0 as the start time.\r
+\r
+  If TimeStamp is other value, then TimeStamp is added to the record as the start time.\r
+\r
+\r
   @param  Handle                  Pointer to environment specific context used\r
                                   to identify the component being measured.\r
   @param  Token                   Pointer to a Null-terminated ASCII string\r
@@ -392,18 +578,16 @@ StartPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+  return InsertPeiFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
-  Fills in the end time of a performance measurement.\r
 \r
-  Looks up the record that matches Handle, Token, and Module.\r
-  If the record can not be found then return RETURN_NOT_FOUND.\r
-  If the record is found and TimeStamp is not zero,\r
-  then TimeStamp is added to the record as the end time.\r
-  If the record is found and TimeStamp is zero, then this function reads\r
-  the current time stamp and adds that time stamp value to the record as the end time.\r
+  Creates a record for the end of a performance measurement.\r
+\r
+  If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.\r
+  If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.\r
+  If the TimeStamp is one, then this function reads 0 as the end time.\r
 \r
   @param  Handle                  Pointer to environment specific context used\r
                                   to identify the component being measured.\r
@@ -426,7 +610,7 @@ EndPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+  return InsertPeiFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -451,6 +635,8 @@ EndPerformanceMeasurement (
   If StartTimeStamp is NULL, then ASSERT().\r
   If EndTimeStamp is NULL, then ASSERT().\r
 \r
+  NOT Support yet.\r
+\r
   @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
                                   0, then the first performance measurement log entry is retrieved.\r
                                   On exit, the key of the next performance of entry entry.\r
@@ -479,8 +665,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
index 08aa064432ec4d439ba7d3494e58c3bbd9cc86a6..ce49db1c8d2fc4b0ea1abc7087fa1e3ca41633c4 100644 (file)
@@ -5,7 +5,7 @@
 #  and consumes GUIDed HOB for performance logging. The GUIDed HOB is passed to DXE phase\r
 #  so that it can be taken over by DxeCorePerformanceLib.  \r
 #  \r
-#  Copyright (c) 2006 - 2014, 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
 [Guids]\r
   ## PRODUCES ## HOB\r
   ## CONSUMES ## HOB\r
-  gPerformanceProtocolGuid\r
-  ## PRODUCES ## HOB\r
-  ## CONSUMES ## HOB\r
-  gPerformanceExProtocolGuid\r
+  gEdkiiFpdtExtendedFirmwarePerformanceGuid\r
 \r
 [Pcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries   ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries16 ## CONSUMES\r
-  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask      ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries     ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries16   ## CONSUMES\r
+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask        ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEdkiiFpdtStringRecordEnableOnly ## CONSUMES\r