]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuDxe: Fix hard code actual TimerPeriod value
authorJeff Fan <jeff.fan@intel.com>
Mon, 20 Feb 2017 08:17:05 +0000 (16:17 +0800)
committerJeff Fan <jeff.fan@intel.com>
Wed, 22 Feb 2017 07:04:06 +0000 (15:04 +0800)
Current CpuGetTimerValue() implementation return hard code TimerPeriod value. We
could calculate the actual TimerPeriod value over period of time (100us) at the
first time invoking CpuGetTimerValue() and save the TimerPeriod value into one
global variable to avoid delay at the next CpuGetTimerValue() invoking.

https://bugzilla.tianocore.org/show_bug.cgi?id=382

Cc: Feng Tian <feng.tian@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@Intel.com>
UefiCpuPkg/CpuDxe/CpuDxe.c
UefiCpuPkg/CpuDxe/CpuDxe.h
UefiCpuPkg/CpuDxe/CpuDxe.inf

index c5be1ff124bb5fd49e0f60d3b029b4f993b72791..1a5a725c6dce03450ee3097bb7c928b1fc25d06c 100644 (file)
@@ -27,6 +27,7 @@ EFI_HANDLE                mCpuHandle = NULL;
 BOOLEAN                   mIsFlushingGCD;\r
 UINT64                    mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
 UINT64                    mValidMtrrBitsMask    = MTRR_LIB_MSR_VALID_MASK;\r
+UINT64                    mTimerPeriod = 0;\r
 \r
 FIXED_MTRR    mFixedMtrrTable[] = {\r
   {\r
@@ -297,6 +298,9 @@ CpuGetTimerValue (
   OUT UINT64                    *TimerPeriod OPTIONAL\r
   )\r
 {\r
+  UINT64          BeginValue;\r
+  UINT64          EndValue;\r
+\r
   if (TimerValue == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -308,10 +312,26 @@ CpuGetTimerValue (
   *TimerValue = AsmReadTsc ();\r
 \r
   if (TimerPeriod != NULL) {\r
+    if (mTimerPeriod == 0) {\r
+      //\r
+      // Read time stamp counter before and after delay of 100 microseconds\r
       //\r
-      // BugBug: Hard coded. Don't know how to do this generically\r
+      BeginValue = AsmReadTsc ();\r
+      MicroSecondDelay (100);\r
+      EndValue   = AsmReadTsc ();\r
       //\r
-      *TimerPeriod = 1000000000;\r
+      // Calculate the actual frequency\r
+      //\r
+      mTimerPeriod = DivU64x64Remainder (\r
+                       MultU64x32 (\r
+                         1000 * 1000 * 1000,\r
+                         100\r
+                         ),\r
+                       EndValue - BeginValue,\r
+                       NULL\r
+                       );\r
+    }\r
+    *TimerPeriod = mTimerPeriod;\r
   }\r
 \r
   return EFI_SUCCESS;\r
index 6dd0ad3f01f273d2c3e627d641dd2411b0e786cf..27ad45bf9b728356ad6e6a76808a340fe9546244 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol.\r
 \r
-  Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -39,6 +39,7 @@
 #include <Library/HobLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/MpInitLib.h>\r
+#include <Library/TimerLib.h>\r
 \r
 #include <Guid/IdleLoopEvent.h>\r
 #include <Guid/VectorHandoffTable.h>\r
index f61b2c9d7ff72e8d15d9c904df0c6c4e2b4c7901..e568ceb53edfb0b1aafc81b06eb0a6a2ff7bdc37 100644 (file)
@@ -43,6 +43,7 @@
   HobLib\r
   ReportStatusCodeLib\r
   MpInitLib\r
+  TimerLib\r
 \r
 [Sources]\r
   CpuDxe.c\r