From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: jordan.l.justen@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Wed, 18 Sep 2019 11:53:12 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2019 11:53:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,521,1559545200"; d="scan'208";a="270951815" Received: from csilveir-mobl.amr.corp.intel.com (HELO localhost) ([10.254.178.50]) by orsmga001.jf.intel.com with ESMTP; 18 Sep 2019 11:53:11 -0700 MIME-Version: 1.0 In-Reply-To: <1568794434-8720-1-git-send-email-liming.gao@intel.com> References: <1568794434-8720-1-git-send-email-liming.gao@intel.com> Cc: mjohn4 , Andrew Fish , Ray Ni , Johnson Subject: Re: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function To: Liming Gao , devel@edk2.groups.io From: "Jordan Justen" Message-ID: <156883279082.11974.1191200603714358108@jljusten-skl> User-Agent: alot/0.8 Date: Wed, 18 Sep 2019 11:53:11 -0700 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On 2019-09-18 01:13:54, Liming Gao wrote: > From: mjohn4 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=3D"Michael Johnson = " >=20 > Add GetTimeInNanoSecond, already declared in the TimerLib API, > to EmulatorPkg implementations of TimerLib. >=20 > Cc: Jordan Justen > Cc: Andrew Fish > Cc: Ray Ni > Signed-off-by: Johnson, Michael To be a valid email address, I think this should either be: Signed-off-by: "Johnson, Michael" or Signed-off-by: Michael Johnson 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 > --- > .../Library/DxeCoreTimerLib/DxeCoreTimerLib.c | 45 +++++++++++++++= +++++- > EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c | 45 +++++++++++++++= +++++- > EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c | 47 +++++++++++++++= ++++++- > 3 files changed, 134 insertions(+), 3 deletions(-) >=20 > diff --git a/EmulatorPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c b/Emu= latorPkg/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. > + Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent > > **/ > > #include > +#include > #include > #include > #include > @@ -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 count= er 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 =3D GetPerformanceCounterProperties (NULL, NULL); > + > + // > + // Ticks > + // Time =3D --------- x 1,000,000,000 > + // Frequency > + // > + NanoSeconds =3D MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Re= mainder), 1000000000u); > + > + // > + // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. > + // Since 2^29 < 1,000,000,000 =3D 0x3B9ACA00 < 2^30, Remainder should= < 2^(64-30) =3D 2^34, > + // i.e. highest bit set in Remainder should <=3D 33. > + // > + Shift =3D MAX (0, HighBitSet64 (Remainder) - 33); > + Remainder =3D RShiftU64 (Remainder, (UINTN) Shift); > + Frequency =3D RShiftU64 (Frequency, (UINTN) Shift); > + NanoSeconds +=3D DivU64x64Remainder (MultU64x32 (Remainder, 100000000= 0u), 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. > + Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved. > 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 count= er 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 =3D GetPerformanceCounterProperties (NULL, NULL); > + > + // > + // Ticks > + // Time =3D --------- x 1,000,000,000 > + // Frequency > + // > + NanoSeconds =3D MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Re= mainder), 1000000000u); > + > + // > + // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. > + // Since 2^29 < 1,000,000,000 =3D 0x3B9ACA00 < 2^30, Remainder should= < 2^(64-30) =3D 2^34, > + // i.e. highest bit set in Remainder should <=3D 33. > + // > + Shift =3D MAX (0, HighBitSet64 (Remainder) - 33); > + Remainder =3D RShiftU64 (Remainder, (UINTN) Shift); > + Frequency =3D RShiftU64 (Frequency, (UINTN) Shift); > + NanoSeconds +=3D DivU64x64Remainder (MultU64x32 (Remainder, 100000000= 0u), 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. > + Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent > > **/ > > #include > +#include > #include > #include > #include > @@ -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 count= er 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 =3D GetPerformanceCounterProperties (NULL, NULL); > + > + // > + // Ticks > + // Time =3D --------- x 1,000,000,000 > + // Frequency > + // > + NanoSeconds =3D MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Re= mainder), 1000000000u); > + > + // > + // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. > + // Since 2^29 < 1,000,000,000 =3D 0x3B9ACA00 < 2^30, Remainder should= < 2^(64-30) =3D 2^34, > + // i.e. highest bit set in Remainder should <=3D 33. > + // > + Shift =3D MAX (0, HighBitSet64 (Remainder) - 33); > + Remainder =3D RShiftU64 (Remainder, (UINTN) Shift); > + Frequency =3D RShiftU64 (Frequency, (UINTN) Shift); > + NanoSeconds +=3D DivU64x64Remainder (MultU64x32 (Remainder, 100000000= 0u), Frequency, NULL); > + > + return NanoSeconds; > +} > --=20 > 2.13.0.windows.1 >=20 >=20 >=20 >=20