From nobody Mon May 6 19:12:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53565+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53565+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1580368358708665.1140752440863; Wed, 29 Jan 2020 23:12:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id OpqBYY1788612xF49EJI1J7M; Wed, 29 Jan 2020 23:12:37 -0800 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web11.4699.1580368356042628467 for ; Wed, 29 Jan 2020 23:12:36 -0800 X-Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00U7BLM4017906; Thu, 30 Jan 2020 07:12:34 GMT X-Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com with ESMTP id 2xu814r989-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Jan 2020 07:12:34 +0000 X-Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 7F3C4AE; Thu, 30 Jan 2020 07:12:33 +0000 (UTC) X-Received: from SZC0PA4FXD.asiapacific.hpqcorp.net (szc0pa4fxd.asiapacific.hpqcorp.net [10.43.42.135]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 395EF3B; Thu, 30 Jan 2020 07:12:30 +0000 (UTC) From: "Lin, Derek (HPS SW)" To: derek.lin2@hpe.com, devel@edk2.groups.io Cc: jordan.l.justen@intel.com, afish@apple.com, ray.ni@intel.com, Kitty Chen Subject: [edk2-devel] [PATCH] EmulatorPkg: TimerLib QueryPerformance functions Date: Thu, 30 Jan 2020 15:12:14 +0800 Message-Id: <20200130071214.16472-1-derek.lin2@hpe.com> MIME-Version: 1.0 X-HPE-SCL: -1 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,derek.lin2@hpe.com X-Gm-Message-State: xVsNHff5Q7PmIM74Gubu07rax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1580368357; bh=lLxXEM+G8TxXRMbcN4NcEkCloyc6AHjbrp3+dKdRwng=; h=Cc:Date:From:Reply-To:Subject:To; b=Gdl+hj6q9FxmVFdqS81fn3ddva7Y2Cr7cPUUFZA8EeCZa+dW/DQOc/pXcNr4F5Km7Pw D4SctOqjOTPFv+GVtplubEF5eCQ5VqMF5N+KzGdVsP4oC0lgzs4Aizm92PaPDWGsXUi3M zWNNaSbTeL5um/X9gHfLmLPxm2UMOU2yDO0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Implement QueryPerformanceCounter() and QueryPerformanceFrequency() for both Unix and Windows. This has been tested in both Unix and Windows in an application using TimerLib. 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(-) diff --git a/EmulatorPkg/Unix/Host/EmuThunk.c b/EmulatorPkg/Unix/Host/EmuTh= unk.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/WinThun= k.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 --=20 2.17.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 (#53565): https://edk2.groups.io/g/devel/message/53565 Mute This Topic: https://groups.io/mt/70266535/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-