]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
MdeModulePkg: Update Performance instances to use new protocol
[mirror_edk2.git] / MdeModulePkg / Library / SmmCorePerformanceLib / SmmCorePerformanceLib.c
index dbc1166f254a2cd3c3d4cc823b58c9c7c7d602ab..e630773562fc59a12fb9fabc61b169cdc4acc2fa 100644 (file)
@@ -54,21 +54,10 @@ SPIN_LOCK            mSmmFpdtLock;
 PERFORMANCE_PROPERTY  mPerformanceProperty;\r
 \r
 //\r
-// Interfaces for SMM Performance Protocol.\r
+// Interfaces for SMM PerformanceMeasurement Protocol.\r
 //\r
-PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
-  StartGauge,\r
-  EndGauge,\r
-  GetGauge\r
-};\r
-\r
-//\r
-// Interfaces for SMM 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
 /**\r
@@ -643,235 +632,6 @@ InsertFpdtMeasurement (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Adds a record at the end of the performance measurement log\r
-  that records the start time of a performance measurement.\r
-\r
-  Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, Module and Identifier.\r
-  The end time of the new record must be set to zero.\r
-  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
-  If TimeStamp is zero, the start time in the record is filled in with the value\r
-  read from the current time stamp.\r
-\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  TimeStamp               64-bit time stamp.\r
-  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
-                                  is same as the one created by 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
-  EFI_STATUS    Status;\r
-\r
-  AcquireSpinLock (&mSmmFpdtLock);\r
-\r
-  Status = InsertFpdtMeasurement (TRUE, Handle, Token, Module, TimeStamp, Identifier);\r
-\r
-  ReleaseSpinLock (&mSmmFpdtLock);\r
-\r
-  return Status;\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
-  EFI_STATUS     Status;\r
-\r
-  AcquireSpinLock (&mSmmFpdtLock);\r
-\r
-  Status = InsertFpdtMeasurement (FALSE, Handle, Token, Module, TimeStamp, Identifier);\r
-\r
-  ReleaseSpinLock (&mSmmFpdtLock);\r
-\r
-  return Status;\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
   SmmReadyToBoot protocol notification event handler.\r
 \r
@@ -942,16 +702,9 @@ InitializeSmmCorePerformanceLib (
   Handle = NULL;\r
   Status = gSmst->SmmInstallProtocolInterface (\r
                     &Handle,\r
-                    &gSmmPerformanceProtocolGuid,\r
-                    EFI_NATIVE_INTERFACE,\r
-                    &mPerformanceInterface\r
-                    );\r
-  ASSERT_EFI_ERROR (Status);\r
-  Status = gSmst->SmmInstallProtocolInterface (\r
-                    &Handle,\r
-                    &gSmmPerformanceExProtocolGuid,\r
+                    &gEdkiiSmmPerformanceMeasurementProtocolGuid,\r
                     EFI_NATIVE_INTERFACE,\r
-                    &mPerformanceExInterface\r
+                    &mPerformanceMeasurementInterface\r
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -1031,6 +784,48 @@ SmmCorePerformanceLibConstructor (
   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, OPTIONAL\r
+  IN CONST VOID                        *Guid,     OPTIONAL\r
+  IN CONST CHAR8                       *String,   OPTIONAL\r
+  IN       UINT64                      TimeStamp, OPTIONAL\r
+  IN       UINT64                      Address,   OPTIONAL\r
+  IN       UINT32                      Identifier,\r
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute\r
+  )\r
+{\r
+  EFI_STATUS   Status;\r
+\r
+  AcquireSpinLock (&mSmmFpdtLock);\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
+  ReleaseSpinLock (&mSmmFpdtLock);\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
@@ -1066,7 +861,17 @@ StartPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return (RETURN_STATUS) StartGaugeEx (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
@@ -1105,7 +910,17 @@ EndPerformanceMeasurementEx (
   IN UINT32       Identifier\r
   )\r
 {\r
-  return (RETURN_STATUS) EndGaugeEx (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
@@ -1198,7 +1013,7 @@ StartPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
+  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r
@@ -1234,7 +1049,7 @@ EndPerformanceMeasurement (
   IN UINT64       TimeStamp\r
   )\r
 {\r
-  return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
+  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
 }\r
 \r
 /**\r