From nobody Tue May 7 00:20:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+47466+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47466+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568794486; cv=none; d=zoho.com; s=zohoarc; b=faXV82yYv++q0kFSr05GeLTWRI2HxpnZbjdiPcb9c3rtzJEBLcfw32CypirOT8ueY1HevNR7cwMcEzcXEq0tKSwAbgFHFKMRPXcyLD1rftKzaxd1Wfv7Poz/jcwx0sZ605324KIwv/C7SY4nVNAxaTG+pFqx0oYQYDKnSPNdPvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568794486; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=ZfRqzYqSFnTLccC9nKBK/e9+cxfk8iTrbCAmSnvJCeU=; b=aUTTosW5ZwGic8w9rqxCklAJLWSTbXZSRbiW8hVXMrbJ8rEPk1j9sdEH1oB90u7Yc68lnlpPgY6EiVn96GmG1KPs/OkSmQdz2egS9qp0fs1t8jWXpGrCNC308ga0ySQiWE8Q/S2jKYNSnl7SGPrFyO2VZy6SINE1s/wZSR7LWOc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47466+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568794486310661.3305500628244; Wed, 18 Sep 2019 01:14:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3P2nYY1788612xJ6IHh35GWb; Wed, 18 Sep 2019 01:14:45 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by groups.io with SMTP; Wed, 18 Sep 2019 01:14:45 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2019 01:14:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,520,1559545200"; d="scan'208";a="211780565" X-Received: from shwde7172.ccr.corp.intel.com ([10.239.158.22]) by fmsmga004.fm.intel.com with ESMTP; 18 Sep 2019 01:14:43 -0700 From: "Liming Gao" To: devel@edk2.groups.io Cc: mjohn4 , Jordan Justen , Andrew Fish , Ray Ni , Johnson Subject: [edk2-devel] [Patch] EmulatorPkg/TimerLib: Add missing GetTimeInNanoSecond function Date: Wed, 18 Sep 2019 16:13:54 +0800 Message-Id: <1568794434-8720-1-git-send-email-liming.gao@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,liming.gao@intel.com X-Gm-Message-State: ArY0OXtDHhiFoXTKkBbVopAKx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1568794485; bh=/HdjVMi9VgrGZknsse/V1PjSKQjoiV0Zg7cZoDp1zxY=; h=Cc:Date:From:Reply-To:Subject:To; b=ik/JXfE4lhoKE+XPqnQj7YonjiA2ovYlUFb4us6LNjK7vknZcG9M2pT49TJ9uAwLeGF VwQdBJ5hXqZIcrwcVYSKAtp0bgCLqTZZzgFH0kfoky2jnM2L+kxLlx6bWtyFKJZXv9aGT hxsFNPLZotjS9GeU1Aqgk78/nMASe/vHaL0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: mjohn4 Add GetTimeInNanoSecond, already declared in the TimerLib API, to EmulatorPkg implementations of TimerLib. Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni Signed-off-by: Johnson, Michael Reviewed-by: Jordan Justen Reviewed-by: Ray Ni --- .../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/Emulat= orPkg/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. =20 - 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 =20 **/ =20 #include +#include #include #include #include @@ -119,4 +120,46 @@ GetPerformanceCounterProperties ( return gEmuThunk->QueryPerformanceFrequency (); } =20 +/** + 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 cou= nter. + + @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, &Remai= nder), 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, 1000000000u)= , Frequency, NULL); =20 + return NanoSeconds; +} diff --git a/EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.c b/EmulatorPkg/Li= brary/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. =20 - 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 =20 **/ @@ -198,3 +198,46 @@ DxeTimerLibConstructor ( return EFI_SUCCESS; } =20 +/** + 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 cou= nter. + + @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, &Remai= nder), 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, 1000000000u)= , Frequency, NULL); + + return NanoSeconds; +} diff --git a/EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.c b/EmulatorPkg/Li= brary/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. =20 - 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 =20 **/ =20 #include +#include #include #include #include @@ -166,3 +167,47 @@ GetPerformanceCounterProperties ( =20 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 cou= nter. + + @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, &Remai= nder), 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, 1000000000u)= , Frequency, NULL); + + return NanoSeconds; +} --=20 2.13.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#47466): https://edk2.groups.io/g/devel/message/47466 Mute This Topic: https://groups.io/mt/34185670/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-