From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id D66E278003C for ; Fri, 29 Dec 2023 03:31:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Pd3yv+lkO9uVWoxNm2gPJKatmxTLOKhI1LSgpZLOzSY=; 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=xRt40YeeaxRq5ffoKd8oyimo9jDlEwcja4nxJQZxv+VbTTxU595b8bZGM5Gp6P7YLhIQWmYA JaBEGgXA/T9IAnAF6TxI5+rZ8p66/UDPjf/8AWYGDU26bsv5R7Xr/ut9OUhT8K4GHwYg56ikeeI 347d0nvOUvld/Qf0HJVj/4YQ= X-Received: by 127.0.0.2 with SMTP id VAyhYY7687511xO5M2ZwqORe; 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: IruZ5Bi5GV1qNDAHlOzFkpU6x7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=xRt40Yee; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 --- UefiCpuPkg/CpuMpPei/CpuPaging.c | 56 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.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; + MpInitLibWhoAmI (&Index); StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)&StackBase; StackBase += BASE_4KB; StackBase &= ~((EFI_PHYSICAL_ADDRESS)BASE_4KB - 1); StackBase -= PcdGet32 (PcdCpuApStackSize); - *(EFI_PHYSICAL_ADDRESS *)Buffer = StackBase; + *((EFI_PHYSICAL_ADDRESS *)Buffer + Index) = StackBase; } /** @@ -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 = 1; } + StackBase = (EFI_PHYSICAL_ADDRESS *)AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) * NumberOfProcessors)); + ASSERT (StackBase != NULL); + if (StackBase == NULL) { + return; + } + + ZeroMem (StackBase, sizeof (EFI_PHYSICAL_ADDRESS) * NumberOfProcessors); + MpInitLibStartupAllAPs (GetStackBase, FALSE, NULL, 0, (VOID *)StackBase, NULL); MpInitLibWhoAmI (&Bsp); - for (Index = 0; Index < NumberOfProcessors; ++Index) { - StackBase = 0; - - if (Index == Bsp) { - Hob.Raw = GetHobList (); - while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) { - if (CompareGuid ( - &gEfiHobMemoryAllocStackGuid, - &(Hob.MemoryAllocationStack->AllocDescriptor.Name) - )) - { - StackBase = Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress; - break; - } - - Hob.Raw = GET_NEXT_HOB (Hob); - } - } else { - // - // Ask AP to return is stack base address. - // - MpInitLibStartupThisAP (GetStackBase, Index, NULL, 0, (VOID *)&StackBase, NULL); + Hob.Raw = GetHobList (); + while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) { + if (CompareGuid ( + &gEfiHobMemoryAllocStackGuid, + &(Hob.MemoryAllocationStack->AllocDescriptor.Name) + )) + { + StackBase[Bsp] = Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress; + break; } - ASSERT (StackBase != 0); + Hob.Raw = GET_NEXT_HOB (Hob); + } + + for (Index = 0; Index < NumberOfProcessors; ++Index) { + ASSERT (StackBase[Index] != 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 )); } + FreePages (StackBase, EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) * NumberOfProcessors)); // // Publish the changes of page table. // -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-