On 2/20/24 18:49, Gerd Hoffmann wrote: > Add support for splitting Hand-Off data into multiple HOBs. This is > required for VMs with thousands of CPUs. The actual CPU count per HOB > is much smaller (128) for better test coverage.
(1) The mention of the count 128 now seems stale for the code. > > Signed-off-by: Gerd Hoffmann <kra...@redhat.com> > --- > UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 44 +++++++++++++++---------- > 1 file changed, 27 insertions(+), 17 deletions(-) > > diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > index f80e00edcff3..8a916a218016 100644 > --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > @@ -126,35 +126,45 @@ SaveCpuMpData ( > IN CPU_MP_DATA *CpuMpData > ) > { > + UINT32 MaxCpusPerHob, CpusInHob; > UINT64 Data64; > - UINTN Index; > + UINT32 Index, HobBase; > CPU_INFO_IN_HOB *CpuInfoInHob; > MP_HAND_OFF *MpHandOff; > UINTN MpHandOffSize; > > + MaxCpusPerHob = (MAX_UINT16 - sizeof (EFI_HOB_GUID_TYPE) - sizeof > (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); (2) MAX_UINT16 should be 0xFFF8 instead; see subthread. > + > // > // When APs are in a state that can be waken up by a store operation to a > memory address, > // report the MP_HAND_OFF data for DXE to use. > // > - CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; > - MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * > CpuMpData->CpuCount; > - MpHandOff = (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, > MpHandOffSize); > - ASSERT (MpHandOff != NULL); > - ZeroMem (MpHandOff, MpHandOffSize); > - MpHandOff->ProcessorIndex = 0; > + CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; > > - MpHandOff->CpuCount = CpuMpData->CpuCount; > - if (CpuMpData->ApLoopMode != ApInHltLoop) { > - MpHandOff->StartupSignalValue = MP_HAND_OFF_SIGNAL; > - MpHandOff->WaitLoopExecutionMode = sizeof (VOID *); > - } > + for (Index = 0; Index < CpuMpData->CpuCount; Index++) { > + if (Index % MaxCpusPerHob == 0) { > + HobBase = Index; > + CpusInHob = MIN (CpuMpData->CpuCount - HobBase, MaxCpusPerHob); > > - for (Index = 0; Index < MpHandOff->CpuCount; Index++) { > - MpHandOff->Info[Index].ApicId = CpuInfoInHob[Index].ApicId; > - MpHandOff->Info[Index].Health = CpuInfoInHob[Index].Health; > + MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * > CpusInHob; > + MpHandOff = (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, > MpHandOffSize); > + ASSERT (MpHandOff != NULL); > + ZeroMem (MpHandOff, MpHandOffSize); > + > + MpHandOff->ProcessorIndex = HobBase; > + MpHandOff->CpuCount = CpusInHob; > + > + if (CpuMpData->ApLoopMode != ApInHltLoop) { > + MpHandOff->StartupSignalValue = MP_HAND_OFF_SIGNAL; > + MpHandOff->WaitLoopExecutionMode = sizeof (VOID *); > + } > + } > + > + MpHandOff->Info[Index-HobBase].ApicId = CpuInfoInHob[Index].ApicId; > + MpHandOff->Info[Index-HobBase].Health = CpuInfoInHob[Index].Health; > if (CpuMpData->ApLoopMode != ApInHltLoop) { > - MpHandOff->Info[Index].StartupSignalAddress = > (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal; > - MpHandOff->Info[Index].StartupProcedureAddress = > (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; > + MpHandOff->Info[Index-HobBase].StartupSignalAddress = > (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal; > + MpHandOff->Info[Index-HobBase].StartupProcedureAddress = > (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; > } > } > (3) The conversion looks good otherwise, but I dislike that StartupSignalValue and WaitLoopExecutionMode get uselessly replicated over all HOBs. Again, it *increases* technical debt. It's fine to ignore existent debt (if you can), but adding to it is not right. Can you file a new TianoCore BZ, for moving these fields to separate dynamic PCDs, or to a new singleton GUID HOB (containing both fields)? If you assign that BZ to yourself, and reference it in patches #4 and #5, I'll be happy to R-b version 3 of the series. (Which is something I'd like to do.) Version 3 may be mergeable regardless, of course, if Ray accepts it. Thanks, Laszlo -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115770): https://edk2.groups.io/g/devel/message/115770 Mute This Topic: https://groups.io/mt/104472313/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-