summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAwiral Shrivastava <awiral.shrivastava@intel.com>2024-07-05 08:37:41 +0530
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-07-30 13:51:41 +0000
commit5b08df03f8193261e4837ed4e91ff81fa7d17e4d (patch)
tree51a2c3c54c65e16a8536d65530ccb6d16ce21217
parent91a822749a6664dcaf0f67a837dcf0cd05783d17 (diff)
downloadedk2-5b08df03f8193261e4837ed4e91ff81fa7d17e4d.tar.gz
MdeModulePkg: Optimize PEI Core Migration Algorithm
REF : https://bugzilla.tianocore.org/show_bug.cgi?id=4750 Migrate the FV that doesn't contain the currently executing PEI Core when permanent memory is initialized but PEI Core is still potentially running from faster memory (Tepmorary RAM). This may reduce the time required to migrate FVs to permanent memory. The FV containing PEI Core is migrated after the PEI Core reentry when it is executed from permanent memory. This may or may not improve performance depending on the behavior of temporary RAM and the actual performance changes must be measured with the feature enabled and disabled. This migration algorithm is only used for FVs specified in the gEdkiiMigrationInfoGuid HOB and built with flag FLAGS_FV_MIGRATE_BEFORE_PEI_CORE_REENTRY. Signed-off-by: Awiral Shrivastava <awiral.shrivastava@intel.com>
-rw-r--r--MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c37
-rw-r--r--MdeModulePkg/Core/Pei/PeiMain/PeiMain.c16
-rw-r--r--MdeModulePkg/Include/Guid/MigratedFvInfo.h3
3 files changed, 47 insertions, 9 deletions
diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index ca37bde482..79ff8d1cf9 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -1205,16 +1205,21 @@ EvacuateTempRam (
PeiCoreFvHandle.FvHandle = (EFI_PEI_FV_HANDLE)SecCoreData->BootFirmwareVolumeBase;
}
- for (FvIndex = 0; FvIndex < Private->FvCount; FvIndex++) {
- if (Private->Fv[FvIndex].FvHandle == PeiCoreFvHandle.FvHandle) {
- CopyMem (&PeiCoreFvHandle, &Private->Fv[FvIndex], sizeof (PEI_CORE_FV_HANDLE));
- break;
+ if (Private->PeimDispatcherReenter) {
+ //
+ // PEI_CORE should be migrated after dispatcher re-enters from main memory.
+ //
+ for (FvIndex = 0; FvIndex < Private->FvCount; FvIndex++) {
+ if (Private->Fv[FvIndex].FvHandle == PeiCoreFvHandle.FvHandle) {
+ CopyMem (&PeiCoreFvHandle, &Private->Fv[FvIndex], sizeof (PEI_CORE_FV_HANDLE));
+ break;
+ }
}
- }
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
- ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);
+ ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);
+ }
Hob.Raw = GetFirstGuidHob (&gEdkiiMigrationInfoGuid);
if (Hob.Raw != NULL) {
@@ -1237,6 +1242,14 @@ EvacuateTempRam (
)
{
if ((MigrationInfo == NULL) || (MigrationInfo->MigrateAll == TRUE)) {
+ if (!Private->PeimDispatcherReenter) {
+ //
+ // Migration before dispatcher reentery is supported only when gEdkiiMigrationInfoGuid
+ // HOB is built for selective FV migration.
+ //
+ return EFI_SUCCESS;
+ }
+
//
// Migrate all FVs and copy raw data
//
@@ -1253,10 +1266,18 @@ EvacuateTempRam (
}
}
- if (Index == MigrationInfo->ToMigrateFvCount) {
+ if ((Index == MigrationInfo->ToMigrateFvCount) ||
+ ((!Private->PeimDispatcherReenter) &&
+ (((FvMigrationFlags & FLAGS_FV_MIGRATE_BEFORE_PEI_CORE_REENTRY) == 0) ||
+ (FvHeader == PeiCoreFvHandle.FvHandle))))
+ {
//
// This FV is not expected to migrate
//
+ // FV should not be migrated before dispatcher reentry if any of the below condition is true:
+ // a. MigrationInfo HOB is not built with flag FLAGS_FV_MIGRATE_BEFORE_PEI_CORE_REENTRY.
+ // b. FV contains currently executing PEI Core.
+ //
continue;
}
}
diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
index 0e3d9a8438..61f5699e1f 100644
--- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
+++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
@@ -323,6 +323,21 @@ PeiCore (
//
OldCoreData->PeiMemoryInstalled = TRUE;
+ if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {
+ DEBUG ((DEBUG_VERBOSE, "Early Migration - PPI lists before temporary RAM evacuation:\n"));
+ DumpPpiList (OldCoreData);
+
+ //
+ // Migrate installed content from Temporary RAM to Permanent RAM at this
+ // stage when PEI core still runs from a cached location.
+ // FVs that doesn't contain PEI_CORE should be migrated here.
+ //
+ EvacuateTempRam (OldCoreData, SecCoreData);
+
+ DEBUG ((DEBUG_VERBOSE, "Early Migration - PPI lists after temporary RAM evacuation:\n"));
+ DumpPpiList (OldCoreData);
+ }
+
//
// Indicate that PeiCore reenter
//
@@ -451,6 +466,7 @@ PeiCore (
//
// Migrate installed content from Temporary RAM to Permanent RAM
+ // FVs containing PEI_CORE should be migrated here.
//
EvacuateTempRam (&PrivateData, SecCoreData);
diff --git a/MdeModulePkg/Include/Guid/MigratedFvInfo.h b/MdeModulePkg/Include/Guid/MigratedFvInfo.h
index 255e278235..99681fb88a 100644
--- a/MdeModulePkg/Include/Guid/MigratedFvInfo.h
+++ b/MdeModulePkg/Include/Guid/MigratedFvInfo.h
@@ -18,7 +18,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// 1: FV raw data will be copied to permanent memory for later phase use (such as
// FV measurement).
//
-#define FLAGS_FV_RAW_DATA_COPY BIT0
+#define FLAGS_FV_RAW_DATA_COPY BIT0
+#define FLAGS_FV_MIGRATE_BEFORE_PEI_CORE_REENTRY BIT1
///
/// In real use cases, not all FVs need migrate to permanent memory before TempRam tears