From patchwork Mon Oct 9 10:36:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13413361 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 7E486E95A91 for ; Mon, 9 Oct 2023 10:37:12 +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=OIAug7eIey8i4SWNg3I23UqM/GLtXQ/5NqP/6LcYiok=; b=OVvxeJE2OWwqT0 7cxCsnklpNXTVWE22t8D1K62eEUwi7GJMeS0HqijIc3VTl2tH6/rYvAKzv/cCvHVJlqTRzH10UNsI oXZNwdMIrm3L5BKIyhgu/Yy/2/vgszGoAz3SRMk+ohob+WfVp02NYNQAoQaBmuRR4MDQFBStxqsGs l7uj7PZFvRuZ1L0s86EAXaQntXBQolWF7rEovkDABpvLtdN6IPnjVPzZnWkgxgQjNzeGGnpwOXX8D UYwqlkIWXM9XvoLFJ0s5KwH0EqEEta7xqNL8zpwFBcuSRNFaaLfdW5WLgVYbQmyc3bsNZ11nwn/LX taEiXFcthU4EYAAJoorw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpncw-00AFdo-21; Mon, 09 Oct 2023 10:36:42 +0000 Received: from mail-wm1-f50.google.com ([209.85.128.50]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpnco-00AFT2-0J for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 10:36:36 +0000 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4054f790190so42143735e9.2 for ; Mon, 09 Oct 2023 03:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696847791; x=1697452591; 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=RmtdGUvSawQ4q9KDGPlbeId1/iTLhEjjDMVIwSogQm4=; b=vRd2l2xDOutOSvMlsfJP4VTrYCE4uXv1W7P1pbhrJEwXIFu8Bqo6wwd+eV44Q4JVR1 q1J6u7exm5UGQu35ILJmNiJN3Faw15s/XT+WhQgxJ3nevq/Eg37ItCc6DGzCItr3OQB6 cUhv4eLZVld7A7chozt6I2QxBqbXv3gpVV+MoLQSZjamc/hCYqeIOwg89XQJ4tcJT0vC XQpHH1Y8fuIM5KrORoXNw0CWLWJ+vNfEVNLy3xvhONBSSda3pzJUMt+pN9bj4bJS5uqV CR9gNJARIXbp14grko0C2kudWBUlYBvLJfcWU2TABaVSFT2uhRs3FalrnE1uewW9WQ52 2XuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696847791; x=1697452591; 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=RmtdGUvSawQ4q9KDGPlbeId1/iTLhEjjDMVIwSogQm4=; b=NVuVHrbG8JKmVKq2AuyJr5IMacvqHKzX0jlawTiLQz8QygmwlDka8ujX7qLmN1ezEx MqK0PmLhq5yGPSyj7hgn4Mou+SdGGevz8TkjTOWg0bG13oqdBV41/CaZjPa/FOoS9Aol ncLr8B9E3EE5QHdbhjFhclOrcGczn8yjSp0GLKkpL4fZMTD8+mXOUjlNyjAQ2VRdLaoV HddtaZisLY+Bow3kS96cpWpX/oRmnAmHJeR6Q/O0hv4LS+HNyy51OkVCuehoRQmfUx+F rjW+7IuaikMEQ1Vw+q2O3p1FI1AKeKSaX1EMfOVRbM302CWsKEPt2Y9+0Shle0FBaDQT Kelg== X-Gm-Message-State: AOJu0YwbbY9yG/Se913CsoyQRXDz22ya9HNaic+mvt9L7BdB0TqbmmyW kECXlOLfUwVPc1M/J+S+3T3cuw== X-Google-Smtp-Source: AGHT+IFsDHg/Rs8MQPYQNA1a7DXBKSokGpRKvXSJgz2PNurvi4j34eIaCQtgEUCXe0uK4YQzK2pDKA== X-Received: by 2002:a05:6000:91:b0:320:67:5580 with SMTP id m17-20020a056000009100b0032000675580mr12443168wrx.5.1696847790816; Mon, 09 Oct 2023 03:36:30 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:53f1:24bc:5e47:821d]) by smtp.gmail.com with ESMTPSA id f16-20020adfdb50000000b0031ff89af0e4sm9226722wrj.99.2023.10.09.03.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 03:36:30 -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, 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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v2 4/6] cpufreq/schedutil: use a fixed reference frequency Date: Mon, 9 Oct 2023 12:36:19 +0200 Message-Id: <20231009103621.374412-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009103621.374412-1-vincent.guittot@linaro.org> References: <20231009103621.374412-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-20231009_033634_168884_A75468E5 X-CRM114-Status: GOOD ( 16.03 ) 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 --- 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 4492608b7d7f..1fa7e74add8f 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) } } +/** + * cpufreq_get_capacity_ref_freq - get the reference frequency of a given CPU that + * has been used to correlate frequency and compute capacity. + * @policy: the cpufreq policy of the CPU in question. + * @use_current: Fallback to current freq instead of policy->cpuinfo.max_freq. + * + * 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)