From nobody Fri Sep 25 02:43:03 2026 Received: from mail-wm2-f13.google.com (mail-wm2-f13.google.com [74.125.225.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD8C3672AF for ; Thu, 17 Sep 2026 12:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649499; cv=none; b=N8LOcfOaFW+e8mYCX2lbaLhhpj/yfXHr+Vel3F49Nh4Nwzg8Xu3Cmyd4Nfoo6IK/CNcD8/OoqQndUJ/S9YJvEZpV9YjLlexAl5uQGuuCOkopRB8ZUAI2S1rj5qWM6TSXQXEp2/VXU8Zd9aNy3z1Om3gspqcKW85E+895xLcmzCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649499; c=relaxed/simple; bh=9OmuWBvelp9lDciabV7GiixARHZSbiIlS541rWDiTO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WwaYEhI8KKnAKQsrqk6MA+xaaoc+RRIqgPuZlHE6o5f0hDDLuPrXZuIdmJjnh9WLT1ibP7fU89K8h0CE9u86XY8R4H7iZKT+LFC9LwMZojnib5Dc/S/cSUFwNey2o6JZeAJlIYZSuAdIaemkfu0PSyxDhQaN8c1VL/MP4uDiQ2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KKMaJNC3; arc=none smtp.client-ip=74.125.225.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KKMaJNC3" Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49e6b885ef8so4605055e9.1 for ; Thu, 17 Sep 2026 05:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789649483; x=1790254283; 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:content-type; bh=fsBJ75Nos/JKeIDPM3xGBy+cj9I+X9kBPg+21akMtHI=; b=KKMaJNC3+nMMzTXrk0Voqe2C5agN2WlPyUOLErXVRdqxyTS9n8RgiDXAWxq7XE8VD9 NOGncy26u5LOKxKpXD95GzRkhW2IC4TcKFIRAR5o2DFvXmoclk5uaqfSgQJTWb7/Am74 uXAcgBZqb4e7mLA3HCnaW44ms1t7WMILYFLDC5I+BF9l0fJOBKzhBlRE2peHYtypaw9G s1KzvZ3KDGLS/PajzTZYD9iIbs7EsQKQRh/+7MRD4xYzJyzDiPJID3O2RPmM1XzJ/7M0 k0+7oGYBxqCEMfLZG6s7qfFAzXLKOQymFGQ+dstAdmSk7Uzr0gJA19/oUulqW/+KlgT9 Eqnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789649483; x=1790254283; 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=fsBJ75Nos/JKeIDPM3xGBy+cj9I+X9kBPg+21akMtHI=; b=vjk67jdf8gSafz1FwwVlvshsssZsDtYm3gpQ/ZNkXgrjFuyA7uAKiFWjnqb8tsozfe rjiEGgdap9LQQ1gMqoy/4etly+IuWeLX+PIf0ui86lsxYCHXPLFE+sLKHcloeXSIuh5G Zr2xGrtIryfDoXr+axXHIJU4Tqzpu58wqbL9j9MXssZjcPERTwVrzFEQL/vCzraa9Utl 69pn3ONloOSYXMvSK/0cXmm0Z0vHCjmy+sCzgKSNaBG3wIUzNZ6B+2dhyzt/eQT6CAM9 KZmErKmtZkoa6zh30ff9bpbg4RISdCMtFQF7EnRif/dpLCkvFVhWEBvV99A6/4f5t+NB xpsQ== X-Forwarded-Encrypted: i=1; AKwUvBxlJ1jPOulOHQs1V+rc0+5vxwxZEqxRyr9XKDbcLUqmBi62riiXVyHISBpt+RznlX+nhXIDojDpBG/XssA=@vger.kernel.org X-Gm-Message-State: AFuF++ncp1suqevXOVb7B5pRCWf3RLyHdk6ZP22zDCnVNELFyyCKY0aM EHJ+kCM7JDuWFFlIGP1Bexbjiw/5ARB0jl14m+Tsk/4yJgmHW4/qTZ/D X-Gm-Gg: AYBFou3SaX2+0S4SUnqYqtppNumgB//EKxGM4c1O1N+II61/etsfR7l3HvZrfiqNMel mwxGFtMbAj4MYf/NKqkeP8qHzx/CVbCFwjh6zZ6kgKgkq4HIib+D+Y8qVS2WyHW24GAe6cA837I PI814Ld7V4Sp3QOQZNQR9Re9ul5NKuRBt9IpasmUgIMKEfj+sEQ+GnNIpO4S3y2DJ0qtIBwD5Ev hhzslZ8yX/HM9A4F2s59zulanRpyZMUrANuuyhFvV3gL/8HPQeL0wpwv/XUC88MJsUqHZ/lpWkh /cmPSkQ8ey5UOUsnKJ8gpJxPvPAkpzGipHlVYBF3bAmvy3BJxh38y3r6ca+BdSNCxLRN/Zvhogc 4Pw6wXU2oLsFs5vx6rhCE5bPu9tgA1e//UHVjLMPIf0lAqoTvB1YSNmrILKkhkwk5BxQ6uQyCsz +dc/wrhxB/NfucrxSn6dW9L40IiW+2xTuqY8QDMkmWKQHmV8zAEZsfZdtM+O3horeX8YGjjRkYl sExuy7O X-Received: by 2002:a05:600c:83c9:b0:49e:7caa:e7b2 with SMTP id 5b1f17b1804b1-49eb733800amr66060375e9.29.1789649483005; Thu, 17 Sep 2026 05:51:23 -0700 (PDT) Received: from localhost.localdomain ([94.252.75.113]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49fbd204d89sm86555015e9.3.2026.09.17.05.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 05:51:22 -0700 (PDT) From: Oleg Keri To: Catalin Marinas , Will Deacon , Mark Rutland , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Sumit Gupta , Beata Michalska , Prasanna Kumar T S M , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH v4 1/2] arm64: topology: fix arch_freq_get_on_cpu() overflow above 4.19 GHz Date: Thu, 17 Sep 2026 14:51:11 +0200 Message-ID: <20260917125112.2283-2-okerixx@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917125112.2283-1-okerixx@gmail.com> References: <20260917125112.2283-1-okerixx@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" arch_freq_get_on_cpu() computes the product of the frequency scale and the reference frequency as a u64, but assigns it to an unsigned int before shifting it back down: freq =3D scale * arch_scale_freq_ref(cpu); freq >>=3D SCHED_CAPACITY_SHIFT; The product is truncated to 32 bits before the shift, so the result wraps once arch_scale_freq_ref() exceeds 2^32 / SCHED_CAPACITY_SCALE, i.e. 4194304 kHz. On a Snapdragon X2 Elite (Glymur) laptop, whose boost OPP is 4723200 kHz, cpuinfo_avg_freq reports 524283 kHz instead of ~4723200 kHz while the CPU demonstrably runs at the boost frequency: a fixed workload completes in 1.72 s at the 4723200 kHz OPP versus 2.01 s at 4032000 kHz, matching the 1.171 frequency ratio. Use cap_scale(), which the scheduler already has for exactly this capacity scaling, so the multiply and the shift stay in 64 bits and only the final value is narrowed by the return type. Move the macro from the scheduler's private header to so it can be used outside kernel/sched. Fixes: 16d1e27475f6 ("arm64: Provide an AMU-based version of arch_freq_get_= on_cpu") Signed-off-by: Oleg Keri --- arch/arm64/kernel/topology.c | 5 +---- include/linux/topology.h | 2 ++ kernel/sched/sched.h | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index d28438f8b83f..07b8c497c9e6 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -186,7 +186,6 @@ int arch_freq_get_on_cpu(int cpu) struct amu_cntr_sample *amu_sample; unsigned int start_cpu =3D cpu; unsigned long last_update; - unsigned int freq =3D 0; u64 scale; =20 if (!amu_fie_cpu_supported(cpu) || !arch_scale_freq_ref(cpu)) @@ -245,9 +244,7 @@ int arch_freq_get_on_cpu(int cpu) * (see amu_scale_freq_tick for details) */ scale =3D arch_scale_freq_capacity(cpu); - freq =3D scale * arch_scale_freq_ref(cpu); - freq >>=3D SCHED_CAPACITY_SHIFT; - return freq; + return cap_scale(arch_scale_freq_ref(cpu), scale); } =20 static void amu_fie_setup(const struct cpumask *cpus) diff --git a/include/linux/topology.h b/include/linux/topology.h index 709a2dcf4c73..0a4ee12a98d5 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -351,4 +351,6 @@ static inline unsigned long topology_get_cpu_scale(int = cpu) =20 void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity); =20 +#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT) + #endif /* _LINUX_TOPOLOGY_H */ diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 6c3ad70e58b8..45796fccdc84 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -236,8 +236,6 @@ static inline int task_has_dl_policy(struct task_struct= *p) return dl_policy(p->policy); } =20 -#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT) - static inline void update_avg(u64 *avg, u64 sample) { s64 diff =3D sample - *avg; --=20 2.55.0 From nobody Fri Sep 25 02:43:03 2026 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430D8344DB7 for ; Thu, 17 Sep 2026 12:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649501; cv=none; b=MDlD7c9/CaNQNJ7iifKqraeAQzXDSYVAyWdtw9W2zIm2Ol5/nznmrq4r64AKKpUEaXhIc8clDu1R4ICZHhFPoyyX0AO3Why3SM9fFVVcIU1d6nqkKzVkYTdYsandI0QxXq7MzcypZD4XA/Cd6KxOdUxjZsxo4KjYXh/sCDkOyak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789649501; c=relaxed/simple; bh=EdyvNUGzZQfOCichJt6a2G8qG+Z+dq696yNIz94RDV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pNGmDaSjy4e+xxQ8MOJ2JkH2yOvyOOSPLLIeGRcEGjuA1g5tlJTGxq35sPdb6n1ZO9MFUJiOFYf5DX6oIKH760l3zNdopat/OV5oCFYoAO6yTQgZK5ioJzBAuT/xYKr0Bx4nwlz88OysZOyXBzGNR7rX8eubgnw6whQIVWELyI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lxOnDJqZ; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lxOnDJqZ" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b912e2406so4225455e9.1 for ; Thu, 17 Sep 2026 05:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789649484; x=1790254284; 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:content-type; bh=SuwmjuHNbGK5+6CI3MWKqt2Q2NhbCap9Z5LDmt81Ho8=; b=lxOnDJqZWJQ6rUn3e8fZTgqNyRiIZadguNCaYIQZdw9XJnL6c3wGngXimE3m9TvTqu Q89Gdbail7OHKTjI5eMDDOPOVbhlzFpDQz54d5VPPx1iBWbnBOBV7c5rpu/8fkCT8tC9 LtWcbI0ZEw43F2kX5OXG8o/NpLDX54bCQM64nCBOMNuaFEnEDaDIzqVH7zMMho3dkGH2 C8npca9FkmH3cMfaYbgVW8WALx3KjHAvWhqEp9LevTtYn40ZJsTeHMt1BSkVq4newc6b tw+vrSw6Aagu+urT8vYSEKZf/j9Hg+xNGBEDCrmA/qftUt8jVNOgaHG3pjykUrhhKR9Y tocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789649484; x=1790254284; 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=SuwmjuHNbGK5+6CI3MWKqt2Q2NhbCap9Z5LDmt81Ho8=; b=2eAi3W+JtxOPeHTPTxLwKusvoMvoV3ipDcCVgQ4dXp8Nj47QpfTTKWBw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cjL X-Received: by 2002:a05:600d:4442:10b0:49e:715d:95ca with SMTP id 5b1f17b1804b1-49fbd1e4f0amr32449375e9.13.1789649484234; Thu, 17 Sep 2026 05:51:24 -0700 (PDT) Received: from localhost.localdomain ([94.252.75.113]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49fbd204d89sm86555015e9.3.2026.09.17.05.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 05:51:23 -0700 (PDT) From: Oleg Keri To: Catalin Marinas , Will Deacon , Mark Rutland , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Sumit Gupta , Beata Michalska , Prasanna Kumar T S M , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH v4 2/2] arch_topology: use the boost frequencies for capacity_freq_ref Date: Thu, 17 Sep 2026 14:51:12 +0200 Message-ID: <20260917125112.2283-3-okerixx@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917125112.2283-1-okerixx@gmail.com> References: <20260917125112.2283-1-okerixx@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" capacity_freq_ref is latched from policy->cpuinfo.max_freq by init_cpu_capacity_callback() on CPUFREQ_CREATE_POLICY. cpufreq_frequency_table_cpuinfo() excludes CPUFREQ_BOOST_FREQ entries while boost is disabled, so on a system that boots with boost off the reference is the non-boost maximum and stays there. Once boost is enabled the CPU runs above its reference. On arm64, where the AMU drives frequency invariance, amu_scale_freq_tick() caps the scale at SCHED_CAPACITY_SCALE, so the scheduler cannot tell a boosted CPU from one at the sustained maximum, and arch_freq_get_on_cpu() cannot report above the reference, so cpuinfo_avg_freq is pinned to it. CPPC based systems do not have the problem: their reference comes from highest_perf, and a disabled boost shows up as cpufreq pressure. Do the same for frequency table drivers and take the highest valid table entry, boost entries included, as the reference. With boost off cpufreq_update_pressure() then reports the difference as pressure. On a Snapdragon X2 Elite (Glymur) laptop with a 4032000 kHz sustained and a 4723200 kHz boost OPP this moves the reference of the big cores from 4032000 to 4723200 kHz. Signed-off-by: Oleg Keri --- drivers/base/arch_topology.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 8c5e47c28d9a..300f64ffea2f 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -386,6 +386,20 @@ static cpumask_var_t cpus_to_visit; static void parsing_done_workfn(struct work_struct *work); static DECLARE_WORK(parsing_done_work, parsing_done_workfn); =20 +static unsigned int topology_policy_max_freq(struct cpufreq_policy *policy) +{ + unsigned int max_freq =3D policy->cpuinfo.max_freq; + struct cpufreq_frequency_table *pos; + + if (!policy->freq_table) + return max_freq; + + cpufreq_for_each_valid_entry(pos, policy->freq_table) + max_freq =3D max(max_freq, pos->frequency); + + return max_freq; +} + static int init_cpu_capacity_callback(struct notifier_block *nb, unsigned long val, @@ -404,7 +418,7 @@ init_cpu_capacity_callback(struct notifier_block *nb, cpumask_andnot(cpus_to_visit, cpus_to_visit, policy->related_cpus); =20 for_each_cpu(cpu, policy->related_cpus) { - per_cpu(capacity_freq_ref, cpu) =3D policy->cpuinfo.max_freq; + per_cpu(capacity_freq_ref, cpu) =3D topology_policy_max_freq(policy); freq_inv_set_max_ratio(cpu, per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); } --=20 2.55.0