[edk2-devel] [Patch V3 1/5] UefiCpuPkg: Refactor the logic for placing APs in HltLoop.

Yuanhao Xie posted 5 patches 2 years, 7 months ago
There is a newer version of this series
[edk2-devel] [Patch V3 1/5] UefiCpuPkg: Refactor the logic for placing APs in HltLoop.
Posted by Yuanhao Xie 2 years, 7 months ago
Refactor the logic for placing APs in HltLoop into a separate function.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index f1f2840714..9560b39220 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -636,6 +636,28 @@ InitializeApData (
   SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
 }
 
+/**
+  This function place APs in Halt loop.
+
+  @param[in] CpuMpData        Pointer to CPU MP Data
+**/
+VOID
+PlaceAPInHltLoop (
+  IN CPU_MP_DATA  *CpuMpData
+  )
+{
+  while (TRUE) {
+    DisableInterrupts ();
+    if (CpuMpData->UseSevEsAPMethod) {
+      SevEsPlaceApHlt (CpuMpData);
+    } else {
+      CpuSleep ();
+    }
+
+    CpuPause ();
+  }
+}
+
 /**
   This function will be called from AP reset code if BSP uses WakeUpAP.
 
@@ -812,19 +834,10 @@ ApWakeupFunction (
     // Place AP is specified loop mode
     //
     if (CpuMpData->ApLoopMode == ApInHltLoop) {
+      PlaceAPInHltLoop (CpuMpData);
       //
-      // Place AP in HLT-loop
+      // Never run here
       //
-      while (TRUE) {
-        DisableInterrupts ();
-        if (CpuMpData->UseSevEsAPMethod) {
-          SevEsPlaceApHlt (CpuMpData);
-        } else {
-          CpuSleep ();
-        }
-
-        CpuPause ();
-      }
     }
 
     while (TRUE) {
-- 
2.36.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106339): https://edk2.groups.io/g/devel/message/106339
Mute This Topic: https://groups.io/mt/99782476/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [Patch V3 1/5] UefiCpuPkg: Refactor the logic for placing APs in HltLoop.
Posted by Ni, Ray 2 years, 7 months ago
Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Xie, Yuanhao <yuanhao.xie@intel.com>
> Sent: Monday, June 26, 2023 1:57 PM
> To: devel@edk2.groups.io
> Cc: Gerd Hoffmann <kraxel@redhat.com>; Dong, Eric <eric.dong@intel.com>; Ni,
> Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Tom
> Lendacky <thomas.lendacky@amd.com>; Xie, Yuanhao
> <yuanhao.xie@intel.com>
> Subject: [Patch V3 1/5] UefiCpuPkg: Refactor the logic for placing APs in HltLoop.
> 
> Refactor the logic for placing APs in HltLoop into a separate function.
> 
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++++++++++++++++++++++++-------
> ----
>  1 file changed, 24 insertions(+), 11 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index f1f2840714..9560b39220 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -636,6 +636,28 @@ InitializeApData (
>    SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);
>  }
> 
> +/**
> +  This function place APs in Halt loop.
> +
> +  @param[in] CpuMpData        Pointer to CPU MP Data
> +**/
> +VOID
> +PlaceAPInHltLoop (
> +  IN CPU_MP_DATA  *CpuMpData
> +  )
> +{
> +  while (TRUE) {
> +    DisableInterrupts ();
> +    if (CpuMpData->UseSevEsAPMethod) {
> +      SevEsPlaceApHlt (CpuMpData);
> +    } else {
> +      CpuSleep ();
> +    }
> +
> +    CpuPause ();
> +  }
> +}
> +
>  /**
>    This function will be called from AP reset code if BSP uses WakeUpAP.
> 
> @@ -812,19 +834,10 @@ ApWakeupFunction (
>      // Place AP is specified loop mode
>      //
>      if (CpuMpData->ApLoopMode == ApInHltLoop) {
> +      PlaceAPInHltLoop (CpuMpData);
>        //
> -      // Place AP in HLT-loop
> +      // Never run here
>        //
> -      while (TRUE) {
> -        DisableInterrupts ();
> -        if (CpuMpData->UseSevEsAPMethod) {
> -          SevEsPlaceApHlt (CpuMpData);
> -        } else {
> -          CpuSleep ();
> -        }
> -
> -        CpuPause ();
> -      }
>      }
> 
>      while (TRUE) {
> --
> 2.36.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106354): https://edk2.groups.io/g/devel/message/106354
Mute This Topic: https://groups.io/mt/99782476/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-