mirror of https://github.com/acidanthera/audk.git
Add new API GetTimeInNanoSecond() to TimerLib to convert elapsed ticks to time in unit of nanoseconds.
Signed-off-by: xdu2 Reviewed-by: mdkinney git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12206 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
6e5ed099af
commit
b9610b9cb5
|
@ -4,9 +4,9 @@
|
||||||
ACPI power management timer is a 24-bit or 32-bit fixed rate free running count-up
|
ACPI power management timer is a 24-bit or 32-bit fixed rate free running count-up
|
||||||
timer that runs off a 3.579545 MHz clock.
|
timer that runs off a 3.579545 MHz clock.
|
||||||
When startup, Duet will check the FADT to determine whether the PM timer is a
|
When startup, Duet will check the FADT to determine whether the PM timer is a
|
||||||
32-bit or 25-bit timer.
|
32-bit or 24-bit timer.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -243,3 +243,39 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return 3579545;
|
return 3579545;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ticks
|
||||||
|
// Time = --------- x 1,000,000,000
|
||||||
|
// Frequency
|
||||||
|
//
|
||||||
|
NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, 3579545, &Remainder), 1000000000u);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)
|
||||||
|
// will not overflow 64-bit.
|
||||||
|
//
|
||||||
|
NanoSeconds += DivU64x32 (MultU64x32 ((UINT64) Remainder, 1000000000u), 3579545);
|
||||||
|
|
||||||
|
return NanoSeconds;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
Provides calibrated delay and performance counter services.
|
Provides calibrated delay and performance counter services.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -94,4 +94,21 @@ GetPerformanceCounterProperties (
|
||||||
OUT UINT64 *EndValue OPTIONAL
|
OUT UINT64 *EndValue OPTIONAL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
A non-functional instance of the Timer Library.
|
A non-functional instance of the Timer Library.
|
||||||
|
|
||||||
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -111,3 +111,24 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return (UINT64)(-1);
|
return (UINT64)(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ASSERT (FALSE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
Timer Library functions built upon ITC on IPF.
|
Timer Library functions built upon ITC on IPF.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -170,3 +170,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;
|
return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
/** @file
|
||||||
Timer Library functions built upon local APIC on IA32/x64.
|
Timer Library functions built upon local APIC on IA32/x64.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -255,3 +255,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return (UINT64) InternalX86GetTimerFrequency (ApicBase);
|
return (UINT64) InternalX86GetTimerFrequency (ApicBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -239,3 +239,39 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return ACPI_TIMER_FREQUENCY;
|
return ACPI_TIMER_FREQUENCY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ticks
|
||||||
|
// Time = --------- x 1,000,000,000
|
||||||
|
// Frequency
|
||||||
|
//
|
||||||
|
NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, ACPI_TIMER_FREQUENCY, &Remainder), 1000000000u);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)
|
||||||
|
// will not overflow 64-bit.
|
||||||
|
//
|
||||||
|
NanoSeconds += DivU64x32 (MultU64x32 ((UINT64) Remainder, 1000000000u), ACPI_TIMER_FREQUENCY);
|
||||||
|
|
||||||
|
return NanoSeconds;
|
||||||
|
}
|
||||||
|
|
|
@ -274,3 +274,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return mTscFrequency;
|
return mTscFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -263,3 +263,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return InternalGetTscFrequency ();
|
return InternalGetTscFrequency ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
/** @file
|
||||||
Timer Library functions built upon ITC on IPF.
|
Timer Library functions built upon ITC on IPF.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -170,3 +170,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;
|
return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
This library uses the local APIC library so that it supports x2APIC mode.
|
This library uses the local APIC library so that it supports x2APIC mode.
|
||||||
|
|
||||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -193,3 +193,47 @@ GetPerformanceCounterProperties (
|
||||||
|
|
||||||
return (UINT64) InternalX86GetTimerFrequency ();
|
return (UINT64) InternalX86GetTimerFrequency ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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