From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: star.zeng@intel.com) Received: from mga06.intel.com (mga06.intel.com []) by groups.io with SMTP; Sat, 01 Jun 2019 01:03:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jun 2019 01:03:46 -0700 X-ExtLoop1: 1 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.82]) by fmsmga008.fm.intel.com with ESMTP; 01 Jun 2019 01:03:44 -0700 From: "Zeng, Star" To: devel@edk2.groups.io Cc: Star Zeng , Laszlo Ersek , Eric Dong , Ruiyu Ni , Chandana Kumar , Kevin Li Subject: [PATCH 1/2] UefiCpuPkg CpuCommFeaturesLib: Disable TraceEn at the beginning Date: Sat, 1 Jun 2019 16:03:40 +0800 Message-Id: <20190601080341.107760-2-star.zeng@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190601080341.107760-1-star.zeng@intel.com> References: <20190601080341.107760-1-star.zeng@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1809 Current code disables TraceEn at the end of ProcTraceInitialize(), then there will be much memory allocated even when ProcTrace feature is disabled. This patch updates code to disable TraceEn and return at the beginning of ProcTraceInitialize() when when ProcTrace feature is disabled. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ruiyu Ni Cc: Chandana Kumar Cc: Kevin Li Signed-off-by: Star Zeng --- .../Library/CpuCommonFeaturesLib/ProcTrace.c | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c index da6f6beb9477..b98eb116b7b6 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c @@ -199,22 +199,6 @@ ProcTraceInitialize ( ProcTraceData = (PROC_TRACE_DATA *) ConfigData; ASSERT (ProcTraceData != NULL); - MemRegionBaseAddr = 0; - FirstIn = FALSE; - - if (ProcTraceData->ThreadMemRegionTable == NULL) { - FirstIn = TRUE; - DEBUG ((DEBUG_INFO, "Initialize Processor Trace\n")); - } - - /// - /// Refer to PROC_TRACE_MEM_SIZE Table for Size Encoding - /// - MemRegionSize = (UINT32) (1 << (ProcTraceData->ProcTraceMemSize + 12)); - if (FirstIn) { - DEBUG ((DEBUG_INFO, "ProcTrace: MemSize requested: 0x%X \n", MemRegionSize)); - } - // // Clear MSR_IA32_RTIT_CTL[0] and IA32_RTIT_STS only if MSR_IA32_RTIT_CTL[0]==1b // @@ -243,6 +227,26 @@ ProcTraceInitialize ( ); } + if (!State) { + return RETURN_SUCCESS; + } + + MemRegionBaseAddr = 0; + FirstIn = FALSE; + + if (ProcTraceData->ThreadMemRegionTable == NULL) { + FirstIn = TRUE; + DEBUG ((DEBUG_INFO, "Initialize Processor Trace\n")); + } + + /// + /// Refer to PROC_TRACE_MEM_SIZE Table for Size Encoding + /// + MemRegionSize = (UINT32) (1 << (ProcTraceData->ProcTraceMemSize + 12)); + if (FirstIn) { + DEBUG ((DEBUG_INFO, "ProcTrace: MemSize requested: 0x%X \n", MemRegionSize)); + } + if (FirstIn) { // // Let BSP allocate and create the necessary memory region (Aligned to the size of @@ -459,11 +463,7 @@ ProcTraceInitialize ( CtrlReg.Bits.OS = 1; CtrlReg.Bits.User = 1; CtrlReg.Bits.BranchEn = 1; - if (!State) { - CtrlReg.Bits.TraceEn = 0; - } else { - CtrlReg.Bits.TraceEn = 1; - } + CtrlReg.Bits.TraceEn = 1; CPU_REGISTER_TABLE_WRITE64 ( ProcessorNumber, Msr, -- 2.21.0.windows.1