From patchwork Mon May 15 10:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 682000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 860B9C7EE24 for ; Mon, 15 May 2023 09:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238325AbjEOJ3C (ORCPT ); Mon, 15 May 2023 05:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238321AbjEOJ23 (ORCPT ); Mon, 15 May 2023 05:28:29 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B7C32130; Mon, 15 May 2023 02:27:49 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QKYnK6gKpzTkGJ; Mon, 15 May 2023 17:23:01 +0800 (CST) Received: from huawei.com (10.175.124.27) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 15 May 2023 17:27:46 +0800 From: Zeng Heng To: , , CC: , , , , , , Subject: [PATCH 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate Date: Mon, 15 May 2023 18:00:03 +0800 Message-ID: <20230515100005.3540793-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500024.china.huawei.com (7.221.188.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org As ARM AMU's document says, all counters are subject to any changes in clock frequency, including clock stopping caused by the WFI and WFE instructions. Therefore, using smp_call_function_single() to trigger target CPU to read self's AMU counters, which ensures the counters are working properly during calculation. Signed-off-by: Zeng Heng --- drivers/cpufreq/cppc_cpufreq.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 022e3555407c..169af7ff9a2a 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -837,29 +837,31 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data, return (reference_perf * delta_delivered) / delta_reference; } +static void cppc_get_perf_ctrs_smp(void *val) +{ + int cpu = smp_processor_id(); + struct cppc_perf_fb_ctrs *fb_ctrs = val; + + cppc_get_perf_ctrs(cpu, fb_ctrs); + + udelay(2); /* 2usec delay between sampling */ + + cppc_get_perf_ctrs(cpu, fb_ctrs + 1); +} + static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) { - struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; + struct cppc_perf_fb_ctrs fb_ctrs[2] = {0}; struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); struct cppc_cpudata *cpu_data = policy->driver_data; u64 delivered_perf; - int ret; cpufreq_cpu_put(policy); - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0); - if (ret) - return ret; - - udelay(2); /* 2usec delay between sampling */ - - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); - if (ret) - return ret; - - delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0, - &fb_ctrs_t1); + smp_call_function_single(cpu, cppc_get_perf_ctrs_smp, fb_ctrs, 1); + delivered_perf = cppc_perf_from_fbctrs(cpu_data, fb_ctrs, + fb_ctrs + 1); return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf); }