/** @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
\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