From mboxrd@z Thu Jan 1 00:00:00 1970 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 B183BC79FB9 for ; Thu, 10 Sep 2026 06:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xU/TVU9R6QqVQBU8DMj4Dr025QCTEz1Y5w5z0voxEUA=; b=xcU/JNTa3vBQK+Ix3YWkzKNTq7 xTOnc0rfdGjpYB3M/CdekXtCnuL+9t3QPg/suc58sG72LD3ksT4S3RR5952tvjdYWh0eUPDn26Yfi bNlqq9rpMDYV0SUooOMfzBD5pdqjvp5mZ7nfj8/k9kpGMPOFwoLbkVanqbcOBbNQK+GriEbkT9ObJ GXq0l9Nq/VLcjbWAqxcmten8rbcMC568f5Z9Dgafb56hjvNS0INkQBqvUGam4nS4C6f/sZxJcXdu/ NQGAqjCMDaIL0htM2TZM7pUGO5/6dlEf3N7ijQR7oyi6vsHDH5ijpAkKvL55Q2sZuHsaRgxhcpr5u W1pT8fOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4YNL-0000000DWsN-0Jq5; Thu, 10 Sep 2026 06:35:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4YNH-0000000DWpG-030f for linux-arm-kernel@bombadil.infradead.org; Thu, 10 Sep 2026 06:35:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=xU/TVU9R6QqVQBU8DMj4Dr025QCTEz1Y5w5z0voxEUA=; b=W/RsWfwzEJR6yfo3v63pYf97iR DtPjMrjUmMHkWxjypAf+ygPxZcWJupDIeq8RO5FDEDKUXAEBicfRnb+B/2yFetnEvhRQCH8/uB+7l sMtqoRujAkqL6Q7RE4bjw6xfciPbWywxMt/aw2eM/jJAvgttGf2pErHIkw8F4GnT/vfB27JT9Vmbp C23jVjGxFXgVrXhumzaltSc8Zv0gOLXCf9UUXyt4xMnDaeOEUhPm8JxohpLL3mhYm8URpyErye0xZ b9NEB58bs9iYYGBUiCl/TUXh/FwF9gVz3W+cY+8WkuCNwI39YLjQnEarpoq1F5tE2EldxZTWFdoAj Nayoj98Q==; Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by desiato.infradead.org with esmtps (Exim 4.99.2 #2 (Red Hat Linux)) id 1x4YNE-000000025D5-053j for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2026 06:35:05 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4995b0343c1so91491455e9.3 for ; Wed, 09 Sep 2026 23:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789022102; x=1789626902; 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:content-type; bh=xU/TVU9R6QqVQBU8DMj4Dr025QCTEz1Y5w5z0voxEUA=; b=dyXF9G92hXu7yEiyfdlcsSyte6+2OspRFMH5ca/IYRbb0wIXpGPi5L3gLa2/3qqodN MPGFkFHq9qyRZ2oTsfUyuEIW5iX+osw6cm6Q8T8KINmmTe4bTNYk0eJGpgbyKCd/s5O6 j5cwHm+i4lndQGCN2r6A3IonvEB6yX8sERap0XYL/SSfNz5+L9fnNepBI8VE/Brh7T2h qaUntER2BKQPmMoUDk0qqsQPDxVIkijud0cQeh0tEIz8DM6A67mrRS4lOFkg6Nejf5n4 DAv4dLMJJEBfg1w3M39IkAQ3THpPHXx3VpM6kXrF65EUvD5QlIiC7JmUtvHP89R2bo0v gviw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789022102; x=1789626902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xU/TVU9R6QqVQBU8DMj4Dr025QCTEz1Y5w5z0voxEUA=; b=LtFCdPLHzOxxfJ8WHyf1asNE5UBoI43dQmV6TPmlW1MuYmIrs84TzFsnSG9FM5bx/K M8pdwpSX4FXZV/ybNc15IiNEQdjyW0/GpEztLgcLvmGUT/Ywvm7s2omfAMFoGj9LAhpu HjJHFz0LwsZlzU0mM8B3YfFom4xRK2d0Zz0V4GFhI1cRNX3jrFvSdbkQ7pzI8GdyA/Cv axK7hGLPkhYodLfh0QtTqJWAkBtnvzlPVYhYuBvqsD3Mpe3qSAm0GM7mdN8UfulasYn1 P7XBCaZxUe77wz0clbohuVHCNExUoo7r6WBoRkLbox38LAOHFTl+HbOIwbBteBNRg8Hv qHcg== X-Gm-Message-State: AFuF++ltKiCRQmr0+P5nAl8BnKmtWVQRyp0rddfoGydTcb6MC/WZY/3o N7k8m0Nhtsr6Sx9iMDZpwpwBoz1wfAZajNKmhc91vqcaX84XoRy3Dex2 X-Gm-Gg: AYBFou2SdpfICJf6DaDPDOIXm7nWk28NAEzMRGrDeuKHILV6P0Ss+qTmjaWdM4+M45O Ie7TqfCG6rvEynHokAEC+FV/yvU83LqPGqll4XSoDTdbRm3E3YBqrbwblfy0/3it1cB4RuEv3Kd si9tNI5p/upHfPE2wNjY9XbWctJ3Sz4ToZkgqKXmwvDrM+fSNyLuICJY3Z5jkIcCDXZuCVKdOxk uinejl6M97Rq8ptsh8H30Sh9ZckJcTeSCR4Q8RYBNYndOkOtBZEVjUfYpb5SzAil/Fv4oECpjD0 k6FUhoJcfMdcJQncvsXbY3RDXsK4+z/hoYdY9F30giFb27wcdCIX0OS1cy8avLVjMXGF3BUbMFb NOVw5aI68y7+ChuVZ68KpRJAXZTsGE8CcFaAnl39df6fnKOdqJpiMTWbqkpwLlNbxbm4kjzSDf4 IrVDyFHAbSKDsLJhDPJ+wjiSQhOMukU9DhMyrNBLoFm6akkuyupoUU9wKxXh5JvX1Nu2ImTf4xR O3G9X7MLnIDl9kFHeYGrvA88hYEc1sU4WzNvVfEiBc= X-Received: by 2002:a05:600c:8b05:b0:49c:edd2:855 with SMTP id 5b1f17b1804b1-49cf823c411mr418633405e9.6.1789022102030; Wed, 09 Sep 2026 23:35:02 -0700 (PDT) Received: from localhost.localdomain (mob-31-26-103-238.net.vodafone.it. [31.26.103.238]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49e2212193esm2595255e9.1.2026.09.09.23.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 23:35:01 -0700 (PDT) From: Oleg Keri To: Catalin Marinas , Will Deacon , Mark Rutland , Sumit Gupta , Prasanna Kumar T S M , Beata Michalska , Russell King , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Viresh Kumar Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, driver-core@lists.linux.dev, linux-pm@vger.kernel.org, jonathan.cameron@oss.qualcomm.com, sibi.sankar@oss.qualcomm.com Subject: [PATCH v3 2/2] cpufreq: update capacity_freq_ref when the boost state changes Date: Thu, 10 Sep 2026 08:34:40 +0200 Message-ID: <20260910063440.4677-3-okerixx@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260910063440.4677-1-okerixx@gmail.com> References: <20260910063440.4677-1-okerixx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260910_073504_261305_2B0E5961 X-CRM114-Status: GOOD ( 20.87 ) 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 capacity_freq_ref is latched from policy->cpuinfo.max_freq by init_cpu_capacity_callback() on CPUFREQ_CREATE_POLICY, and never updated afterwards. cpufreq_frequency_table_cpuinfo() excludes CPUFREQ_BOOST_FREQ entries while boost is disabled, so on a system that boots with boost off the latched value is the non-boost maximum. Enabling boost later raises policy->cpuinfo.max_freq but leaves capacity_freq_ref behind. Two things then go wrong on arm64, where the AMU drives frequency invariance. amu_scale_freq_tick() caps the computed scale at SCHED_CAPACITY_SCALE, so a CPU running above capacity_freq_ref saturates at 1024: the scheduler cannot tell a boosted CPU from one at the sustained maximum, and utilisation is underestimated. And arch_freq_get_on_cpu(), which reverses that computation, cannot report more than capacity_freq_ref, so cpuinfo_avg_freq is pinned to the non-boost maximum. On a Snapdragon X2 Elite (Glymur) laptop with a 4032000 kHz sustained and a 4723200 kHz boost OPP, cpuinfo_avg_freq reads exactly 4032000 while the CPU runs at 4723200; a fixed workload completes in 1.72 s rather than the 2.01 s that frequency would imply. Factor the update out of init_cpu_capacity_callback() into topology_update_freq_ref() and call it from policy_set_boost(), which is the common path for the global boost knob, the per-policy one, and the CPU online path. Signed-off-by: Oleg Keri --- arch/arm/include/asm/topology.h | 1 + arch/arm64/include/asm/topology.h | 1 + arch/riscv/include/asm/topology.h | 1 + drivers/base/arch_topology.c | 19 +++++++++++++------ drivers/cpufreq/cpufreq.c | 2 ++ include/linux/arch_topology.h | 1 + include/linux/cpufreq.h | 7 +++++++ 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h index ad36b6570067..a776a79885ee 100644 --- a/arch/arm/include/asm/topology.h +++ b/arch/arm/include/asm/topology.h @@ -11,6 +11,7 @@ #ifndef CONFIG_BL_SWITCHER /* Replace task scheduler's default frequency-invariant accounting */ #define arch_set_freq_scale topology_set_freq_scale +#define arch_update_freq_ref topology_update_freq_ref #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant #define arch_scale_freq_ref topology_get_freq_ref diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/topology.h index b9eaf4ad7085..a4b96a7ee4a5 100644 --- a/arch/arm64/include/asm/topology.h +++ b/arch/arm64/include/asm/topology.h @@ -22,6 +22,7 @@ void update_freq_counters_refs(void); /* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_tick topology_scale_freq_tick #define arch_set_freq_scale topology_set_freq_scale +#define arch_update_freq_ref topology_update_freq_ref #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant #define arch_scale_freq_ref topology_get_freq_ref diff --git a/arch/riscv/include/asm/topology.h b/arch/riscv/include/asm/topology.h index fe1a8bf6902d..a363d72c174f 100644 --- a/arch/riscv/include/asm/topology.h +++ b/arch/riscv/include/asm/topology.h @@ -11,6 +11,7 @@ /* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_tick topology_scale_freq_tick #define arch_set_freq_scale topology_set_freq_scale +#define arch_update_freq_ref topology_update_freq_ref #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant #define arch_scale_freq_ref topology_get_freq_ref diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 8c5e47c28d9a..79eb1681065d 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -317,6 +317,18 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) return !ret; } +void topology_update_freq_ref(const struct cpumask *cpus, unsigned int max_freq) +{ + int cpu; + + for_each_cpu(cpu, cpus) { + per_cpu(capacity_freq_ref, cpu) = max_freq; + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); + } +} +EXPORT_SYMBOL_GPL(topology_update_freq_ref); + void __weak freq_inv_set_max_ratio(int cpu, u64 max_rate) { } @@ -392,7 +404,6 @@ init_cpu_capacity_callback(struct notifier_block *nb, void *data) { struct cpufreq_policy *policy = data; - int cpu; if (val != CPUFREQ_CREATE_POLICY) return 0; @@ -403,11 +414,7 @@ init_cpu_capacity_callback(struct notifier_block *nb, cpumask_andnot(cpus_to_visit, cpus_to_visit, policy->related_cpus); - for_each_cpu(cpu, policy->related_cpus) { - per_cpu(capacity_freq_ref, cpu) = policy->cpuinfo.max_freq; - freq_inv_set_max_ratio(cpu, - per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); - } + topology_update_freq_ref(policy->related_cpus, policy->cpuinfo.max_freq); if (cpumask_empty(cpus_to_visit)) { if (raw_capacity) { diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 96515880b4ac..a70805a1d9d3 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -594,6 +594,8 @@ static int policy_set_boost(struct cpufreq_policy *policy, bool enable) return ret; } + arch_update_freq_ref(policy->related_cpus, policy->cpuinfo.max_freq); + return 0; } diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index ebd7f8935f96..4974f5e1a7fe 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -31,6 +31,7 @@ static inline unsigned long topology_get_freq_scale(int cpu) void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq, unsigned long max_freq); +void topology_update_freq_ref(const struct cpumask *cpus, unsigned int max_freq); bool topology_scale_freq_invariant(void); enum scale_freq_source { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 35ce665edfd8..5b904e13eb21 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -1235,6 +1235,13 @@ void arch_set_freq_scale(const struct cpumask *cpus, } #endif +#ifndef arch_update_freq_ref +static __always_inline +void arch_update_freq_ref(const struct cpumask *cpus, unsigned int max_freq) +{ +} +#endif + /* the following are really really optional */ extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; extern struct freq_attr cpufreq_freq_attr_scaling_boost_freqs; -- 2.55.0