Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2470427rda; Wed, 25 Oct 2023 03:54:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEetX9nQU7BHCg8uNyuartDEf0bDh2CgSTHSeLY2cUo9B0TR/n/VjJJajdlR1dvtEN7pqsy X-Received: by 2002:a81:48c9:0:b0:5a7:ba02:9c9a with SMTP id v192-20020a8148c9000000b005a7ba029c9amr16909402ywa.2.1698231289592; Wed, 25 Oct 2023 03:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698231289; cv=none; d=google.com; s=arc-20160816; b=GJ/GmiRl5fCs56JXhKv62wSXzBKPaPj7u0lGUPUOoEWjYh6GiE2dT4sACvkJYcdfB9 sJ5BPMoRC5QN47x6P0WrcM0AYeCp1p6+A1/VNTtvpSc/Lz9ho5Z4PggPiZC00u7VKHvp iIlsfa9KBvl3GD57Yy+tVLa8djxg8T6JeLUqMKvkGeJ40H/JPOs0gaoJ3cwmDSUer4r0 aZyQZHL37WQMkuj9VhHhQ5ZTvbBiu4GfbzZtnJIHsV7Gp82RQ44LxNhozQzeki7xpkQS tM549qBNB4THer27OIEqEDhx3tsHwgFYrU/crUepY1/IXRl7xOSFJ2cO9erE7g1hJeU9 aGbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=iTkhvRiF8QlemacpZMmcKLJz3PjBmTHndSBK/6Xhh84=; fh=RhXqtdGm40bKf7FRoFgxIsrGORYltF07tFYRacCwg98=; b=aHr6XKeIAML3B/vqisOPeBONRvRxfGt+gno8UVmfxxahTy6u4pUQJW1rJjWXjahSAF 87WDo/4n79hVnFwfGgrLAoLpLWoz1OCzgJCjOC27KkWuut9CHcukx1MwT0xWeXbdj0S0 jVEVt0FO6XG3TZLUKGmNCLmNvIXj2L2zXjCG92R4PPXCJsHTChLgl+KU5p80yCtbEOGz yOrHHPaeXprImxEwE+zLyB3vfCsaF5dG2m0wSu98OSSQE+jI97QrEAMcv42C7z6/PIxy GIhOmnHAsCW2M2Sd1bwl3rYCgkGmzNpfsaDty/SXXJ09gMmw3YnEV/llSYEkAp8brOy6 Ui6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u140-20020a0deb92000000b00583b2eacc35si10619028ywe.264.2023.10.25.03.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 03:54:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 69B42802B3E1; Wed, 25 Oct 2023 03:54:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234811AbjJYKyj (ORCPT + 99 others); Wed, 25 Oct 2023 06:54:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234804AbjJYKyc (ORCPT ); Wed, 25 Oct 2023 06:54:32 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 824DD130; Wed, 25 Oct 2023 03:54:23 -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 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231025093847.3740104-3-zengheng4@huawei.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 03:54:45 -0700 (PDT) [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 >