From nobody Thu May 2 00:31:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1508743366885640.5474886589432; Mon, 23 Oct 2017 00:22:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0B6AA202E6169; Mon, 23 Oct 2017 00:19:03 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 84AEE2034CF9C for ; Mon, 23 Oct 2017 00:19:01 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 23 Oct 2017 00:22:44 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.64]) by orsmga003.jf.intel.com with ESMTP; 23 Oct 2017 00:22:41 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,421,1503385200"; d="scan'208";a="1028152306" From: Eric Dong To: edk2-devel@lists.01.org Date: Mon, 23 Oct 2017 15:22:37 +0800 Message-Id: <1508743358-3640-2-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1508743358-3640-1-git-send-email-eric.dong@intel.com> References: <1508743358-3640-1-git-send-email-eric.dong@intel.com> Subject: [edk2] [Patch 1/2] UefiCpuPkg/MpInitLib: Change AP Index variable name. 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: , Cc: Ruiyu Ni MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Original AP index variable name not well express the meaning of the variable. Also this name is better used in later patch. So change the variable name for better understanding. Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong Reviewed-by: Jeff Fan Reviewed-by: Ruiyu Ni --- UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 2 +- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 4 ++-- UefiCpuPkg/Library/MpInitLib/MpLib.c | 6 +++--- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 +- UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 2 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc b/UefiCpuPkg/Libra= ry/MpInitLib/Ia32/MpEqu.inc index 6276230..976af1f 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc @@ -33,7 +33,7 @@ GdtrLocation equ LockLocation + 1= 0h IdtrLocation equ LockLocation + 16h BufferStartLocation equ LockLocation + 1Ch ModeOffsetLocation equ LockLocation + 20h -NumApsExecutingLocation equ LockLocation + 24h +ApIndexLocation equ LockLocation + 24h CodeSegmentLocation equ LockLocation + 28h DataSegmentLocation equ LockLocation + 2Ch EnableExecuteDisableLocation equ LockLocation + 30h diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 52363e6..1b9c6a6 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -130,7 +130,7 @@ TestLock: jz TestLock =20 mov ecx, esi - add ecx, NumApsExecutingLocation + add ecx, ApIndexLocation inc dword [ecx] mov ebx, [ecx] =20 @@ -200,7 +200,7 @@ CProcedureInvoke: mov eax, ASM_PFX(InitializeFloatingPointUnits) call eax ; Call assembly function to initialize FP= U per UEFI spec =20 - push ebx ; Push NumApsExecuting + push ebx ; Push ApIndex mov eax, esi add eax, LockLocation push eax ; push address of exchange info data buff= er diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f3ee6d4..db923c9 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -542,7 +542,7 @@ VOID EFIAPI ApWakeupFunction ( IN MP_CPU_EXCHANGE_INFO *ExchangeInfo, - IN UINTN NumApsExecuting + IN UINTN ApIndex ) { CPU_MP_DATA *CpuMpData; @@ -574,7 +574,7 @@ ApWakeupFunction ( // Add CPU number // InterlockedIncrement ((UINT32 *) &CpuMpData->CpuCount); - ProcessorNumber =3D NumApsExecuting; + ProcessorNumber =3D ApIndex; // // This is first time AP wakeup, get BIST information from AP stack // @@ -764,7 +764,7 @@ FillExchangeInfoData ( ExchangeInfo->Cr3 =3D AsmReadCr3 (); =20 ExchangeInfo->CFunction =3D (UINTN) ApWakeupFunction; - ExchangeInfo->NumApsExecuting =3D 0; + ExchangeInfo->ApIndex =3D 0; ExchangeInfo->InitFlag =3D (UINTN) CpuMpData->InitFlag; ExchangeInfo->CpuInfo =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData-= >CpuInfoInHob; ExchangeInfo->CpuMpData =3D CpuMpData; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 84ae24f..e41d2db 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -169,7 +169,7 @@ typedef struct { IA32_DESCRIPTOR IdtrProfile; UINTN BufferStart; UINTN ModeOffset; - UINTN NumApsExecuting; + UINTN ApIndex; UINTN CodeSegment; UINTN DataSegment; UINTN EnableExecuteDisable; diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc b/UefiCpuPkg/Librar= y/MpInitLib/X64/MpEqu.inc index 5b2529b..114f4e0 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc @@ -33,7 +33,7 @@ GdtrLocation equ LockLocation + 2= 0h IdtrLocation equ LockLocation + 2Ah BufferStartLocation equ LockLocation + 34h ModeOffsetLocation equ LockLocation + 3Ch -NumApsExecutingLocation equ LockLocation + 44h +ApIndexLocation equ LockLocation + 44h CodeSegmentLocation equ LockLocation + 4Ch DataSegmentLocation equ LockLocation + 54h EnableExecuteDisableLocation equ LockLocation + 5Ch diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 0b14a53..4ada649 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -134,7 +134,7 @@ TestLock: cmp rax, NotVacantFlag jz TestLock =20 - lea ecx, [esi + NumApsExecutingLocation] + lea ecx, [esi + ApIndexLocation] inc dword [ecx] mov ebx, [ecx] =20 @@ -206,7 +206,7 @@ CProcedureInvoke: call rax ; Call assembly function to initialize FP= U per UEFI spec add rsp, 20h =20 - mov edx, ebx ; edx is NumApsExecuting + mov edx, ebx ; edx is ApIndex mov ecx, esi add ecx, LockLocation ; rcx is address of exchange info data bu= ffer =20 --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 00:31:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1508743369945804.4615088002744; Mon, 23 Oct 2017 00:22:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3D4DB202E6187; Mon, 23 Oct 2017 00:19:06 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 DCA862034CF9C for ; Mon, 23 Oct 2017 00:19:04 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 23 Oct 2017 00:22:47 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.64]) by orsmga003.jf.intel.com with ESMTP; 23 Oct 2017 00:22:44 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,421,1503385200"; d="scan'208";a="1028152327" From: Eric Dong To: edk2-devel@lists.01.org Date: Mon, 23 Oct 2017 15:22:38 +0800 Message-Id: <1508743358-3640-3-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1508743358-3640-1-git-send-email-eric.dong@intel.com> References: <1508743358-3640-1-git-send-email-eric.dong@intel.com> Subject: [edk2] [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: , Cc: Ruiyu Ni MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current logic always waiting for a specific value to collect all APs count. 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. Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong Reviewed-by: Jeff Fan Reviewed-by: Ruiyu Ni --- 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(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc b/UefiCpuPkg/Libra= ry/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 + 3= 0h 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/Li= brary/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: ; protect= ed 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/MpIn= itLib/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->NumAps= Executing); =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) CpuMpData-= >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/MpIn= itLib/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/Librar= y/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 + 5= Ch 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/Lib= rary/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 --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel