From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9E1FC0032E for ; Wed, 25 Oct 2023 10:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0dMRjj2SoejtNKUfPaadASrgkqdQ2YI7/SeIhzgeZEE=; b=BMB0q0GpxQHEo7 lBC67ost7iNf51cXV5JbR6/VNu473kpQohIBF6+T6U40NjqaZrd+mg1xw/8FnHh6faQgkIjt+MnWK YWydjbcGXP21sq6J+W68SAppzH8QFy69UNQcewhTVmTC2CxpFlpyjOQe8RHRRCQWuJVFM5t7eHEtW b2uG49bSNfiTQZQenz+TWC1NoobRamv8Um5HSy6CY1bQbyENyJ7DstXrodEXmjqCB5un+sUo+NkdD pWgsHORTK//rneuwSzuyWOSxv6XlTVitMdpskqRK3lXZePhfdj2D19OIaZxp/e04yNwZn1dSqUj4h b8LhK4H+MfxTQabsi4OA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvbX1-00C7s7-06; Wed, 25 Oct 2023 10:54:35 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvbWy-00C7qb-0K for linux-arm-kernel@lists.infradead.org; Wed, 25 Oct 2023 10:54:34 +0000 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 1E9FB2F4; Wed, 25 Oct 2023 03:55:04 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.69.205]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EB5AF3F738; Wed, 25 Oct 2023 03:54:19 -0700 (PDT) Date: Wed, 25 Oct 2023 11:54:16 +0100 From: Mark Rutland To: Zeng Heng Cc: broonie@kernel.org, joey.gouly@arm.com, will@kernel.org, amit.kachhap@arm.com, rafael@kernel.org, catalin.marinas@arm.com, james.morse@arm.com, maz@kernel.org, viresh.kumar@linaro.org, sumitg@nvidia.com, yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wangxiongfeng2@huawei.com, xiexiuqi@huawei.com, Ionela Voinescu Subject: Re: [PATCH 2/3] cpufreq: CPPC: Keep the target core awake when reading its cpufreq rate Message-ID: References: <20231025093847.3740104-1-zengheng4@huawei.com> <20231025093847.3740104-3-zengheng4@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231025093847.3740104-3-zengheng4@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231025_035432_233675_23B3DFDC X-CRM114-Status: GOOD ( 21.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org [adding Ionela] On Wed, Oct 25, 2023 at 05:38:46PM +0800, Zeng Heng wrote: > 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_on_cpu() to trigger target CPU to > read self's AMU counters, which ensures the counters are working > properly while cstate feature is enabled. IIUC there's a pretty deliberate split with all the actual reading of the AMU living in arch/arm64/kernel/topolgy.c, and the driver code being (relatively) generic. We already have code in arch/arm64/kernel/topolgy.c to read counters on a specific CPU; why can't e reuse that (and avoid exporting cpu_has_amu_feat())? Mark. > > Reported-by: Sumit Gupta > Link: https://lore.kernel.org/all/20230418113459.12860-7-sumitg@nvidia.com/ > Signed-off-by: Zeng Heng > --- > drivers/cpufreq/cppc_cpufreq.c | 39 ++++++++++++++++++++++++++-------- > 1 file changed, 30 insertions(+), 9 deletions(-) > > diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c > index fe08ca419b3d..321a9dc9484d 100644 > --- a/drivers/cpufreq/cppc_cpufreq.c > +++ b/drivers/cpufreq/cppc_cpufreq.c > @@ -90,6 +90,12 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data, > struct cppc_perf_fb_ctrs *fb_ctrs_t0, > struct cppc_perf_fb_ctrs *fb_ctrs_t1); > > +struct fb_ctr_pair { > + u32 cpu; > + struct cppc_perf_fb_ctrs fb_ctrs_t0; > + struct cppc_perf_fb_ctrs fb_ctrs_t1; > +}; > + > /** > * cppc_scale_freq_workfn - CPPC arch_freq_scale updater for frequency invariance > * @work: The work item. > @@ -840,9 +846,24 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data, > return (reference_perf * delta_delivered) / delta_reference; > } > > +static int cppc_get_perf_ctrs_pair(void *val) > +{ > + struct fb_ctr_pair *fb_ctrs = val; > + int cpu = fb_ctrs->cpu; > + int ret; > + > + ret = cppc_get_perf_ctrs(cpu, &fb_ctrs->fb_ctrs_t0); > + if (ret) > + return ret; > + > + udelay(2); /* 2usec delay between sampling */ > + > + return cppc_get_perf_ctrs(cpu, &fb_ctrs->fb_ctrs_t1); > +} > + > static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) > { > - struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; > + struct fb_ctr_pair fb_ctrs = { .cpu = cpu, }; > struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > struct cppc_cpudata *cpu_data = policy->driver_data; > u64 delivered_perf; > @@ -850,18 +871,18 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) > > cpufreq_cpu_put(policy); > > - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0); > - if (ret) > - return 0; > - > - udelay(2); /* 2usec delay between sampling */ > + if (cpu_has_amu_feat(cpu)) > + ret = smp_call_on_cpu(cpu, cppc_get_perf_ctrs_pair, > + &fb_ctrs, false); > + else > + ret = cppc_get_perf_ctrs_pair(&fb_ctrs); > > - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); > if (ret) > return 0; > > - delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0, > - &fb_ctrs_t1); > + delivered_perf = cppc_perf_from_fbctrs(cpu_data, > + &fb_ctrs.fb_ctrs_t0, > + &fb_ctrs.fb_ctrs_t1); > > return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf); > } > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel