From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: star.zeng@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Mon, 12 Aug 2019 03:26:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2019 03:26:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,377,1559545200"; d="scan'208";a="177435781" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga007.fm.intel.com with ESMTP; 12 Aug 2019 03:26:44 -0700 Received: from fmsmsx121.amr.corp.intel.com (10.18.125.36) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 12 Aug 2019 03:26:44 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx121.amr.corp.intel.com (10.18.125.36) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 12 Aug 2019 03:26:44 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.19]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.112]) with mapi id 14.03.0439.000; Mon, 12 Aug 2019 18:26:42 +0800 From: "Zeng, Star" To: "Kuo, Donald" , "devel@edk2.groups.io" CC: "Ni, Ray" , "Dong, Eric" , "Zeng, Star" Subject: Re: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf Thread-Topic: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15) TSC leaf Thread-Index: AQHVUNK6m+TUprkOmU2SLRKbZZdBaab3Tevw Date: Mon, 12 Aug 2019 10:26:41 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB048310403983A6@shsmsx102.ccr.corp.intel.com> References: <20190812055641.15500-1-donald.kuo@intel.com> In-Reply-To: <20190812055641.15500-1-donald.kuo@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: star.zeng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Some comments below. > -----Original Message----- > From: Kuo, Donald > Sent: Monday, August 12, 2019 1:57 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Zeng, Star ; Dong, E= ric > > Subject: [PATCH] UefiCpuPkg: Adding a new TSC library by using CPUID(0x15= ) > TSC leaf >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1909 >=20 > Cc: Ray Ni > Cc: Star Zeng > Cc: Eric Dong > Signed-off-by: Donald Kuo > --- > .../Library/BaseCpuTimerLib/BaseCpuTimerLib.c | 40 +++ > .../Library/BaseCpuTimerLib/BaseCpuTimerLib.inf | 35 +++ > .../Library/BaseCpuTimerLib/BaseCpuTimerLib.uni | 17 ++ > UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c | 290 > +++++++++++++++++++++ > UefiCpuPkg/UefiCpuPkg.dec | 8 + > UefiCpuPkg/UefiCpuPkg.dsc | 4 +- > 6 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.c > create mode 100644 > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf > create mode 100644 > UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.uni > create mode 100644 UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c >=20 [Trimmed] > + > diff --git a/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c > b/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c > new file mode 100644 > index 0000000000..5ed01146cf > --- /dev/null > +++ b/UefiCpuPkg/Library/BaseCpuTimerLib/CpuTimerLib.c > @@ -0,0 +1,290 @@ > +/** @file > + CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer Lib= rary. > + > + Copyright (c) 2019 Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + Internal function to retrieves the 64-bit frequency in Hz. > + > + Internal function to retrieves the 64-bit frequency in Hz. > + > + @return The frequency in Hz. > + > +**/ > +UINT64 > +InternalGetPerformanceCounterFrequency ( > + VOID > + ); > + > +/** > + CPUID Leaf 0x15 for Core Crystal Clock Frequency. > + > + The TSC counting frequency is determined by using CPUID leaf 0x15. > Frequency in MHz =3D Core XTAL frequency * EBX/EAX. > + In newer flavors of the CPU, core xtal frequency is returned in ECX or= 0 if > not supported. > + @return The number of TSC counts per second. > + > +**/ > +UINT64 > +CpuidCoreClockCalculateTscFrequency ( > + VOID > + ) > +{ > + CPUID_VERSION_INFO_EAX Eax; > + UINT64 TscFrequency; > + UINT64 CoreXtalFrequency; > + UINT32 RegEax; > + UINT32 RegEbx; > + UINT32 RegEcx; > + > + // > + // Display CPU FAMILY / MODEL / STEPPING ID Info // AsmCpuid > + (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL); DEBUG > + ((DEBUG_INFO, "CPUID =3D %X\n", (Eax.Uint32 & 0x0FFF0FFF))); Suggest removing this debugging code block. > + > + // > + // Use CPUID leaf 0x15 Time Stamp Counter and Nominal Core Crystal > + Clock Information // EBX returns 0 if not supported. ECX, if non zero, > provides Core Xtal Frequency in hertz. > + // TSC frequency =3D (ECX, Core Xtal Frequency) * EBX/EAX. > + // > + AsmCpuid (CPUID_TIME_STAMP_COUNTER, &RegEax, &RegEbx, &RegEcx, > NULL); > + DEBUG ((DEBUG_INFO, "Denominator of the TSC ratio =3D %d\n", RegEax)); > + DEBUG ((DEBUG_INFO, "Numerator of the TSC ratio =3D %d\n", RegEbx)); > + DEBUG ((DEBUG_INFO, "Nominal frequency (hertz) =3D %d\n", RegEcx)); Suggest removing this debug message codes as the timerlib may be used by AP= . > + > + // > + // If EBX returns 0, the XTAL ratio is not enumerated. > + // > + if (RegEbx =3D=3D 0) { > + DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock > Frequency !!\n")); Suggest removing this debug message codes as the timerlib may be used by AP= . Then the if condition can be also removed. > + ASSERT (RegEbx !=3D 0); > + } > + // > + // If ECX returns 0, the XTAL frequency is not enumerated. > + // > + if (RegEcx =3D=3D 0) { > + DEBUG ((DEBUG_ERROR, "The CPU is not capble for Core Crystal Clock > Frequency !!\n")); Suggest removing this debug message codes as the timerlib may be used by AP= . > + CoreXtalFrequency =3D PcdGet64 (PcdCpuCoreCrystalClockFrequency); > + DEBUG ((DEBUG_INFO, "CoreXtalFrequency (hertz) from PCD =3D %d\n", > CoreXtalFrequency)); Suggest removing this debug message codes as the timerlib may be used by AP= . > + //ASSERT (RegEcx !=3D 0); Suggest removing this line > + } else { > + CoreXtalFrequency =3D (UINT64) RegEcx; } > + > + // > + // Calculate TSC frequency =3D (ECX, Core Xtal Frequency) * EBX/EAX /= / > + TscFrequency =3D DivU64x32 (MultU64x32 (CoreXtalFrequency, RegEbx) + > + (UINT64)(RegEax >> 1), RegEax); > + > + return TscFrequency; > +} > + [Trimmed] > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -42,7 +42,7 @@ > PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf > PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf >=20 > PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanc > eLibNull.inf > - > TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTem > plate.inf > +# > +TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTe > mpla > +te.inf Suggest removing this line. Thanks, Star >=20 > DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLi > bNull.inf >=20 > LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.in > f >=20 > ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseR > eportStatusCodeLibNull.inf > @@ -56,6 +56,7 @@ >=20 > PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base > PeCoffGetEntryPointLib.inf >=20 > PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP > eCoffExtraActionLibNull.inf >=20 > TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp > mMeasurementLibNull.inf > + TimerLib|UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf >=20 > [LibraryClasses.common.SEC] >=20 > PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.i > nf > @@ -143,6 +144,7 @@ >=20 > SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFea > turesLibStm.inf > } > UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf > + UefiCpuPkg/Library/BaseCpuTimerLib/BaseCpuTimerLib.inf >=20 > [BuildOptions] > *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES > -- > 2.14.2.windows.3