public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/6] Support source debugging on DXE AP function
@ 2016-12-26 11:20 Jeff Fan
  2016-12-26 11:20 ` [PATCH 1/6] UefiCpuPkg/DxeMpInitLib: Support source debugging on " Jeff Fan
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:20 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

The current DxeDebugAgentLib supports source debugging on AP function. This
update is to update DxeMpInitLib to consume Debug Agent Library by
DEBUG_AGENT_INIT_DXE_AP flag. Thus, we could source debugging AP function
invoked by CPU MP Protocol.

However, current SecPeiDebugAgentLib does not support source debugging on AP
function invoked by CPU MP PPI. I have submitted one bugzilla to add this
support at https://bugzilla.tianocore.org/show_bug.cgi?id=308.

We also fixed some bugs during switching BSP, when source debugging feature
enabled. 

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>

Jeff Fan (6):
  UefiCpuPkg/DxeMpInitLib: Support source debugging on AP function
  UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs
  UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker()
  UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state
  UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt
  UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP

 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  5 ++
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c       | 58 ++++++++++++-----
 UefiCpuPkg/Library/MpInitLib/MpLib.c          | 91 ++++++++++++++++++++++++++-
 UefiCpuPkg/Library/MpInitLib/MpLib.h          | 15 +++++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c       | 12 ++++
 5 files changed, 164 insertions(+), 17 deletions(-)

-- 
2.9.3.windows.2



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

* [PATCH 1/6] UefiCpuPkg/DxeMpInitLib: Support source debugging on AP function
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
@ 2016-12-26 11:20 ` Jeff Fan
  2016-12-26 11:20 ` [PATCH 2/6] UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs Jeff Fan
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:20 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

The current DxeDebugAgentLib supports source debugging on AP function. This
update is to update DxeMpInitLib to consume Debug Agent Library by
DEBUG_AGENT_INIT_DXE_AP flag. Thus, we could source debugging AP function
invoked by CPU MP Protocol.

However, current SecPeiDebugAgentLib does not support source debugging on AP
function invoked by CPU MP PPI. I have submitted one bugzilla to add this
support at https://bugzilla.tianocore.org/show_bug.cgi?id=308.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  2 ++
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c       | 16 ++++++++++++++++
 UefiCpuPkg/Library/MpInitLib/MpLib.c          |  4 ++++
 UefiCpuPkg/Library/MpInitLib/MpLib.h          |  9 +++++++++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c       | 12 ++++++++++++
 5 files changed, 43 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 11b2301..cc4f2e9 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -43,6 +43,7 @@
 
 [Packages]
   MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
@@ -54,6 +55,7 @@
   CpuLib
   UefiCpuLib
   UefiBootServicesTableLib
+  DebugAgentLib
 
 [Guids]
   gEfiEventExitBootServicesGuid                 ## CONSUMES  ## Event
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index e75c269..1204abd 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -16,6 +16,7 @@
 
 #include <Library/UefiLib.h>
 #include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugAgentLib.h>
 
 #define  AP_CHECK_INTERVAL     (EFI_TIMER_PERIOD_MILLISECONDS (100))
 #define  AP_SAFE_STACK_SIZE    128
@@ -30,6 +31,21 @@ UINTN            mReservedTopOfApStack;
 volatile UINT32  mNumberToFinish = 0;
 
 /**
+  Enable Debug Agent to support source debugging on AP function.
+
+**/
+VOID
+EnableDebugAgent (
+  VOID
+  )
+{
+  //
+  // Initialize Debug Agent to support source level debug in DXE phase
+  //
+  InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_AP, NULL, NULL);
+}
+
+/**
   Get the pointer to CPU MP Data structure.
 
   @return  The pointer to CPU MP Data structure.
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 0495b0f..a21a980 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -539,6 +539,10 @@ ApWakeupFunction (
         if (Procedure != NULL) {
           SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateBusy);
           //
+          // Enable source debugging on AP function
+          //         
+          EnableDebugAgent ();
+          //
           // Invoke AP function here
           //
           Procedure (Parameter);
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 9861a5c..b67ea9d 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -575,5 +575,14 @@ RestoreWakeupBuffer(
   IN CPU_MP_DATA              *CpuMpData
   );
 
+/**
+  Enable Debug Agent to support source debugging on AP function.
+
+**/
+VOID
+EnableDebugAgent (
+  VOID
+  );
+
 #endif
 
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index a4166a4..fb1d48f 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -25,6 +25,18 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMpInitLibNotifyList = {
   CpuMpEndOfPeiCallback
 };
 
+
+/**
+  Enable Debug Agent to support source debugging on AP function.
+
+**/
+VOID
+EnableDebugAgent (
+  VOID
+  )
+{
+}
+
 /**
   Get pointer to CPU MP Data structure.
 
-- 
2.9.3.windows.2



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

* [PATCH 2/6] UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
  2016-12-26 11:20 ` [PATCH 1/6] UefiCpuPkg/DxeMpInitLib: Support source debugging on " Jeff Fan
