]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Update Performance instances to use new protocol
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index 68b29ac5a9e291493060ec913bb9468f8652342a..7982060518405f93843b3c292e0de666e9e7caf3 100644 (file)
@@ -82,21 +82,10 @@ BOOLEAN  mLockInsertRecord    = FALSE;
 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;\r
 \r
 //\r
-// Interfaces for Performance Protocol.\r
+// Interfaces for PerformanceMeasurement Protocol.\r
 //\r
-PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
-  StartGauge,\r
-  EndGauge,\r
-  GetGauge\r
-  };\r
-\r
-//\r
-// Interfaces for PerformanceEx Protocol.\r
-//\r
-PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r
-  StartGaugeEx,\r
-  EndGaugeEx,\r
-  GetGaugeEx\r
+EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {\r
+  CreatePerformanceMeasurement,\r
   };\r
 \r
 PERFORMANCE_PROPERTY  mPerformanceProperty;\r
@@ -799,18 +788,11 @@ InsertFpdtMeasurement (
   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
@@ -824,7 +806,6 @@ InsertFpdtMeasurement (
   // 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
@@ -844,7 +825,6 @@ InsertFpdtMeasurement (
         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
@@ -866,7 +846,6 @@ InsertFpdtMeasurement (
                               );\r
 \r
       if (mPerformancePointer == NULL) {\r
-        mLockInsertRecord = FALSE;\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
       mMaxPerformanceLength = mPerformanceLength + RecordInfo.RecordSize + FIRMWARE_RECORD_BUFFER;\r
@@ -963,11 +942,9 @@ InsertFpdtMeasurement (
     //\r
     // Record is not supported in current DXE phase, return EFI_ABORTED\r
     //\r
-    mLockInsertRecord = FALSE;\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  mLockInsertRecord = FALSE;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1063,219 +1040,6 @@ ReportFpdtRecordBuffer (
   }\r
 }\r
 \r
-/**\r
-  Adds a record at the end of the performance measurement log\r
-  that records the start time of a performance measurement.\r
-\r
-  Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, Module and Identifier.\r
-  The end time of the new record must be set to zero.\r
-  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
-  If TimeStamp is zero, the start time in the record is filled in with the value\r
-  read from the current time stamp.\r
-\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  TimeStamp               64-bit time stamp.\r
-  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
-                                  is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\r
-\r
-  @retval EFI_SUCCESS             The data was read correctly from the device.\r
-  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-StartGaugeEx (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp,\r
-  IN UINT32       Identifier\r
-  )\r
-{\r
-  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
-}\r
-\r
-/**\r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first matching record that contains a zero end time and fills in a valid end time.\r
-\r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
-  If the record can not be found then return EFI_NOT_FOUND.\r
-  If the record is found and TimeStamp is not zero,\r
-  then the end time in the record is filled in with the value specified by TimeStamp.\r
-  If the record is found and TimeStamp is zero, then the end time in the matching record\r
-  is filled in with the current time stamp value.\r
-\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  TimeStamp               64-bit time stamp.\r
-  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
-                                  is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.\r
-\r
-  @retval EFI_SUCCESS             The end of  the measurement was recorded.\r
-  @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EndGaugeEx (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp,\r
-  IN UINT32       Identifier\r
-  )\r
-{\r
-  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
-}\r
-\r
-/**\r
-  Retrieves a previously logged performance measurement.\r
-  It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r
-  and then assign the Identifier with 0.\r
-\r
-    !!! 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
-\r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  GaugeDataEntryEx        The indirect pointer to the extended gauge data entry specified by LogEntryKey\r
-                                  if the retrieval is successful.\r
-\r
-  @retval EFI_SUCCESS             The GuageDataEntryEx is successfully found based on LogEntryKey.\r
-  @retval EFI_NOT_FOUND           The LogEntryKey is the last entry (equals to the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  The LogEntryKey is not a valid entry (greater than the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntryEx is NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetGaugeEx (\r
-  IN  UINTN                 LogEntryKey,\r
-  OUT GAUGE_DATA_ENTRY_EX   **GaugeDataEntryEx\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
-  Adds a record at the end of the performance measurement log\r
-  that records the start time of a performance measurement.\r
-\r
-  Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, and Module.\r
-  The end time of the new record must be set to zero.\r
-  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
-  If TimeStamp is zero, the start time in the record is filled in with the value\r
-  read from the current time stamp.\r
-\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  TimeStamp               64-bit time stamp.\r
-\r
-  @retval EFI_SUCCESS             The data was read correctly from the device.\r
-  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-StartGauge (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
-  )\r
-{\r
-  return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
-}\r
-\r
-/**\r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first matching record that contains a zero end time and fills in a valid end time.\r
-\r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
-  If the record can not be found then return EFI_NOT_FOUND.\r
-  If the record is found and TimeStamp is not zero,\r
-  then the end time in the record is filled in with the value specified by TimeStamp.\r
-  If the record is found and TimeStamp is zero, then the end time in the matching record\r
-  is filled in with the current time stamp value.\r
-\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  TimeStamp               64-bit time stamp.\r
-\r
-  @retval EFI_SUCCESS             The end of  the measurement was recorded.\r
-  @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-EndGauge (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
-  )\r
-{\r
-  return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
-}\r
-\r
-/**\r
-  Retrieves a previously logged performance measurement.\r
-  It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,\r
-  and then eliminate the Identifier.\r
-\r
-    !!! 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
-\r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  GaugeDataEntry          The indirect pointer to the gauge data entry specified by LogEntryKey\r
-                                  if the retrieval is successful.\r
-\r
-  @retval EFI_SUCCESS             The GuageDataEntry is successfully found based on LogEntryKey.\r
-  @retval EFI_NOT_FOUND           The LogEntryKey is the last entry (equals to the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  The LogEntryKey is not a valid entry (greater than the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetGauge (\r
-  IN  UINTN               LogEntryKey,\r
-  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
 /**\r
   The constructor function initializes Performance infrastructure for DXE phase.\r
 \r
@@ -1319,10 +1083,8 @@ DxeCorePerformanceLibConstructor (
   Handle = NULL;\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Handle,\r
-                  &gPerformanceProtocolGuid,\r
-                  &mPerformanceInterface,\r
-                  &gPerformanceExProtocolGuid,\r
-                  &mPerformanceExInterface,\r
+                  &gEdkiiPerformanceMeasurementProtocolGuid,\r
+                  &mPerformanceMeasurementInterface,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
@@ -1359,6 +1121,55 @@ DxeCorePerformanceLibConstructor (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Create performance record with event description and a timestamp.\r
+\r
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.\r
+  @param Guid              - Pointer to a GUID.\r
+  @param String            - Pointer to a string describing the measurement.\r
+  @param TimeStamp         - 64-bit time stamp.\r
+  @param Address           - Pointer to a location in memory relevant to the measurement.\r
+  @param Identifier        - Performance identifier describing the type of measurement.\r
+  @param Attribute         - The attribute of the measurement. According to attribute can create a start\r
+                             record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
+                             or a general record for other Perf macros.\r
+\r
+  @retval EFI_SUCCESS           - Successfully created performance record.\r
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.\r
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                  pointer or invalid PerfId.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CreatePerformanceMeasurement (\r
+  IN CONST VOID                        *CallerIdentifier,\r
+  IN CONST VOID                        *Guid,   OPTIONAL\r
+  IN CONST CHAR8                       *String, OPTIONAL\r
+  IN       UINT64                      TimeStamp,\r
+  IN       UINT64                      Address,  OPTIONAL\r
+  IN       UINT32                      Identifier,\r
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute\r
+  )\r
+{\r
+  EFI_STATUS   Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (mLockInsertRecord) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  mLockInsertRecord = TRUE;\r
+\r
+  if (Attribute == PerfStartEntry) {\r
+    Status = InsertFpdtMeasurement (TRUE, CallerIdentifier, String, String, TimeStamp, Identifier);\r
+  } else if (Attribute == PerfEndEntry) {\r
+    Status = InsertFpdtMeasurement (FALSE, CallerIdentifier, String, String, TimeStamp, Identifier);\r
+  }\r
+  mLockInsertRecord = FALSE;\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Adds a record at the end of the performance measurement log\r
   that records the start time of a performance measurement.\r
@@ -1394,7 +1205,17 @@ StartPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
+  CONST CHAR8     *String;\r
+\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);\r
 }\r
 \r
 /**\r
@@ -1433,7 +1254,17 @@ EndPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
+  CONST CHAR8     *String;\r
+\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);\r
 }\r
 \r
 /**\r
@@ -1527,7 +1358,7 @@ StartPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, 0);\r
+  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -1563,7 +1394,7 @@ EndPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, 0);\r
+  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r