From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.11661.1580405442244356890 for ; Thu, 30 Jan 2020 09:30:42 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: michael.d.kinney@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2020 09:30:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,382,1574150400"; d="scan'208";a="233019109" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by orsmga006.jf.intel.com with ESMTP; 30 Jan 2020 09:30:41 -0800 Received: from orsmsx154.amr.corp.intel.com (10.22.226.12) by ORSMSX109.amr.corp.intel.com (10.22.240.7) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 30 Jan 2020 09:30:40 -0800 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.57]) by ORSMSX154.amr.corp.intel.com ([169.254.11.134]) with mapi id 14.03.0439.000; Thu, 30 Jan 2020 09:30:40 -0800 From: "Michael D Kinney" To: "devel@edk2.groups.io" , "derek.lin2@hpe.com" , "Kinney, Michael D" CC: "Justen, Jordan L" , "afish@apple.com" , "Ni, Ray" , Kitty Chen Subject: Re: [edk2-devel] [PATCH] EmulatorPkg: TimerLib QueryPerformance functions Thread-Topic: [edk2-devel] [PATCH] EmulatorPkg: TimerLib QueryPerformance functions Thread-Index: AQHV1zywVWPec562qUSaratXISo2PagDdLsA Date: Thu, 30 Jan 2020 17:30:40 +0000 Message-ID: References: <20200130071214.16472-1-derek.lin2@hpe.com> In-Reply-To: <20200130071214.16472-1-derek.lin2@hpe.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Return-Path: michael.d.kinney@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Derik, The Linux service clock_gettime() returns a structure with seconds and nanoseconds and you are retuning the number of nanoseconds from QueryPerformanceCounter(). Doesn't that imply that the rate of the performance counter is 1 ns? Does this allow you to remove the calibration code? Depending on the clock source=20 used by clock_gettime(), there may be large jumps in the number of ns. You can use clock_getres() to see if the resolution is acceptable. It looks like clock_gettime() optionally supports other time sources that may be based on features such like TSC and those may require calibration. Mike > -----Original Message----- > From: devel@edk2.groups.io On > Behalf Of Lin, Derek (HPS SW) > Sent: Wednesday, January 29, 2020 11:12 PM > To: derek.lin2@hpe.com; devel@edk2.groups.io > Cc: Justen, Jordan L ; > afish@apple.com; Ni, Ray ; Kitty Chen > > Subject: [edk2-devel] [PATCH] EmulatorPkg: TimerLib > QueryPerformance functions >=20 > Implement QueryPerformanceCounter() and > QueryPerformanceFrequency() > for both Unix and Windows. >=20 > This has been tested in both Unix and Windows in an > application using > TimerLib. >=20 > Signed-off-by: Derek Lin > Signed-off-by: Kitty Chen > --- > EmulatorPkg/Unix/Host/EmuThunk.c | 40 > +++++++++++++++++++++----------- > EmulatorPkg/Win/Host/WinThunk.c | 10 +++++--- > 2 files changed, 34 insertions(+), 16 deletions(-) >=20 > diff --git a/EmulatorPkg/Unix/Host/EmuThunk.c > b/EmulatorPkg/Unix/Host/EmuThunk.c > index 1e9dc99187..92703d3088 100644 > --- a/EmulatorPkg/Unix/Host/EmuThunk.c > +++ b/EmulatorPkg/Unix/Host/EmuThunk.c > @@ -11,6 +11,7 @@ >=20 > Copyright (c) 2004 - 2019, Intel Corporation. All > rights reserved.
> Portions copyright (c) 2008 - 2011, Apple Inc. All > rights reserved.
> +(C) Copyright 2020 Hewlett Packard Enterprise > Development LP
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -33,6 +34,7 @@ struct timeval settimer_timeval; > UINTN settimer_callback =3D 0; >=20 > BOOLEAN gEmulatorInterruptEnabled =3D FALSE; > +UINT64 mPerformanceFrequency =3D 0; >=20 >=20 > UINTN > @@ -236,16 +238,6 @@ SecInterruptEanbled (void) > return gEmulatorInterruptEnabled; > } >=20 > - > -UINT64 > -QueryPerformanceFrequency ( > - VOID > - ) > -{ > - // Hard code to nanoseconds > - return 1000000000ULL; > -} > - > UINT64 > QueryPerformanceCounter ( > VOID > @@ -274,12 +266,34 @@ QueryPerformanceCounter ( >=20 > return (Start * sTimebaseInfo.numer) / > sTimebaseInfo.denom; > #else > - // Need to figure out what to do for Linux? > - return 0; > + int status; > + struct timespec time; > + status =3D clock_gettime(CLOCK_REALTIME, &time); > + return MultU64x32 (time.tv_sec, 1000000000) + > time.tv_nsec; > + > #endif > } >=20 > - > +UINT64 > +QueryPerformanceFrequency ( > + VOID > + ) > +{ > + UINT64 Counter1; > + UINT64 Counter2; > + if (mPerformanceFrequency) { > + return mPerformanceFrequency; > + } > + // > + // Don't know how to query performance frequency in > Linux, > + // so instead, sleep 0.1 second and calculate it. > + // > + Counter1 =3D QueryPerformanceCounter(); > + SecSleep (100* 1000 * 1000); > + Counter2 =3D QueryPerformanceCounter(); > + mPerformanceFrequency =3D (Counter2-Counter1) * 10; > + return mPerformanceFrequency; > +} >=20 > VOID > SecSleep ( > diff --git a/EmulatorPkg/Win/Host/WinThunk.c > b/EmulatorPkg/Win/Host/WinThunk.c > index a77be2a64b..41b5cffe18 100644 > --- a/EmulatorPkg/Win/Host/WinThunk.c > +++ b/EmulatorPkg/Win/Host/WinThunk.c > @@ -1,6 +1,7 @@ > /**@file >=20 > Copyright (c) 2006 - 2018, Intel Corporation. All > rights reserved.
> +(C) Copyright 2020 Hewlett Packard Enterprise > Development LP
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > Module Name: > @@ -438,8 +439,9 @@ SecQueryPerformanceFrequency ( > VOID > ) > { > - // Hard code to nanoseconds > - return 1000000000ULL; > + UINT64 Frequency; > + QueryPerformanceFrequency ((LARGE_INTEGER *) > &Frequency); > + return Frequency; > } >=20 > UINT64 > @@ -447,7 +449,9 @@ SecQueryPerformanceCounter ( > VOID > ) > { > - return 0; > + UINT64 PerformanceCount; > + QueryPerformanceCounter ((LARGE_INTEGER *) > &PerformanceCount); > + return PerformanceCount; > } >=20 >=20 > -- > 2.17.0.windows.1 >=20 >=20 >=20