Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp566506rwr; Wed, 19 Apr 2023 10:00:27 -0700 (PDT) X-Google-Smtp-Source: AKy350aZXjpCg5KHBuZ2vF7L5v2X+pFxU4O8/dkfgYAUfmIxl0cbJLe7uwz7dldFdFjzXgc1H4Fq X-Received: by 2002:a17:903:245:b0:1a6:5333:bf6a with SMTP id j5-20020a170903024500b001a65333bf6amr6078435plh.12.1681923627246; Wed, 19 Apr 2023 10:00:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681923627; cv=none; d=google.com; s=arc-20160816; b=cqdA3EWeJ5tWW7bdOAfupMkVJ72xP73M55AZF9krCM1RwqHnoADCVQ48ZZ2xw8vr05 LuKjluEOgJqYCfy+kGp0djFoUAdXEyfKl+USEXZ7pUgf1y7qD2H0KMTOLbuI/3yHQtcS yTj8EiXcjAHLKW2nPGldYupOjE8DY72H6yAAyZBJnPo2c3fPsXMmD0tdC672Ts61GxA2 Wk3hRs3vWKykpqUOssI658Gw2jm/h8rJ+O/J4AEF9IfhMaMBbU5u07bwYT+HUZHidliX 0cck7qF2bPbTcZXpRYtSPFzKTcRifrqjFZPOCEXRo9TlqC2slFZCAXbnUBt74W3J7zK3 ObtA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=YeYhHcwKRGD9wISE0r2/vqaNH3z13x4+bBIhhgsNeCA=; b=hShnowRFbQr0szyUv0lgoBqav3fJx2lWQBqpye+qM9GbwG3KXJTBXVA3akZd1ttRaw 4qJnyMa9401R2cX0TKAjBovQtOTT1liHrYbIzQlyoWSeF4F9rPHp5L1ZczglZeoNdeL1 qukHh/K1xWbn1Isiif0wDG09r5ekpXJYCItKkPKN79pOiB5+5QVQTXlX2w1RMfAkJN59 k+fPhEUY0ISsCdV/HmOvfPX7ev7IvjI8gwsQzsZ35GVc7xqygUKjnOp8oRPE4nCVChSn t1kTKqWBiLv7/dFVyuLsncIfxtnEbArHDlSiVYurDO+WweeCzk+UyVuja6XYXoKznJTx YjkA== 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 c18-20020a17090abf1200b002475b063d35si2122669pjs.142.2023.04.19.10.00.11; Wed, 19 Apr 2023 10:00:27 -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 S233266AbjDSQxG (ORCPT + 99 others); Wed, 19 Apr 2023 12:53:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232378AbjDSQxF (ORCPT ); Wed, 19 Apr 2023 12:53:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 42996BB; Wed, 19 Apr 2023 09:53:04 -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 BAD741424; Wed, 19 Apr 2023 09:53:47 -0700 (PDT) Received: from [192.168.1.12] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BE86F3F5A1; Wed, 19 Apr 2023 09:53:02 -0700 (PDT) Message-ID: <41ae3b9e-c774-5061-b045-d5ec2a658880@arm.com> Date: Wed, 19 Apr 2023 18:52:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH] cpufreq: CPPC: use 10ms delay instead of 2us to avoid high error Content-Language: en-US From: Pierre Gondois To: Yang Shi Cc: viresh.kumar@linaro.org, scott@os.amperecomputing.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" References: <20230328193846.8757-1-yang@os.amperecomputing.com> <4bda6b02-cc50-fa47-c9b6-acda4cf201a8@arm.com> <195c95b2-f47c-f3d0-5663-97dd4c929ea4@arm.com> <3e239024-91d8-ea06-25a4-631496576319@os.amperecomputing.com> <7b57e680-0ba3-0b8b-851e-7cc369050386@os.amperecomputing.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 > > Just 2 other comments: > a- > It might be interesting to change the order in which cpc registers are read > just to see if it has an impact, but even if it has, I m not sure how this > could be exploitable. > Just in case, I mean doing that, but I think that b. might be better to try. > > diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c > index c51d3ccb4cca..479b55006020 100644 > --- a/drivers/acpi/cppc_acpi.c > +++ b/drivers/acpi/cppc_acpi.c > @@ -1350,8 +1350,8 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) > } > } > > - cpc_read(cpunum, delivered_reg, &delivered); > cpc_read(cpunum, reference_reg, &reference); > + cpc_read(cpunum, delivered_reg, &delivered); > cpc_read(cpunum, ref_perf_reg, &ref_perf); > > /* > > b- > In the trace that you shared, the cpc_read() calls in the fist > cppc_get_perf_ctrs() calls seem to always take a bit more time than in the > second cppc_get_perf_ctrs() call. > Would it be possible to collect traces similar as above with 3 or 4 calls to > cppc_get_perf_ctrs() instead of 2 ? It would allow to check whether in the first > call, accessing the cpc registers takes more time than in the following calls, > due to cache misses or other reasons. > Ideally statistics on the result would be the best, or if you have a trace.dat > to share containing a trace with multiple cppc_cpufreq_get_rate() calls. > > Example of code where we do 4 calls to cppc_get_perf_ctrs(): > > diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c > index 022e3555407c..6370f2f0bdad 100644 > --- a/drivers/cpufreq/cppc_cpufreq.c > +++ b/drivers/cpufreq/cppc_cpufreq.c > @@ -853,6 +853,20 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) > > udelay(2); /* 2usec delay between sampling */ > > + ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); > + if (ret) > + return ret; > + > + udelay(2); /* 2usec delay between sampling */ > + > + /* Do a third call. */ > + ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); > + if (ret) > + return ret; > + > + udelay(2); /* 2usec delay between sampling */ > + > + /* Do a fourth call. */ > ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); > if (ret) > return ret; And also, if the cpc_read() calls in the third/fourth call are actually faster, would it be possible to check whether the computed frequency is more accurate (i.e. no over/undershoot) ?