Enhance the PeiPerformanceLib to produce the Performance
Measurement PPI.

Cc: Dmitry Antipov <dma...@microsoft.com>
Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Liming Gao <liming....@intel.com>
Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan...@intel.com>
---
 .../Library/PeiPerformanceLib/PeiPerformanceLib.c  | 81 ++++++++++++++++++++++
 .../PeiPerformanceLib/PeiPerformanceLib.inf        |  1 +
 2 files changed, 82 insertions(+)

diff --git a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c 
b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
index 808a63501e..528bf12303 100644
--- a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
+++ b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
@@ -30,14 +30,52 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include <Library/HobLib.h>
 #include <Library/BaseLib.h>
 #include <Library/TimerLib.h>
 #include <Library/PcdLib.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/PeiServicesLib.h>
 
 #define  STRING_SIZE            (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof 
(CHAR8))
 #define  PEI_MAX_RECORD_SIZE    (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + 
STRING_SIZE)
 
+/**
+  Create performance record with event description and a timestamp.
+
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.
+  @param Guid              - Pointer to a GUID.
+  @param String            - Pointer to a string describing the measurement.
+  @param TimeStamp         - 64-bit time stamp.
+  @param Address           - Pointer to a location in memory relevant to the 
measurement.
+  @param Identifier        - Performance identifier describing the type of 
measurement.
+  @param Attribute         - The attribute of the measurement. According to 
attribute can create a start
+                             record for PERF_START/PERF_START_EX, or a end 
record for PERF_END/PERF_END_EX,
+                             or a general record for other Perf macros.
+
+  @retval EFI_SUCCESS           - Successfully created performance record.
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
+                                  pointer or invalid PerfId.
+**/
+EFI_STATUS
+EFIAPI
+CreatePerformanceMeasurementPpi (
+  IN CONST VOID                        *CallerIdentifier,
+  IN CONST VOID                        *Guid,   OPTIONAL
+  IN CONST CHAR8                       *String, OPTIONAL
+  IN       UINT64                      TimeStamp,
+  IN       UINT64                      Address,  OPTIONAL
+  IN       UINT32                      Identifier,
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute
+  );
+
+EDKII_PERFORMANCE_MEASUREMENT_PPI mPerformancePpi = 
{CreatePerformanceMeasurementPpi};
+
+EFI_PEI_PPI_DESCRIPTOR  mPerformancePpiDesc = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEdkiiPerformanceMeasurementPpiGuid,
+  &mPerformancePpi
+};
 
 /**
   Return the pointer to the FPDT record in the allocated memory.
 
   @param  RecordSize                The size of FPDT record.
@@ -56,10 +94,12 @@ GetFpdtRecordPtr (
 {
   UINT16                                PeiPerformanceLogEntries;
   UINTN                                 PeiPerformanceSize;
   UINT8                                 *PeiFirmwarePerformance;
   EFI_HOB_GUID_TYPE                     *GuidHob;
+  EFI_HOB_GUID_TYPE                     *FirstGuidHob;
+  EFI_STATUS                            Status;
 
   //
   // Get the number of PeiPerformanceLogEntries form PCD.
   //
   PeiPerformanceLogEntries = (UINT16) (PcdGet16 
(PcdMaxPeiPerformanceLogEntries16) != 0 ?
@@ -68,10 +108,11 @@ GetFpdtRecordPtr (
 
   //
   // Create GUID HOB Data.
   //
   GuidHob = GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid);
+  FirstGuidHob = GuidHob;
   PeiFirmwarePerformance = NULL;
   while (GuidHob != NULL) {
     //
     // PEI Performance HOB was found, then return the existing one.
     //
@@ -89,10 +130,16 @@ GetFpdtRecordPtr (
     //
     GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, 
GET_NEXT_HOB (GuidHob));
   }
 
   if (GuidHob == NULL) {
+    if (FirstGuidHob == NULL) {
+      Status = PeiServicesInstallPpi(&mPerformancePpiDesc);
+      if (EFI_ERROR(Status)) {
+        DEBUG((DEBUG_ERROR, "PeiCorePerformanceLib - %a - InstallPpi returned 
%r!\n", __FUNCTION__, Status));
+      }
+    }
     //
     // PEI Performance HOB was not found, then build one.
     //
     PeiPerformanceSize      = sizeof (FPDT_PEI_EXT_PERF_HEADER) +
                               PEI_MAX_RECORD_SIZE * PeiPerformanceLogEntries;
@@ -513,10 +560,44 @@ InsertFpdtRecord (
   PeiPerformanceLogHeader->SizeOfAllEntries += 
FpdtRecordPtr.RecordHeader->Length;
 
   return EFI_SUCCESS;
 }
 
+/**
+  Create performance record with event description and a timestamp.
+
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.
+  @param Guid              - Pointer to a GUID.
+  @param String            - Pointer to a string describing the measurement.
+  @param TimeStamp         - 64-bit time stamp.
+  @param Address           - Pointer to a location in memory relevant to the 
measurement.
+  @param Identifier        - Performance identifier describing the type of 
measurement.
+  @param Attribute         - The attribute of the measurement. According to 
attribute can create a start
+                             record for PERF_START/PERF_START_EX, or a end 
record for PERF_END/PERF_END_EX,
+                             or a general record for other Perf macros.
+
+  @retval EFI_SUCCESS           - Successfully created performance record.
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
+                                  pointer or invalid PerfId.
+**/
+EFI_STATUS
+EFIAPI
+CreatePerformanceMeasurementPpi (
+  IN CONST VOID                        *CallerIdentifier,
+  IN CONST VOID                        *Guid,   OPTIONAL
+  IN CONST CHAR8                       *String, OPTIONAL
+  IN       UINT64                      TimeStamp,
+  IN       UINT64                      Address,  OPTIONAL
+  IN       UINT32                      Identifier,
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute
+  )
+{
+  return InsertFpdtRecord (CallerIdentifier, Guid, String, TimeStamp, Address, 
(UINT16)Identifier, Attribute);
+
+}
+
 /**
   Creates a record for the beginning of a performance measurement.
 
   If TimeStamp is zero, then this function reads the current time stamp
   and adds that time stamp value to the record as the start time.
diff --git a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf 
b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
index cad3a120a2..9b40af0738 100644
--- a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
+++ b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
@@ -52,10 +52,11 @@
 
 [Guids]
   ## PRODUCES ## HOB
   ## CONSUMES ## HOB
   gEdkiiFpdtExtendedFirmwarePerformanceGuid
+  gEdkiiPerformanceMeasurementPpiGuid
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries     ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries16   ## CONSUMES
   gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask        ## CONSUMES
-- 
2.14.3.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to