Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp820616rwl; Fri, 31 Mar 2023 02:56:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZMwL8c3J0LOL/7LTMEY21p6RKfYrkweBr1UOEJAZTmo/T6JC40SNsN6D7ExaHMtayAJvpx X-Received: by 2002:a17:902:ea01:b0:1a2:175a:6153 with SMTP id s1-20020a170902ea0100b001a2175a6153mr5643992plg.1.1680256572782; Fri, 31 Mar 2023 02:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680256572; cv=none; d=google.com; s=arc-20160816; b=VJ5KlxDu5WZ0r/zn3GfiuPkdCPmm/3ZBNgTj/OVqVzJC+TencTDZp10JNfTT9NZEt9 ygYTDZ+kNf7Cc90/eJcYVLKVc3LOI0BgIHWyB1I8xMy/XjKZETAY9ZKwHZcKQtZmgYC+ w1jnxisXVj2AkwC8cG/AMp6DmSPPW12IdbI+e0XPIegNV7U802FG/jvxJUrz4yN4a4UE e4nNWIbLqiI3uEQg13KrXbgEYa3CoNqaAzMYyN75b1x+5XYvyg019TJsCWXM0fRPGYkC ehZ1Zn3Xems1qGqQabtOPD+XpAq6opwc7Gq3fTUtE9+BGXoYx0bNSBTBTcrHKANcM/xp Xeow== 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=LiY18fWKoEYSxBqAxHs8cN7FJuIx+CRb2Vcyp7ZFOTA=; b=kTxuJ/eoGwBXio+/2raIAjNF+t9RsS7DJyAKqIH1qwlevuh7PO/5k3jwnbt0OD4ae5 l6uFVSKh5VF2e/06mRFmsshRQwQvpCUJge1PW64SWSK8Pzeo6YXREcgJ0yq7PBBiROAZ NUgFGI0fn05fmFATSq+NlK1sq/4LalTVz9X/13PEkfhRogMdKM8GVCvP+egFS2kzQPLH eQCaq+AMznDmng6sxAhpOCQ/uyYiTombnGqxTBm9YnVkMqVZrCj7T+9DziCdamZ03hBT ANKk7T7l5vW+MITzXqTfkazZBg7Fl4bZEllAXD7t82BZgrX2vGRYa5E3mUYlYoXdwJmO H9rg== 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 i31-20020a63221f000000b00502ee712648si2002305pgi.578.2023.03.31.02.56.01; Fri, 31 Mar 2023 02:56:12 -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 S230171AbjCaJzL (ORCPT + 99 others); Fri, 31 Mar 2023 05:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231672AbjCaJyZ (ORCPT ); Fri, 31 Mar 2023 05:54:25 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE3B0C648; Fri, 31 Mar 2023 02:53:44 -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 D7B692F4; Fri, 31 Mar 2023 02:54:28 -0700 (PDT) Received: from [10.57.20.151] (unknown [10.57.20.151]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8DB743F6C4; Fri, 31 Mar 2023 02:53:42 -0700 (PDT) Message-ID: Date: Fri, 31 Mar 2023 11:53:25 +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 To: Viresh Kumar , Yang Shi Cc: rafael@kernel.org, scott@os.amperecomputing.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, vincent.guittot@linaro.org, lukasz.luba@arm.com, ionela.voinescu@arm.com References: <20230328193846.8757-1-yang@os.amperecomputing.com> <20230330035612.ekh2lpqzohggg6uf@vireshk-i7> From: Pierre Gondois In-Reply-To: <20230330035612.ekh2lpqzohggg6uf@vireshk-i7> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Hello, On 3/30/23 05:56, Viresh Kumar wrote: > + few folks. > > On 28-03-23, 12:38, Yang Shi wrote: >> When testing CPPC cpufreq on our platform, we noticed the error may be quite >> high and the high error may happen quite often. For example, on a platform >> with a maximum frequency of 2.8GHz when the CPUs were fully loaded (100% load), >> we saw cpuinfo_cur_freq may show 4GHz, it means the error is > 40%. And the >> high error (> 1%) happened 256 times out of 2127 samples (sampled every 3 >> seconds) in an approximate 2hrs test. >> >> We tried to enlarge the delay, and tested with 100us, 1ms and 10ms. The >> below is the results. >> >> 100us: >> The highest error is 4GHz, 22 times out of 3623 samples >> >> 1ms: >> The highest error is 3.3GHz, 3 times out of 2814 samples >> >> 10ms: >> No high error anymore >> >> Increase the measurement delay in cppc_cpufreq_get_rate to 10ms to avoid >> high measurement errors. >> >> Signed-off-by: Yang Shi >> --- >> drivers/cpufreq/cppc_cpufreq.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c >> index 022e3555407c..c2bf65448d3d 100644 >> --- a/drivers/cpufreq/cppc_cpufreq.c >> +++ b/drivers/cpufreq/cppc_cpufreq.c >> @@ -851,7 +851,7 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) >> if (ret) >> return ret; >> >> - udelay(2); /* 2usec delay between sampling */ >> + mdelay(10); /* 10msec delay between sampling */ >> >> ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); >> if (ret) >> -- >> 2.39.2 > Just 2 considerations: - When using the schedutil governor, frequencies should be updated with a period of cppc_cpufreq_get_transition_delay_us(). This period should be 1ms if CPPC doesn't rely on PCC channels, otherwise the value depends on the PCC channel (cf. cppc_get_transition_latency()). If the evaluation duration for the perf/ref counters is higher than this period, I think this would mean that multiple frequency update would happen while trying to evaluate the current frequency of a CPU. - There is a TimeWindowRegister field in CPPC (cf. enum cppc_regs::TIME_WINDOW and ACPI 6.5 s8.4.6.1.2.5 "Time Window Register") that should approximately match what this patch aims to solve. """ When Autonomous Selection is enabled, values written to the Time Window Register are ignored. Reads of the Time Window register indicate minimum length of time (in ms) between successive reads of the platform’s performance counters. """ The only issue being that we should be in the case where Autonomous Selection is disabled, where the description of the register is different. Regards, Pierre