From nobody Fri Dec 19 13:55:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BFE4CA0FE1 for ; Fri, 1 Sep 2023 13:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349662AbjIAND3 (ORCPT ); Fri, 1 Sep 2023 09:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349610AbjIAND0 (ORCPT ); Fri, 1 Sep 2023 09:03:26 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47205E0 for ; Fri, 1 Sep 2023 06:03:23 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3ff7d73a6feso18807685e9.1 for ; Fri, 01 Sep 2023 06:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693573402; x=1694178202; 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=jBj2auLlUAXmJtm0JLBXBgA7sNg7bnkhJEMz0GdiTZI=; b=OpK4JaCciL5TRL2pawG/VmQ8Jdds1w2k8OeopaJ/tilLw+/YIJqEoh7PyKYrzSHBNP 1ed2IdIpZ/eI5oFahFSwshrTxJNvovEjUUrrFbHBWg+HoXHettVV5zZ44DMlcyabng8M 39ZqV5TYraxwOsvPuqUMnicMoXvIPAjseghcabVIw+f5UA3fOBa9ynuLukGnDp6BYEO5 RdG4gBzPb+hYTs5jz+5Ec5RmrcX/9Olow8iVhxp4NhW2KxOumnlUMLKD1KG6MCnsd2fk XceG41egOaQIT7RTvxmyXM/aZBGf99nJUzsxu9Ff1BcFRESd3Hw4VVcjCJ9eb+WMEjnG 4NYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693573402; x=1694178202; 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=jBj2auLlUAXmJtm0JLBXBgA7sNg7bnkhJEMz0GdiTZI=; b=b5q4ghJimWZ/w2Mq384IeIJ/EQX5GmtaPf+HaHPGR1D5cHDK3RpVmRubY5Fr62+mtT mbBEK2P+FgPczhOKcM1utSl2Mj2ysmVJxbOvje4SmoNw7nEA7cqrVl2YgpQWxvF9nrDC 45LVbzaglvVMNAzhgMRmVzxcKXCtMpJdpV00kMYiaMZGqxRbrc60kOhE1ckkdJhqEioq 4nE9Btm35Gpnvf7M3vEj/wM7Nb+XxzTMM2JZ3IvNi7ZVSalw/aqOPAuJx44EmjZYcGt/ PJoF59yW9byq+Bvme2tTwL5nN5Fb9SkYqQW+0/yy8L2zEb059zsMRspYqqnIlsmu1JSn 27+g== X-Gm-Message-State: AOJu0YzC+i5k2n3IY4IhQUaGdXGrYynJZ2vMpmomRstWVl1Wyupyw4Lh 8BS2M6xU5ns5kJizbDffaxKnUg== X-Google-Smtp-Source: AGHT+IEQD39cpHWbAVr3Bfe0Bk2YZV7G5Wbn5InEVXtG214GUwMtcEYoELLPBmdXYyGWOssaBv1Vxw== X-Received: by 2002:a05:600c:234a:b0:401:bd95:2e02 with SMTP id 10-20020a05600c234a00b00401bd952e02mr1551706wmq.39.1693573401777; Fri, 01 Sep 2023 06:03:21 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:e9bd:add1:d9ac:7b3e]) by smtp.gmail.com with ESMTPSA id i14-20020adfdece000000b003142e438e8csm5167452wrn.26.2023.09.01.06.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:03:21 -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, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH 3/4] cpufreq/schedutil: use a fixed reference frequency Date: Fri, 1 Sep 2023 15:03:11 +0200 Message-Id: <20230901130312.247719-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901130312.247719-1-vincent.guittot@linaro.org> References: <20230901130312.247719-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cpuinfo_max_freq can change at runtime because of boost as example. This implies that the value could not be the same 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 frequency reference that can be used when computing a frequency based on utilization. Use this arch_scale_freq_ref() when available and fallback to cpuinfo.max_freq otherwise. Signed-off-by: Vincent Guittot --- kernel/sched/cpufreq_schedutil.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedu= til.c index 4492608b7d7f..9996ef429e2b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -114,6 +114,31 @@ static void sugov_deferred_update(struct sugov_policy = *sg_policy) } } =20 +#ifdef arch_scale_freq_ref +/** + * arch_scale_freq_ref_policy - get the reference frequency of a given CPU= that + * has been used to correlate frequency and compute capacity. + * @cpu: the CPU in question. + * + * Return: the reference CPU frequency. + */ +static __always_inline +unsigned long arch_scale_freq_ref_policy(struct cpufreq_policy *policy) +{ + return arch_scale_freq_ref(policy->cpu); +} +#else +static __always_inline +unsigned long arch_scale_freq_ref_policy(struct cpufreq_policy *policy) +{ + if (arch_scale_freq_invariant()) + return policy->cpuinfo.max_freq; + + + return policy->cur; +} +#endif + /** * get_next_freq - Compute a new frequency for a given cpufreq policy. * @sg_policy: schedutil policy object to compute the new frequency for. @@ -139,11 +164,11 @@ static void sugov_deferred_update(struct sugov_policy= *sg_policy) static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned long util, unsigned long max) { + unsigned int freq; struct cpufreq_policy *policy =3D sg_policy->policy; - unsigned int freq =3D arch_scale_freq_invariant() ? - policy->cpuinfo.max_freq : policy->cur; =20 util =3D map_util_perf(util); + freq =3D arch_scale_freq_ref_policy(policy); freq =3D map_util_freq(util, freq, max); =20 if (freq =3D=3D sg_policy->cached_raw_freq && !sg_policy->need_freq_updat= e) --=20 2.34.1