Skip to content

Commit

Permalink
Merged PR 4945: Add support for non-blocking AP dispatch in PEI.
Browse files Browse the repository at this point in the history
Add support for non-blocking AP dispatch in PEI.
  • Loading branch information
joschock authored and kenlautner committed May 5, 2023
1 parent c68f52b commit 6504c2f
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 4 deletions.
47 changes: 47 additions & 0 deletions MdePkg/Include/Ppi/MpServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,52 @@ EFI_STATUS
IN VOID *ProcedureArgument OPTIONAL
);

// MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.

/**
This service lets the caller get one enabled AP to execute a caller-provided
function. This service may only be called from the BSP.
This function is used to dispatch one enabled AP to the function specified by
Procedure passing in the argument specified by ProcedureArgument.
The execution is in non-blocking mode. The BSP continues executing immediately
after starting the AP.
Caller is responsible for ensuring that the scheduled AP task is complete (via
caller-specific logic) before dispatching further tasks on the AP using this
or other routines in the API.
@param[in] PeiServices An indirect pointer to the PEI Services Table
published by the PEI Foundation.
@param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
@param[in] Procedure A pointer to the function to be run on enabled APs of
the system.
@param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
total number of logical processors minus 1. The total
number of logical processors can be retrieved by
EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
@param[in] ProcedureArgument The parameter passed into Procedure for all APs.
@retval EFI_SUCCESS Indicates that the procedure was successfully
started on the AP
@retval EFI_DEVICE_ERROR The calling processor is an AP.
@retval EFI_NOT_FOUND The processor with the handle specified by
ProcessorNumber does not exist.
@retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
@retval EFI_INVALID_PARAMETER Procedure is NULL.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PEI_MP_SERVICES_STARTUP_THIS_AP_NONBLOCK)(
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_MP_SERVICES_PPI *This,
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN VOID *ProcedureArgument OPTIONAL
);
// MU_CHANGE - End Add basic support for non-blocking AP dispatch in PEI.

/**
Switch the boot strap processor.
Expand Down Expand Up @@ -270,6 +316,7 @@ struct _EFI_PEI_MP_SERVICES_PPI {
EFI_PEI_MP_SERVICES_SWITCH_BSP SwitchBSP;
EFI_PEI_MP_SERVICES_ENABLEDISABLEAP EnableDisableAP;
EFI_PEI_MP_SERVICES_WHOAMI WhoAmI;
EFI_PEI_MP_SERVICES_STARTUP_THIS_AP_NONBLOCK StartupThisApNonBlocking;
};

extern EFI_GUID gEfiPeiMpServicesPpiGuid;
Expand Down
63 changes: 63 additions & 0 deletions UefiCpuPkg/CpuMpPei/CpuMpPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EFI_PEI_MP_SERVICES_PPI mMpServicesPpi = {
PeiSwitchBSP,
PeiEnableDisableAP,
PeiWhoAmI,
PeiStartupThisAPNonBlocking,
};

EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiList[] = {
Expand Down Expand Up @@ -278,6 +279,68 @@ PeiStartupThisAP (
);
}

// MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.

/**
This service lets the caller get one enabled AP to execute a caller-provided
function. This service may only be called from the BSP.
This function is used to dispatch one enabled AP to the function specified by
Procedure passing in the argument specified by ProcedureArgument.
The execution is in non-blocking mode. The BSP continues executing immediately
after starting the AP.
Caller is responsible for ensuring that the scheduled AP task is complete (via
caller-specific logic) before dispatching further tasks on the AP using this
or other routines in the API.
@param[in] PeiServices An indirect pointer to the PEI Services Table
published by the PEI Foundation.
@param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
@param[in] Procedure A pointer to the function to be run on enabled APs of
the system.
@param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
total number of logical processors minus 1. The total
number of logical processors can be retrieved by
EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
@param[in] ProcedureArgument The parameter passed into Procedure for all APs.
@retval EFI_SUCCESS Indicates that the procedure was successfully
started on the AP
@retval EFI_DEVICE_ERROR The calling processor is an AP.
@retval EFI_NOT_FOUND The processor with the handle specified by
ProcessorNumber does not exist.
@retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
@retval EFI_INVALID_PARAMETER Procedure is NULL.
**/
EFI_STATUS
EFIAPI
PeiStartupThisAPNonBlocking (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_MP_SERVICES_PPI *This,
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN VOID *ProcedureArgument OPTIONAL
)
{
// Note: MpLib uses WaitEvent!=NULL as a trigger to execute in non-blocking
// mode but delegates actual usage of it as an event to the DxeMpLib wrapper.
// So we set it to '1' to allow startup of the AP in non-blocking mode, but
// in the PEI implementation its role is simply as a boolean flag indicating
// non-blocking mode - it is not an actual "Event" in the DXE sense.
return MpInitLibStartupThisAP (
Procedure,
ProcessorNumber,
(EFI_EVENT)1,
0,
ProcedureArgument,
NULL
);
}

