From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4D6DC211F889C for ; Thu, 28 Jun 2018 04:29:24 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2018 04:29:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,283,1526367600"; d="scan'208";a="68448779" Received: from ydong10-win10.ccr.corp.intel.com ([10.239.9.24]) by orsmga001.jf.intel.com with ESMTP; 28 Jun 2018 04:29:20 -0700 From: Eric Dong To: edk2-devel@lists.01.org Cc: Ruiyu Ni , Jeff Fan , Laszlo Ersek Date: Thu, 28 Jun 2018 19:29:19 +0800 Message-Id: <20180628112920.5296-1-eric.dong@intel.com> X-Mailer: git-send-email 2.15.0.windows.1 Subject: [Patch 1/2] UefiCpuPkg/MpInitLib: Not use disabled AP. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2018 11:29:24 -0000 Based on PI spec description, disabled APs should not been include in the StartupAllAPs task. Current implementation always change AP state to CpuStateReady in WakeUpAP function which also let Disabled APs to do the task. This patch reduce the CPU state to only three state: Idle, busy and disabled. The possible change process is: Idel -> busy -> Idle Idle -> disabled -> Idle Done Tests: 1.PI SCT Test 2.Boot OS / S3 Cc: Ruiyu Ni Cc: Jeff Fan Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 +++++++++++++--------------------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 -- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index f2ff40417a..3945771764 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -460,8 +460,6 @@ CollectProcessorCount ( IN CPU_MP_DATA *CpuMpData ) { - UINTN Index; - // // Send 1st broadcast IPI to APs to wakeup APs // @@ -499,12 +497,6 @@ CollectProcessorCount ( // Enable x2APIC on BSP // SetApicMode (LOCAL_APIC_MODE_X2APIC); - // - // Set BSP/Aps state to IDLE - // - for (Index = 0; Index < CpuMpData->CpuCount; Index++) { - SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); - } } DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ())); // @@ -648,7 +640,7 @@ ApWakeupFunction ( CpuFlushTlb (); } - if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateReady) { + if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateIdle) { Procedure = (EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction; Parameter = (VOID *) CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument; if (Procedure != NULL) { @@ -691,7 +683,7 @@ ApWakeupFunction ( } } } - SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished); + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } } @@ -1005,7 +997,6 @@ WakeUpAP ( CpuData = &CpuMpData->CpuData[Index]; CpuData->ApFunction = (UINTN) Procedure; CpuData->ApFunctionArgument = (UINTN) ProcedureArgument; - SetApState (CpuData, CpuStateReady); if (CpuMpData->InitFlag != ApInitConfig) { *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL; } @@ -1052,7 +1043,6 @@ WakeUpAP ( CpuData = &CpuMpData->CpuData[ProcessorNumber]; CpuData->ApFunction = (UINTN) Procedure; CpuData->ApFunctionArgument = (UINTN) ProcedureArgument; - SetApState (CpuData, CpuStateReady); // // Wakeup specified AP // @@ -1345,11 +1335,10 @@ CheckThisAP ( // // If the AP finishes for StartupThisAP(), return EFI_SUCCESS. // - if (GetApState(CpuData) == CpuStateFinished) { + if (GetApState(CpuData) != CpuStateBusy) { if (CpuData->Finished != NULL) { *(CpuData->Finished) = TRUE; } - SetApState (CpuData, CpuStateIdle); return EFI_SUCCESS; } else { // @@ -1410,10 +1399,9 @@ CheckAllAPs ( // 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. // - if (GetApState(CpuData) == CpuStateFinished) { + if (GetApState(CpuData) != CpuStateBusy) { CpuMpData->RunningCount ++; CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE; - SetApState(CpuData, CpuStateIdle); // // If in Single Thread mode, then search for the next waiting AP for execution. @@ -1625,6 +1613,13 @@ MpInitLibInitialize ( ); } if (MaxLogicalProcessorNumber > 1) { + // + // Initial AP to idle state, later ApWakeupFunction based on + // this state to decide whether need to execute AP procedure. + // + for (Index = 0; Index < CpuMpData->CpuCount; Index++) { + SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); + } // // Wakeup APs to do some AP initialize sync // @@ -1636,9 +1631,6 @@ MpInitLibInitialize ( CpuPause (); } CpuMpData->InitFlag = ApInitDone; - for (Index = 0; Index < CpuMpData->CpuCount; Index++) { - SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); - } } } @@ -1838,7 +1830,7 @@ SwitchBSPWorker ( // // Wait for old BSP finished AP task // - while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) { + while (GetApState (&CpuMpData->CpuData[CallerNumber]) == CpuStateBusy) { CpuPause (); } @@ -2112,7 +2104,7 @@ StartupAllAPsWorker ( ApState = GetApState (CpuData); if (ApState != CpuStateDisabled) { HasEnabledAp = TRUE; - if (ApState != CpuStateIdle) { + if (ApState == CpuStateBusy) { // // If any enabled APs are busy, return EFI_NOT_READY. // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h index e7f9a4de0a..90c09fb8fb 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -83,9 +83,7 @@ typedef enum { // typedef enum { CpuStateIdle, - CpuStateReady, CpuStateBusy, - CpuStateFinished, CpuStateDisabled } CPU_STATE; -- 2.15.0.windows.1