From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.10.1601006534778932906 for ; Thu, 24 Sep 2020 21:02:14 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: yun.lou@intel.com) IronPort-SDR: +7pWkvh74BrMvspWR8H3R3idCbx8OgeR5eKKSTOneTWJL2nO84aB2NK4jzyc3bjowjJ7xiDZEb xP0ppxZo9dtQ== X-IronPort-AV: E=McAfee;i="6000,8403,9754"; a="149182785" X-IronPort-AV: E=Sophos;i="5.77,300,1596524400"; d="scan'208";a="149182785" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2020 21:02:13 -0700 IronPort-SDR: Ya6HxZDV4u0u58f5CeEfa+sVnqlvYyeS5RiJDYRDwVFsTEDs27uROD3x3ClMLK7Pwton4nRqdb zF4ofM00zsOQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,300,1596524400"; d="scan'208";a="339356499" Received: from yunlou-mobl1.ccr.corp.intel.com ([10.238.4.28]) by orsmga008.jf.intel.com with ESMTP; 24 Sep 2020 21:02:12 -0700 From: yun.lou@intel.com To: devel@edk2.groups.io Cc: jasonlouyun , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v1 1/1] UefiCpuPkg: Remove PEI/DXE instances of CpuTimerLib. Date: Fri, 25 Sep 2020 11:57:55 +0800 Message-Id: <20200925035755.3442-1-yun.lou@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2832 1. Remove PEI instance(PeiCpuTimerLib). PeiCpuTimerLib is currently designed to save time by getting CPU TSC frequn= cy from Hob. BaseCpuTimerLib is designed to calculate TSC frequency by using CPUID[15h] = each time. The time it takes to find CpuCrystalFrequencyHob (about 2000ns) is much lon= ger than it takes to calculate TSC frequency with CPUID[15h] (about 450ns), which means using Ba= seCpuTimerLib to trigger a delay is more accurate than using PeiCpuTimerLib, recommend to us= e BaseCpuTimerLib instead of PeiCpuTimerLib. 2. Remove DXE instance(DxeCpuTimerLib). DxeCpuTimerLib is designed to calculate TSC frequency with CPUID[15h] in it= s constructor function, then save it in a global variable. For this design, once the driver contain= ing this instance is running, the constructor function is called, it will take extra time to cal= culate TSC frequency. The time it takes to get TSC frequncy from global variable is shorter than = it takes to calculate TSC frequency with CPUID[15h], but 450ns is a short time, the impact on the= platform is very limited. In addition, in order to simplify the code, recommend to use BaseCpuTimerLi= b instead of DxeCpuTimerLib. I did some experiments on one Intel server platform and collected the follo= wing data: 1. Average time taken to find CpuCrystalFrequencyHob: about 2000 ns. 2. Average time taken to calculate TSC frequency: about 450 ns. Reference code: // // Calculate average time taken to find Hob. // DEBUG((DEBUG_ERROR, "[PeiCpuTimerLib] GetPerformanceCounterFrequency - = GetFirstGuidHob (1000 cycles)\n")); Ticks1 =3D AsmReadTsc(); for (i =3D 0; i < 1000; i++) { GuidHob =3D GetFirstGuidHob (&mCpuCrystalFrequencyHobGuid); } Ticks2 =3D AsmReadTsc(); if (GuidHob =3D=3D NULL) { DEBUG((DEBUG_ERROR, "[PeiCpuTimerLib] - CpuCrystalFrequencyHob can n= ot be found!\n")); } else { DEBUG((DEBUG_ERROR, "[PeiCpuTimerLib] - Average time taken to find H= ob =3D %d ns\n", \ DivU64x32(DivU64x64Remainder(MultU64x32((Ticks2 - Ticks1), 100000= 0000), *CpuCrystalCounterFrequency, NULL), 1000))); } // // Calculate average time taken to calculate CPU frequency. // DEBUG((DEBUG_ERROR, "[PeiCpuTimerLib] GetPerformanceCounterFrequency - = CpuidCoreClockCalculateTscFrequency (1000 cycles)\n")); Ticks1 =3D AsmReadTsc(); for (i =3D 0; i < 1000; i++) { Freq =3D CpuidCoreClockCalculateTscFrequency (); } Ticks2 =3D AsmReadTsc(); DEBUG((DEBUG_ERROR, "[PeiCpuTimerLib] - Average time taken to calculat= e TSC frequency =3D %d ns\n", \ DivU64x32(DivU64x64Remainder(MultU64x32((Ticks2 - Ticks1), 10000000= 00), *CpuCrystalCounterFrequency, NULL), 1000))); Signed-off-by: Jason Lou Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c | 85 -------------------- UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c | 58 ------------- UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf | 37 --------- UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni | 17 ---- UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf | 36 --------- UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni | 17 ---- UefiCpuPkg/UefiCpuPkg.dsc | 4 +- 7 files changed, 1 insertion(+), 253 deletions(-) diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c b/UefiCpuPkg/L= ibrary/CpuTimerLib/DxeCpuTimerLib.c deleted file mode 100644 index 269e5a3e83d7..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c +++ /dev/null @@ -1,85 +0,0 @@ -/** @file=0D - CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer Libra= ry.=0D -=0D - Copyright (c) 2019 Intel Corporation. All rights reserved.
=0D - SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#include =0D -#include =0D -#include =0D -#include =0D -=0D -extern GUID mCpuCrystalFrequencyHobGuid;=0D -=0D -/**=0D - CPUID Leaf 0x15 for Core Crystal Clock Frequency.=0D -=0D - The TSC counting frequency is determined by using CPUID leaf 0x15. Frequ= ency in MHz =3D Core XTAL frequency * EBX/EAX.=0D - In newer flavors of the CPU, core xtal frequency is returned in ECX or 0= if not supported.=0D - @return The number of TSC counts per second.=0D -=0D -**/=0D -UINT64=0D -CpuidCoreClockCalculateTscFrequency (=0D - VOID=0D - );=0D -=0D -//=0D -// Cached CPU Crystal counter frequency=0D -//=0D -UINT64 mCpuCrystalCounterFrequency =3D 0;=0D -=0D -=0D -/**=0D - Internal function to retrieves the 64-bit frequency in Hz.=0D -=0D - Internal function to retrieves the 64-bit frequency in Hz.=0D -=0D - @return The frequency in Hz.=0D -=0D -**/=0D -UINT64=0D -InternalGetPerformanceCounterFrequency (=0D - VOID=0D - )=0D -{=0D - return mCpuCrystalCounterFrequency;=0D -}=0D -=0D -/**=0D - The constructor function is to initialize CpuCrystalCounterFrequency.=0D -=0D - @param ImageHandle The firmware allocated handle for the EFI image.=0D - @param SystemTable A pointer to the EFI System Table.=0D -=0D - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -DxeCpuTimerLibConstructor (=0D - IN EFI_HANDLE ImageHandle,=0D - IN EFI_SYSTEM_TABLE *SystemTable=0D - )=0D -{=0D - EFI_HOB_GUID_TYPE *GuidHob;=0D -=0D - //=0D - // Initialize CpuCrystalCounterFrequency=0D - //=0D - GuidHob =3D GetFirstGuidHob (&mCpuCrystalFrequencyHobGuid);=0D - if (GuidHob !=3D NULL) {=0D - mCpuCrystalCounterFrequency =3D *(UINT64*)GET_GUID_HOB_DATA (GuidHob);= =0D - } else {=0D - mCpuCrystalCounterFrequency =3D CpuidCoreClockCalculateTscFrequency ()= ;=0D - }=0D -=0D - if (mCpuCrystalCounterFrequency =3D=3D 0) {=0D - return EFI_UNSUPPORTED;=0D - }=0D -=0D - return EFI_SUCCESS;=0D -}=0D -=0D diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c b/UefiCpuPkg/L= ibrary/CpuTimerLib/PeiCpuTimerLib.c deleted file mode 100644 index 91a721205653..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c +++ /dev/null @@ -1,58 +0,0 @@ -/** @file=0D - CPUID Leaf 0x15 for Core Crystal Clock frequency instance as PEI Timer L= ibrary.=0D -=0D - Copyright (c) 2019 Intel Corporation. All rights reserved.
=0D - SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#include =0D -#include =0D -#include =0D -#include =0D -#include =0D -=0D -extern GUID mCpuCrystalFrequencyHobGuid;=0D -=0D -/**=0D - CPUID Leaf 0x15 for Core Crystal Clock Frequency.=0D -=0D - The TSC counting frequency is determined by using CPUID leaf 0x15. Frequ= ency in MHz =3D Core XTAL frequency * EBX/EAX.=0D - In newer flavors of the CPU, core xtal frequency is returned in ECX or 0= if not supported.=0D - @return The number of TSC counts per second.=0D -=0D -**/=0D -UINT64=0D -CpuidCoreClockCalculateTscFrequency (=0D - VOID=0D - );=0D -=0D -/**=0D - Internal function to retrieves the 64-bit frequency in Hz.=0D -=0D - Internal function to retrieves the 64-bit frequency in Hz.=0D -=0D - @return The frequency in Hz.=0D -=0D -**/=0D -UINT64=0D -InternalGetPerformanceCounterFrequency (=0D - VOID=0D - )=0D -{=0D - UINT64 *CpuCrystalCounterFrequency;=0D - EFI_HOB_GUID_TYPE *GuidHob;=0D -=0D - CpuCrystalCounterFrequency =3D NULL;=0D - GuidHob =3D GetFirstGuidHob (&mCpuCrystalFrequencyHobGuid);=0D - if (GuidHob =3D=3D NULL) {=0D - CpuCrystalCounterFrequency =3D (UINT64*)BuildGuidHob(&mCpuCrystalFreq= uencyHobGuid, sizeof (*CpuCrystalCounterFrequency));=0D - ASSERT (CpuCrystalCounterFrequency !=3D NULL);=0D - *CpuCrystalCounterFrequency =3D CpuidCoreClockCalculateTscFrequency ()= ;=0D - } else {=0D - CpuCrystalCounterFrequency =3D (UINT64*)GET_GUID_HOB_DATA (GuidHob);=0D - }=0D -=0D - return *CpuCrystalCounterFrequency;=0D -}=0D -=0D diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf b/UefiCpuPkg= /Library/CpuTimerLib/DxeCpuTimerLib.inf deleted file mode 100644 index 6c83549c87da..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf +++ /dev/null @@ -1,37 +0,0 @@ -## @file=0D -# DXE CPU Timer Library=0D -#=0D -# Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The = performance=0D -# counter features are provided by the processors time stamp counter.=0D -#=0D -# Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D -# SPDX-License-Identifier: BSD-2-Clause-Patent=0D -#=0D -##=0D -=0D -[Defines]=0D - INF_VERSION =3D 0x00010005=0D - BASE_NAME =3D DxeCpuTimerLib=0D - FILE_GUID =3D F22CC0DA-E7DB-4E4D-ABE2-A608188233A2= =0D - MODULE_TYPE =3D DXE_DRIVER=0D - VERSION_STRING =3D 1.0=0D - LIBRARY_CLASS =3D TimerLib|DXE_CORE DXE_DRIVER DXE_RUNT= IME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE=0D - CONSTRUCTOR =3D DxeCpuTimerLibConstructor=0D - MODULE_UNI_FILE =3D DxeCpuTimerLib.uni=0D -=0D -[Sources]=0D - CpuTimerLib.c=0D - DxeCpuTimerLib.c=0D -=0D -[Packages]=0D - MdePkg/MdePkg.dec=0D - UefiCpuPkg/UefiCpuPkg.dec=0D -=0D -[LibraryClasses]=0D - BaseLib=0D - PcdLib=0D - DebugLib=0D - HobLib=0D -=0D -[Pcd]=0D - gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES=0D diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni b/UefiCpuPkg= /Library/CpuTimerLib/DxeCpuTimerLib.uni deleted file mode 100644 index f55b92abace7..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni +++ /dev/null @@ -1,17 +0,0 @@ -// /** @file=0D -// DXE CPU Timer Library=0D -//=0D -// Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The= performance=0D -// counter features are provided by the processors time stamp counter.=0D -//=0D -// Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D -//=0D -// SPDX-License-Identifier: BSD-2-Clause-Patent=0D -//=0D -// **/=0D -=0D -=0D -#string STR_MODULE_ABSTRACT #language en-US "CPU Timer Library= "=0D -=0D -#string STR_MODULE_DESCRIPTION #language en-US "Provides basic ti= mer support using CPUID Leaf 0x15 XTAL frequency."=0D -=0D diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf b/UefiCpuPkg= /Library/CpuTimerLib/PeiCpuTimerLib.inf deleted file mode 100644 index 7af0fc44a65d..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -## @file=0D -# PEI CPU Timer Library=0D -#=0D -# Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The = performance=0D -# counter features are provided by the processors time stamp counter.=0D -#=0D -# Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D -# SPDX-License-Identifier: BSD-2-Clause-Patent=0D -#=0D -##=0D -=0D -[Defines]=0D - INF_VERSION =3D 0x00010005=0D - BASE_NAME =3D PeiCpuTimerLib=0D - FILE_GUID =3D 2B13DE00-1A5F-4DD7-A298-01B08AF1015A= =0D - MODULE_TYPE =3D BASE=0D - VERSION_STRING =3D 1.0=0D - LIBRARY_CLASS =3D TimerLib|PEI_CORE PEIM=0D - MODULE_UNI_FILE =3D PeiCpuTimerLib.uni=0D -=0D -[Sources]=0D - CpuTimerLib.c=0D - PeiCpuTimerLib.c=0D -=0D -[Packages]=0D - MdePkg/MdePkg.dec=0D - UefiCpuPkg/UefiCpuPkg.dec=0D -=0D -[LibraryClasses]=0D - BaseLib=0D - PcdLib=0D - DebugLib=0D - HobLib=0D -=0D -[Pcd]=0D - gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES=0D diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni b/UefiCpuPkg= /Library/CpuTimerLib/PeiCpuTimerLib.uni deleted file mode 100644 index 49beb44908d6..000000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni +++ /dev/null @@ -1,17 +0,0 @@ -// /** @file=0D -// PEI CPU Timer Library=0D -//=0D -// Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The= performance=0D -// counter features are provided by the processors time stamp counter.=0D -//=0D -// Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D -//=0D -// SPDX-License-Identifier: BSD-2-Clause-Patent=0D -//=0D -// **/=0D -=0D -=0D -#string STR_MODULE_ABSTRACT #language en-US "CPU Timer Library= "=0D -=0D -#string STR_MODULE_DESCRIPTION #language en-US "Provides basic ti= mer support using CPUID Leaf 0x15 XTAL frequency."=0D -=0D diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index b2b6d78a71b0..e915b5c81b66 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -1,7 +1,7 @@ ## @file=0D # UefiCpuPkg Package=0D #=0D -# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.
= =0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -107,8 +107,6 @@ [Components] UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf= =0D UefiCpuPkg/Application/Cpuid/Cpuid.inf=0D UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf=0D - UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf=0D - UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf=0D =0D [Components.IA32, Components.X64]=0D UefiCpuPkg/CpuDxe/CpuDxe.inf=0D --=20 2.28.0.windows.1