Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp151837rdh; Wed, 25 Oct 2023 20:22:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuRujL9lOGLPz0mWd+xsyPK0nTezpt7KbDMp+0SV9vWNPBs5PJ+AwYS47vLkjWjiEnMhJq X-Received: by 2002:a25:8186:0:b0:d81:5d5a:25a3 with SMTP id p6-20020a258186000000b00d815d5a25a3mr16851766ybk.43.1698290546981; Wed, 25 Oct 2023 20:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698290546; cv=none; d=google.com; s=arc-20160816; b=WNIAXTMPcApUpAKcZgdX0nymJNmf1UZNtrgHECyqWaxkHcWJF243VkgfzfEp21FIXi W/IKPj5uQl7C8NIeQi8JXOmmwhG48J5w5YXzL6z53LMIM/0uKK40yR5mNnHwecDe2iII TfkKsDm1nIW/ipRav+NYcg9wvq/nqdgr/I8Cln8cekwsBsrBmj2eckmtnaGXPqXUiVLm JOYVf9Yh81Tvlsrhc39I8zikmT5QrgM0UISv2s7SPlt8zQM5ezc3BZsWE9uAkAL3pdDM VpN0+8IqEKOvXhevXRga+1GflOXRlMMngs91tBXhlu9mlTjYc+iXdWY9O5XBrGIPo5/c zT+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=z+kQN+llB8uATfzPRupsc5VVE/5clDzcvgBdACsmHk8=; fh=wHg0t/mn/RwnR8AkbjfFUU1utLc2vsaghuMnnkeNdik=; b=jdbLvovLU9csQabMfd3bjqg3S6et2Tfs7Rtm4hJjApc0lnhzPhsVwRMxBHcBNPwsOr XFZsZHkvcStK2NqPV2biysu/YaeTKrQ66sjWQlrIASRsAXciaW8nrzvNN8BzkpZqYJGz zjOLKIrHSvvtMr/QhTE1VK0s2JAEQQWEYhcXWf+Hssd1yXe7UJ7efd03dFlimfRpJsll LBWejCS7U2+f2sA0T6cJKvq/x9jFXgWWLI+/c6i3sOnQ4qyQUZaXe0vFTKuYL+Q8BKZ0 wEtqpv1DA0wY/4PxYf/MtqXXiB9Z9DdSLIwyMeZ2TqqBSAtvDaLyFCJ9HHGGuau4ADha vd2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g35-20020a25ae63000000b00d9cb02219e1si12946487ybe.265.2023.10.25.20.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 20:22:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C4D1B819875C; Wed, 25 Oct 2023 20:22:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229954AbjJZDVn (ORCPT + 99 others); Wed, 25 Oct 2023 23:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjJZDVl (ORCPT ); Wed, 25 Oct 2023 23:21:41 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4682A3; Wed, 25 Oct 2023 20:21:38 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SG9w82X5qzVlNM; Thu, 26 Oct 2023 11:17:44 +0800 (CST) Received: from [10.174.179.163] (10.174.179.163) 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.31; Thu, 26 Oct 2023 11:21:35 +0800 Message-ID: Date: Thu, 26 Oct 2023 11:21:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 2/3] cpufreq: CPPC: Keep the target core awake when reading its cpufreq rate Content-Language: en-US To: Mark Rutland CC: , , , , , , , , , , , , , , , , Ionela Voinescu References: <20231025093847.3740104-1-zengheng4@huawei.com> <20231025093847.3740104-3-zengheng4@huawei.com> From: Zeng Heng In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.163] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500024.china.huawei.com (7.221.188.100) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 25 Oct 2023 20:22:24 -0700 (PDT) 在 2023/10/25 18:54, Mark Rutland 写道: > [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. In this scenario, both topology.c and cppc_acpi.c do not provide an API to keep the AMU online during the whole sampling period. Just using cpc_read_ffh at the start and end of the sampling period is not enough. However, I can propose cpc_ffh_supported() function to replace the cpu_has_amu_feat() as v2 if you think this patch set is still valuable. Thanks, Zeng Heng >> 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 >>