// MU_CHANGE - End Add basic support for non-blocking AP dispatch in PEI.

/**
This service switches the requested AP to be the BSP from that point onward.
This service changes the BSP for all purposes. This call can only be performed
Expand Down
47 changes: 47 additions & 0 deletions UefiCpuPkg/CpuMpPei/CpuMpPei.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,53 @@ PeiStartupThisAP (
IN VOID *ProcedureArgument OPTIONAL
);

// MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.

/**
This service lets the caller get one enabled AP to execute a caller-provided
function. This service may only be called from the BSP.
This function is used to dispatch one enabled AP to the function specified by
Procedure passing in the argument specified by ProcedureArgument.
The execution is in non-blocking mode. The BSP continues executing immediately
after starting the AP.
Caller is responsible for ensuring that the scheduled AP task is complete (via
caller-specific logic) before dispatching further tasks on the AP using this
or other routines in the API.
@param[in] PeiServices An indirect pointer to the PEI Services Table
published by the PEI Foundation.
@param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
@param[in] Procedure A pointer to the function to be run on enabled APs of
the system.
@param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
total number of logical processors minus 1. The total
number of logical processors can be retrieved by
EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
@param[in] ProcedureArgument The parameter passed into Procedure for all APs.
@retval EFI_SUCCESS Indicates that the procedure was successfully
started on the AP
@retval EFI_DEVICE_ERROR The calling processor is an AP.
@retval EFI_NOT_FOUND The processor with the handle specified by
ProcessorNumber does not exist.
@retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
@retval EFI_INVALID_PARAMETER Procedure is NULL.
**/
EFI_STATUS
EFIAPI
PeiStartupThisAPNonBlocking (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_MP_SERVICES_PPI *This,
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN VOID *ProcedureArgument OPTIONAL
);

// MU_CHANGE - End Add basic support for non-blocking AP dispatch in PEI.

/**
This service switches the requested AP to be the BSP from that point onward.
This service changes the BSP for all purposes. This call can only be performed
Expand Down
33 changes: 29 additions & 4 deletions UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,29 @@ CheckAndUpdateApsStatus (
VOID
)
{
// MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.
UINTN ProcessorNumber;
EFI_STATUS Status;
CPU_MP_DATA *CpuMpData;

CpuMpData = GetCpuMpData ();

//
// check whether pending StartupThisAPs() callings exist.
//
for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
if (CpuMpData->CpuData[ProcessorNumber].WaitEvent == NULL) {
continue;
}

Status = CheckThisAP (ProcessorNumber);

if (Status != EFI_NOT_READY) {
CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;
}
}

// MU_CHANGE - End Add basic support for non-blocking AP dispatch in PEI.
}

/**
Expand Down Expand Up @@ -628,14 +651,16 @@ MpInitLibStartupThisAP (
OUT BOOLEAN *Finished OPTIONAL
)
{
if (WaitEvent != NULL) {
return EFI_UNSUPPORTED;
}
// MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.
// if (WaitEvent != NULL) {
// return EFI_UNSUPPORTED;
// }
// MU_CHANGE - End Add basic support for non-blocking AP dispatch in PEI.

return StartupThisAPWorker (
Procedure,
ProcessorNumber,
NULL,
WaitEvent, // MU_CHANGE - Add basic support for non-blocking AP dispatch in PEI.
TimeoutInMicroseconds,
ProcedureArgument,
Finished
Expand Down

0 comments on commit 6504c2f

Please sign in to comment.