UefiCpuPkg/MpInitLib: Optimize get processor number performance.

Current function has low performance because it calls GetApicId
in the loop, so it maybe called more than once.

New logic 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>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Eric Dong 2018-07-04 16:29:07 +08:00
parent a3fffb4f5e
commit e52838d358

View File

@ -435,16 +435,19 @@ GetProcessorNumber (
UINTN TotalProcessorNumber; UINTN TotalProcessorNumber;
UINTN Index; UINTN Index;
CPU_INFO_IN_HOB *CpuInfoInHob; CPU_INFO_IN_HOB *CpuInfoInHob;
UINT32 CurrentApicId;
CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
TotalProcessorNumber = CpuMpData->CpuCount; TotalProcessorNumber = CpuMpData->CpuCount;
CurrentApicId = GetApicId ();
for (Index = 0; Index < TotalProcessorNumber; Index ++) { for (Index = 0; Index < TotalProcessorNumber; Index ++) {
if (CpuInfoInHob[Index].ApicId == GetApicId ()) { if (CpuInfoInHob[Index].ApicId == CurrentApicId) {
*ProcessorNumber = Index; *ProcessorNumber = Index;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }