From patchwork Fri Oct 27 08:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13438205 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A1C3C25B67 for ; Fri, 27 Oct 2023 08:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GSraL0nOBL7SA0IK50I6u8je3CP1KomsnoqczUxocPU=; b=xqZVn7HSeoit10 arDlAFfr0l3kyF39HqNcf4PBWH4P3sjoETub91QFDMYdFJ8UYPm7CpAOIpH9I6hXsf9+wRsnYL885 DK92+VOjwGn1aJHEKOzxnN36r5CzSLgdcHEN2O65m5My7J1xVxWPPBRpcxYxntIFPyx+BfxoZa7hG Zk9GF8XMn7pqTNeI8IuNjOmZ+lJy9nu8akpUINoC6jb16uxzPoB1kOoRvYEBRwucixzirCW77b34P LwiZzQfJ11DOs44NRG3GZDm/aRrjnkdqjqHEseQzeK0MypP3xkSnzciIDW/qMfhBZQpLAyXt+7IXO 2lTyLUKW1n0eDAxVJnyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qwHpj-00FsbV-0m; Fri, 27 Oct 2023 08:04:43 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qwHpF-00FsHw-1d for linux-arm-kernel@lists.infradead.org; Fri, 27 Oct 2023 08:04:15 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40859c46447so12255945e9.1 for ; Fri, 27 Oct 2023 01:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393851; x=1698998651; darn=lists.infradead.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=dSBNSdhUUZqc2Qsa/vWUie4JzPq1MZxdRrVYaDQGW4IwtWzM5aaatlUH8hY5IcG9p1 mjAF5MFWMwiI8RZqQkaqWA18KMmLz1MQEX9rFhY2OT5IdWsJyChnE9B+XJvSJ5yEBOym eLYPxvdiBgR8n4uFy1ZoGep/FrHuN0S7O6EVtaMF00Q8z7uAD4cvUtsoQjTdItiUynj6 9fg8iIQYcxRYi5rbX8oh0TxZmjb2TiqAjetlQWTTfI/QjlGnjywWZ/62DN0LKVDAEv5l LJhabx9u8ZWmAzjJG+FEdE7d+P1CWo/n6Q8s9fXrqns3n+RViMRLIsv+ksOqh00cwEK9 2p8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393851; x=1698998651; 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=pWbAQtf/UVIg3lyQDdo/Q7SvxKMLAnm32/MOb8DhV2OYOJcc1sYu/nXld8BkTCTtuK fA185D6F4Bg+O2BxbR9JD8o8zulSimBrJnXXopF5tNNPYgxd8DNH4LcesTVx+LV/7rZj JRcZfPh3/dW8iEh8rIFS3EH/YmzbS7IVa1Li7xwC+VWmaxb2mnxgtsMn1aqQmdpl7clt bkFMUVw7fUfGl5rKSLWj58mvkrO5VLjbk9RtUoGjY/1/6L3Y8WY6f+fjUWS8WP5B++TJ OKiwTDzitTaRRjp1U9nOZ7sl0ckt2WutRze+dvzGo+yT3OuQVE0VQb7FpJs+SrSlBt/U O4Ww== X-Gm-Message-State: AOJu0Ywp6QtqscCf2D4jyct4WwJ6Orkx/6S381ROAJhZKch1Iy5mWoMb MEK2Qn2c14q5LFkkWSoXBotAow== X-Google-Smtp-Source: AGHT+IHHJHw9trOJbFgvgeyKGPFkJl88ylA+IM/8RiCtB8m/EeKXjTdIKw4FH7YnjB4Tz158dwBttg== X-Received: by 2002:a05:600c:3594:b0:405:4daa:6e3d with SMTP id p20-20020a05600c359400b004054daa6e3dmr1555522wmq.39.1698393851126; Fri, 27 Oct 2023 01:04:11 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:10 -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, 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, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 3/7] cpufreq/schedutil: use a fixed reference frequency Date: Fri, 27 Oct 2023 10:03:56 +0200 Message-Id: <20231027080400.56703-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231027_010413_543149_FB954B00 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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)