Skip to content

Commit

Permalink
MdeModulePkg: Optimize PEI Core Migration Algorithm
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
awiralsh authored and lgao4 committed Jul 30, 2024
1 parent 84fc1ec commit bf6a551
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
37 changes: 29 additions & 8 deletions MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
//
Expand All @@ -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;
}
}
Expand Down
16 changes: 16 additions & 0 deletions MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion MdeModulePkg/Include/Guid/MigratedFvInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf6a551

Please sign in to comment.