From c156d27b397489814a85f700abb584fc835644a7 Mon Sep 17 00:00:00 2001 From: Chen Fan Date: Fri, 21 Nov 2014 22:46:36 +0000 Subject: EmulatorPkg/MpService: StartupAllAPs should verify processor state before setting state if any enabled APs are not in idle state, StartupAllAPs() should return immediately, and must not change the other idled processor state. so we checked the state before changed them. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen Fan Reviewed-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16416 6f19259b-4bc3-4df7-8a09-765794883524 --- EmulatorPkg/CpuRuntimeDxe/MpService.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/EmulatorPkg/CpuRuntimeDxe/MpService.c b/EmulatorPkg/CpuRuntimeDxe/MpService.c index 2312fc527e..f941519c29 100644 --- a/EmulatorPkg/CpuRuntimeDxe/MpService.c +++ b/EmulatorPkg/CpuRuntimeDxe/MpService.c @@ -420,6 +420,24 @@ CpuMpServicesStartupAllAps ( return EFI_UNSUPPORTED; } + for (Number = 0; Number < gMPSystem.NumberOfProcessors; Number++) { + ProcessorData = &gMPSystem.ProcessorData[Number]; + if ((ProcessorData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) == PROCESSOR_AS_BSP_BIT) { + // Skip BSP + continue; + } + + if ((ProcessorData->Info.StatusFlag & PROCESSOR_ENABLED_BIT) == 0) { + // Skip Disabled processors + continue; + } + gThread->MutexLock(ProcessorData->StateLock); + if (ProcessorData->State != CPU_STATE_IDLE) { + gThread->MutexUnlock (ProcessorData->StateLock); + return EFI_NOT_READY; + } + gThread->MutexUnlock(ProcessorData->StateLock); + } if (FailedCpuList != NULL) { gMPSystem.FailedList = AllocatePool ((gMPSystem.NumberOfProcessors + 1) * sizeof (UINTN)); @@ -461,17 +479,13 @@ CpuMpServicesStartupAllAps ( // if not "SingleThread", all APs are put to ready state from the beginning // gThread->MutexLock(ProcessorData->StateLock); - if (ProcessorData->State == CPU_STATE_IDLE) { - ProcessorData->State = APInitialState; - gThread->MutexUnlock (ProcessorData->StateLock); + ASSERT (ProcessorData->State == CPU_STATE_IDLE); + ProcessorData->State = APInitialState; + gThread->MutexUnlock (ProcessorData->StateLock); - gMPSystem.StartCount++; - if (SingleThread) { - APInitialState = CPU_STATE_BLOCKED; - } - } else { - gThread->MutexUnlock (ProcessorData->StateLock); - return EFI_NOT_READY; + gMPSystem.StartCount++; + if (SingleThread) { + APInitialState = CPU_STATE_BLOCKED; } } -- cgit v1.2.3