Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1024009rdf; Sat, 4 Nov 2023 03:59:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGmb9kfIc5A3enm16YvPNueEMCpxt0DSF61DjflGhT5HR4c+WO6OD9VnnTABt4VjB/9cuf X-Received: by 2002:a05:6a00:2356:b0:6c3:4c72:8b81 with SMTP id j22-20020a056a00235600b006c34c728b81mr6049846pfj.3.1699095580290; Sat, 04 Nov 2023 03:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699095580; cv=none; d=google.com; s=arc-20160816; b=sQMd+ZczrzPNewiW8IlMsJGOXkdo3mYuJxP9aq+QegUPBicT5gMC7E8i73Ur3PWYzd 5Hwp9x3jlHtq8f+TFOvh4/+erpySGBxwAvskCRhuej1z1D2jFGky0i+Eg1Sn2Ydg+ykS ts0ILCSTtlQB171TSZQ99xWaqd0Aj1A/VwbuD0VoEkQeMUg3N7u6hQo8J3fUV3IPJ3H7 gLb1t2IoqRTFUhCFGXho8KP10kB/4w5jPchxGPnr8hZgAG6rVQSx+N8szhdLIxcO0c9h AR3oOfAsf7CeNssNt+nUMWWIuFIl+FUORP5MTHdeoIawPjtfaEXAdnfAUqdTf55160Qn /bdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; fh=L/x1gaxbgFaXxO89heY0nsloKarclpkg/B6XUTvdMKw=; b=ypw/QjAvkAzN9R/VwfwaPeVKN4zRxI5091CQ6JjXcnyS5q+HqhacMLiw/tdBdAFUcY uVwf/+0A3UkMg+S4E2UQhR3UC6Euq+ceRgXq8NVTpau+dscLb5+XvEVQe9ZLH383qXO2 obKb2vrLnGbwms/R0oq/hM8FKW7DahKgk2TCGPB/1g5+Lrg3PNlr4xRQsp7snAYhLNED uZ9ebB+uSU+NHC+Pz2ifxKgI9SJIOkqwLKS8QfFt1gPPOSvHw1KGoVp81R/erOnlxHkO VIe1/68+u0tibY3pIO0R9OV5Qf8h356KgVKz87jRNrYiOkLpEaNCVRU1JrgR92llAOKh 7GmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="vU3YRG/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id g5-20020a656cc5000000b00565ecee8793si3724289pgw.875.2023.11.04.03.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 03:59:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="vU3YRG/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0E3E080295E2; Sat, 4 Nov 2023 03:59:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232009AbjKDK70 (ORCPT + 99 others); Sat, 4 Nov 2023 06:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232003AbjKDK7V (ORCPT ); Sat, 4 Nov 2023 06:59:21 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B15DD4E for ; Sat, 4 Nov 2023 03:59:18 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40836ea8cbaso20963695e9.0 for ; Sat, 04 Nov 2023 03:59:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699095556; x=1699700356; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; b=vU3YRG/y1EFkg/c24C+73H0U0uDXnUJmgDFM8DAJj2XemHxuh5ExcFMi1rOhf5lyDb OfbDNiNROLZnYOBvRtqkHQeDokNPyDzT4MEJn5/UzqSjQvdd8nAl0ZyJJyFpGrny9Chb ujo+4JtjVlYJDJ9BqKY9rMEKPvhBP1s1+8fQVR2xZmGp/dnF4aIdEVcXSWay5guP9Rk8 i6VZQqIKfo2EtS+My3f/rHLrLPMitZIqC/uV7mORn2jrZntYqV86xruhpp7vbALyoJp+ O8xIGVVCcTCDgm4z4Uccc91YFUQhtVSeBcoPGH1kePB+xk/bj6fkInpor0YWIrtDVgk/ iiHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699095556; x=1699700356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; b=BSouWaeziksWXvKPDAMv2L0FYMK5cWC9SE3S5bu5BxxRyc35CBtcICsVo8bvRBzwSZ 8A4Y9uohaTYYhipY63eIvti3EHIoHRyNK/AO1iExGNbb9LcTWJG9uWQMCtMD9okyMt5+ lbHiUDjapLrPIDN+e6/d9Q7/cFR4tadnTvZVFK9r0DrkrmVCakihXte9buAy7EcOnEP7 LCFEzConvhjAM+oXO2Tz+l5Y1PB7hNwehu/s7oMXa8WDVvbIFhjRggq6p5DCiOBaEGZu s/XoKNXVasMuG7yEdQAdnFhMSoIsFDDzPL8hmfZdgTVlNEShEnB8z/sfkZVr3H4XU7MP HX+w== X-Gm-Message-State: AOJu0Ywn3uTEQ6U4Kx/AckzJ+NijCnIwzAbAq3OyhSv9uy6M+6PNtinq C/BMDpqTp6ugFwgEoz+3gH8mAQ== X-Received: by 2002:a05:600c:470e:b0:408:4f50:9602 with SMTP id v14-20020a05600c470e00b004084f509602mr20968669wmo.12.1699095556439; Sat, 04 Nov 2023 03:59:16 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:3172:eb13:5bac:126a]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b004053a6b8c41sm5315809wmq.12.2023.11.04.03.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 03:59:15 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, beata.michalska@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v5 3/7] cpufreq/schedutil: Use a fixed reference frequency Date: Sat, 4 Nov 2023 11:59:03 +0100 Message-Id: <20231104105907.1365392-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231104105907.1365392-1-vincent.guittot@linaro.org> References: <20231104105907.1365392-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sat, 04 Nov 2023 03:59:36 -0700 (PDT) cpuinfo.max_freq can change at runtime because of boost as an example. This implies that the value could be different than the one that has been used when computing the capacity of a CPU. The new arch_scale_freq_ref() returns a fixed and coherent reference frequency that can be used when computing a frequency based on utilization. Use this arch_scale_freq_ref() when available and fallback to policy otherwise. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Acked-by: Rafael J. Wysocki Reviewed-by: Dietmar Eggemann --- kernel/sched/cpufreq_schedutil.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 458d359f5991..f3a87fa16332 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -114,6 +114,28 @@ static void sugov_deferred_update(struct sugov_policy *sg_policy) } } +/** + * get_capacity_ref_freq - get the reference frequency that has been used to + * correlate frequency and compute capacity for a given cpufreq policy. We use + * the CPU managing it for the arch_scale_freq_ref() call in the function. + * @policy: the cpufreq policy of the CPU in question. + * + * Return: the reference CPU frequency to compute a capacity. + */ +static __always_inline +unsigned long get_capacity_ref_freq(struct cpufreq_policy *policy) +{ + unsigned int freq = arch_scale_freq_ref(policy->cpu); + + if (freq) + return freq; + + if (arch_scale_freq_invariant()) + return policy->cpuinfo.max_freq; + + return policy->cur; +} + /** * get_next_freq - Compute a new frequency for a given cpufreq policy. * @sg_policy: schedutil policy object to compute the new frequency for. @@ -140,10 +162,10 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned long util, unsigned long max) { struct cpufreq_policy *policy = sg_policy->policy; - unsigned int freq = arch_scale_freq_invariant() ? - policy->cpuinfo.max_freq : policy->cur; + unsigned int freq; util = map_util_perf(util); + freq = get_capacity_ref_freq(policy); freq = map_util_freq(util, freq, max); if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) -- 2.34.1