@ 2016-12-26 11:20 ` Jeff Fan
  2016-12-26 11:20 ` [PATCH 3/6] UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker() Jeff Fan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:20 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

If APs are waken up by INIT-SIPI-SIPI command, they will lose original local
APIC timer setting. As a result, the timer library instance based on local APIC
timer cannot work on APs function.

This fix is to save BSP's local APIC timer settings before waking up APs and
to sync to APs when APs wakeup by INIT-SIPI-SIPI command.

Setting BSP's current counter to AP's initial counter could make sure BSP and
APs have same counter value across BSP switching.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 55 +++++++++++++++++++++++++++++++++++-
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  6 ++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index a21a980..e5842ef 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -110,6 +110,53 @@ SetApState (
 }
 
 /**
+  Save BSP's local APIC timer setting
+
+  @param[in] CpuMpData          Pointer to CPU MP Data
+**/
+VOID
+SaveLocalApicTimerSetting (
+  IN CPU_MP_DATA   *CpuMpData
+  )
+{
+  //
+  // Record the current local APIC timer setting of BSP
+  //
+  GetApicTimerState (
+    &CpuMpData->DivideValue,
+    &CpuMpData->PeriodicMode,
+    &CpuMpData->Vector
+    );
+  CpuMpData->CurrentTimerCount   = GetApicTimerCurrentCount ();
+  CpuMpData->TimerInterruptState = GetApicTimerInterruptState ();
+}
+
+/**
+  Sync local APIC timer setting from BSP to AP.
+
+  @param[in] CpuMpData          Pointer to CPU MP Data
+**/
+VOID
+SyncLocalApicTimerSetting (
+  IN CPU_MP_DATA   *CpuMpData
+  )
+{
+  //
+  // Sync local APIC timer setting from BSP to AP
+  //
+  InitializeApicTimer (
+    CpuMpData->DivideValue,
+    CpuMpData->CurrentTimerCount,
+    CpuMpData->PeriodicMode,
+    CpuMpData->Vector
+    );
+  //
+  // Disable AP's local APIC timer interrupt
+  //
+  DisableApicTimerInterrupt ();
+}
+
+/**
   Save the volatile registers required to be restored following INIT IPI.
 
   @param[out]  VolatileRegisters    Returns buffer saved the volatile resisters
@@ -488,7 +535,12 @@ ApWakeupFunction (
   //
   CpuMpData = ExchangeInfo->CpuMpData;
 
-  ProgramVirtualWireMode (); 
+  //
+  // AP's local APIC settings will be lost after received INIT IPI
+  // We need to re-initialize them at here
+  //
+  ProgramVirtualWireMode ();
+  SyncLocalApicTimerSetting (CpuMpData);
 
   while (TRUE) {
     if (CpuMpData->InitFlag == ApInitConfig) {
@@ -736,6 +788,7 @@ WakeUpAP (
     ResetVectorRequired = TRUE;
     AllocateResetVector (CpuMpData);
     FillExchangeInfoData (CpuMpData);
+    SaveLocalApicTimerSetting (CpuMpData);
   } else if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
     //
     // Get AP target C-state each time when waking up AP,
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index b67ea9d..7a272d7 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -227,6 +227,12 @@ struct _CPU_MP_DATA {
   UINT16                         PmCodeSegment;
   CPU_AP_DATA                    *CpuData;
   volatile MP_CPU_EXCHANGE_INFO  *MpCpuExchangeInfo;
+
+  UINT32                         CurrentTimerCount;
+  UINTN                          DivideValue;
+  UINT8                          Vector;
+  BOOLEAN                        PeriodicMode;
+  BOOLEAN                        TimerInterruptState;
 };
 
 extern EFI_GUID mCpuInitMpLibHobGuid;
-- 
2.9.3.windows.2



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

* [PATCH 3/6] UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker()
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
  2016-12-26 11:20 ` [PATCH 1/6] UefiCpuPkg/DxeMpInitLib: Support source debugging on " Jeff Fan
  2016-12-26 11:20 ` [PATCH 2/6] UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs Jeff Fan
@ 2016-12-26 11:20 ` Jeff Fan
  2016-12-26 11:21 ` [PATCH 4/6] UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state Jeff Fan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:20 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

During switching BSP phase, we need to disable CPU interruput to prevent stack
crashed by Timer interrupt handle. But when we enabled source debugging feature,
debug timer interrupt handler (existing on both PEI and DXE) also could crash
the stack used during switching BSP. So,we need to move save/restore interrupt
to SwitchBSPWorker().

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 19 -------------------
 UefiCpuPkg/Library/MpInitLib/MpLib.c    | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 1204abd..733a9fb 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -646,29 +646,10 @@ MpInitLibSwitchBSP (
   )
 {
   EFI_STATUS            Status;
-  BOOLEAN               OldInterruptState;
 
-  //
-  // Before send both BSP and AP to a procedure to exchange their roles,
-  // interrupt must be disabled. This is because during the exchange role
-  // process, 2 CPU may use 1 stack. If interrupt happens, the stack will
-  // be corrupted, since interrupt return address will be pushed to stack
-  // by hardware.
-  //
-  OldInterruptState = SaveAndDisableInterrupts ();
-
-  //
-  // Mask LINT0 & LINT1 for the old BSP
-  //
-  DisableLvtInterrupts ();
 
   Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);
 
-  //
-  // Restore interrupt state.
-  //
-  SetInterruptState (OldInterruptState);
-
   return Status;
 }
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index e5842ef..9dae827 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1511,6 +1511,21 @@ SwitchBSPWorker (
   UINTN                        CallerNumber;
   CPU_STATE                    State;
   MSR_IA32_APIC_BASE_REGISTER  ApicBaseMsr;
+  BOOLEAN                      OldInterruptState;
+
+  //
+  // Before send both BSP and AP to a procedure to exchange their roles,
+  // interrupt must be disabled. This is because during the exchange role
+  // process, 2 CPU may use 1 stack. If interrupt happens, the stack will
+  // be corrupted, since interrupt return address will be pushed to stack
+  // by hardware.
+  //
+  OldInterruptState = SaveAndDisableInterrupts ();
+
+  //
+  // Mask LINT0 & LINT1 for the old BSP
+  //
+  DisableLvtInterrupts ();
 
   CpuMpData = GetCpuMpData ();
 
@@ -1593,6 +1608,12 @@ SwitchBSPWorker (
   //
   CpuMpData->BspNumber = (UINT32) ProcessorNumber;
 
+  //
+  // Restore interrupt state.
+  //
+  SetInterruptState (OldInterruptState);
+
+
   return EFI_SUCCESS;
 }
 
-- 
2.9.3.windows.2



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

* [PATCH 4/6] UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
                   ` (2 preceding siblings ...)
  2016-12-26 11:20 ` [PATCH 3/6] UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker() Jeff Fan
@ 2016-12-26 11:21 ` Jeff Fan
  2016-12-26 11:21 ` [PATCH 5/6] UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt Jeff Fan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:21 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

We need to swap local APIC timer interrupt state between old BSP and new BSP.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 9dae827..77d855a 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1512,8 +1512,14 @@ SwitchBSPWorker (
   CPU_STATE                    State;
   MSR_IA32_APIC_BASE_REGISTER  ApicBaseMsr;
   BOOLEAN                      OldInterruptState;
+  BOOLEAN                      OldTimerInterruptState;
 
   //
+  // Save and Disable Local APIC timer interrupt
+  //
+  OldTimerInterruptState = GetApicTimerInterruptState ();
+  DisableApicTimerInterrupt ();
+  //
   // Before send both BSP and AP to a procedure to exchange their roles,
   // interrupt must be disabled. This is because during the exchange role
   // process, 2 CPU may use 1 stack. If interrupt happens, the stack will
@@ -1613,6 +1619,9 @@ SwitchBSPWorker (
   //
   SetInterruptState (OldInterruptState);
 
+  if (OldTimerInterruptState) {
+    EnableApicTimerInterrupt ();
+  }
 
   return EFI_SUCCESS;
 }
-- 
2.9.3.windows.2



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

* [PATCH 5/6] UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
                   ` (3 preceding siblings ...)
  2016-12-26 11:21 ` [PATCH 4/6] UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state Jeff Fan
@ 2016-12-26 11:21 ` Jeff Fan
  2016-12-26 11:21 ` [PATCH 6/6] UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP Jeff Fan
  2016-12-28  7:33 ` [PATCH 0/6] Support source debugging on DXE AP function Tian, Feng
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:21 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

We need to disable system timer interrup to avoid generating the pending
interrupt on the old BSP.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  3 +++
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c       | 31 ++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index cc4f2e9..9751ba1 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -57,6 +57,9 @@
   UefiBootServicesTableLib
   DebugAgentLib
 
+[Protocols]
+  gEfiTimerArchProtocolGuid                     ## SOMETIMES_CONSUMES
+
 [Guids]
   gEfiEventExitBootServicesGuid                 ## CONSUMES  ## Event
   gEfiEventLegacyBootGuid                       ## CONSUMES  ## Event
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 733a9fb..5e50b4c 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -18,6 +18,8 @@
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/DebugAgentLib.h>
 
+#include <Protocol/Timer.h>
+
 #define  AP_CHECK_INTERVAL     (EFI_TIMER_PERIOD_MILLISECONDS (100))
 #define  AP_SAFE_STACK_SIZE    128
 
@@ -645,11 +647,38 @@ MpInitLibSwitchBSP (
   IN BOOLEAN                   EnableOldBSP
   )
 {
-  EFI_STATUS            Status;
+  EFI_STATUS                   Status;
+  EFI_TIMER_ARCH_PROTOCOL      *Timer;
+  UINT64                       TimerPeriod;
 
+  //
+  // Locate Timer Arch Protocol
+  //
+  Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Timer);
+  if (EFI_ERROR (Status)) {
+    Timer = NULL;
+  }
+
+  if (Timer != NULL) {
+    //
+    // Save current rate of DXE Timer
+    //
+    Timer->GetTimerPeriod (Timer, &TimerPeriod);
+    //
+    // Disable DXE Timer and drain pending interrupts
+    //
+    Timer->SetTimerPeriod (Timer, 0);
+  }
 
   Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);
 
+  if (Timer != NULL) {
+    //
+    // Enable and restore rate of DXE Timer
+    //
+    Timer->SetTimerPeriod (Timer, TimerPeriod);
+  }
+
   return Status;
 }
 
-- 
2.9.3.windows.2



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

* [PATCH 6/6] UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
                   ` (4 preceding siblings ...)
  2016-12-26 11:21 ` [PATCH 5/6] UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt Jeff Fan
@ 2016-12-26 11:21 ` Jeff Fan
  2016-12-28  7:33 ` [PATCH 0/6] Support source debugging on DXE AP function Tian, Feng
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Fan @ 2016-12-26 11:21 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Kinney, Michael D, Ruiyu Ni

We need to set new AP to idle state if it is expected to be waken up by new BSP
later.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 77d855a..78d18b6 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1608,6 +1608,8 @@ SwitchBSPWorker (
   //
   if (!EnableOldBSP) {
     SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateDisabled);
+  } else {
+    SetApState (&CpuMpData->CpuData[CallerNumber], CpuStateIdle);
   }
   //
   // Save new BSP number
-- 
2.9.3.windows.2



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

* Re: [PATCH 0/6] Support source debugging on DXE AP function
  2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
                   ` (5 preceding siblings ...)
  2016-12-26 11:21 ` [PATCH 6/6] UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP Jeff Fan
@ 2016-12-28  7:33 ` Tian, Feng
  6 siblings, 0 replies; 8+ messages in thread
From: Tian, Feng @ 2016-12-28  7:33 UTC (permalink / raw)
  To: Fan, Jeff, edk2-devel@lists.01.org
  Cc: Kinney, Michael D, Ni, Ruiyu, Tian, Feng

Reviewed-by: Feng Tian <feng.tian@intel.com>

Thanks
Feng

-----Original Message-----
From: Fan, Jeff 
Sent: Monday, December 26, 2016 7:21 PM
To: edk2-devel@lists.01.org
Cc: Tian, Feng <feng.tian@intel.com>; Kinney; Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
Subject: [PATCH 0/6] Support source debugging on DXE AP function

The current DxeDebugAgentLib supports source debugging on AP function. This update is to update DxeMpInitLib to consume Debug Agent Library by DEBUG_AGENT_INIT_DXE_AP flag. Thus, we could source debugging AP function invoked by CPU MP Protocol.

However, current SecPeiDebugAgentLib does not support source debugging on AP function invoked by CPU MP PPI. I have submitted one bugzilla to add this support at https://bugzilla.tianocore.org/show_bug.cgi?id=308.

We also fixed some bugs during switching BSP, when source debugging feature enabled. 

Cc: Feng Tian <feng.tian@intel.com>
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>

Jeff Fan (6):
  UefiCpuPkg/DxeMpInitLib: Support source debugging on AP function
  UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs
  UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker()
  UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state
  UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt
  UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP

 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  5 ++
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c       | 58 ++++++++++++-----
 UefiCpuPkg/Library/MpInitLib/MpLib.c          | 91 ++++++++++++++++++++++++++-
 UefiCpuPkg/Library/MpInitLib/MpLib.h          | 15 +++++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c       | 12 ++++
 5 files changed, 164 insertions(+), 17 deletions(-)

--
2.9.3.windows.2



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

end of thread, other threads:[~2016-12-28  7:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-26 11:20 [PATCH 0/6] Support source debugging on DXE AP function Jeff Fan
2016-12-26 11:20 ` [PATCH 1/6] UefiCpuPkg/DxeMpInitLib: Support source debugging on " Jeff Fan
2016-12-26 11:20 ` [PATCH 2/6] UefiCpuPkg/MpInitLib: Sync BSP's local APIC timer settings to APs Jeff Fan
2016-12-26 11:20 ` [PATCH 3/6] UefiCpuPkg/MpInitLib: Move save/restore interrupt to SwitchBSPWorker() Jeff Fan
2016-12-26 11:21 ` [PATCH 4/6] UefiCpuPkg/MpInitLib: Swap local APIC timer interrupt state Jeff Fan
2016-12-26 11:21 ` [PATCH 5/6] UefiCpuPkg/MpInitLib: Disable and restore system timer interrupt Jeff Fan
2016-12-26 11:21 ` [PATCH 6/6] UefiCpuPkg/MpInitLib: Set new AP to idle state after switching BSP Jeff Fan
2016-12-28  7:33 ` [PATCH 0/6] Support source debugging on DXE AP function Tian, Feng

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