]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/MpInitLib: Remove StartCount and volatile definition.
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.c
index e5c701ddeb464d36a66321343f07931dd93e93bb..0e57cc86bf7965b596c7164a8fca208553d70d43 100644 (file)
@@ -435,16 +435,19 @@ GetProcessorNumber (
   UINTN                   TotalProcessorNumber;\r
   UINTN                   Index;\r
   CPU_INFO_IN_HOB         *CpuInfoInHob;\r
+  UINT32                  CurrentApicId;\r
 \r
   CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;\r
 \r
   TotalProcessorNumber = CpuMpData->CpuCount;\r
+  CurrentApicId = GetApicId ();\r
   for (Index = 0; Index < TotalProcessorNumber; Index ++) {\r
-    if (CpuInfoInHob[Index].ApicId == GetApicId ()) {\r
+    if (CpuInfoInHob[Index].ApicId == CurrentApicId) {\r
       *ProcessorNumber = Index;\r
       return EFI_SUCCESS;\r
     }\r
   }\r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -693,7 +696,7 @@ ApWakeupFunction (
             }\r
           }\r
         }\r
-        SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);\r
+        SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle);\r
       }\r
     }\r
 \r
@@ -1349,18 +1352,17 @@ CheckThisAP (
   CpuData   = &CpuMpData->CpuData[ProcessorNumber];\r
 \r
   //\r
-  //  Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.\r
+  //  Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task.\r
   //  Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the\r
-  //  value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.\r
+  //  value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value.\r
   //\r
   //\r
   // If the AP finishes for StartupThisAP(), return EFI_SUCCESS.\r
   //\r
-  if (GetApState(CpuData) == CpuStateFinished) {\r
+  if (GetApState(CpuData) == CpuStateIdle) {\r
     if (CpuData->Finished != NULL) {\r
       *(CpuData->Finished) = TRUE;\r
     }\r
-    SetApState (CpuData, CpuStateIdle);\r
     return EFI_SUCCESS;\r
   } else {\r
     //\r
@@ -1417,14 +1419,13 @@ CheckAllAPs (
 \r
     CpuData = &CpuMpData->CpuData[ProcessorNumber];\r
     //\r
-    // Check the CPU state of AP. If it is CpuStateFinished, then the AP has finished its task.\r
+    // Check the CPU state of AP. If it is CpuStateIdle, then the AP has finished its task.\r
     // Only BSP and corresponding AP access this unit of CPU Data. This means the AP will not modify the\r
-    // value of state after setting the it to CpuStateFinished, so BSP can safely make use of its value.\r
+    // value of state after setting the it to CpuStateIdle, so BSP can safely make use of its value.\r
     //\r
-    if (GetApState(CpuData) == CpuStateFinished) {\r
-      CpuMpData->RunningCount ++;\r
+    if (GetApState(CpuData) == CpuStateIdle) {\r
+      CpuMpData->RunningCount --;\r
       CpuMpData->CpuData[ProcessorNumber].Waiting = FALSE;\r
-      SetApState(CpuData, CpuStateIdle);\r
 \r
       //\r
       // If in Single Thread mode, then search for the next waiting AP for execution.\r
@@ -1448,7 +1449,7 @@ CheckAllAPs (
   //\r
   // If all APs finish, return EFI_SUCCESS.\r
   //\r
-  if (CpuMpData->RunningCount == CpuMpData->StartCount) {\r
+  if (CpuMpData->RunningCount == 0) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -1465,7 +1466,7 @@ CheckAllAPs (
     //\r
     if (CpuMpData->FailedCpuList != NULL) {\r
       *CpuMpData->FailedCpuList =\r
-         AllocatePool ((CpuMpData->StartCount - CpuMpData->FinishedCount + 1) * sizeof (UINTN));\r
+         AllocatePool ((CpuMpData->RunningCount + 1) * sizeof (UINTN));\r
       ASSERT (*CpuMpData->FailedCpuList != NULL);\r
     }\r
     ListIndex = 0;\r
@@ -1920,7 +1921,7 @@ SwitchBSPWorker (
   //\r
   // Wait for old BSP finished AP task\r
   //\r
-  while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateFinished) {\r
+  while (GetApState (&CpuMpData->CpuData[CallerNumber]) != CpuStateIdle) {\r
     CpuPause ();\r
   }\r
 \r
@@ -2211,7 +2212,7 @@ StartupAllAPsWorker (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  CpuMpData->StartCount = 0;\r
+  CpuMpData->RunningCount = 0;\r
   for (ProcessorNumber = 0; ProcessorNumber < ProcessorCount; ProcessorNumber++) {\r
     CpuData = &CpuMpData->CpuData[ProcessorNumber];\r
     CpuData->Waiting = FALSE;\r
@@ -2221,7 +2222,7 @@ StartupAllAPsWorker (
         // Mark this processor as responsible for current calling.\r
         //\r
         CpuData->Waiting = TRUE;\r
-        CpuMpData->StartCount++;\r
+        CpuMpData->RunningCount++;\r
       }\r
     }\r
   }\r
@@ -2230,7 +2231,6 @@ StartupAllAPsWorker (
   CpuMpData->ProcArguments = ProcedureArgument;\r
   CpuMpData->SingleThread  = SingleThread;\r
   CpuMpData->FinishedCount = 0;\r
-  CpuMpData->RunningCount  = 0;\r
   CpuMpData->FailedCpuList = FailedCpuList;\r
   CpuMpData->ExpectedTime  = CalculateTimeout (\r
                                TimeoutInMicroseconds,\r