On 2/15/24 10:31, Gerd Hoffmann wrote:
> Remove the MpHandOff parameter. This is not useful in case multiple
> HOBs are present in the system. The function will use GetMpHandOffHob()
> to loop over all HOBs instead.
>
> Signed-off-by: Gerd Hoffmann <[email protected]>
> ---
> UefiCpuPkg/Library/MpInitLib/MpLib.c | 26 ++++++++++++++++----------
> 1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index e0a2366073a7..8e6cf50ed171 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -1894,26 +1894,32 @@ CheckAllAPs (
> /**
> This function Get BspNumber.
>
> - @param[in] MpHandOff Pointer to MpHandOff
> @return BspNumber
> **/
> UINT32
> GetBspNumber (
> - IN CONST MP_HAND_OFF *MpHandOff
> + VOID
> )
> {
> - UINT32 ApicId;
> - UINT32 BspNumber;
> - UINT32 Index;
> + UINT32 ApicId;
> + UINT32 BspNumber;
> + UINT32 Index;
> + MP_HAND_OFF *MpHandOff;
>
> //
> // Get the processor number for the BSP
> //
> BspNumber = MAX_UINT32;
> ApicId = GetInitialApicId ();
> - for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
> - if (MpHandOff->Info[Index].ApicId == ApicId) {
> - BspNumber = Index;
> +
> + for (MpHandOff = GetMpHandOffHob (0);
> + MpHandOff != NULL;
> + MpHandOff = GetMpHandOffHob (MpHandOff->ProcessorIndex +
> MpHandOff->CpuCount))
> + {
> + for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
> + if (MpHandOff->Info[Index].ApicId == ApicId) {
> + BspNumber = MpHandOff->ProcessorIndex + Index;
> + }
> }
> }
>
(I'm missing the larger picture here -- is this related to the problem
-- too many CPUs to fit their infos into a single HOB -- that Pawel
worked on for a while?
"UefiCpuPkg/Library/MpInitLib/MpHandOff.h" was created in commit
8bb018afaf2a ("UefiCpuPkg: Create MpHandOff.", 2023-07-11); I don't have
memories from that time frame. Either way, I do have a question /
observation here:)
The outer loop is suboptimal, IMO, to just open-coding another HOB scan
-- this approach looks quadratic, even though it could be linear. More
or less, as proposed, we call GetMpHandOffHob() for each MP_HAND_OFF
HOB, which will scan n/2 HOBs on average. (Even if the GUID HOB list is
sorted by ProcessorIndex, we'll scan 1 + 2 + 3 +... HOBs.) But if we
open-coded GetFirstGuidHob() and GetNextGuidHob() here, then a single
scan would suffice.
Laszlo
> @@ -1941,7 +1947,7 @@ SwitchApContext (
> UINTN Index;
> UINT32 BspNumber;
>
> - BspNumber = GetBspNumber (MpHandOff);
> + BspNumber = GetBspNumber ();
>
> for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
> if (Index != BspNumber) {
> @@ -2191,7 +2197,7 @@ MpInitLibInitialize (
> }
>
> CpuMpData->CpuCount = MpHandOff->CpuCount;
> - CpuMpData->BspNumber = GetBspNumber (MpHandOff);
> + CpuMpData->BspNumber = GetBspNumber ();
> CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
> for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
> InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock);
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115590): https://edk2.groups.io/g/devel/message/115590
Mute This Topic: https://groups.io/mt/104369845/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-