]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
index 2ddd983126ecdf4dba6f52eca3c10b932f63025f..8e35cc4302a784689611bc033948d2d0468bc0ff 100644 (file)
@@ -6,21 +6,14 @@
   to log performance data. If both PerformanceEx and Performance Protocol is not available, it does not log any\r
   performance information.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-\r
 #include <PiDxe.h>\r
 \r
-#include <Guid/Performance.h>\r
+#include <Guid/PerformanceMeasurement.h>\r
 \r
 #include <Library/PerformanceLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -30,8 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 // The cached Performance Protocol and PerformanceEx Protocol interface.\r
 //\r
-PERFORMANCE_PROTOCOL        *mPerformance = NULL;\r
-PERFORMANCE_EX_PROTOCOL     *mPerformanceEx = NULL;\r
+EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL  *mPerformanceMeasurement = NULL;\r
 \r
 /**\r
   The function caches the pointers to PerformanceEx protocol and Performance Protocol.\r
@@ -43,35 +35,24 @@ PERFORMANCE_EX_PROTOCOL     *mPerformanceEx = NULL;
 \r
 **/\r
 EFI_STATUS\r
-GetPerformanceProtocol (\r
+GetPerformanceMeasurementProtocol (\r
   VOID\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  PERFORMANCE_PROTOCOL      *Performance;\r
-  PERFORMANCE_EX_PROTOCOL   *PerformanceEx;\r
-\r
-  if (mPerformanceEx != NULL || mPerformance != NULL) {\r
-    return EFI_SUCCESS;\r
-  }\r
+  EFI_STATUS                              Status;\r
+  EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL  *PerformanceMeasurement;\r
 \r
-  Status = gBS->LocateProtocol (&gPerformanceExProtocolGuid, NULL, (VOID **) &PerformanceEx);\r
-  if (!EFI_ERROR (Status)) {\r
-    ASSERT (PerformanceEx != NULL);\r
-    //\r
-    // Cache PerformanceEx Protocol.\r
-    //\r
-    mPerformanceEx = PerformanceEx;\r
+  if (mPerformanceMeasurement != NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);\r
+  Status = gBS->LocateProtocol (&gEdkiiPerformanceMeasurementProtocolGuid, NULL, (VOID **)&PerformanceMeasurement);\r
   if (!EFI_ERROR (Status)) {\r
-    ASSERT (Performance != NULL);\r
+    ASSERT (PerformanceMeasurement != NULL);\r
     //\r
-    // Cache performance protocol.\r
+    // Cache PerformanceMeasurement Protocol.\r
     //\r
-    mPerformance = Performance;\r
+    mPerformanceMeasurement = PerformanceMeasurement;\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -103,35 +84,42 @@ GetPerformanceProtocol (
 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 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
+  EFI_STATUS   Status;\r
+  CONST CHAR8  *String;\r
 \r
-  Status = GetPerformanceProtocol ();\r
+  Status = GetPerformanceMeasurementProtocol ();\r
   if (EFI_ERROR (Status)) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
+    return RETURN_NOT_FOUND;\r
   }\r
 \r
-  if (mPerformanceEx != NULL) {\r
-    Status = mPerformanceEx->StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
-  } else if (mPerformance != NULL) {\r
-    Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  if (mPerformanceMeasurement != NULL) {\r
+    Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);\r
   } else {\r
     ASSERT (FALSE);\r
   }\r
 \r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS)Status;\r
 }\r
 \r
 /**\r
   Fills in the end time of a performance measurement.\r
 \r
-  Looks up the record that matches Handle, Token, Module and Identifier.\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
@@ -155,29 +143,36 @@ StartPerformanceMeasurementEx (
 RETURN_STATUS\r
 EFIAPI\r
 EndPerformanceMeasurementEx (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN 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
+  EFI_STATUS   Status;\r
+  CONST CHAR8  *String;\r
 \r
-  Status = GetPerformanceProtocol ();\r
+  Status = GetPerformanceMeasurementProtocol ();\r
   if (EFI_ERROR (Status)) {\r
     return RETURN_NOT_FOUND;\r
   }\r
 \r
-  if (mPerformanceEx != NULL) {\r
-    Status = mPerformanceEx->EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
-  } else if (mPerformance != NULL) {\r
-    Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  if (mPerformanceMeasurement != NULL) {\r
+    Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);\r
   } else {\r
     ASSERT (FALSE);\r
   }\r
 \r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS)Status;\r
 }\r
 \r
 /**\r
@@ -224,67 +219,16 @@ EndPerformanceMeasurementEx (
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurementEx (\r
-  IN  UINTN       LogEntryKey, \r
-  OUT CONST VOID  **Handle,\r
-  OUT CONST CHAR8 **Token,\r
-  OUT CONST CHAR8 **Module,\r
-  OUT UINT64      *StartTimeStamp,\r
-  OUT UINT64      *EndTimeStamp,\r
-  OUT UINT32      *Identifier\r
+  IN  UINTN        LogEntryKey,\r
+  OUT CONST VOID   **Handle,\r
+  OUT CONST CHAR8  **Token,\r
+  OUT CONST CHAR8  **Module,\r
+  OUT UINT64       *StartTimeStamp,\r
+  OUT UINT64       *EndTimeStamp,\r
+  OUT UINT32       *Identifier\r
   )\r
 {\r
-  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 = GetPerformanceProtocol ();\r
-  if (EFI_ERROR (Status)) {\r
-    return 0;\r
-  }\r
-\r
-  if (mPerformanceEx != NULL) {\r
-    Status = mPerformanceEx->GetGaugeEx (LogEntryKey++, &GaugeData);\r
-  } else if (mPerformance != NULL) {\r
-    Status = mPerformance->GetGauge (LogEntryKey++, (GAUGE_DATA_ENTRY **) &GaugeData);\r
-  } else {\r
-    ASSERT (FALSE);\r
-    return 0;\r
-  }\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
-  if (mPerformanceEx != NULL) {\r
-    *Identifier   = GaugeData->Identifier;\r
-  } else {\r
-    *Identifier   = 0;\r
-  }\r
-\r
-  return LogEntryKey;\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -310,9 +254,9 @@ GetPerformanceMeasurementEx (
 RETURN_STATUS\r
 EFIAPI\r
 StartPerformanceMeasurement (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\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
@@ -344,9 +288,9 @@ StartPerformanceMeasurement (
 RETURN_STATUS\r
 EFIAPI\r
 EndPerformanceMeasurement (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\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
@@ -395,16 +339,15 @@ EndPerformanceMeasurement (
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  IN  UINTN       LogEntryKey,\r
-  OUT CONST VOID  **Handle,\r
-  OUT CONST CHAR8 **Token,\r
-  OUT CONST CHAR8 **Module,\r
-  OUT UINT64      *StartTimeStamp,\r
-  OUT UINT64      *EndTimeStamp\r
+  IN  UINTN        LogEntryKey,\r
+  OUT CONST VOID   **Handle,\r
+  OUT CONST CHAR8  **Token,\r
+  OUT CONST CHAR8  **Module,\r
+  OUT UINT64       *StartTimeStamp,\r
+  OUT UINT64       *EndTimeStamp\r
   )\r
 {\r
-  UINT32 Identifier;\r
-  return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -425,5 +368,74 @@ PerformanceMeasurementEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\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 Address           - Pointer to a location in memory relevant to the measurement\r
+  @param Identifier        - Performance identifier describing the type of measurement\r
+\r
+  @retval RETURN_SUCCESS           - Successfully created performance record\r
+  @retval RETURN_OUT_OF_RESOURCES  - Ran out of space to store the records\r
+  @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                     pointer or invalid PerfId\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LogPerformanceMeasurement (\r
+  IN CONST VOID   *CallerIdentifier,\r
+  IN CONST VOID   *Guid     OPTIONAL,\r
+  IN CONST CHAR8  *String   OPTIONAL,\r
+  IN  UINT64      Address  OPTIONAL,\r
+  IN UINT32       Identifier\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = GetPerformanceMeasurementProtocol ();\r
+  if (EFI_ERROR (Status)) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  if (mPerformanceMeasurement != NULL) {\r
+    Status = mPerformanceMeasurement->CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);\r
+  } else {\r
+    ASSERT (FALSE);\r
+  }\r
+\r
+  return (RETURN_STATUS)Status;\r
+}\r
+\r
+/**\r
+  Check whether the specified performance measurement can be logged.\r
+\r
+  This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
+  and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
+\r
+  @param Type        - Type of the performance measurement entry.\r
+\r
+  @retval TRUE         The performance measurement can be logged.\r
+  @retval FALSE        The performance measurement can NOT be logged.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LogPerformanceMeasurementEnabled (\r
+  IN  CONST UINTN  Type\r
+  )\r
+{\r
+  //\r
+  // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
+  //\r
+  if (PerformanceMeasurementEnabled () && ((PcdGet8 (PcdPerformanceLibraryPropertyMask) & Type) == 0)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
 }\r