[edk2-devel] [PATCH] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue

duntan posted 1 patch 8 months, 1 week ago
Failed in applying to current master (apply log)
There is a newer version of this series
MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
[edk2-devel] [PATCH] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue
Posted by duntan 8 months, 1 week ago
Fix smm perf issue in DxeCorePerformanceLib. In
current code logic, total SMM perf record is copied
multiple times to FPDT table if multiple ReadyToBoot
events are signaled. This patch changes the function
InternalGetSmmPerfData() to only get newly generated
Smm perf data. Then previous generated Smm perf data
won't be copied to FPDT again.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4470
Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
index ef14bc0738..2c7b960c30 100644
--- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
+++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
@@ -10,7 +10,7 @@
   This library is mainly used by DxeCore to start performance logging to ensure that
   Performance Protocol is installed at the very beginning of DXE phase.
 
-Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2023, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -73,6 +73,7 @@ UINT8    *mPerformancePointer  = NULL;
 UINT8    *mBootRecordBuffer    = NULL;
 BOOLEAN  mLockInsertRecord     = FALSE;
 CHAR8    *mDevicePathString    = NULL;
+UINTN    mBootRecordOffset     = 0;
 
 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;
 
@@ -236,6 +237,7 @@ InternalGetSmmPerfData (
   VOID                                     *SmmBootRecordData;
   UINTN                                    SmmBootRecordDataSize;
   UINTN                                    ReservedMemSize;
+  UINTN                                    CurrentRecordOffset;
 
   //
   // Collect boot records from SMM drivers.
@@ -297,28 +299,32 @@ InternalGetSmmPerfData (
           }
 
           //
-          // Get all boot records
+          // Get boot records starting from mBootRecordOffset
           //
-          SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;
-          SmmBootRecordDataSize = SmmCommData->BootRecordSize;
-          SmmBootRecordData     = AllocateZeroPool (SmmBootRecordDataSize);
+          SmmCommData->Function         = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;
+          SmmCommData->BootRecordOffset = mBootRecordOffset;
+          SmmBootRecordDataSize         = SmmCommData->BootRecordSize - mBootRecordOffset;
+          SmmBootRecordData             = AllocateZeroPool (SmmBootRecordDataSize);
+          CurrentRecordOffset           = 0;
           ASSERT (SmmBootRecordData  != NULL);
-          SmmCommData->BootRecordOffset = 0;
-          SmmCommData->BootRecordData   = (VOID *)((UINTN)SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
-          SmmCommData->BootRecordSize   = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;
-          while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {
+          SmmCommData->BootRecordData = (VOID *)((UINTN)SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
+          SmmCommData->BootRecordSize = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;
+          while (CurrentRecordOffset < SmmBootRecordDataSize) {
             Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
             ASSERT_EFI_ERROR (Status);
             ASSERT_EFI_ERROR (SmmCommData->ReturnStatus);
-            if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
-              CopyMem ((UINT8 *)SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);
+            if (CurrentRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
+              CopyMem ((UINT8 *)SmmBootRecordData + CurrentRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - CurrentRecordOffset);
             } else {
-              CopyMem ((UINT8 *)SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
+              CopyMem ((UINT8 *)SmmBootRecordData + CurrentRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
             }
 
-            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
+            CurrentRecordOffset           += SmmCommData->BootRecordSize;
+            SmmCommData->BootRecordOffset += SmmCommData->BootRecordSize;
           }
 
+          mBootRecordOffset = SmmCommData->BootRecordOffset;
+
           *SmmPerfData     = SmmBootRecordData;
           *SmmPerfDataSize = SmmBootRecordDataSize;
         }
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108001): https://edk2.groups.io/g/devel/message/108001
Mute This Topic: https://groups.io/mt/100931879/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue
Posted by Ni, Ray 8 months ago
2 comments as follows, starting with "[ray"

@@ -73,6 +73,7 @@ UINT8    *mPerformancePointer  = NULL;
 UINT8    *mBootRecordBuffer    = NULL;
 BOOLEAN  mLockInsertRecord     = FALSE;
 CHAR8    *mDevicePathString    = NULL;
+UINTN    mBootRecordOffset     = 0;

[ray.1] How about mSmmBootRecordOffset?

 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;

@@ -236,6 +237,7 @@ InternalGetSmmPerfData (
   VOID                                     *SmmBootRecordData;
   UINTN                                    SmmBootRecordDataSize;
   UINTN                                    ReservedMemSize;
+  UINTN                                    CurrentRecordOffset;

[ray.2] How about "SmmBootRecordDataRetrieved"?



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108051): https://edk2.groups.io/g/devel/message/108051
Mute This Topic: https://groups.io/mt/100931879/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-