From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 BBF25211F887E for ; Tue, 17 Jul 2018 22:19:43 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 22:19:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,368,1526367600"; d="scan'208";a="58546627" Received: from ydong10-win10.ccr.corp.intel.com ([10.239.9.24]) by orsmga006.jf.intel.com with ESMTP; 17 Jul 2018 22:19:42 -0700 From: Eric Dong To: edk2-devel@lists.01.org Cc: Ruiyu Ni , Jeff Fan , Laszlo Ersek Date: Wed, 18 Jul 2018 13:19:29 +0800 Message-Id: <20180718051929.18172-1-eric.dong@intel.com> X-Mailer: git-send-email 2.15.0.windows.1 Subject: [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2018 05:19:43 -0000 Current function has low performance because it calls GetApicId many times. New logic call GetApicId once and base on this value to search the processor. V2 changes: Rollback V1 change which base on stack info to get AP index because this solution may return error AP index if stack buffer overflow. 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 722db2a01f..0bb0582985 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -435,16 +435,19 @@ GetProcessorNumber ( UINTN TotalProcessorNumber; UINTN Index; CPU_INFO_IN_HOB *CpuInfoInHob; + UINT32 CurrentApicId; CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; TotalProcessorNumber = CpuMpData->CpuCount; + CurrentApicId = GetApicId (); for (Index = 0; Index < TotalProcessorNumber; Index ++) { - if (CpuInfoInHob[Index].ApicId == GetApicId ()) { + if (CpuInfoInHob[Index].ApicId == CurrentApicId) { *ProcessorNumber = Index; return EFI_SUCCESS; } } + return EFI_NOT_FOUND; } -- 2.15.0.windows.1