From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702F0134A5; Tue, 16 Jan 2024 00:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UJAQ9izY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B89B7C433F1; Tue, 16 Jan 2024 00:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705363766; bh=E80ZqvypKZgAiKoQd+KTe0rB7tWMiiHrKbQ0B4NTSEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJAQ9izYnE3DZhFWSA4RJUkGcjHFBX1xmzGFfXvP1c3g8XHa230P9C+7ZpHbF+c7H xtBOtsVPWNMlBkSnf68Efp9+kN8k4xEF+Hs89mYHT7sOhaH9BWxw3ZM+7YVAnBmRmN Rw6X9Bc5HA4BFdG1puf0NiJ+9F+IHPI//tFEoxYlRD8kxgSfz39U1b2khIx0dPnfON kkipgsFsR0n2CUHG5oMhyKnU/0vGHqD32Fh5h/Da1RrAl6KymY4Ug8dP5DNs82R2KF p6qiKbjIxivetN7jU09MZyFHDQ6VNhozdtwzDCiQmpGVFDlDlqxFYtKHFecW4Rwj62 ocdONC5lThQlQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vincent Guittot , Ingo Molnar , Lukasz Luba , Dietmar Eggemann , "Rafael J . Wysocki" , Viresh Kumar , Sasha Levin , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 5/6] cpufreq/schedutil: Use a fixed reference frequency Date: Mon, 15 Jan 2024 19:09:00 -0500 Message-ID: <20240116000909.212520-5-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116000909.212520-1-sashal@kernel.org> References: <20240116000909.212520-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.12 Content-Transfer-Encoding: 8bit From: Vincent Guittot [ Upstream commit b3edde44e5d4504c23a176819865cd603fd16d6c ] 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 Signed-off-by: Ingo Molnar Tested-by: Lukasz Luba Reviewed-by: Lukasz Luba Reviewed-by: Dietmar Eggemann Acked-by: Rafael J. Wysocki Acked-by: Viresh Kumar Link: https://lore.kernel.org/r/20231211104855.558096-4-vincent.guittot@linaro.org Signed-off-by: Sasha Levin --- 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..7f6c9874a200 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,9 +162,9 @@ 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; + freq = get_capacity_ref_freq(policy); util = map_util_perf(util); freq = map_util_freq(util, freq, max); -- 2.43.0