From nobody Fri May 17 06:54:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112996+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112996+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1703820677; cv=none; d=zohomail.com; s=zohoarc; b=FQH/QXv+G0TdJoZ5v9Smf+hxkMpTBo7KwRc1HV9cf2R5y2e9TvxzFl2bwaMLS9lGLow5WQnIDgbQTz41x4/j9pC2wie3Lwv/MoOjZ8s0FsDkEgT6bWUpII5cg4M33uj7OBe1jWkTpIMXB/by1cj+LHsL06yYEHJo1Vezxw9ig8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703820677; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=FrwRhXgP8mKFhj73DOiQm38E/1VwYHommmN6kyMdAS0=; b=Ji6LmYIZmWtQzhDsgFROl41vjjIzI2bTE3PNZH9j+ZNXb4mZ1vrdHXFShYnh4WBscUBfk68xjLvtyPi2Q1to8QCwqVSMLGhB4R/HPmuPg2ir7kGaxDYq+j9oVK0Wqxu5T3zFNhM1juYecGENVwEZ7MBjjqhDYs1ffaGaIk+UpN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112996+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1703820677089362.4530437017354; Thu, 28 Dec 2023 19:31:17 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rypQ2XFTQR1zauh+hFsSH92pV/OBTgHLGk9MsJvTSSs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1703820676; v=1; b=dsrrDhSdGNcw+pYi8G3dpoBsXp//xC16rxnN5a0bgccnvvEJ2OMIFbZTtTvQcQP6sX+v171c RqHipcDAq5bEqTrx13LqQetfOfrpUDZuP5RR1UbJQdRNxXE0aBsIF/uq1H7euAOzK8tqF3Rmfu8 caJkb0o1UAtWTr05zMtStwKc= X-Received: by 127.0.0.2 with SMTP id XPBNYY1788612xYtqck6yunX; Thu, 28 Dec 2023 19:31:16 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.138830.1703820675635450217 for ; Thu, 28 Dec 2023 19:31:15 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="376771552" X-IronPort-AV: E=Sophos;i="6.04,313,1695711600"; d="scan'208";a="376771552" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 19:29:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="754923215" X-IronPort-AV: E=Sophos;i="6.04,313,1695711600"; d="scan'208";a="754923215" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 19:29:48 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann , Star Zeng , Daoxiang Li Subject: [edk2-devel] [PATCH] UefiCpuPkg/CpuMpPei: Parallel get stack base for better performance. Date: Fri, 29 Dec 2023 11:29:38 +0800 Message-Id: <20231229032938.1129-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhiguang.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: M7KB1HF7itEVpjCxY1OacWDnx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1703820679239100003 Content-Type: text/plain; charset="utf-8" Parallel run the function GetStackBase for all APs for better performance. Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Star Zeng Cc: Daoxiang Li Signed-off-by: Zhiguang Liu Reviewed-by: Ray Ni --- UefiCpuPkg/CpuMpPei/CpuPaging.c | 56 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPagin= g.c index 2dd7237141..15c7015fb8 100644 --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c @@ -267,13 +267,15 @@ GetStackBase ( ) { EFI_PHYSICAL_ADDRESS StackBase; + UINTN Index; =20 + MpInitLibWhoAmI (&Index); StackBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)&StackBase; StackBase +=3D BASE_4KB; StackBase &=3D ~((EFI_PHYSICAL_ADDRESS)BASE_4KB - 1); StackBase -=3D PcdGet32 (PcdCpuApStackSize); =20 - *(EFI_PHYSICAL_ADDRESS *)Buffer =3D StackBase; + *((EFI_PHYSICAL_ADDRESS *)Buffer + Index) =3D StackBase; } =20 /** @@ -287,7 +289,7 @@ SetupStackGuardPage ( ) { EFI_PEI_HOB_POINTERS Hob; - EFI_PHYSICAL_ADDRESS StackBase; + EFI_PHYSICAL_ADDRESS *StackBase; UINTN NumberOfProcessors; UINTN Bsp; UINTN Index; @@ -308,44 +310,44 @@ SetupStackGuardPage ( NumberOfProcessors =3D 1; } =20 + StackBase =3D (EFI_PHYSICAL_ADDRESS *)AllocatePages (EFI_SIZE_TO_PAGES (= sizeof (EFI_PHYSICAL_ADDRESS) * NumberOfProcessors)); + ASSERT (StackBase !=3D NULL); + if (StackBase =3D=3D NULL) { + return; + } + + ZeroMem (StackBase, sizeof (EFI_PHYSICAL_ADDRESS) * NumberOfProcessors); + MpInitLibStartupAllAPs (GetStackBase, FALSE, NULL, 0, (VOID *)StackBase,= NULL); MpInitLibWhoAmI (&Bsp); - for (Index =3D 0; Index < NumberOfProcessors; ++Index) { - StackBase =3D 0; - - if (Index =3D=3D Bsp) { - Hob.Raw =3D GetHobList (); - while ((Hob.Raw =3D GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.= Raw)) !=3D NULL) { - if (CompareGuid ( - &gEfiHobMemoryAllocStackGuid, - &(Hob.MemoryAllocationStack->AllocDescriptor.Name) - )) - { - StackBase =3D Hob.MemoryAllocationStack->AllocDescriptor.MemoryB= aseAddress; - break; - } - - Hob.Raw =3D GET_NEXT_HOB (Hob); - } - } else { - // - // Ask AP to return is stack base address. - // - MpInitLibStartupThisAP (GetStackBase, Index, NULL, 0, (VOID *)&Stack= Base, NULL); + Hob.Raw =3D GetHobList (); + while ((Hob.Raw =3D GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)= ) !=3D NULL) { + if (CompareGuid ( + &gEfiHobMemoryAllocStackGuid, + &(Hob.MemoryAllocationStack->AllocDescriptor.Name) + )) + { + StackBase[Bsp] =3D Hob.MemoryAllocationStack->AllocDescriptor.Memory= BaseAddress; + break; } =20 - ASSERT (StackBase !=3D 0); + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + + for (Index =3D 0; Index < NumberOfProcessors; ++Index) { + ASSERT (StackBase[Index] !=3D 0); // // Set Guard page at stack base address. // - ConvertMemoryPageToNotPresent (StackBase, EFI_PAGE_SIZE); + ConvertMemoryPageToNotPresent (StackBase[Index], EFI_PAGE_SIZE); DEBUG (( DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n", - (UINT64)StackBase, + (UINT64)StackBase[Index], (UINT64)Index )); } =20 + FreePages (StackBase, EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) *= NumberOfProcessors)); // // Publish the changes of page table. // --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112996): https://edk2.groups.io/g/devel/message/112996 Mute This Topic: https://groups.io/mt/103412489/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-