From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A01CF821C5 for ; Tue, 21 Feb 2017 23:01:52 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 21 Feb 2017 23:01:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,193,1484035200"; d="scan'208";a="228256652" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 21 Feb 2017 23:01:52 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 21 Feb 2017 23:01:52 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 21 Feb 2017 23:01:51 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.177]) by SHSMSX104.ccr.corp.intel.com ([10.239.4.70]) with mapi id 14.03.0248.002; Wed, 22 Feb 2017 15:01:50 +0800 From: "Tian, Feng" To: "Fan, Jeff" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Tian, Feng" Thread-Topic: [PATCH] UefiCpuPkg/CpuDxe: Fix hard code actual TimerPeriod value Thread-Index: AQHSi1SyorjWvmo5LESXPrPyX46kxqF0nF3g Date: Wed, 22 Feb 2017 07:01:49 +0000 Message-ID: <7F1BAD85ADEA444D97065A60D2E97EE5699B42EC@SHSMSX101.ccr.corp.intel.com> References: <20170220083808.27256-1-jeff.fan@intel.com> In-Reply-To: <20170220083808.27256-1-jeff.fan@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] UefiCpuPkg/CpuDxe: Fix hard code actual TimerPeriod value X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Feb 2017 07:01:52 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Feng Tian -----Original Message----- From: Fan, Jeff=20 Sent: Monday, February 20, 2017 4:38 PM To: edk2-devel@lists.01.org Cc: Tian, Feng ; Kinney, Michael D Subject: [PATCH] UefiCpuPkg/CpuDxe: Fix hard code actual TimerPeriod value Current CpuGetTimerValue() implementation return hard code TimerPeriod valu= e. We could calculate the actual TimerPeriod value over period of time (100= us) at the first time invoking CpuGetTimerValue() and save the TimerPeriod = value into one global variable to avoid delay at the next CpuGetTimerValue(= ) invoking. https://bugzilla.tianocore.org/show_bug.cgi?id=3D382 Cc: Feng Tian Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/CpuDxe/CpuDxe.c | 26 +++++++++++++++++++++++--- UefiCpuPkg/CpuDxe/CpuDxe.h | 3 ++- UefiCpuPkg/CpuDxe/CpuDxe.inf | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index = f6d0a67..9fb6d76 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -1,7 +1,7 @@ /** @file CPU DXE Module to produce CPU ARCH Protocol. =20 - Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2017, Intel Corporation. All rights=20 + reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -23,6 +23,7 @@ EFI_HANDLE mCpuHandle =3D NULL; BOOLEAN mIsFlushingGCD; UINT64 mValidMtrrAddressMask =3D MTRR_LIB_CACHE_VALID_A= DDRESS; UINT64 mValidMtrrBitsMask =3D MTRR_LIB_MSR_VALID_MAS= K; +UINT64 mTimerPeriod =3D 0; =20 FIXED_MTRR mFixedMtrrTable[] =3D { { @@ -293,6 +294,9 @@ CpuGetTimerValue ( OUT UINT64 *TimerPeriod OPTIONAL ) { + UINT64 BeginValue; + UINT64 EndValue; + if (TimerValue =3D=3D NULL) { return EFI_INVALID_PARAMETER; } @@ -304,10 +308,26 @@ CpuGetTimerValue ( *TimerValue =3D AsmReadTsc (); =20 if (TimerPeriod !=3D NULL) { + if (mTimerPeriod =3D=3D 0) { + // + // Read time stamp counter before and after delay of 100=20 + microseconds // - // BugBug: Hard coded. Don't know how to do this generically + BeginValue =3D AsmReadTsc (); + MicroSecondDelay (100); + EndValue =3D AsmReadTsc (); // - *TimerPeriod =3D 1000000000; + // Calculate the actual frequency + // + mTimerPeriod =3D DivU64x64Remainder ( + MultU64x32 ( + 1000 * 1000 * 1000, + 100 + ), + EndValue - BeginValue, + NULL + ); + } + *TimerPeriod =3D mTimerPeriod; } =20 return EFI_SUCCESS; diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h index = 6dd0ad3..27ad45b 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.h +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h @@ -1,7 +1,7 @@ /** @file CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol. =20 - Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2017, Intel Corporation. All rights=20 + reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -39,6 +39,7 @@ #include #include #include +#include =20 #include #include diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf in= dex bf389bb..3cedce1 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf @@ -1,7 +1,7 @@ ## @file # CPU driver installs CPU Architecture Protocol and CPU MP protocol. # -# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, Intel Corporation. All rights=20 +reserved.
# This program and the accompanying materials # are licensed and made a= vailable under the terms and conditions of the BSD License # which accomp= anies this distribution. The full text of the license may be found at @@ -= 44,6 +44,7 @@ HobLib ReportStatusCodeLib MpInitLib + TimerLib =20 [Sources] CpuDxe.c -- 2.9.3.windows.2