]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
Rename PcdPlatformBusSpeed to PcdFSBClock and update help text.
[mirror_edk2.git] / EdkModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index c75ab851f70c2377b60e874c05f0041fde7ab5a7..268a6a04f24b445a33098040489710fba4c40cb7 100644 (file)
@@ -118,7 +118,8 @@ GetGauge (
 STATIC GAUGE_DATA_HEADER    *mGaugeData;\r
 STATIC UINT32               mMaxGaugeRecords;\r
 \r
-PERFORMANCE_PROTOCOL PerformanceInterface = {\r
+EFI_HANDLE           mHandle = NULL;\r
+PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
   StartGauge,\r
   EndGauge,\r
   GetGauge\r
@@ -213,7 +214,6 @@ StartGauge (
   UINTN                     GaugeDataSize;\r
   UINTN                     OldGaugeDataSize;\r
   GAUGE_DATA_HEADER         *OldGaugeData;\r
-  EFI_STATUS                Status;\r
   UINT32                    Index;\r
 \r
   Index = mGaugeData->NumberOfEntries;\r
@@ -223,23 +223,20 @@ StartGauge (
     //\r
     OldGaugeData      = mGaugeData;\r
     OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+\r
     mMaxGaugeRecords *= 2;\r
     GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
-    Status            = gBS->AllocatePool (\r
-                               EfiBootServicesData,\r
-                               GaugeDataSize,\r
-                               (VOID **) &mGaugeData\r
-                               );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
+    \r
+    mGaugeData = AllocateZeroPool (GaugeDataSize);\r
+    if (mGaugeData == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
     //\r
     // Initialize new data arry and migrate old data one. \r
     //\r
-    mGaugeData        = ZeroMem (mGaugeData, GaugeDataSize);\r
-    mGaugeData        = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
+    mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
     \r
-    gBS->FreePool (OldGaugeData); \r
+    FreePool (OldGaugeData); \r
   }\r
   \r
   GaugeEntryArray               = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
@@ -423,31 +420,28 @@ DxeCorePerformanceLibConstructor (
   )\r
 {\r
   EFI_STATUS                Status;\r
-  EFI_HANDLE                Handle;\r
-  UINTN                     GaugeDataSize;\r
 \r
+  if (!PerformanceMeasurementEnabled ()) {\r
+    //\r
+    // Do not initialize performance infrastructure if not required.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
   //\r
   // Install the protocol interfaces.\r
   //\r
-  Handle = NULL;\r
   Status = gBS->InstallProtocolInterface (\r
-                  &Handle,\r
+                  &mHandle,\r
                   &gPerformanceProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
-                  &PerformanceInterface\r
+                  &mPerformanceInterface\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + MAX_PEI_PERFORMANCE_LOG_ENTRIES;\r
-  GaugeDataSize   = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  GaugeDataSize,\r
-                  (VOID **) &mGaugeData\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
 \r
-  ZeroMem (mGaugeData, GaugeDataSize);\r
+  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
+  ASSERT (mGaugeData != NULL);\r
 \r
   InternalGetPeiPerformance ();\r
 \r
@@ -532,34 +526,46 @@ EndPerformanceMeasurement (
 }\r
 \r
 /**\r
-  Retrieves a previously logged performance measurement\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log\r
   \r
-  Retrieves the performance log entry from the performance log\r
-  that immediately follows the log entry specified by LogEntryKey.\r
-  If LogEntryKey is zero, then the first entry from the performance log is returned.\r
-  If the log entry specified by LogEntryKey is the last entry in the performance log,\r
-  then 0 is returned.  Otherwise, the performance log entry is returned in Handle,\r
-  Token, Module, StartTimeStamp, and EndTimeStamp.\r
-  The key for the current performance log entry is returned. \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  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  StartTimeStamp          The 64-bit time stamp that was recorded when the measurement was started.\r
-  @param  EndTimeStamp            The 64-bit time stamp that was recorded when the measurement was ended.\r
-\r
-  @return The key for the current performance log entry.\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\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 lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  UINTN           LogEntryKey, \r
+  IN  UINTN       LogEntryKey, \r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r