public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance.
@ 2018-07-18  5:19 Eric Dong
  2018-07-19  4:40 ` Ni, Ruiyu
  2018-07-19 14:53 ` Laszlo Ersek
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dong @ 2018-07-18  5:19 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ruiyu Ni, Jeff Fan, Laszlo Ersek

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 <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 | 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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance.
  2018-07-18  5:19 [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance Eric Dong
@ 2018-07-19  4:40 ` Ni, Ruiyu
  2018-07-19 14:53 ` Laszlo Ersek
  1 sibling, 0 replies; 3+ messages in thread
From: Ni, Ruiyu @ 2018-07-19  4:40 UTC (permalink / raw)
  To: Dong, Eric, edk2-devel@lists.01.org; +Cc: Jeff Fan, Laszlo Ersek

Reviewed-by: Ruiyu Ni <Ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: Dong, Eric
> Sent: Wednesday, July 18, 2018 1:19 PM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ruiyu <ruiyu.ni@intel.com>; Jeff Fan <vanjeff_919@hotmail.com>;
> Laszlo Ersek <lersek@redhat.com>
> Subject: [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number
> performance.
> 
> 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 <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 | 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance.
  2018-07-18  5:19 [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance Eric Dong
  2018-07-19  4:40 ` Ni, Ruiyu
@ 2018-07-19 14:53 ` Laszlo Ersek
  1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2018-07-19 14:53 UTC (permalink / raw)
  To: Eric Dong, edk2-devel; +Cc: Ruiyu Ni

On 07/18/18 07:19, Eric Dong wrote:
> 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 <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 | 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;
>  }
>  
> 

Nice and clean.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Sorry about the delay in my getting to this patch.
Laszlo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-19 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-18  5:19 [Patch v2] UefiCpuPkg/MpInitLib: Optimize get processor number performance Eric Dong
2018-07-19  4:40 ` Ni, Ruiyu
2018-07-19 14:53 ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox