From nobody Sun May 19 18:10:00 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+103510+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+103510+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1682401680; cv=none; d=zohomail.com; s=zohoarc; b=fRWAiCaOaiAscohgQvZrxzV9hhAn9PS6Ulyr7R60CoPH2NziGx+k5tvvo7P0wDkNPFF6NIyNem+CgGim6LcI51vJXIVJ2DP7Do6zwRZVyhjIj/cZlYBgj9Fx+IH6QK13/bKcLXDnEGIG0qHAHgvvGNmIpCrH/SBSnHwJi1gKfRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682401680; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cn1a5X9bw0ZDflFLit/sB4kEeWV1JlzKLvraxoVziEQ=; b=U7Qp4sa7ej5swvj3TiQGOdOJQs+n3LCSaGfNhO6trDJCvQ9bJ+uj5K3PMDHQTnDVh2E4iKojDaAISOaPziqTzRYGYk6IIJNLuUmJkFkHtNb4ahgYW+qttZuDowVY+XAd2CzA2fJo1tvN8dWnQgqSdMTNFv4U4bMFaGzee2X1HfA= 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+103510+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1682401680369624.7336041941072; Mon, 24 Apr 2023 22:48:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MYvQYY1788612xisI0IGEMVh; Mon, 24 Apr 2023 22:48:00 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.72550.1682401675815309799 for ; Mon, 24 Apr 2023 22:47:59 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="335560773" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="335560773" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:47:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="757978765" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="757978765" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:47:57 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Xiao X Chen Subject: [edk2-devel] [PATCH 1/3] UefiCpuPkg: Update code to support enable ProcTrace only on BSP Date: Tue, 25 Apr 2023 13:47:36 +0800 Message-Id: <20230425054738.2937-2-dun.tan@intel.com> In-Reply-To: <20230425054738.2937-1-dun.tan@intel.com> References: <20230425054738.2937-1-dun.tan@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,dun.tan@intel.com X-Gm-Message-State: BGBPTaprtEfgS2c1lpJmm33px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682401680; bh=NT1Rtphs0q5BlrLo2gywuZD/xUhum1+L6VjmcTWEjC0=; h=Cc:Date:From:Reply-To:Subject:To; b=veC/L6jmSme8Qs1952X5A8CsYprkeW96XPMMGG/VLVRPnNBVaDyfam9e9PYHFtJ547A g9cFqW9k9F+cTFuM+pwZKeJmklV5hvLCrOqqzTS8csgGxbktNpojwnmRfNCjeEJr9zuaB iekbFjzQOgTGRHGSJq0HztkqQRABneWwmwI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682401681957100001 Content-Type: text/plain; charset="utf-8" Update code to support enable ProcTrace only on BSP. Add a new dynamic PCD to indicate if enable ProcTrace only on BSP. In ProcTrace.c code, if this new PCD is true, only allocate buffer and set CtrlReg.Bits.TraceEn to 1 for BSP. Bugzila: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4423 Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Xiao X Chen --- UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf | 11 +++= +++----- UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c | 159 +++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++------------------------------------------------------= ------ UefiCpuPkg/UefiCpuPkg.dec | 7 +++= ++++ 3 files changed, 112 insertions(+), 65 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.i= nf b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf index 7fbcd8da0e..319c8b4842 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -4,7 +4,7 @@ # This library registers CPU features defined in Intel(R) 64 and IA-32 # Architectures Software Developer's Manual. # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -58,7 +58,8 @@ LocalApicLib =20 [Pcd] - gUefiCpuPkgTokenSpaceGuid.PcdCpuClockModulationDutyCycle ## SOMETIMES_= CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdIsPowerOnReset ## SOMETIMES_= CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme ## SOMETIMES_= CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceMemSize ## SOMETIMES_= CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuClockModulationDutyCycle ## SOMETI= MES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdIsPowerOnReset ## SOMETI= MES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme ## SOMETI= MES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceMemSize ## SOMETI= MES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdEnableProcessorTraceOnBspOnly ## SOMETI= MES_CONSUMES diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c b/UefiCpuP= kg/Library/CpuCommonFeaturesLib/ProcTrace.c index 04e6a60728..f57544bf7d 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c @@ -1,7 +1,7 @@ /** @file Intel Processor Trace feature. =20 - Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -188,6 +188,8 @@ ProcTraceInitialize ( MSR_IA32_RTIT_OUTPUT_BASE_REGISTER OutputBaseReg; MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER OutputMaskPtrsReg; RTIT_TOPA_TABLE_ENTRY *TopaEntryPtr; + BOOLEAN IsBsp; + BOOLEAN EnableOnBspOnly; =20 // // The scope of the MSR_IA32_RTIT_* is core for below processor type, on= ly program @@ -236,6 +238,13 @@ ProcTraceInitialize ( return RETURN_SUCCESS; } =20 + IsBsp =3D (CpuInfo->ProcessorInfo.StatusFlag & BIT0) ? TRUE : = FALSE; + EnableOnBspOnly =3D (PcdGetBool (PcdEnableProcessorTraceOnBspOnly)) ? TR= UE : FALSE; + + if (EnableOnBspOnly && (IsBsp =3D=3D FALSE)) { + return RETURN_SUCCESS; + } + MemRegionBaseAddr =3D 0; FirstIn =3D FALSE; =20 @@ -260,43 +269,59 @@ ProcTraceInitialize ( // address base in MSR, IA32_RTIT_OUTPUT_BASE (560h) bits 47:12. Not= e that all regions must be // aligned based on their size, not just 4K. Thus a 2M region must h= ave bits 20:12 cleared. // - ThreadMemRegionTable =3D (UINTN *)AllocatePool (ProcTraceData->NumberO= fProcessors * sizeof (UINTN *)); - if (ThreadMemRegionTable =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "Allocate ProcTrace ThreadMemRegionTable Failed= \n")); - return RETURN_OUT_OF_RESOURCES; - } - - ProcTraceData->ThreadMemRegionTable =3D ThreadMemRegionTable; =20 - for (Index =3D 0; Index < ProcTraceData->NumberOfProcessors; Index++, = ProcTraceData->AllocatedThreads++) { - Pages =3D EFI_SIZE_TO_PAGES (MemRegionSize); - Alignment =3D MemRegionSize; + Pages =3D EFI_SIZE_TO_PAGES (MemRegionSize); + Alignment =3D MemRegionSize; + if (EnableOnBspOnly) { AlignedAddress =3D (UINTN)AllocateAlignedReservedPages (Pages, Align= ment); if (AlignedAddress =3D=3D 0) { - DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated only for %d= threads\n", ProcTraceData->AllocatedThreads)); - if (Index =3D=3D 0) { - // - // Could not allocate for BSP even - // - FreePool ((VOID *)ThreadMemRegionTable); - ThreadMemRegionTable =3D NULL; - return RETURN_OUT_OF_RESOURCES; + // + // Could not allocate for BSP even + // + DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, failed to allocate bu= ffer for BSP\n")); + return RETURN_OUT_OF_RESOURCES; + } + + DEBUG ((DEBUG_INFO, "ProcTrace: Allocated PT mem for BSP only.\n")); + } else { + ThreadMemRegionTable =3D (UINTN *)AllocatePool (ProcTraceData->Numbe= rOfProcessors * sizeof (UINTN *)); + if (ThreadMemRegionTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Allocate ProcTrace ThreadMemRegionTable Fail= ed\n")); + return RETURN_OUT_OF_RESOURCES; + } + + ProcTraceData->ThreadMemRegionTable =3D ThreadMemRegionTable; + + for (Index =3D 0; Index < ProcTraceData->NumberOfProcessors; Index++= , ProcTraceData->AllocatedThreads++) { + AlignedAddress =3D (UINTN)AllocateAlignedReservedPages (Pages, Ali= gnment); + if (AlignedAddress =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated only for = %d threads\n", ProcTraceData->AllocatedThreads)); + if (Index =3D=3D 0) { + // + // Could not allocate for BSP even + // + FreePool ((VOID *)ThreadMemRegionTable); + ThreadMemRegionTable =3D NULL; + return RETURN_OUT_OF_RESOURCES; + } + + break; } =20 - break; + ThreadMemRegionTable[Index] =3D AlignedAddress; + DEBUG ((DEBUG_INFO, "ProcTrace: PT MemRegionBaseAddr(aligned) for = thread %d: 0x%llX \n", Index, (UINT64)ThreadMemRegionTable[Index])); } =20 - ThreadMemRegionTable[Index] =3D AlignedAddress; - DEBUG ((DEBUG_INFO, "ProcTrace: PT MemRegionBaseAddr(aligned) for th= read %d: 0x%llX \n", Index, (UINT64)ThreadMemRegionTable[Index])); + DEBUG ((DEBUG_INFO, "ProcTrace: Allocated PT mem for %d thread \n", = ProcTraceData->AllocatedThreads)); } - - DEBUG ((DEBUG_INFO, "ProcTrace: Allocated PT mem for %d thread \n", Pr= ocTraceData->AllocatedThreads)); } =20 - if (ProcessorNumber < ProcTraceData->AllocatedThreads) { - MemRegionBaseAddr =3D ProcTraceData->ThreadMemRegionTable[ProcessorNum= ber]; - } else { - return RETURN_SUCCESS; + if (!EnableOnBspOnly) { + if (ProcessorNumber < ProcTraceData->AllocatedThreads) { + MemRegionBaseAddr =3D ProcTraceData->ThreadMemRegionTable[ProcessorN= umber]; + } else { + return RETURN_SUCCESS; + } } =20 /// @@ -367,50 +392,64 @@ ProcTraceInitialize ( // if (FirstIn) { DEBUG ((DEBUG_INFO, "ProcTrace: Enabling ToPA scheme \n")); - // - // Let BSP allocate ToPA table mem for all threads - // - TopaMemArray =3D (UINTN *)AllocatePool (ProcTraceData->AllocatedThre= ads * sizeof (UINTN *)); - if (TopaMemArray =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "ProcTrace: Allocate mem for ToPA Failed\n")); - return RETURN_OUT_OF_RESOURCES; - } =20 - ProcTraceData->TopaMemArray =3D TopaMemArray; + Pages =3D EFI_SIZE_TO_PAGES (sizeof (PROC_TRACE_TOPA_TABLE)); + Alignment =3D 0x1000; =20 - for (Index =3D 0; Index < ProcTraceData->AllocatedThreads; Index++) { - Pages =3D EFI_SIZE_TO_PAGES (sizeof (PROC_TRACE_TOPA_TABL= E)); - Alignment =3D 0x1000; + if (EnableOnBspOnly) { AlignedAddress =3D (UINTN)AllocateAlignedReservedPages (Pages, Ali= gnment); if (AlignedAddress =3D=3D 0) { - if (Index < ProcTraceData->AllocatedThreads) { - ProcTraceData->AllocatedThreads =3D Index; - } + DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, failed to allocate = ToPA mem for BSP")); + return RETURN_OUT_OF_RESOURCES; + } =20 - DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated ToPA mem= only for %d threads\n", ProcTraceData->AllocatedThreads)); - if (Index =3D=3D 0) { - // - // Could not allocate for BSP even - // - FreePool ((VOID *)TopaMemArray); - TopaMemArray =3D NULL; - return RETURN_OUT_OF_RESOURCES; + DEBUG ((DEBUG_INFO, "ProcTrace: Allocated ToPA mem for BSP only\n"= )); + } else { + // + // Let BSP allocate ToPA table mem for all threads + // + TopaMemArray =3D (UINTN *)AllocatePool (ProcTraceData->AllocatedTh= reads * sizeof (UINTN *)); + if (TopaMemArray =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "ProcTrace: Allocate mem for ToPA Failed\n"= )); + return RETURN_OUT_OF_RESOURCES; + } + + ProcTraceData->TopaMemArray =3D TopaMemArray; + + for (Index =3D 0; Index < ProcTraceData->AllocatedThreads; Index++= ) { + AlignedAddress =3D (UINTN)AllocateAlignedReservedPages (Pages, A= lignment); + if (AlignedAddress =3D=3D 0) { + if (Index < ProcTraceData->AllocatedThreads) { + ProcTraceData->AllocatedThreads =3D Index; + } + + DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated ToPA m= em only for %d threads\n", ProcTraceData->AllocatedThreads)); + if (Index =3D=3D 0) { + // + // Could not allocate for BSP even + // + FreePool ((VOID *)TopaMemArray); + TopaMemArray =3D NULL; + return RETURN_OUT_OF_RESOURCES; + } + + break; } =20 - break; + TopaMemArray[Index] =3D AlignedAddress; + DEBUG ((DEBUG_INFO, "ProcTrace: Topa table address(aligned) for = thread %d is 0x%llX \n", Index, (UINT64)TopaMemArray[Index])); } =20 - TopaMemArray[Index] =3D AlignedAddress; - DEBUG ((DEBUG_INFO, "ProcTrace: Topa table address(aligned) for th= read %d is 0x%llX \n", Index, (UINT64)TopaMemArray[Index])); + DEBUG ((DEBUG_INFO, "ProcTrace: Allocated ToPA mem for %d thread \= n", ProcTraceData->AllocatedThreads)); } - - DEBUG ((DEBUG_INFO, "ProcTrace: Allocated ToPA mem for %d thread \n"= , ProcTraceData->AllocatedThreads)); } =20 - if (ProcessorNumber < ProcTraceData->AllocatedThreads) { - TopaTableBaseAddr =3D ProcTraceData->TopaMemArray[ProcessorNumber]; - } else { - return RETURN_SUCCESS; + if (!EnableOnBspOnly) { + if (ProcessorNumber < ProcTraceData->AllocatedThreads) { + TopaTableBaseAddr =3D ProcTraceData->TopaMemArray[ProcessorNumber]; + } else { + return RETURN_SUCCESS; + } } =20 TopaTable =3D (PROC_TRACE_TOPA_TABLE *)TopaTableBaseAd= dr; diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index a5528277ff..1a4b9333ab 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -422,5 +422,12 @@ # @Prompt GHCB Hypervisor Features gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures|0x0|UINT64|0x60000018 =20 + ## This PCD indicates whether CPU processor trace is enabled on BSP only= when CPU processor trace is enabled.

+ # This PCD is ignored if CPU processor trace is disabled.

+ # TRUE - CPU processor trace is enabled on BSP only.
+ # FASLE - CPU processor trace is enabled on all CPU.
+ # @Prompt Enable CPU processor trace only on BSP. + gUefiCpuPkgTokenSpaceGuid.PcdEnableProcessorTraceOnBspOnly|FALSE|BOOLEAN= |0x60000019 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni --=20 2.39.1.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 (#103510): https://edk2.groups.io/g/devel/message/103510 Mute This Topic: https://groups.io/mt/98487617/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- From nobody Sun May 19 18:10:00 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+103511+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+103511+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1682401683; cv=none; d=zohomail.com; s=zohoarc; b=oIj2apIGanWSqnKnY+cUw/YNHpBF5ArW82vJTC+dllL5k/JR7vULaV24BkZ921ljk1t9w9RKMPyndwf0d7w3newl9F2vycQdVACbr/qsOxtOVdgteFbiNkYLS8avlL2yYnRkPbXHfiIKv5eI8TjeZOECks7raCOGjmTKd2YVCVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682401683; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uA+TEC4+tSFDBp8lOeZ+NBmxzD5VGYEtfD5PM3yX62k=; b=diKzGoIUM1+LUuTeDBshQfm36L4eq+vAFjjMGOqdHZNoa2gYJb7XSvBM9V9c6BTjYb16w/tSJOQZuFX86aGPGWb4I6UrxOebPxqzckDoOtipiahLxl2Brtyoix8pgBSm+a2Q8lHIX5MwAAuDdeSbGRA/vRFKlKxdaIz6i8qU7TU= 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+103511+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1682401683607334.6326573660333; Mon, 24 Apr 2023 22:48:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BddCYY1788612xq0eV1EgAKK; Mon, 24 Apr 2023 22:48:03 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.72550.1682401675815309799 for ; Mon, 24 Apr 2023 22:48:02 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="335560789" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="335560789" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:48:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="757978768" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="757978768" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:47:59 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Xiao X Chen Subject: [edk2-devel] [PATCH 2/3] UefiCpuPkg: Update PT code to support enable collect performance Date: Tue, 25 Apr 2023 13:47:37 +0800 Message-Id: <20230425054738.2937-3-dun.tan@intel.com> In-Reply-To: <20230425054738.2937-1-dun.tan@intel.com> References: <20230425054738.2937-1-dun.tan@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,dun.tan@intel.com X-Gm-Message-State: iwXRmlTl4GlSi2tjoa28YQiux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682401683; bh=SCB6qR7BzEWiBu+CiFbeKpWIGR5jX5TIWfyprXD70Xo=; h=Cc:Date:From:Reply-To:Subject:To; b=lWM8emKF+AQiyulWtytel9z5p7TsZKTU6kTn3oR2jqP7su5bvntUga7R2jeVyLomUXy 8kU4ZGbpd103Ms5/YrKm8yUI0XJVPGtm+Q07Wl9e88nUnvwzIJcv0y3wXDqvV+0Als5ly WBbUzU1NhSmS9IpNXdE5UpCRZPgpkjeVjEo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682401684512100005 Content-Type: text/plain; charset="utf-8" Update ProcTrace feature code to support enable collect performance data by generating CYC and TSC packets. Add a new dynamic PCD to indicate if enable performance collecting. In ProcTrace.c code, if this new PCD is true, CYC and TSC packets will be generated by setting the corresponding MSR bits feilds. Bugzila: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4423 Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Xiao X Chen --- UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf | 1 + UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c | 66 ++++= +++++++++++++++++++++++++++++++++++++++++++------------------- UefiCpuPkg/UefiCpuPkg.dec | 8 ++++= ++++ 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.i= nf b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf index 319c8b4842..e31c1e7317 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -63,3 +63,4 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme ## SOMETI= MES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceMemSize ## SOMETI= MES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdEnableProcessorTraceOnBspOnly ## SOMETI= MES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.ProcTraceEnablePerformanceCollecting ## SOMETI= MES_CONSUMES diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c b/UefiCpuP= kg/Library/CpuCommonFeaturesLib/ProcTrace.c index f57544bf7d..1a101b7288 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c @@ -171,25 +171,26 @@ ProcTraceInitialize ( IN BOOLEAN State ) { - UINT32 MemRegionSize; - UINTN Pages; - UINTN Alignment; - UINTN MemRegionBaseAddr; - UINTN *ThreadMemRegionTable; - UINTN Index; - UINTN TopaTableBaseAddr; - UINTN AlignedAddress; - UINTN *TopaMemArray; - PROC_TRACE_TOPA_TABLE *TopaTable; - PROC_TRACE_DATA *ProcTraceData; - BOOLEAN FirstIn; - MSR_IA32_RTIT_CTL_REGISTER CtrlReg; - MSR_IA32_RTIT_STATUS_REGISTER StatusReg; - MSR_IA32_RTIT_OUTPUT_BASE_REGISTER OutputBaseReg; - MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER OutputMaskPtrsReg; - RTIT_TOPA_TABLE_ENTRY *TopaEntryPtr; - BOOLEAN IsBsp; - BOOLEAN EnableOnBspOnly; + UINT32 MemRegionSize; + UINTN Pages; + UINTN Alignment; + UINTN MemRegionBaseAddr; + UINTN *ThreadMemRegionTable; + UINTN Index; + UINTN TopaTableBaseAddr; + UINTN AlignedAddress; + UINTN *TopaMemArray; + PROC_TRACE_TOPA_TABLE *TopaTable; + PROC_TRACE_DATA *ProcTraceData; + BOOLEAN FirstIn; + MSR_IA32_RTIT_CTL_REGISTER CtrlReg; + MSR_IA32_RTIT_STATUS_REGISTER StatusReg; + MSR_IA32_RTIT_OUTPUT_BASE_REGISTER OutputBaseReg; + MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER OutputMaskPtrsReg; + RTIT_TOPA_TABLE_ENTRY *TopaEntryPtr; + BOOLEAN IsBsp; + BOOLEAN EnableOnBspOnly; + CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF_EBX Ebx; =20 // // The scope of the MSR_IA32_RTIT_* is core for below processor type, on= ly program @@ -510,6 +511,33 @@ ProcTraceInitialize ( CtrlReg.Bits.User =3D 1; CtrlReg.Bits.BranchEn =3D 1; CtrlReg.Bits.TraceEn =3D 1; + + AsmCpuidEx (CPUID_INTEL_PROCESSOR_TRACE, CPUID_INTEL_PROCESSOR_TRACE_MAI= N_LEAF, NULL, &Ebx.Uint32, NULL, NULL); + + // + // Generate CYC/TSC timing packets to to collect performance data. + // + if (PcdGetBool (ProcTraceEnablePerformanceCollecting)) { + if (Ebx.Bits.ConfigurablePsb =3D=3D 1) { + CtrlReg.Bits.CYCEn =3D 1; + CtrlReg.Bits.CYCThresh =3D 5; + + // + // Write to TSCEn is always supported + // + CtrlReg.Bits.TSCEn =3D 1; + } else { + DEBUG ((DEBUG_INFO, "ProcTrace: CYC packet is not supported. Failed = to enable Performance Collecting \n")); + } + } else { + if (Ebx.Bits.ConfigurablePsb =3D=3D 1) { + CtrlReg.Bits.CYCEn =3D 0; + CtrlReg.Bits.CYCThresh =3D 0; + } + + CtrlReg.Bits.TSCEn =3D 0; + } + CPU_REGISTER_TABLE_WRITE64 ( ProcessorNumber, Msr, diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 1a4b9333ab..2b0de6d5c3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -429,5 +429,13 @@ # @Prompt Enable CPU processor trace only on BSP. gUefiCpuPkgTokenSpaceGuid.PcdEnableProcessorTraceOnBspOnly|FALSE|BOOLEAN= |0x60000019 =20 + ## This PCD indicates if enable performance collecting when CPU processo= r trace is enabled.

+ # CYC/TSC timing packets will be generated to collect performance data = if this PCD is TRUE. + # This PCD is ignored if CPU processor trace is disabled.

+ # TRUE - Performance collecting will be enabled in processor trace.
+ # FASLE - Performance collecting will be disabled in processor trace. + # @Prompt Enable performance collecting when processor trace is enabled. + gUefiCpuPkgTokenSpaceGuid.ProcTraceEnablePerformanceCollecting|FALSE|BOO= LEAN|0x60000020 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni --=20 2.39.1.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 (#103511): https://edk2.groups.io/g/devel/message/103511 Mute This Topic: https://groups.io/mt/98487618/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- From nobody Sun May 19 18:10:00 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+103512+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+103512+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1682401685; cv=none; d=zohomail.com; s=zohoarc; b=g1C9yJMalR3guRPtT98ulpfrh+5JAMFDzt85F95wWjhk59Py8iS2uzhAMe8l5PVw9gQo0BqCgVS2HU37wBdVKPlygl+uKtCNVQxoQ/kMSX0nNzuc+HSPnc1Se5NsRG9DmXll99L4CeoEuLTGbMde3aEraFnSwdIvHHrl4WmYVTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682401685; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=baQUmI4E9XinS7zedeuJE6fBdFs5KdCLsY/jOkILxWc=; b=Z0WJD93vtBzsZ2e0MoED92lwkW1QQxRrkWSBy0sm35qRfYp/uVMdewmndhVahZ/dGu3h49WppmTq+eKlB5pHxWauL9X0gpxnRag9FuYAyJoxGJe0OURSGf15xb3zQhizgHAShxy/SoG+s1nOLy+TwgrE/AQF6fbfOJTC9uppjew= 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+103512+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1682401685906187.30702957250924; Mon, 24 Apr 2023 22:48:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IRUkYY1788612xjDJeVlrsGA; Mon, 24 Apr 2023 22:48:05 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.72550.1682401675815309799 for ; Mon, 24 Apr 2023 22:48:04 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="335560821" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="335560821" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:48:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="757978772" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="757978772" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:48:02 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Xiao X Chen Subject: [edk2-devel] [PATCH 3/3] UefiCpuPkg: Disable MTC packet by default Date: Tue, 25 Apr 2023 13:47:38 +0800 Message-Id: <20230425054738.2937-4-dun.tan@intel.com> In-Reply-To: <20230425054738.2937-1-dun.tan@intel.com> References: <20230425054738.2937-1-dun.tan@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,dun.tan@intel.com X-Gm-Message-State: JGXeyPMBm4Cozd0qKE6H8ib6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682401685; bh=jg5nRNQ2L97nuV3beQNdUySfRW0maDY97UDp7SGgH5w=; h=Cc:Date:From:Reply-To:Subject:To; b=QNKX8HyutyZwaacXC9+7M9mVt+L2vkIAis1cTU6YEPHphMeV40H6dxqKrU+xSAU2iKq /KkklIi95mpM6X6V0CTmoz40q0bSkZSDZvAfsHdFq4L0RasiR4WcHz0N8POX6gNwMrJRD 53bvwD7gN2cZeOkYI+rdfoxm/DcxAO/Ei0w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682401686936100011 Content-Type: text/plain; charset="utf-8" MTC packet is not needed and disable MTC packet by default. Bugzila: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4423 Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Xiao X Chen --- UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c b/UefiCpuP= kg/Library/CpuCommonFeaturesLib/ProcTrace.c index 1a101b7288..3f109bf29c 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c @@ -538,6 +538,14 @@ ProcTraceInitialize ( CtrlReg.Bits.TSCEn =3D 0; } =20 + // + // MTC packet is not needed. Turn it off by default. + // + if (Ebx.Bits.Mtc =3D=3D 1) { + CtrlReg.Bits.MTCEn =3D 0; + CtrlReg.Bits.MTCFreq =3D 0; + } + CPU_REGISTER_TABLE_WRITE64 ( ProcessorNumber, Msr, --=20 2.39.1.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 (#103512): https://edk2.groups.io/g/devel/message/103512 Mute This Topic: https://groups.io/mt/98487623/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-