From nobody Tue Apr 16 10:29:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+73770+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73770+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1617783396; cv=none; d=zohomail.com; s=zohoarc; b=Gs5OqRZo2zcGkMH/XsoisGdN2GJvlOjYtPEWGe7baZ3BZPlmuzA5bqx5iZb/XNVrSoMzRuzXlIIYdCPZIRtIsOSnlXVVWu2SSMskkIs9tditPiyO4AfGrlYLLltL5tHLZMym8xLsuA1Cf+ZrepwOTbPtGP/Rrw8aSWOo+4It4x0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617783396; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=2C3CcmtbqUufR2TTlh5EdwKDxMgzrOaLtsfzVF+v9mc=; b=UAlE6JMv8CS529w6jweuM9QgqpoAQXw05lUpI+TIO++8JO6jt2TACAswpnKV6jlyV36jQNtKnJoilPKLkC2lyJhhCmwldfd2cJGw0NFLKlPOv7akZyFM9CPB6FGEWF0T97oA+U5Oii5I0gpix1sOo2Y3z1oxmV5HAByq/BzDyzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73770+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1617783396700642.7096369415739; Wed, 7 Apr 2021 01:16:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4TBnYY1788612xQZRQEkCD52; Wed, 07 Apr 2021 01:16:36 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.4179.1617783395523757436 for ; Wed, 07 Apr 2021 01:16:35 -0700 IronPort-SDR: NnJ006bWBNx42aKuD1qgvrQrVu49CKQCH0FkF9wSMXJ90Ti8KTY6xVDhoQ0XZGo4xk0iuHkGC+ SVhLnFqDjHfg== X-IronPort-AV: E=McAfee;i="6000,8403,9946"; a="193296792" X-IronPort-AV: E=Sophos;i="5.82,203,1613462400"; d="scan'208";a="193296792" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2021 01:16:33 -0700 IronPort-SDR: JTgduepcbeV2uVQXSOWwXRBUrg4HrbAiz8+AphVnJrh10jb6/hjPfuCR234gQ1853N0/T66sNg /pV0HRUBX5jQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,203,1613462400"; d="scan'208";a="458260157" X-Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by orsmga001.jf.intel.com with ESMTP; 07 Apr 2021 01:16:31 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason Lou , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH v2] UefiCpuPkg: Remove PEI/DXE instances of CpuTimerLib. Date: Wed, 7 Apr 2021 16:16:25 +0800 Message-Id: <20210407081625.14254-1-yun.lou@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,yun.lou@intel.com X-Gm-Message-State: T83oLmjoVfVHnJGgg7d772oox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1617783396; bh=tktrgAHRnq6CXeBeVLnAcDfXNXwGeGc7J7ruNbWkxG8=; h=Cc:Date:From:Reply-To:Subject:To; b=nAU5MBSIfkxF/6XQFXeTk3jvUhnSJ5rEcuW1pcQXNpxC8ywUtNo2XxXAdCKIoJF1MEY rbweZbVlNXdDMQFaYq2t4nXSUagRDFQHzws50Ikrav21Hcthbu1YOqa8RhqQLYRHkSYTN zOs1BL/ulOA8nkpgHtcXh623aZ2yk7b9SpI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Jason Lou 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 frequency 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 longer than it takes to calculate TSC frequency with CPUID[15h] (about 450ns), which means using BaseCpuTimerLib to trigger a delay is more accurate than using PeiCpuTimerLib, recommend to use BaseCpuTimerLib instead of PeiCpuTimerLib. 2. Remove DXE instance(DxeCpuTimerLib). DxeCpuTimerLib is designed to calculate TSC frequency with CPUID[15h] in its constructor function, then save it in a global variable. For this design, once the driver containing this instance is running, this constructor function is called, it will take extra time to calculate TSC frequency. The time it takes to get TSC frequency 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 BaseCpuTimerLib instead of DxeCpuTimerLib. I did some experiments on one server platform and collected following data: 1. Average time required to find CpuCrystalFrequencyHob: about 2000 ns. 2. Average time required to find the last Hob: about 2700 ns. 2. Average time required to calculate TSC frequency: about 450 ns. Reference code: // // Calculate average time required 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 required to fin= d Hob =3D %d ns\n", \ DivU64x32(DivU64x64Remainder(MultU64x32((Ticks2 - Ticks1), 100000= 0000), *CpuCrystalCounterFrequency, NULL), 1000))); } // // Calculate average time required 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 required to calcu= late 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 Reviewed-by: Ray Ni --- 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 | 2 - 7 files changed, 252 deletions(-) diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c b/UefiCpuPkg/L= ibrary/CpuTimerLib/DxeCpuTimerLib.c deleted file mode 100644 index 269e5a3e83..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.c +++ /dev/null @@ -1,85 +0,0 @@ -/** @file - CPUID Leaf 0x15 for Core Crystal Clock frequency instance of Timer Libra= ry. - - Copyright (c) 2019 Intel Corporation. All rights reserved.
- SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include -#include -#include -#include - -extern GUID mCpuCrystalFrequencyHobGuid; - -/** - CPUID Leaf 0x15 for Core Crystal Clock Frequency. - - The TSC counting frequency is determined by using CPUID leaf 0x15. Frequ= ency 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 - ); - -// -// Cached CPU Crystal counter frequency -// -UINT64 mCpuCrystalCounterFrequency =3D 0; - - -/** - 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 - ) -{ - return mCpuCrystalCounterFrequency; -} - -/** - The constructor function is to initialize CpuCrystalCounterFrequency. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -DxeCpuTimerLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_HOB_GUID_TYPE *GuidHob; - - // - // Initialize CpuCrystalCounterFrequency - // - GuidHob =3D GetFirstGuidHob (&mCpuCrystalFrequencyHobGuid); - if (GuidHob !=3D NULL) { - mCpuCrystalCounterFrequency =3D *(UINT64*)GET_GUID_HOB_DATA (GuidHob); - } else { - mCpuCrystalCounterFrequency =3D CpuidCoreClockCalculateTscFrequency (); - } - - if (mCpuCrystalCounterFrequency =3D=3D 0) { - return EFI_UNSUPPORTED; - } - - return EFI_SUCCESS; -} - diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c b/UefiCpuPkg/L= ibrary/CpuTimerLib/PeiCpuTimerLib.c deleted file mode 100644 index 91a7212056..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.c +++ /dev/null @@ -1,58 +0,0 @@ -/** @file - CPUID Leaf 0x15 for Core Crystal Clock frequency instance as PEI Timer L= ibrary. - - Copyright (c) 2019 Intel Corporation. All rights reserved.
- SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include -#include -#include -#include -#include - -extern GUID mCpuCrystalFrequencyHobGuid; - -/** - CPUID Leaf 0x15 for Core Crystal Clock Frequency. - - The TSC counting frequency is determined by using CPUID leaf 0x15. Frequ= ency 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 - ); - -/** - 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 - ) -{ - UINT64 *CpuCrystalCounterFrequency; - EFI_HOB_GUID_TYPE *GuidHob; - - CpuCrystalCounterFrequency =3D NULL; - GuidHob =3D GetFirstGuidHob (&mCpuCrystalFrequencyHobGuid); - if (GuidHob =3D=3D NULL) { - CpuCrystalCounterFrequency =3D (UINT64*)BuildGuidHob(&mCpuCrystalFreq= uencyHobGuid, sizeof (*CpuCrystalCounterFrequency)); - ASSERT (CpuCrystalCounterFrequency !=3D NULL); - *CpuCrystalCounterFrequency =3D CpuidCoreClockCalculateTscFrequency (); - } else { - CpuCrystalCounterFrequency =3D (UINT64*)GET_GUID_HOB_DATA (GuidHob); - } - - return *CpuCrystalCounterFrequency; -} - diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf b/UefiCpuPkg= /Library/CpuTimerLib/DxeCpuTimerLib.inf deleted file mode 100644 index 6c83549c87..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf +++ /dev/null @@ -1,37 +0,0 @@ -## @file -# DXE CPU Timer Library -# -# Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The = performance -# counter features are provided by the processors time stamp counter. -# -# Copyright (c) 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D DxeCpuTimerLib - FILE_GUID =3D F22CC0DA-E7DB-4E4D-ABE2-A608188233A2 - MODULE_TYPE =3D DXE_DRIVER - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D TimerLib|DXE_CORE DXE_DRIVER DXE_RUNT= IME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE - CONSTRUCTOR =3D DxeCpuTimerLibConstructor - MODULE_UNI_FILE =3D DxeCpuTimerLib.uni - -[Sources] - CpuTimerLib.c - DxeCpuTimerLib.c - -[Packages] - MdePkg/MdePkg.dec - UefiCpuPkg/UefiCpuPkg.dec - -[LibraryClasses] - BaseLib - PcdLib - DebugLib - HobLib - -[Pcd] - gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni b/UefiCpuPkg= /Library/CpuTimerLib/DxeCpuTimerLib.uni deleted file mode 100644 index f55b92abac..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.uni +++ /dev/null @@ -1,17 +0,0 @@ -// /** @file -// DXE CPU Timer Library -// -// Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The= performance -// counter features are provided by the processors time stamp counter. -// -// Copyright (c) 2019, Intel Corporation. All rights reserved.
-// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "CPU Timer Library" - -#string STR_MODULE_DESCRIPTION #language en-US "Provides basic ti= mer support using CPUID Leaf 0x15 XTAL frequency." - diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf b/UefiCpuPkg= /Library/CpuTimerLib/PeiCpuTimerLib.inf deleted file mode 100644 index 7af0fc44a6..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf +++ /dev/null @@ -1,36 +0,0 @@ -## @file -# PEI CPU Timer Library -# -# Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The = performance -# counter features are provided by the processors time stamp counter. -# -# Copyright (c) 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D PeiCpuTimerLib - FILE_GUID =3D 2B13DE00-1A5F-4DD7-A298-01B08AF1015A - MODULE_TYPE =3D BASE - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D TimerLib|PEI_CORE PEIM - MODULE_UNI_FILE =3D PeiCpuTimerLib.uni - -[Sources] - CpuTimerLib.c - PeiCpuTimerLib.c - -[Packages] - MdePkg/MdePkg.dec - UefiCpuPkg/UefiCpuPkg.dec - -[LibraryClasses] - BaseLib - PcdLib - DebugLib - HobLib - -[Pcd] - gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni b/UefiCpuPkg= /Library/CpuTimerLib/PeiCpuTimerLib.uni deleted file mode 100644 index 49beb44908..0000000000 --- a/UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.uni +++ /dev/null @@ -1,17 +0,0 @@ -// /** @file -// PEI CPU Timer Library -// -// Provides basic timer support using CPUID Leaf 0x15 XTAL frequency. The= performance -// counter features are provided by the processors time stamp counter. -// -// Copyright (c) 2019, Intel Corporation. All rights reserved.
-// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "CPU Timer Library" - -#string STR_MODULE_DESCRIPTION #language en-US "Provides basic ti= mer support using CPUID Leaf 0x15 XTAL frequency." - diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 98c4c53465..c16cf8d1b9 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -116,8 +116,6 @@ UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf UefiCpuPkg/Application/Cpuid/Cpuid.inf UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf - UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf - UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf =20 --=20 2.28.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 (#73770): https://edk2.groups.io/g/devel/message/73770 Mute This Topic: https://groups.io/mt/81910860/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-