From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 552AE2034A7CB for ; Mon, 23 Oct 2017 22:59:47 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2017 23:03:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,426,1503385200"; d="scan'208";a="1028586672" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga003.jf.intel.com with ESMTP; 23 Oct 2017 23:03:29 -0700 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 23 Oct 2017 23:03:29 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 23 Oct 2017 23:03:29 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.152]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.213]) with mapi id 14.03.0319.002; Tue, 24 Oct 2017 14:02:27 +0800 From: "Ni, Ruiyu" To: "Dong, Eric" , "edk2-devel@lists.01.org" Thread-Topic: [Patch 2/2] UefiCpuPkg/MpInitLib: Enhance waiting for AP initialization logic. Thread-Index: AQHTS8/AIwFL/bhvsEaVnrqOfW/LDKLyguAw Date: Tue, 24 Oct 2017 06:02:26 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BAA35C3@SHSMSX104.ccr.corp.intel.com> References: <1508743358-3640-1-git-send-email-eric.dong@intel.com> <1508743358-3640-3-git-send-email-eric.dong@intel.com> In-Reply-To: <1508743358-3640-3-git-send-email-eric.dong@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch 2/2] UefiCpuPkg/MpInitLib: Enhance waiting for AP initialization logic. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Oct 2017 05:59:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable You need to have "volatile" for "UINTN NumApsExecuting;". Otherwise, compiler may optimize the code to cause below code wait forever: while (CpuMpData->MpCpuExchangeInfo->NumApsExecuting !=3D 0) { CpuPause(); } Thanks/Ray > -----Original Message----- > From: Dong, Eric > Sent: Monday, October 23, 2017 3:23 PM > To: edk2-devel@lists.01.org > Cc: Ni, Ruiyu > Subject: [Patch 2/2] UefiCpuPkg/MpInitLib: Enhance waiting for AP > initialization logic. >=20 > Current logic always waiting for a specific value to collect all APs coun= t. This > logic may caused some platforms cost too much time to wait for time out. > This patch add new logic to collect APs count. It adds new variable > NumApsExecuting to detect whether all APs have finished initialization. > Each AP let NumApsExecuting++ when begin to initialize itself and let > NumApsExecuting-- when it finish the initialization. BSP base on whether > NumApsExecuting =3D=3D 0 to finished the collect AP process. >=20 > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 1 + > UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 6 ++++++ > UefiCpuPkg/Library/MpInitLib/MpLib.c | 20 ++++++++++++++------ > UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + > UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 3 ++- > UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 6 ++++++ > 6 files changed, 30 insertions(+), 7 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc > b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc > index 976af1f..bdfe0d3 100644 > --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc > +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc > @@ -40,4 +40,5 @@ EnableExecuteDisableLocation equ LockLocation + > 30h > Cr3Location equ LockLocation + 34h > InitFlagLocation equ LockLocation + 38h > CpuInfoLocation equ LockLocation + 3Ch > +NumApsExecutingLocation equ LockLocation + 40h >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > index 1b9c6a6..2b6c27d 100644 > --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > @@ -86,6 +86,12 @@ Flat32Start: ; prote= cted mode entry > point >=20 > mov esi, ebx >=20 > + ; Increment the number of APs executing here as early as possible > + ; This is decremented in C code when AP is finished executing > + mov edi, esi > + add edi, NumApsExecutingLocation > + lock inc dword [edi] > + > mov edi, esi > add edi, EnableExecuteDisableLocation > cmp byte [edi], 0 > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c > b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index db923c9..48f930b 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -662,6 +662,7 @@ ApWakeupFunction ( > // AP finished executing C code > // > InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount); > + InterlockedDecrement ((UINT32 *) > + &CpuMpData->MpCpuExchangeInfo->NumApsExecuting); >=20 > // > // Place AP is specified loop mode > @@ -765,6 +766,7 @@ FillExchangeInfoData ( >=20 > ExchangeInfo->CFunction =3D (UINTN) ApWakeupFunction; > ExchangeInfo->ApIndex =3D 0; > + ExchangeInfo->NumApsExecuting =3D 0; > ExchangeInfo->InitFlag =3D (UINTN) CpuMpData->InitFlag; > ExchangeInfo->CpuInfo =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpDat= a- > >CpuInfoInHob; > ExchangeInfo->CpuMpData =3D CpuMpData; > @@ -934,13 +936,19 @@ WakeUpAP ( > } > if (CpuMpData->InitFlag =3D=3D ApInitConfig) { > // > - // Wait for all potential APs waken up in one specified period > + // Wait for one potential AP waken up in one specified period > // > - TimedWaitForApFinish ( > - CpuMpData, > - PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, > - PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) > - ); > + if (CpuMpData->CpuCount =3D=3D 0) { > + TimedWaitForApFinish ( > + CpuMpData, > + PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, > + PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) > + ); > + } > + > + while (CpuMpData->MpCpuExchangeInfo->NumApsExecuting !=3D 0) { > + CpuPause(); > + } > } else { > // > // Wait all APs waken up if this is not the 1st broadcast of SIPI = diff --git > a/UefiCpuPkg/Library/MpInitLib/MpLib.h > b/UefiCpuPkg/Library/MpInitLib/MpLib.h > index e41d2db..d13d5c0 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h > @@ -176,6 +176,7 @@ typedef struct { > UINTN Cr3; > UINTN InitFlag; > CPU_INFO_IN_HOB *CpuInfo; > + UINTN NumApsExecuting; > CPU_MP_DATA *CpuMpData; > UINTN InitializeFloatingPointUnitsAddress; > } MP_CPU_EXCHANGE_INFO; > diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc > b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc > index 114f4e0..d255ca5 100644 > --- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc > +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc > @@ -40,5 +40,6 @@ EnableExecuteDisableLocation equ LockLocation + > 5Ch > Cr3Location equ LockLocation + 64h > InitFlagLocation equ LockLocation + 6Ch > CpuInfoLocation equ LockLocation + 74h > -InitializeFloatingPointUnitsAddress equ LockLocation + 84h > +NumApsExecutingLocation equ LockLocation + 7Ch > +InitializeFloatingPointUnitsAddress equ LockLocation + 8Ch >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > index 4ada649..21d2786 100644 > --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > @@ -124,6 +124,12 @@ LongModeStart: > cmp qword [edi], 1 ; ApInitConfig > jnz GetApicId >=20 > + ; Increment the number of APs executing here as early as possible > + ; This is decremented in C code when AP is finished executing > + mov edi, esi > + add edi, NumApsExecutingLocation > + lock inc dword [edi] > + > ; AP init > mov edi, esi > add edi, LockLocation > -- > 2.7.0.windows.1