Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp987824rdh; Fri, 27 Oct 2023 01:04:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYCgJ6sBRh/FsgIT4qitCGPxr5CFmP9C60s07qKZUPnyS7I6MiH29tXFOMnq/h9NbddAaw X-Received: by 2002:a25:595:0:b0:da0:3972:a062 with SMTP id 143-20020a250595000000b00da03972a062mr1666003ybf.39.1698393872931; Fri, 27 Oct 2023 01:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698393872; cv=none; d=google.com; s=arc-20160816; b=vnLIFXMbww/MehSTXfP8BMPVjMroo4cxR9afOO+v5TS3a2NWRUKh6gv2Xj7P2AOL8l Mv96ovUKXMkHyc32CevYZM/RIJAX6GF0WvBNy1ou6JV1Px4rvOKKBkHWI4+HEojTDEK7 EMfppXhk22eDG3UuCVYoSaOhpkATsM2dtE2Dy4NVwtTiGgRaggSPaVm+eutXyv9gT/3e Afqj42eEn/oMIa1O3vhhy8mfYr4vzVN58Iu0AeDhh1EUt61FTbZY3nP2Q6hEq9+EGNdX GkcNIC4Cb+wlzAxdnoG0Lh1pYJ2MNZ0unW68+MlPB8RSUZRChdYX691x5d492nHux15a zNcQ== 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=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=kTikxRI0NkQZ1WHkncf6fl4zBpEDwX48uugTKJ+vISm1U6qZSOxEW6Qnptl4kTIFMM 9pGW3rCf9rvmAUnfOqwFBeVUsVA5HS7NAq2pKmgq6Qvxk/0P9p4ZtVmMbuP0KPsKP8dQ VD3X0wCuecnOcv1YzsWc+cdL7qqclc/AJojZMZi2kUvknRN+QomHvPzqSUyzpku2NGF9 0iwXtwiF7x8LDg0ukYjOCAbBaN1MZbE413DRg/dhRX+J81qmbDyWH0AooOZXRu1M4Y6R rdM9OcrEOl0d8wtIbM69V6rGR/5jwJolmRRH/9urJVCA/u4YPy+TD4441NcUInfpb/22 KP+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L24RwGMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e69-20020a253748000000b00d8470acdee0si1847274yba.674.2023.10.27.01.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L24RwGMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id A78F382B484B; Fri, 27 Oct 2023 01:04:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235100AbjJ0IEY (ORCPT + 99 others); Fri, 27 Oct 2023 04:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjJ0IEQ (ORCPT ); Fri, 27 Oct 2023 04:04:16 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13EF31B9 for ; Fri, 27 Oct 2023 01:04:13 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40859c46447so12255935e9.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=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=L24RwGMHA181FTA5H2iJVIE6oJBGLqBWg85c0yDhYhDgZ9Ox9Hc1ORQ7rO0MXisXlL 0gDMH/x0sTlJQINhM/UOCAIxOmENsXtaySZKUDbDbWabcZqTlVqEmMywfmSRiuebHLwF 4yNZajeH7zjRYQArVx5+D+fHTOTrhCyNHlvarxz5n/o7CFvnPubPdSGuhWViWJ5BKugn E70mGdjeQx2nEWovHP81d3oULXEYupE9mopY2Kzx1YHA7B2EOaxPe8tyBEGLAzjIWmWE RerpeqIsAz94yMRTE3jbOEmJAU4Zz4D0A/lcE5xRtd9ITvtFNhUIFZa0z6W5vI7EWPLy cZTg== 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=b8Vfzi6sYDTI/ahRc/6WiIMEPW8urF32NNYQLMKiYksWu0jjmvQy9dvQZiv8gRO9RV zN7W/rpZeMZb87IViJyW/ByTYR2zmQOPYQgZR3cxX1wqWswm7EnHMRHmgK/Ce22tizpa 2NQrbnMRpcdlcIfrh4SrE/1jFdjuTLA0wQxY1XQ2+iH/tjTHbbRRHxf7LfeuZ50MrinQ nv+UqbXZUyY6ePryOZfhwdoDre+FGnTopNztHgQLoNd3EBTeXQ+AJBw7hHfftgzywQ6V lI1I15QzFfvdD6qsLhmZA9AXpqC4Bi7VkFY+5hGosS+fHsRdx51hqcJjT5QegfH8rlIb iueA== X-Gm-Message-State: AOJu0YyGE/v6xhtK9fBVrEOsbjcLSk5u8BAR6F8dbNgezvVAkmx0QBwI CL6Ky1nLGpu9KXtOnBUBwAod+w== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:04:31 -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