]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
Make EdkModulePkg pass Intel IPF compiler with /W4 /WX switches, solving warning...
[mirror_edk2.git] / EdkModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index e4e7b3bb3b689080aa87e824d45cc60abc8d95ac..727133226c74b38f1683302217abed3efd3ec29c 100644 (file)
@@ -45,6 +45,7 @@ Abstract:
   @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 StartGauge (\r
@@ -78,6 +79,7 @@ StartGauge (
   @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EndGauge (\r
@@ -105,6 +107,7 @@ EndGauge (
   @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL. \r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GetGauge (\r
@@ -118,7 +121,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
@@ -143,6 +147,7 @@ PERFORMANCE_PROTOCOL PerformanceInterface = {
   @retval The index of gauge entry in the array.\r
 \r
 **/\r
+STATIC\r
 UINT32\r
 InternalSearchForGaugeEntry (\r
   IN CONST VOID                 *Handle,  OPTIONAL\r
@@ -200,6 +205,7 @@ InternalSearchForGaugeEntry (
   @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 StartGauge (\r
@@ -213,7 +219,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 +228,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
@@ -286,6 +288,7 @@ StartGauge (
   @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EndGauge (\r
@@ -330,6 +333,7 @@ EndGauge (
   @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL. \r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GetGauge (\r
@@ -366,6 +370,7 @@ GetGauge (
   to DXE performance data structures.\r
 \r
 **/\r
+STATIC\r
 VOID\r
 InternalGetPeiPerformance (\r
   VOID\r
@@ -423,31 +428,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
@@ -631,5 +633,5 @@ PerformanceMeasurementEnabled (
   VOID\r
   )\r
 {\r
-  return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
 }\r