* [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
@ 2019-09-18 8:13 Liming Gao
2019-09-18 18:53 ` [edk2-devel] " Jordan Justen
0 siblings, 1 reply; 4+ messages in thread
From: Liming Gao @ 2019-09-18 8:13 UTC (permalink / raw)
To: devel; +Cc: mjohn4, Jordan Justen, Andrew Fish, Ray Ni, Johnson
From: mjohn4 <michael.johnson@intel.com>
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: Johnson, Michael <michael.johnson@intel.com>
---
.../Library/DxeCoreTimerLib/DxeCoreTimerLib.c | 45 ++++++++++++++++++++-
EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c | 45 ++++++++++++++++++++-
EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c | 47 +++++++++++++++++++++-
3 files changed, 134 insertions(+), 3 deletions(-)
diff --git a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
index c331cbba9c..ab0de143c4 100644
--- a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
+++ b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
@@ -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;
+}
diff --git a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
index 14cae4214c..1bbc9e0162 100644
--- a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
+++ b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
@@ -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;
+}
diff --git a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
index cce46fb366..132abb2c04 100644
--- a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
+++ b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
@@ -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;
+}
--
2.13.0.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
2019-09-18 8:13 [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function Liming Gao
@ 2019-09-18 18:53 ` Jordan Justen
2019-09-18 19:01 ` Ni, Ray
2019-09-19 6:38 ` Liming Gao
0 siblings, 2 replies; 4+ messages in thread
From: Jordan Justen @ 2019-09-18 18:53 UTC (permalink / raw)
To: Liming Gao, devel; +Cc: mjohn4, Andrew Fish, Ray Ni, Johnson
On 2019-09-18 01:13:54, Liming Gao wrote:
> From: mjohn4 <michael.johnson@intel.com>
It looks like the author is not set properly. If you run "git log -1",
then it'll probably show mjohn4 rather than Michael Johnson.
Michael should run:
$ git config --global user.name "Michael Johnson"
After that when git commit it will get the correct author name in the
patch.
Michael, Liming: You can adjust it locally with:
git commit --amend --author="Michael Johnson <michael.johnson@intel.com>"
>
> 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: Johnson, Michael <michael.johnson@intel.com>
To be a valid email address, I think this should either be:
Signed-off-by: "Johnson, Michael" <michael.johnson@intel.com>
or
Signed-off-by: Michael Johnson <michael.johnson@intel.com>
The second form is more common.
If user.name was set as above then "git commit -s" would add it to the
patch automatically, and correctly.
Aside from all that, it seems like the code matches other
implementations in edk2, so:
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
> ---
> .../Library/DxeCoreTimerLib/DxeCoreTimerLib.c | 45 ++++++++++++++++++++-
> EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c | 45 ++++++++++++++++++++-
> EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c | 47 +++++++++++++++++++++-
> 3 files changed, 134 insertions(+), 3 deletions(-)
>
> diff --git a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> index c331cbba9c..ab0de143c4 100644
> --- a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> +++ b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> @@ -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;
> +}
> diff --git a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> index 14cae4214c..1bbc9e0162 100644
> --- a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> +++ b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> @@ -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;
> +}
> diff --git a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> index cce46fb366..132abb2c04 100644
> --- a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> +++ b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> @@ -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;
> +}
> --
> 2.13.0.windows.1
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
2019-09-18 18:53 ` [edk2-devel] " Jordan Justen
@ 2019-09-18 19:01 ` Ni, Ray
2019-09-19 6:38 ` Liming Gao
1 sibling, 0 replies; 4+ messages in thread
From: Ni, Ray @ 2019-09-18 19:01 UTC (permalink / raw)
To: devel@edk2.groups.io, Justen, Jordan L, Gao, Liming
Cc: Johnson, Michael, Andrew Fish
Reviewed-by: Ray Ni <ray.ni@intel.com>
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jordan Justen
> Sent: Wednesday, September 18, 2019 11:53 AM
> To: Gao, Liming <liming.gao@intel.com>; devel@edk2.groups.io
> Cc: Johnson, Michael <michael.johnson@intel.com>; Andrew Fish <afish@apple.com>; Ni, Ray <ray.ni@intel.com>;
> Johnson
> Subject: Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
>
> On 2019-09-18 01:13:54, Liming Gao wrote:
> > From: mjohn4 <michael.johnson@intel.com>
>
> It looks like the author is not set properly. If you run "git log -1",
> then it'll probably show mjohn4 rather than Michael Johnson.
>
> Michael should run:
>
> $ git config --global user.name "Michael Johnson"
>
> After that when git commit it will get the correct author name in the
> patch.
>
> Michael, Liming: You can adjust it locally with:
>
> git commit --amend --author="Michael Johnson <michael.johnson@intel.com>"
>
> >
> > 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: Johnson, Michael <michael.johnson@intel.com>
>
> To be a valid email address, I think this should either be:
>
> Signed-off-by: "Johnson, Michael" <michael.johnson@intel.com>
>
> or
>
> Signed-off-by: Michael Johnson <michael.johnson@intel.com>
>
> The second form is more common.
>
> If user.name was set as above then "git commit -s" would add it to the
> patch automatically, and correctly.
>
> Aside from all that, it seems like the code matches other
> implementations in edk2, so:
>
> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
>
> > ---
> > .../Library/DxeCoreTimerLib/DxeCoreTimerLib.c | 45 ++++++++++++++++++++-
> > EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c | 45 ++++++++++++++++++++-
> > EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c | 47 +++++++++++++++++++++-
> > 3 files changed, 134 insertions(+), 3 deletions(-)
> >
> > diff --git a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> > index c331cbba9c..ab0de143c4 100644
> > --- a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> > +++ b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
> > @@ -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;
> > +}
> > diff --git a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> > index 14cae4214c..1bbc9e0162 100644
> > --- a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> > +++ b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
> > @@ -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;
> > +}
> > diff --git a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> > index cce46fb366..132abb2c04 100644
> > --- a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> > +++ b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
> > @@ -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;
> > +}
> > --
> > 2.13.0.windows.1
> >
> >
> >
> >
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function
2019-09-18 18:53 ` [edk2-devel] " Jordan Justen
2019-09-18 19:01 ` Ni, Ray
@ 2019-09-19 6:38 ` Liming Gao
1 sibling, 0 replies; 4+ messages in thread
From: Liming Gao @ 2019-09-19 6:38 UTC (permalink / raw)
To: Justen, Jordan L, devel@edk2.groups.io
Cc: Johnson, Michael, Andrew Fish, Ni, Ray
Jordan:
Thanks for your suggestion. I update the style and push @ d652b458f576de785e9f905e6690e28904b1eed1
Thanks
Liming
>-----Original Message-----
>From: Justen, Jordan L
>Sent: Thursday, September 19, 2019 2:53 AM
>To: Gao, Liming <liming.gao@intel.com>; devel@edk2.groups.io
>Cc: Johnson, Michael <michael.johnson@intel.com>; Andrew Fish
><afish@apple.com>; Ni, Ray <ray.ni@intel.com>; Johnson
>Subject: Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing
>GetTimeInNanoSecond function
>
>On 2019-09-18 01:13:54, Liming Gao wrote:
>> From: mjohn4 <michael.johnson@intel.com>
>
>It looks like the author is not set properly. If you run "git log -1",
>then it'll probably show mjohn4 rather than Michael Johnson.
>
>Michael should run:
>
>$ git config --global user.name "Michael Johnson"
>
>After that when git commit it will get the correct author name in the
>patch.
>
>Michael, Liming: You can adjust it locally with:
>
>git commit --amend --author="Michael Johnson
><michael.johnson@intel.com>"
>
>>
>> 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: Johnson, Michael <michael.johnson@intel.com>
>
>To be a valid email address, I think this should either be:
>
>Signed-off-by: "Johnson, Michael" <michael.johnson@intel.com>
>
>or
>
>Signed-off-by: Michael Johnson <michael.johnson@intel.com>
>
>The second form is more common.
>
>If user.name was set as above then "git commit -s" would add it to the
>patch automatically, and correctly.
>
>Aside from all that, it seems like the code matches other
>implementations in edk2, so:
>
>Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
>
>> ---
>> .../Library/DxeCoreTimerLib/DxeCoreTimerLib.c | 45
>++++++++++++++++++++-
>> EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c | 45
>++++++++++++++++++++-
>> EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c | 47
>+++++++++++++++++++++-
>> 3 files changed, 134 insertions(+), 3 deletions(-)
>>
>> diff --git a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
>b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
>> index c331cbba9c..ab0de143c4 100644
>> --- a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
>> +++ b/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
>> @@ -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;
>> +}
>> diff --git a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
>b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
>> index 14cae4214c..1bbc9e0162 100644
>> --- a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
>> +++ b/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c
>> @@ -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;
>> +}
>> diff --git a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
>b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
>> index cce46fb366..132abb2c04 100644
>> --- a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
>> +++ b/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c
>> @@ -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;
>> +}
>> --
>> 2.13.0.windows.1
>>
>>
>>
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-09-19 6:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-18 8:13 [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function Liming Gao
2019-09-18 18:53 ` [edk2-devel] " Jordan Justen
2019-09-18 19:01 ` Ni, Ray
2019-09-19 6:38 ` Liming Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox