Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp743735imn; Tue, 26 Jul 2022 08:10:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vSYVyd229dtKCPbC8o4iq/Ba0wRi6Q486EpGB1C+Z+sVDM1mWHbq9qRjyicp4qctSJgEZH X-Received: by 2002:a05:6402:358a:b0:43b:ce8f:df00 with SMTP id y10-20020a056402358a00b0043bce8fdf00mr18987291edc.219.1658848202707; Tue, 26 Jul 2022 08:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658848202; cv=none; d=google.com; s=arc-20160816; b=GBopgU5ld7KnPYvLkFkUuUcRRnpR7LFa0aghZjHRONZnpos5VSgATcWPNuAddqXnSH 3jC5tdzT43DisUMiX6+UfJhXgwUYzELGnUQPmPtcee2OUmHWwlOXRPcagHMyDHLwX8Af 2rvmWRpCag7a8SS9ttvbCSshQ0LuDftMWy/E+HSXPMjlpsGe+KWcthvFHn0ZUJdtW0SZ h0w7Y5xuqIMWssmjPMkdTh5BDwAMxwfWFp+VFoKtwf0h74gwgfOLNb/jXZlIqcE43oyO 9mVZCKKVuUH0RpE0R4cALD/UkEnJRlb658ardgbigcuvvTNypxjTFm/a4k8Y9VSWhfEU JA7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1NM1uGRqarZDaN0y/oUJo9vEM4vLrIBa+LrnEXa0sm4=; b=pcZAPXiHf6EbMMHwzzMz8NmO7MtM8+rmYool+TTqLX45rZMk6FEiutM3Nh1SlsxXLF ZjnvM0gjkRNNNkiun11nkjuTC5DsHn4ujG/wdf1+mNDFTjFQgi1x8PpWGdpRd7u588KM 9DxZrF55GG9aTihG7R1FyfwLmNUM+2IGr1MdU7ynloFyoTALafYT+Vbi3FE5G90o25TJ b0cuK6harWkhDNJjKN1Hz/4gdRQCG8lLJgWI4IPy+jjKWWxUMJRecmeeMT0Dv42uW87h QPfvPbONOxEXv5LQE3hPvlze74254zmoNlKXmUL+TJHVsdwtzM2i/skuU0h43OQZtL7i zUew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a056402355400b0043bea1ef410si7618313edd.394.2022.07.26.08.09.38; Tue, 26 Jul 2022 08:10:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239473AbiGZPAY (ORCPT + 99 others); Tue, 26 Jul 2022 11:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239184AbiGZPAW (ORCPT ); Tue, 26 Jul 2022 11:00:22 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A15B1DEB7; Tue, 26 Jul 2022 08:00:20 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0768D1FB; Tue, 26 Jul 2022 08:00:21 -0700 (PDT) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 49D633F73B; Tue, 26 Jul 2022 08:00:20 -0700 (PDT) From: Jeremy Linton To: linux-pm@vger.kernel.org Cc: rafael@kernel.org, lenb@kernel.org, viresh.kumar@linaro.org, robert.moore@intel.com, devel@acpica.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [PATCH] ACPI: CPPC: Disable FIE if registers in PCC regions Date: Tue, 26 Jul 2022 09:59:48 -0500 Message-Id: <20220726145948.2194684-1-jeremy.linton@arm.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PCC regions utilize a mailbox to set/retrieve register values used by the CPPC code. This is fine as long as the operations are infrequent. With the FIE code enabled though the overhead can range from 2-11% of system CPU overhead (ex: as measured by top) on Arm based machines. So, before enabling FIE assure none of the registers used by cppc_get_perf_ctrs() are in the PCC region. Furthermore lets also enable a module parameter which can also disable it at boot or module reload. Signed-off-by: Jeremy Linton --- drivers/acpi/cppc_acpi.c | 31 +++++++++++++++++++++++++++++++ drivers/cpufreq/cppc_cpufreq.c | 19 +++++++++++++++---- include/acpi/cppc_acpi.h | 5 +++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 3c6d4ef87be0..ad84c55b6409 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1246,6 +1246,37 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps) } EXPORT_SYMBOL_GPL(cppc_get_perf_caps); +int cppc_perf_ctrs_in_pcc(void) +{ + int cpu; + struct cpc_desc *cpc_desc; + struct cpc_register_resource *delivered_reg, *reference_reg, + *ref_perf_reg, *ctr_wrap_reg; + + for_each_present_cpu(cpu) { + cpc_desc = per_cpu(cpc_desc_ptr, cpu); + delivered_reg = &cpc_desc->cpc_regs[DELIVERED_CTR]; + reference_reg = &cpc_desc->cpc_regs[REFERENCE_CTR]; + ref_perf_reg = &cpc_desc->cpc_regs[REFERENCE_PERF]; + ctr_wrap_reg = &cpc_desc->cpc_regs[CTR_WRAP_TIME]; + + /* + * If reference perf register is not supported then we should + * use the nominal perf value + */ + if (!CPC_SUPPORTED(ref_perf_reg)) + ref_perf_reg = &cpc_desc->cpc_regs[NOMINAL_PERF]; + + /* Are any of the regs PCC ?*/ + if (CPC_IN_PCC(delivered_reg) || CPC_IN_PCC(reference_reg) || + CPC_IN_PCC(ctr_wrap_reg) || CPC_IN_PCC(ref_perf_reg)) { + return true; + } + } + return false; +} +EXPORT_SYMBOL_GPL(cppc_perf_ctrs_in_pcc); + /** * cppc_get_perf_ctrs - Read a CPU's performance feedback counters. * @cpunum: CPU from which to read counters. diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 24eaf0ec344d..a66d3013d0f8 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -63,6 +63,10 @@ static struct cppc_workaround_oem_info wa_info[] = { static struct cpufreq_driver cppc_cpufreq_driver; +static bool fie_disabled; +module_param(fie_disabled, bool, 0444); +MODULE_PARM_DESC(fie_disabled, "Disable Frequency Invariance Engine (FIE)"); + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE /* Frequency invariance support */ @@ -158,7 +162,7 @@ static void cppc_cpufreq_cpu_fie_init(struct cpufreq_policy *policy) struct cppc_freq_invariance *cppc_fi; int cpu, ret; - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + if (fie_disabled) return; for_each_cpu(cpu, policy->cpus) { @@ -199,7 +203,7 @@ static void cppc_cpufreq_cpu_fie_exit(struct cpufreq_policy *policy) struct cppc_freq_invariance *cppc_fi; int cpu; - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + if (fie_disabled) return; /* policy->cpus will be empty here, use related_cpus instead */ @@ -229,7 +233,12 @@ static void __init cppc_freq_invariance_init(void) }; int ret; - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + if (cppc_perf_ctrs_in_pcc()) { + pr_debug("FIE not enabled on systems with registers in PCC\n"); + fie_disabled = true; + } + + if (fie_disabled) return; kworker_fie = kthread_create_worker(0, "cppc_fie"); @@ -247,7 +256,7 @@ static void __init cppc_freq_invariance_init(void) static void cppc_freq_invariance_exit(void) { - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + if (fie_disabled) return; kthread_destroy_worker(kworker_fie); @@ -940,6 +949,8 @@ static void cppc_check_hisi_workaround(void) } } + fie_disabled = true; + acpi_put_table(tbl); } diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index d389bab54241..f4ff571fcdcb 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -140,6 +140,7 @@ extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs); extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); extern int cppc_set_enable(int cpu, bool enable); extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); +extern int cppc_perf_ctrs_in_pcc(void); extern bool acpi_cpc_valid(void); extern bool cppc_allow_fast_switch(void); extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data); @@ -173,6 +174,10 @@ static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps) { return -ENOTSUPP; } +extern int cppc_perf_ctrs_in_pcc(void) +{ + return false; +} static inline bool acpi_cpc_valid(void) { return false; -- 2.37.1