From 96a80ae3ce24905539e0fbd55b398e4d8ec9f410 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 3 Mar 2016 15:28:16 +0000 Subject: [PATCH] ArmPkg/ArmArchTimerLib: add GetTimeInNanoSecond() to ArmArchTimerLib 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 Reviewed-by: Ryan Harkin Reviewed-by: Ard Biesheuvel --- .../Library/ArmArchTimerLib/ArmArchTimerLib.c | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c index 4361905e14..1be90c515c 100644 --- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c +++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c @@ -1,7 +1,7 @@ /** @file Generic ARM implementation of TimerLib.h - Copyright (c) 2011-2014, ARM Limited. All rights reserved. + Copyright (c) 2011-2016, ARM Limited. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -242,3 +242,52 @@ GetPerformanceCounterProperties ( return (UINT64)ArmGenericTimerGetTimerFreq (); } + +/** + Converts elapsed ticks of performance counter to time in nanoseconds. + + This function converts the elapsed ticks of running performance counter to + time value in unit of nanoseconds. + + @param Ticks The number of elapsed ticks of running performance counter. + + @return The elapsed time in nanoseconds. + +**/ +UINT64 +EFIAPI +GetTimeInNanoSecond ( + IN UINT64 Ticks + ) +{ + UINT64 NanoSeconds; + UINT32 Remainder; + UINT32 TimerFreq; + + TimerFreq = GetPlatformTimerFreq (); + // + // Ticks + // Time = --------- x 1,000,000,000 + // Frequency + // + NanoSeconds = MultU64xN ( + DivU64x32Remainder ( + Ticks, + TimerFreq, + &Remainder), + 1000000000U + ); + + // + // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000) + // will not overflow 64-bit. + // + NanoSeconds += DivU64x32 ( + MultU64xN ( + (UINT64) Remainder, + 1000000000U), + TimerFreq + ); + + return NanoSeconds; +}