UefiCpuPkg: Preserve Local APIC Timer Settings During BSP Switch

This update ensures the consistency of Local APIC timer settings across
all processors when a BSP switch occurs.
The Local APIC timer is utilized in two distinct scenarios:
1. As a delay mechanism within the timer library.
2. To generate periodic timer interrupts during the DXE phase.

For scenario 1, APs can simply inherit the initial settings from the
BSP. Even the local APIC timer setting is changed by BSP later, AP
can still use the old setting. Therefore, the code to save the Local
APIC timer can be moved to MpInitLibInitialize().

For scenario 2, because normal AP doesn't enable timer interrupt, we
only need to care SwitchBsp case. It is crucial that the periodic
timer interrupts remain operational after BSP is switched. To achieve
this, the Local APIC timer settings on old BSP are now preserved and
synced to new BSP.

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
This commit is contained in:
Zhiguang Liu 2024-05-28 11:22:10 +08:00 committed by mergify[bot]
parent 76f441c57c
commit 7033f359a9

View File

@ -1258,7 +1258,6 @@ WakeUpAP (
AllocateResetVectorBelow1Mb (CpuMpData);
AllocateSevEsAPMemory (CpuMpData);
FillExchangeInfoData (CpuMpData);
SaveLocalApicTimerSetting (CpuMpData);
}
if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
@ -2236,6 +2235,7 @@ MpInitLibInitialize (
// Enable the local APIC for Virtual Wire Mode.
//
ProgramVirtualWireMode ();
SaveLocalApicTimerSetting (CpuMpData);
if (FirstMpHandOff == NULL) {
if (MaxLogicalProcessorNumber > 1) {
@ -2611,6 +2611,11 @@ SwitchBSPWorker (
ApicBaseMsr.Bits.BSP = 0;
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
//
// Save BSP's local APIC timer setting.
//
SaveLocalApicTimerSetting (CpuMpData);
//
// Need to wakeUp AP (future BSP).
//