[edk2-devel] [Patch V3 2/5] UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop.

Ni, Ray ray.ni at intel.com
Mon Jun 26 09:10:22 UTC 2023


Reviewed-by: Ray Ni <ray.ni at intel.com>

> -----Original Message-----
> From: Xie, Yuanhao <yuanhao.xie at intel.com>
> Sent: Monday, June 26, 2023 1:57 PM
> To: devel at edk2.groups.io
> Cc: Gerd Hoffmann <kraxel at redhat.com>; Dong, Eric <eric.dong at intel.com>; Ni,
> Ray <ray.ni at intel.com>; Kumar, Rahul R <rahul.r.kumar at intel.com>; Tom
> Lendacky <thomas.lendacky at amd.com>; Xie, Yuanhao
> <yuanhao.xie at intel.com>
> Subject: [Patch V3 2/5] UefiCpuPkg: Refactor the logic for placing APs in
> Mwait/Runloop.
> 
> Refactor the logic for placing APs in
> Mwait/Runloop into a separate function.
> 
> Cc: Gerd Hoffmann <kraxel at redhat.com>
> Cc: Eric Dong <eric.dong at intel.com>
> Cc: Ray Ni <ray.ni at intel.com>
> Cc: Rahul Kumar <rahul1.kumar at intel.com>
> Cc: Tom Lendacky <thomas.lendacky at amd.com>
> Signed-off-by: Yuanhao Xie <yuanhao.xie at intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 83
> ++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
> ----------
>  1 file changed, 50 insertions(+), 33 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 9560b39220..e8dd640f9b 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -658,6 +658,54 @@ PlaceAPInHltLoop (
>    }
>  }
> 
> +/**
> +  This function place APs in Mwait or Run loop.
> +
> +  @param[in] ApLoopMode                   Ap Loop Mode
> +  @param[in] ApStartupSignalBuffer        Pointer to Ap Startup Signal Buffer
> +  @param[in] ApTargetCState               Ap Target CState
> +**/
> +VOID
> +PlaceAPInMwaitLoopOrRunLoop (
> +  IN UINT8            ApLoopMode,
> +  IN volatile UINT32  *ApStartupSignalBuffer,
> +  IN UINT8            ApTargetCState
> +  )
> +{
> +  while (TRUE) {
> +    DisableInterrupts ();
> +    if (ApLoopMode == ApInMwaitLoop) {
> +      //
> +      // Place AP in MWAIT-loop
> +      //
> +      AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0);
> +      if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
> +        //
> +        // Check AP start-up signal again.
> +        // If AP start-up signal is not set, place AP into
> +        // the specified C-state
> +        //
> +        AsmMwait (ApTargetCState << 4, 0);
> +      }
> +    } else if (ApLoopMode == ApInRunLoop) {
> +      //
> +      // Place AP in Run-loop
> +      //
> +      CpuPause ();
> +    } else {
> +      ASSERT (FALSE);
> +    }
> +
> +    //
> +    // If AP start-up signal is written, AP is waken up
> +    // otherwise place AP in loop again
> +    //
> +    if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
> +      break;
> +    }
> +  }
> +}
> +
>  /**
>    This function will be called from AP reset code if BSP uses WakeUpAP.
> 
> @@ -838,39 +886,8 @@ ApWakeupFunction (
>        //
>        // Never run here
>        //
> -    }
> -
> -    while (TRUE) {
> -      DisableInterrupts ();
> -      if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
> -        //
> -        // Place AP in MWAIT-loop
> -        //
> -        AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0);
> -        if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
> -          //
> -          // Check AP start-up signal again.
> -          // If AP start-up signal is not set, place AP into
> -          // the specified C-state
> -          //
> -          AsmMwait (CpuMpData->ApTargetCState << 4, 0);
> -        }
> -      } else if (CpuMpData->ApLoopMode == ApInRunLoop) {
> -        //
> -        // Place AP in Run-loop
> -        //
> -        CpuPause ();
> -      } else {
> -        ASSERT (FALSE);
> -      }
> -
> -      //
> -      // If AP start-up signal is written, AP is waken up
> -      // otherwise place AP in loop again
> -      //
> -      if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
> -        break;
> -      }
> +    } else {
> +      PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode,
> ApStartupSignalBuffer, CpuMpData->ApTargetCState);
>      }
>    }
>  }
> --
> 2.36.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106355): https://edk2.groups.io/g/devel/message/106355
Mute This Topic: https://groups.io/mt/99782481/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3943202/1813853/130120423/xyzzy [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list