From nobody Sun May 5 04:10:35 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; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1530693465585132.06277872538135; Wed, 4 Jul 2018 01:37:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9346020988445; Wed, 4 Jul 2018 01:37:42 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 6DAF520986AAB for ; Wed, 4 Jul 2018 01:37:41 -0700 (PDT) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 01:37:40 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.9.24]) by orsmga006.jf.intel.com with ESMTP; 04 Jul 2018 01:37:38 -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=192.55.52.93; helo=mga11.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,306,1526367600"; d="scan'208";a="55032999" From: Eric Dong To: edk2-devel@lists.01.org Date: Wed, 4 Jul 2018 16:37:36 +0800 Message-Id: <20180704083736.9272-1-eric.dong@intel.com> X-Mailer: git-send-email 2.15.0.windows.1 Subject: [edk2] [Patch] UefiCpuPkg/MpInitLib: Optimize get processor number performance. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Laszlo Ersek 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 function has low performance because it calls GetApicId many times. New logic first try to base on the stack range used by AP to find the processor number. If this solution failed, then call GetApicId once and base on this value to search the processor. Cc: Ruiyu Ni Cc: Jeff Fan Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index eb2765910c..abd65bee1a 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -418,7 +418,8 @@ ApInitializeSync ( } =20 /** - Find the current Processor number by APIC ID. + First try to find the current Processor number by stack address, + if it failed, then base on APIC ID. =20 @param[in] CpuMpData Pointer to PEI CPU MP Data @param[out] ProcessorNumber Return the pocessor number found @@ -435,16 +436,34 @@ GetProcessorNumber ( UINTN TotalProcessorNumber; UINTN Index; CPU_INFO_IN_HOB *CpuInfoInHob; + UINT32 CurrentApicId; =20 + TotalProcessorNumber =3D CpuMpData->CpuCount; CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; =20 - TotalProcessorNumber =3D CpuMpData->CpuCount; + // + // First try to base on current stack address to find the AP index. + // &TotalProcessorNumber value located in the stack range. + // for (Index =3D 0; Index < TotalProcessorNumber; Index ++) { - if (CpuInfoInHob[Index].ApicId =3D=3D GetApicId ()) { + if ((CpuInfoInHob[Index].ApTopOfStack > (UINTN) (&TotalProcessorNumber= )) && + (CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize < (U= INTN) (&TotalProcessorNumber))) { *ProcessorNumber =3D Index; return EFI_SUCCESS; } } + + // + // If can't base on stack to find the AP index, use the APIC ID. + // + CurrentApicId =3D GetApicId (); + for (Index =3D 0; Index < TotalProcessorNumber; Index ++) { + if (CpuInfoInHob[Index].ApicId =3D=3D CurrentApicId) { + *ProcessorNumber =3D Index; + return EFI_SUCCESS; + } + } + return EFI_NOT_FOUND; } =20 --=20 2.15.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel