X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=UefiCpuPkg%2FLibrary%2FMpInitLib%2FMpLib.c;h=0e57cc86bf7965b596c7164a8fca208553d70d43;hp=e5c701ddeb464d36a66321343f07931dd93e93bb;hb=2da3e96cb7aa4510f5b5086efca0c2188c055751;hpb=58942277bcbf41abda5f6e3a1c89d571105d5983 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index e5c701ddeb..0e57cc86bf 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -435,16 +435,19 @@ GetProcessorNumber ( UINTN TotalProcessorNumber; UINTN Index; CPU_INFO_IN_HOB *CpuInfoInHob; + UINT32 CurrentApicId; CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; TotalProcessorNumber = CpuMpData->CpuCount; + CurrentApicId = GetApicId (); for (Index = 0; Index < TotalProcessorNumber; Index ++) { - if (CpuInfoInHob[Index].ApicId == GetApicId ()) { + if (CpuInfoInHob[Index].ApicId == CurrentApicId) { *ProcessorNumber = Index; return EFI_SUCCESS; } } + return EFI_NOT_FOUND; } @@ -693,7 +696,7 @@ ApWakeupFunction ( } } } - SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished); + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } } @@ -1349,18 +1352,17 @@ CheckThisAP ( CpuData = &CpuMpData->CpuData[ProcessorNumber]; // - // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task. + // Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task. // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the - // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value. + // value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value. // // // If the AP finishes for StartupThisAP(), return EFI_SUCCESS. // - if (GetApState(CpuData) == CpuStateFinished) { + if (GetApState(CpuData) == CpuStateIdle) { if (CpuData->Finished != NULL) { *(CpuData->Finished) = TRUE; } - SetApState (CpuData, CpuStateIdle); return EFI_SUCCESS; } else { // @@ -1417,14 +1419,13 @@ CheckAllAPs ( CpuData = &CpuMpData->CpuData[ProcessorNumber]; // - // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task. + // Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task. // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the - // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value. + // value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value. // - if (GetApState(CpuData) == CpuStateFinished) { - CpuMpData->RunningCount ++; + if (GetApState(CpuData) == CpuStateIdle) { + CpuMpData->RunningCount --; CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE; - SetApState(CpuData, CpuStateIdle); // // If in Single Thread mode, then search for the next waiting AP for execution. @@ -1448,7 +1449,7 @@ CheckAllAPs ( // // If all APs finish, return EFI_SUCCESS. // - if (CpuMpData->RunningCount == CpuMpData->StartCount) { + if (CpuMpData->RunningCount == 0) { return EFI_SUCCESS; } @@ -1465,7 +1466,7 @@ CheckAllAPs ( // if (CpuMpData->FailedCpuList != NULL) { *CpuMpData->FailedCpuList = - AllocatePool ((CpuMpData->StartCount - CpuMpData->FinishedCount + 1) * sizeof (UINTN)); + AllocatePool ((CpuMpData->RunningCount + 1) * sizeof (UINTN)); ASSERT (*CpuMpData->FailedCpuList != NULL); } ListIndex = 0; @@ -1920,7 +1921,7 @@ SwitchBSPWorker ( // // Wait for old BSP finished AP task // - while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) { + while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateIdle) { CpuPause (); } @@ -2211,7 +2212,7 @@ StartupAllAPsWorker ( return EFI_NOT_STARTED; } - CpuMpData->StartCount = 0; + CpuMpData->RunningCount = 0; for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) { CpuData = &CpuMpData->CpuData[ProcessorNumber]; CpuData->Waiting = FALSE; @@ -2221,7 +2222,7 @@ StartupAllAPsWorker ( // Mark this processor as responsible for current calling. // CpuData->Waiting = TRUE; - CpuMpData->StartCount++; + CpuMpData->RunningCount++; } } } @@ -2230,7 +2231,6 @@ StartupAllAPsWorker ( CpuMpData->ProcArguments = ProcedureArgument; CpuMpData->SingleThread = SingleThread; CpuMpData->FinishedCount = 0; - CpuMpData->RunningCount = 0; CpuMpData->FailedCpuList = FailedCpuList; CpuMpData->ExpectedTime = CalculateTimeout ( TimeoutInMicroseconds,