mirror of https://github.com/acidanthera/audk.git
EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
Add GetTimeInNanoSecond, already declared in the TimerLib API, to EmulatorPkg implementations of TimerLib. Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Andrew Fish <afish@apple.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Michael Johnson <michael.johnson@intel.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
parent
136dad0956
commit
d652b458f5
|
@ -1,12 +1,13 @@
|
|||
/** @file
|
||||
A non-functional instance of the Timer Library.
|
||||
|
||||
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <PiPei.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/TimerLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/EmuThunkLib.h>
|
||||
|
@ -119,4 +120,46 @@ GetPerformanceCounterProperties (
|
|||
return gEmuThunk->QueryPerformanceFrequency ();
|
||||
}
|
||||
|
||||
/**
|
||||
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 Frequency;
|
||||
UINT64 NanoSeconds;
|
||||
UINT64 Remainder;
|
||||
INTN Shift;
|
||||
|
||||
Frequency = GetPerformanceCounterProperties (NULL, NULL);
|
||||
|
||||
//
|
||||
// Ticks
|
||||
// Time = --------- x 1,000,000,000
|
||||
// Frequency
|
||||
//
|
||||
NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u);
|
||||
|
||||
//
|
||||
// Ensure (Remainder * 1,000,000,000) will not overflow 64-bit.
|
||||
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
|
||||
// i.e. highest bit set in Remainder should <= 33.
|
||||
//
|
||||
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
|
||||
Remainder = RShiftU64 (Remainder, (UINTN) Shift);
|
||||
Frequency = RShiftU64 (Frequency, (UINTN) Shift);
|
||||
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
|
||||
|
||||
return NanoSeconds;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
A non-functional instance of the Timer Library.
|
||||
|
||||
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
@ -198,3 +198,46 @@ DxeTimerLibConstructor (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
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 Frequency;
|
||||
UINT64 NanoSeconds;
|
||||
UINT64 Remainder;
|
||||
INTN Shift;
|
||||
|
||||
Frequency = GetPerformanceCounterProperties (NULL, NULL);
|
||||
|
||||
//
|
||||
// Ticks
|
||||
// Time = --------- x 1,000,000,000
|
||||
// Frequency
|
||||
//
|
||||
NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u);
|
||||
|
||||
//
|
||||
// Ensure (Remainder * 1,000,000,000) will not overflow 64-bit.
|
||||
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
|
||||
// i.e. highest bit set in Remainder should <= 33.
|
||||
//
|
||||
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
|
||||
Remainder = RShiftU64 (Remainder, (UINTN) Shift);
|
||||
Frequency = RShiftU64 (Frequency, (UINTN) Shift);
|
||||
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
|
||||
|
||||
return NanoSeconds;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/** @file
|
||||
A non-functional instance of the Timer Library.
|
||||
|
||||
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <PiPei.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/TimerLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/PeiServicesLib.h>
|
||||
|
@ -166,3 +167,47 @@ GetPerformanceCounterProperties (
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
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 Frequency;
|
||||
UINT64 NanoSeconds;
|
||||
UINT64 Remainder;
|
||||
INTN Shift;
|
||||
|
||||
Frequency = GetPerformanceCounterProperties (NULL, NULL);
|
||||
|
||||
//
|
||||
// Ticks
|
||||
// Time = --------- x 1,000,000,000
|
||||
// Frequency
|
||||
//
|
||||
NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u);
|
||||
|
||||
//
|
||||
// Ensure (Remainder * 1,000,000,000) will not overflow 64-bit.
|
||||
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
|
||||
// i.e. highest bit set in Remainder should <= 33.
|
||||
//
|
||||
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
|
||||
Remainder = RShiftU64 (Remainder, (UINTN) Shift);
|
||||
Frequency = RShiftU64 (Frequency, (UINTN) Shift);
|
||||
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
|
||||
|
||||
return NanoSeconds;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue