public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue
@ 2023-08-30  7:35 duntan
  2023-08-30 10:21 ` Ni, Ray
  0 siblings, 1 reply; 3+ messages in thread
From: duntan @ 2023-08-30  7:35 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Liming Gao, Ray Ni

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..0a994be6a5 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    mSmmBootRecordOffset  = 0;
 
 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;
 
@@ -236,6 +237,7 @@ InternalGetSmmPerfData (
   VOID                                     *SmmBootRecordData;
   UINTN                                    SmmBootRecordDataSize;
   UINTN                                    ReservedMemSize;
+  UINTN                                    SmmBootRecordDataRetrieved;
 
   //
   // Collect boot records from SMM drivers.
@@ -297,28 +299,32 @@ InternalGetSmmPerfData (
           }
 
           //
-          // Get all boot records
+          // Get boot records starting from mSmmBootRecordOffset
           //
-          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 = mSmmBootRecordOffset;
+          SmmBootRecordDataSize         = SmmCommData->BootRecordSize - mSmmBootRecordOffset;
+          SmmBootRecordData             = AllocateZeroPool (SmmBootRecordDataSize);
+          SmmBootRecordDataRetrieved    = 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 (SmmBootRecordDataRetrieved < 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 (SmmBootRecordDataRetrieved + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
+              CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmBootRecordDataRetrieved);
             } else {
-              CopyMem ((UINT8 *)SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
+              CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
             }
 
-            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
+            SmmBootRecordDataRetrieved    += SmmCommData->BootRecordSize;
+            SmmCommData->BootRecordOffset += SmmCommData->BootRecordSize;
           }
 
+          mSmmBootRecordOffset = 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 (#108118): https://edk2.groups.io/g/devel/message/108118
Mute This Topic: https://groups.io/mt/101047988/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue
  2023-08-30  7:35 [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue duntan
@ 2023-08-30 10:21 ` Ni, Ray
  0 siblings, 0 replies; 3+ messages in thread
From: Ni, Ray @ 2023-08-30 10:21 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io; +Cc: Wang, Jian J, Gao, Liming

[-- Attachment #1: Type: text/plain, Size: 6006 bytes --]

Reviewed-by: Ray Ni <ray.ni@intel.com>

Thanks,
Ray
________________________________
From: Tan, Dun <dun.tan@intel.com>
Sent: Wednesday, August 30, 2023 3:35 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue

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..0a994be6a5 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    mSmmBootRecordOffset  = 0;

 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;

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

   //
   // Collect boot records from SMM drivers.
@@ -297,28 +299,32 @@ InternalGetSmmPerfData (
           }

           //
-          // Get all boot records
+          // Get boot records starting from mSmmBootRecordOffset
           //
-          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 = mSmmBootRecordOffset;
+          SmmBootRecordDataSize         = SmmCommData->BootRecordSize - mSmmBootRecordOffset;
+          SmmBootRecordData             = AllocateZeroPool (SmmBootRecordDataSize);
+          SmmBootRecordDataRetrieved    = 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 (SmmBootRecordDataRetrieved < 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 (SmmBootRecordDataRetrieved + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
+              CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmBootRecordDataRetrieved);
             } else {
-              CopyMem ((UINT8 *)SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
+              CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
             }

-            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
+            SmmBootRecordDataRetrieved    += SmmCommData->BootRecordSize;
+            SmmCommData->BootRecordOffset += SmmCommData->BootRecordSize;
           }

+          mSmmBootRecordOffset = 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 (#108141): https://edk2.groups.io/g/devel/message/108141
Mute This Topic: https://groups.io/mt/101047988/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 11639 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue
       [not found] <1780190419D49EE1.31776@groups.io>
@ 2023-09-01  4:06 ` duntan
  0 siblings, 0 replies; 3+ messages in thread
From: duntan @ 2023-09-01  4:06 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun; +Cc: Wang, Jian J, Gao, Liming, Ni, Ray

Hi Jian and Liming,

Could you please help to review this patch?

Thanks,
Dun
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Wednesday, August 30, 2023 3:36 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue

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..0a994be6a5 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    mSmmBootRecordOffset  = 0;
 
 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;
 
@@ -236,6 +237,7 @@ InternalGetSmmPerfData (
   VOID                                     *SmmBootRecordData;
   UINTN                                    SmmBootRecordDataSize;
   UINTN                                    ReservedMemSize;
+  UINTN                                    SmmBootRecordDataRetrieved;
 
   //
   // Collect boot records from SMM drivers.
@@ -297,28 +299,32 @@ InternalGetSmmPerfData (
           }
 
           //
-          // Get all boot records
+          // Get boot records starting from mSmmBootRecordOffset
           //
-          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 = mSmmBootRecordOffset;
+          SmmBootRecordDataSize         = SmmCommData->BootRecordSize - mSmmBootRecordOffset;
+          SmmBootRecordData             = AllocateZeroPool (SmmBootRecordDataSize);
+          SmmBootRecordDataRetrieved    = 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 (SmmBootRecordDataRetrieved < 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 (SmmBootRecordDataRetrieved + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
+              CopyMem ((UINT8 *)SmmBootRecordData + 
+ SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, 
+ SmmBootRecordDataSize - SmmBootRecordDataRetrieved);
             } else {
-              CopyMem ((UINT8 *)SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
+              CopyMem ((UINT8 *)SmmBootRecordData + 
+ SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, 
+ SmmCommData->BootRecordSize);
             }
 
-            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;
+            SmmBootRecordDataRetrieved    += SmmCommData->BootRecordSize;
+            SmmCommData->BootRecordOffset += 
+ SmmCommData->BootRecordSize;
           }
 
+          mSmmBootRecordOffset = 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 (#108224): https://edk2.groups.io/g/devel/message/108224
Mute This Topic: https://groups.io/mt/101047988/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-01  9:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30  7:35 [edk2-devel] [Patch V2] MdeModulePkg/DxeCorePerformanceLib:fix smm perf issue duntan
2023-08-30 10:21 ` Ni, Ray
     [not found] <1780190419D49EE1.31776@groups.io>
2023-09-01  4:06 ` duntan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox