]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmArchTimerLib: add GetTimeInNanoSecond() to ArmArchTimerLib
authorSami Mujawar <sami.mujawar@arm.com>
Thu, 3 Mar 2016 15:28:16 +0000 (15:28 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 1 Apr 2016 13:52:17 +0000 (15:52 +0200)
FirmwarePerformanceDxe.c utilizes the Timer Library function
GetTimeInNanoSecond() which was not implemented by the ArmArchTimerLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Evan Lloyd <evan.lloyd@arm.com>
Reviewed-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c

index 4361905e143f7963cd64e2a8d35abcb7688fa91b..1be90c515c4de1907ac875658cac60418a39d661 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Generic ARM implementation of TimerLib.h\r
 \r
-  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+  Copyright (c) 2011-2016, ARM Limited. All rights reserved.\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -242,3 +242,52 @@ GetPerformanceCounterProperties (
 \r
   return (UINT64)ArmGenericTimerGetTimerFreq ();\r
 }\r
+\r
+/**\r
+  Converts elapsed ticks of performance counter to time in nanoseconds.\r
+\r
+  This function converts the elapsed ticks of running performance counter to\r
+  time value in unit of nanoseconds.\r
+\r
+  @param  Ticks     The number of elapsed ticks of running performance counter.\r
+\r
+  @return The elapsed time in nanoseconds.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetTimeInNanoSecond (\r
+  IN      UINT64                     Ticks\r
+  )\r
+{\r
+  UINT64  NanoSeconds;\r
+  UINT32  Remainder;\r
+  UINT32  TimerFreq;\r
+\r
+  TimerFreq = GetPlatformTimerFreq ();\r
+  //\r
+  //          Ticks\r
+  // Time = --------- x 1,000,000,000\r
+  //        Frequency\r
+  //\r
+  NanoSeconds = MultU64xN (\r
+                  DivU64x32Remainder (\r
+                    Ticks,\r
+                    TimerFreq,\r
+                    &Remainder),\r
+                  1000000000U\r
+                  );\r
+\r
+  //\r
+  // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)\r
+  // will not overflow 64-bit.\r
+  //\r
+  NanoSeconds += DivU64x32 (\r
+                   MultU64xN (\r
+                     (UINT64) Remainder,\r
+                     1000000000U),\r
+                   TimerFreq\r
+                   );\r
+\r
+  return NanoSeconds;\r
+}\r