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>
This commit is contained in:
Awiral Shrivastava 2024-07-05 08:37:41 +05:30 committed by mergify[bot]
parent 91a822749a
commit 5b08df03f8
3 changed files with 48 additions and 10 deletions

View File

@ -1205,17 +1205,22 @@ 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;
ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);
}
Status = EFI_SUCCESS;
ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);
Hob.Raw = GetFirstGuidHob (&gEdkiiMigrationInfoGuid);
if (Hob.Raw != NULL) {
MigrationInfo = GET_GUID_HOB_DATA (Hob);
@ -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;
}
}

View File

@ -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);

View File

@ -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