From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 CF3E081F19 for ; Fri, 25 Nov 2016 03:06:38 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CD6B70029; Fri, 25 Nov 2016 11:06:38 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-35.phx2.redhat.com [10.3.116.35]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAPB6atf000537; Fri, 25 Nov 2016 06:06:37 -0500 To: Jeff Fan , edk2-devel@ml01.01.org References: <20161125060312.27932-1-jeff.fan@intel.com> <20161125060312.27932-4-jeff.fan@intel.com> Cc: Feng Tian , Michael D Kinney From: Laszlo Ersek Message-ID: <375958cb-fb4c-7207-e6fe-e0693a519b25@redhat.com> Date: Fri, 25 Nov 2016 12:06:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <20161125060312.27932-4-jeff.fan@intel.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 Nov 2016 11:06:38 +0000 (UTC) Subject: Re: [PATCH v2 3/5] UefiCpuPkg/DxeMpLib: Make sure APs in safe loop code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Nov 2016 11:06:39 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 11/25/16 07:03, Jeff Fan wrote: > Add one semaphore to make sure BSP to wait till all APs run in AP safe loop > code. > > Cc: Laszlo Ersek > Cc: Feng Tian > Cc: Michael D Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jeff Fan > --- > UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 8 +++++++- > UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 4 +++- > UefiCpuPkg/Library/MpInitLib/MpLib.h | 3 ++- > UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 4 +++- > 4 files changed, 15 insertions(+), 4 deletions(-) Looks good to me. Reviewed-by: Laszlo Ersek Thanks Laszlo > diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > index 5a3b02c..8f5074b 100644 > --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > @@ -27,6 +27,7 @@ EFI_EVENT mLegacyBootEvent = NULL; > volatile BOOLEAN mStopCheckAllApsStatus = TRUE; > VOID *mReservedApLoopFunc = NULL; > UINTN mReservedTopOfApStack; > +volatile UINT32 mNumberToFinish = 0; > > /** > Get the pointer to CPU MP Data structure. > @@ -253,7 +254,8 @@ RelocateApLoop ( > MwaitSupport, > CpuMpData->ApTargetCState, > CpuMpData->PmCodeSegment, > - mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE > + mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE, > + (UINTN) &mNumberToFinish > ); > // > // It should never reach here > @@ -282,7 +284,11 @@ MpInitChangeApLoopCallback ( > CpuMpData->SaveRestoreFlag = TRUE; > CpuMpData->PmCodeSegment = GetProtectedModeCS (); > CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode); > + mNumberToFinish = CpuMpData->CpuCount - 1; > WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL); > + while (mNumberToFinish > 0) { > + CpuPause (); > + } > DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__)); > } > > diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > index 7ab136b..a48f0bc 100644 > --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm > @@ -215,7 +215,7 @@ CProcedureInvoke: > RendezvousFunnelProcEnd: > > ;------------------------------------------------------------------------------------- > -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack); > +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish); > ;------------------------------------------------------------------------------------- > global ASM_PFX(AsmRelocateApLoop) > ASM_PFX(AsmRelocateApLoop): > @@ -227,6 +227,8 @@ AsmRelocateApLoopStart: > mov ebp, esp > mov ebx, [eax + 8] ; ApTargetCState > mov ecx, [eax + 4] ; MwaitSupport > + mov eax, [eax + 20] ; CountTofinish > + lock dec dword [eax] ; (*CountTofinish)-- > cmp cl, 1 ; Check mwait-monitor support > jnz HltLoop > MwaitLoop: > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h > index e6dea18..49305ad 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h > @@ -251,7 +251,8 @@ VOID > IN BOOLEAN MwaitSupport, > IN UINTN ApTargetCState, > IN UINTN PmCodeSegment, > - IN UINTN TopOfApStack > + IN UINTN TopOfApStack, > + IN UINTN NumberToFinish > ); > > /** > diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > index 7869970..f8f4712 100644 > --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm > @@ -222,11 +222,13 @@ CProcedureInvoke: > RendezvousFunnelProcEnd: > > ;------------------------------------------------------------------------------------- > -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack); > +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish); > ;------------------------------------------------------------------------------------- > global ASM_PFX(AsmRelocateApLoop) > ASM_PFX(AsmRelocateApLoop): > AsmRelocateApLoopStart: > + mov rax, [rsp + 40] ; CountTofinish > + lock dec dword [rax] ; (*CountTofinish)-- > mov rsp, r9 > push rcx > push rdx >