From: Eric Dong <eric.dong@intel.com>
To: edk2-devel@lists.01.org
Cc: Ruiyu Ni <ruiyu.ni@intel.com>, Jeff Fan <vanjeff_919@hotmail.com>,
Laszlo Ersek <lersek@redhat.com>
Subject: [Patch] UefiCpuPkg/MpInitLib: Optimize get processor number performance.
Date: Wed, 4 Jul 2018 16:37:36 +0800 [thread overview]
Message-ID: <20180704083736.9272-1-eric.dong@intel.com> (raw)
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 <ruiyu.ni@intel.com>
Cc: Jeff Fan <vanjeff_919@hotmail.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <eric.dong@intel.com>
---
UefiCpuPkg/Library/MpInitLib/MpLib.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index eb2765910c..abd65bee1a 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -418,7 +418,8 @@ ApInitializeSync (
}
/**
- 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.
@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;
+ TotalProcessorNumber = CpuMpData->CpuCount;
CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
- TotalProcessorNumber = CpuMpData->CpuCount;
+ //
+ // First try to base on current stack address to find the AP index.
+ // &TotalProcessorNumber value located in the stack range.
+ //
for (Index = 0; Index < TotalProcessorNumber; Index ++) {
- if (CpuInfoInHob[Index].ApicId == GetApicId ()) {
+ if ((CpuInfoInHob[Index].ApTopOfStack > (UINTN) (&TotalProcessorNumber)) &&
+ (CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize < (UINTN) (&TotalProcessorNumber))) {
*ProcessorNumber = Index;
return EFI_SUCCESS;
}
}
+
+ //
+ // If can't base on stack to find the AP index, use the APIC ID.
+ //
+ CurrentApicId = GetApicId ();
+ for (Index = 0; Index < TotalProcessorNumber; Index ++) {
+ if (CpuInfoInHob[Index].ApicId == CurrentApicId) {
+ *ProcessorNumber = Index;
+ return EFI_SUCCESS;
+ }
+ }
+
return EFI_NOT_FOUND;
}
--
2.15.0.windows.1
next reply other threads:[~2018-07-04 8:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-04 8:37 Eric Dong [this message]
[not found] ` <SN6PR19MB22695C13EA19A741F4B1FB88D7410@SN6PR19MB2269.namprd19.prod.outlook.com>
2018-07-05 1:26 ` [Patch] UefiCpuPkg/MpInitLib: Optimize get processor number performance Dong, Eric
2018-07-05 8:10 ` Laszlo Ersek
2018-07-05 13:04 ` 答复: " Laszlo Ersek
2018-07-05 13:15 ` Laszlo Ersek
2018-07-09 3:04 ` Dong, Eric
2018-07-09 6:13 ` Dong, Eric
2018-07-09 8:48 ` Laszlo Ersek
2018-07-11 7:45 ` Yao, Jiewen
2018-07-11 11:31 ` Dong, Eric
2018-07-11 15:11 ` Laszlo Ersek
2018-07-12 3:04 ` Dong, Eric
2018-07-18 2:50 ` Dong, Eric
2018-07-09 8:47 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180704083736.9272-1-eric.dong@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox