From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30BC5C4167B for ; Thu, 9 Nov 2023 10:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233262AbjKIKO5 (ORCPT ); Thu, 9 Nov 2023 05:14:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbjKIKOw (ORCPT ); Thu, 9 Nov 2023 05:14:52 -0500 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 700DF2D73 for ; Thu, 9 Nov 2023 02:14:50 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c7420d5a83so4633231fa.0 for ; Thu, 09 Nov 2023 02:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524889; x=1700129689; 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=UZHd4Q0/7Gj/HYpU63Kx8UoTWa/0lydYthjIniNUNCQ=; b=N5uDv07ImQLBw5fxm/msYLJ+xQaGauZUKIw/cPOycO6TKtzNrHV5G5kS5k15hQqVmM Un5Q8QVOGRdjKiXGO2cr2uIu3NrxDfbyZG/t0PfLnHrdo6GsOR6aG+bCWN7yvrz+bnee taNuZ+1QEEujvmuhG+T0OsGLRrV/rj86DPlx3IhRdkGGnXDcfb3cUAUfc/3dgXmlSG6i QqmLXjvA7zj6ifG3DiXF8fDYtpMbwAO/JrgA5aMjaWYh7xTuC9G+wxVJaK/pMBvMCtoU 60Ck4BVxjH5uNVPxqfJX0jsWKDw0rx8KneR2V0tGf2ClWfiu5KsQw1y6T0vd4CUiY/hi xddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524889; x=1700129689; 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=UZHd4Q0/7Gj/HYpU63Kx8UoTWa/0lydYthjIniNUNCQ=; b=ghe5EGmf8kcuWZlIjwzgdZaH0W1l+7GenfYerL6PE2/wn6vkXWhwz5ImzqVAEEyDs0 QuEE5uMxCbgavyxy9T9IzFvEcICYZ0V7rSnA4A/0GrpxID54KzVVjz+YfBX7YvVAms7Y ws0QtZ/KweWn4zGMBT66LV5oTAd79iY8beuRuxDH6taK+QY7I2f+HCoCX9A9MsaGbXfq 16oGJoH1Zyxxs44d72vnUwmgrEK4jDD24EZwY467VIT/2o9r577iZ4Znkcn+gtZvrNTu tlPapqvD1B9JYWmKb9RIeWcR8i1iDf3LYRqfOSsZQELI4HUYysCYCoLpytIxRTrsX7YU VJEg== X-Gm-Message-State: AOJu0Yx/pvM3DUcXsuvM8Gc9XupRnhnb0rrKzjbbkB85rvrwg0FmlYnx CtCsnJYQC/9nlcNBH+CtZ/RPdA== X-Google-Smtp-Source: AGHT+IFzSGT/2ARlAkyBpCbVthGu2S6+dkq+V3FmAfhv1iZuIGqmYIvAERnuPKPypzZ1uKKlA6pX/w== X-Received: by 2002:a05:6512:36d3:b0:500:b553:c09e with SMTP id e19-20020a05651236d300b00500b553c09emr864687lfs.32.1699524888525; Thu, 09 Nov 2023 02:14:48 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:48 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 1/7] topology: Add a new arch_scale_freq_reference Date: Thu, 9 Nov 2023 11:14:32 +0100 Message-Id: <20231109101438.1139696-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Create a new method to get a unique and fixed max frequency. Currently cpuinfo.max_freq or the highest (or last) state of performance domain are used as the max frequency when computing the frequency for a level of utilization but: - cpuinfo_max_freq can change at runtime. boost is one example of such change. - cpuinfo.max_freq and last item of the PD can be different leading to different results between cpufreq and energy model. We need to save the reference frequency that has been used when computing the CPUs capacity and use this fixed and coherent value to convert between frequency and CPU's capacity. In fact, we already save the frequency that has been used when computing the capacity of each CPU. We extend the precision to save kHz instead of MHz currently and we modify the type to be aligned with other variables used when converting frequency to capacity and the other way. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Acked-by: Sudeep Holla Tested-by: Pierre Gondois --- 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 | 29 ++++++++++++++--------------- include/linux/arch_topology.h | 7 +++++++ include/linux/sched/topology.h | 8 ++++++++ 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topolog= y.h index c7d2510e5a78..853c4f81ba4a 100644 --- a/arch/arm/include/asm/topology.h +++ b/arch/arm/include/asm/topology.h @@ -13,6 +13,7 @@ #define arch_set_freq_scale topology_set_freq_scale #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 #endif =20 /* Replace task scheduler's default cpu-invariant accounting */ diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/top= ology.h index 9fab663dd2de..a323b109b9c4 100644 --- a/arch/arm64/include/asm/topology.h +++ b/arch/arm64/include/asm/topology.h @@ -23,6 +23,7 @@ void update_freq_counters_refs(void); #define arch_set_freq_scale topology_set_freq_scale #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 =20 #ifdef CONFIG_ACPI_CPPC_LIB #define arch_init_invariance_cppc topology_init_cpu_capacity_cppc diff --git a/arch/riscv/include/asm/topology.h b/arch/riscv/include/asm/top= ology.h index e316ab3b77f3..61183688bdd5 100644 --- a/arch/riscv/include/asm/topology.h +++ b/arch/riscv/include/asm/topology.h @@ -9,6 +9,7 @@ #define arch_set_freq_scale topology_set_freq_scale #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 =20 /* Replace task scheduler's default cpu-invariant accounting */ #define arch_scale_cpu_capacity topology_get_cpu_scale diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b741b5ba82bd..e8d1cdf1f761 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #define CREATE_TRACE_POINTS #include @@ -26,7 +27,8 @@ static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data); static struct cpumask scale_freq_counters_mask; static bool scale_freq_invariant; -static DEFINE_PER_CPU(u32, freq_factor) =3D 1; +DEFINE_PER_CPU(unsigned long, capacity_freq_ref) =3D 1; +EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref); =20 static bool supports_scale_freq_counters(const struct cpumask *cpus) { @@ -170,9 +172,9 @@ DEFINE_PER_CPU(unsigned long, thermal_pressure); * operating on stale data when hot-plug is used for some CPUs. The * @capped_freq reflects the currently allowed max CPUs frequency due to * thermal capping. It might be also a boost frequency value, which is big= ger - * than the internal 'freq_factor' max frequency. In such case the pressure - * value should simply be removed, since this is an indication that there = is - * no thermal throttling. The @capped_freq must be provided in kHz. + * than the internal 'capacity_freq_ref' max frequency. In such case the + * pressure value should simply be removed, since this is an indication th= at + * there is no thermal throttling. The @capped_freq must be provided in kH= z. */ void topology_update_thermal_pressure(const struct cpumask *cpus, unsigned long capped_freq) @@ -183,10 +185,7 @@ void topology_update_thermal_pressure(const struct cpu= mask *cpus, =20 cpu =3D cpumask_first(cpus); max_capacity =3D arch_scale_cpu_capacity(cpu); - max_freq =3D per_cpu(freq_factor, cpu); - - /* Convert to MHz scale which is used in 'freq_factor' */ - capped_freq /=3D 1000; + max_freq =3D arch_scale_freq_ref(cpu); =20 /* * Handle properly the boost frequencies, which should simply clean @@ -279,13 +278,13 @@ void topology_normalize_cpu_scale(void) =20 capacity_scale =3D 1; for_each_possible_cpu(cpu) { - capacity =3D raw_capacity[cpu] * per_cpu(freq_factor, cpu); + capacity =3D raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); capacity_scale =3D max(capacity, capacity_scale); } =20 pr_debug("cpu_capacity: capacity_scale=3D%llu\n", capacity_scale); for_each_possible_cpu(cpu) { - capacity =3D raw_capacity[cpu] * per_cpu(freq_factor, cpu); + capacity =3D raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); capacity =3D div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity_scale); topology_set_cpu_scale(cpu, capacity); @@ -321,15 +320,15 @@ bool __init topology_parse_cpu_capacity(struct device= _node *cpu_node, int cpu) cpu_node, raw_capacity[cpu]); =20 /* - * Update freq_factor for calculating early boot cpu capacities. + * Update capacity_freq_ref for calculating early boot cpu capacities. * For non-clk CPU DVFS mechanism, there's no way to get the * frequency value now, assuming they are running at the same - * frequency (by keeping the initial freq_factor value). + * frequency (by keeping the initial capacity_freq_ref value). */ cpu_clk =3D of_clk_get(cpu_node, 0); if (!PTR_ERR_OR_ZERO(cpu_clk)) { - per_cpu(freq_factor, cpu) =3D - clk_get_rate(cpu_clk) / 1000; + per_cpu(capacity_freq_ref, cpu) =3D + clk_get_rate(cpu_clk) / HZ_PER_KHZ; clk_put(cpu_clk); } } else { @@ -411,7 +410,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(freq_factor, cpu) =3D policy->cpuinfo.max_freq / 1000; + per_cpu(capacity_freq_ref, cpu) =3D policy->cpuinfo.max_freq; =20 if (cpumask_empty(cpus_to_visit)) { topology_normalize_cpu_scale(); diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index a07b510e7dc5..32c24ff4f2a8 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -27,6 +27,13 @@ static inline unsigned long topology_get_cpu_scale(int c= pu) =20 void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity); =20 +DECLARE_PER_CPU(unsigned long, capacity_freq_ref); + +static inline unsigned long topology_get_freq_ref(int cpu) +{ + return per_cpu(capacity_freq_ref, cpu); +} + DECLARE_PER_CPU(unsigned long, arch_freq_scale); =20 static inline unsigned long topology_get_freq_scale(int cpu) diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index de545ba85218..a6e04b4a21d7 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -279,6 +279,14 @@ void arch_update_thermal_pressure(const struct cpumask= *cpus, { } #endif =20 +#ifndef arch_scale_freq_ref +static __always_inline +unsigned int arch_scale_freq_ref(int cpu) +{ + return 0; +} +#endif + static inline int task_node(const struct task_struct *p) { return cpu_to_node(task_cpu(p)); --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21BEFC4167B for ; Thu, 9 Nov 2023 10:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233394AbjKIKPB (ORCPT ); Thu, 9 Nov 2023 05:15:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233110AbjKIKOy (ORCPT ); Thu, 9 Nov 2023 05:14:54 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49AEF2D77 for ; Thu, 9 Nov 2023 02:14:52 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-507bd64814fso913243e87.1 for ; Thu, 09 Nov 2023 02:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524890; x=1700129690; 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=TkZaHixUrwPrJIZcMAT2UI1CVMoJazwhG5L/qYNHDpM=; b=xEsaEFtyijZ+lrkgLWdBlKEF9XzHJAYABDemz8qJ7g6trDSydEg+717Paacds7L1RW ihBUmwGqLNYnnuwzrQkOYzfE6HJF7T60yL/GSUFpjTDQbtgtRMDtiL3ZxUmm0bvvoJBU OdpHItJ2Ab/GnrLM6yLVFTqmrbAMuI3HW+3wvr3jtTDBictXHHbN4XoJM1YoU4xlfowx XaUV4s2eD11I4ai+roVkUi8J3w+CdVFlXjm22oKeOKVGdA2Uu6avHXnbHr/1zfc4AvJ9 zcMWBokvNNn11nxHlT1wSGClBTlsw6J8wfeOOlbTspqKHC1dJMsY+BIOT9V90TryMp29 5KPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524890; x=1700129690; 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=TkZaHixUrwPrJIZcMAT2UI1CVMoJazwhG5L/qYNHDpM=; b=HveJ18orZJucR10Km+CpIsrD5kp7MDKdbfS7JGA416+J0nWuKEHuJ9EPanj6xxBBhA Gn6DHM1ezLzUAgzslTSezH9qLqoYTLu9zuPbU6dazFKdurY/cz5pqwVbRvSl4bmDUf8g rdT2tTyA33t1fi3dPa3ZtMyuZZATMFEe5D2e+xX48qxGoyiLqAslwmNdgG45azdIATv8 66Fzr9Im+EtRprf8y2lvPSADJGBNfXNYOg7aCzZAUSUfOvIGDBXM7SacM20nc57gCOYs 4bq2W58IzWd20F7I0jo+DOBKPR0FM4f38jsuevPiwNp/o3HNd2s1APEOWfzDZlOFzhvB +pcg== X-Gm-Message-State: AOJu0YzELMQXJ9XtaKOkhid0JGBmGSF9lCophOoBTDgQcCBokWGQVhK6 WbZx8eV0hSenxxL+FlECztOerA== X-Google-Smtp-Source: AGHT+IEqILPvUko85d9wgnJYU7Vruxwgnn1FhQ0YwiIKlK4c+JNlTI9/ER4u8xuUQ0y1qhtyeTmH+g== X-Received: by 2002:a05:6512:70d:b0:509:47b9:63d0 with SMTP id b13-20020a056512070d00b0050947b963d0mr880323lfs.61.1699524890509; Thu, 09 Nov 2023 02:14:50 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:49 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 2/7] cpufreq: Use the fixed and coherent frequency for scaling capacity Date: Thu, 9 Nov 2023 11:14:33 +0100 Message-Id: <20231109101438.1139696-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cpuinfo.max_freq can change at runtime because of boost as an example. This implies that the value could be different from the frequency that has been used to compute the capacity of a CPU. The new arch_scale_freq_ref() returns a fixed and coherent frequency that can be used to compute the capacity for a given frequency. Signed-off-by: Vincent Guittot Acked-by: Viresh Kumar Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Acked-by: Rafael J. Wysocki Tested-by: Pierre Gondois --- drivers/cpufreq/cpufreq.c | 4 ++-- include/linux/cpufreq.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 60ed89000e82..8c4f9c2f9c44 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -454,7 +454,7 @@ void cpufreq_freq_transition_end(struct cpufreq_policy = *policy, =20 arch_set_freq_scale(policy->related_cpus, policy->cur, - policy->cpuinfo.max_freq); + arch_scale_freq_ref(policy->cpu)); =20 spin_lock(&policy->transition_lock); policy->transition_ongoing =3D false; @@ -2174,7 +2174,7 @@ unsigned int cpufreq_driver_fast_switch(struct cpufre= q_policy *policy, =20 policy->cur =3D freq; arch_set_freq_scale(policy->related_cpus, freq, - policy->cpuinfo.max_freq); + arch_scale_freq_ref(policy->cpu)); cpufreq_stats_record_transition(policy, freq); =20 if (trace_cpu_frequency_enabled()) { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 71d186d6933a..738dcddf3cfe 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -1211,6 +1211,7 @@ void arch_set_freq_scale(const struct cpumask *cpus, { } #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; --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00B96C04E83 for ; Thu, 9 Nov 2023 10:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233203AbjKIKPL (ORCPT ); Thu, 9 Nov 2023 05:15:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233163AbjKIKPG (ORCPT ); Thu, 9 Nov 2023 05:15:06 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBEF62D79 for ; Thu, 9 Nov 2023 02:14:53 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4084e49a5e5so4710035e9.3 for ; Thu, 09 Nov 2023 02:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524892; x=1700129692; 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=PpSbnRMVClcVCq7PxMg71+AnKN7hK0FrYIohngsI4P6PFOOh1MqbWWwQKkFPvt8XWi g2qDWb8opx5p+U7mtBOtiMHX3VWz5X9qugns5VaH+noBdExOA76oWa26tGHV7XtWa4rF epu7BVSF9Lew6K/jC8vFe2kZ9o/sMwwPFyq8TpFIAwob5uDkz/pk/GZ33QZ0GtSQeKO/ /Nv9P7VWzBeyAqNuPUKfrIFtQbAiA3+k8Q4pZqES2p3nAQLrzRzMvtB6UKrAjfSkTjJ5 zPO7pzg3wrMsO3NKMmThfuRrz8GX/u2EpHmR9V5yX08tOBFXUcFF4xBiXqhRH7hukxrS Rwvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524892; x=1700129692; 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=JP9APSSLOqdchV93y48BFHhNcgtN+mayoSBffC3odZLS7mNsmnTTq5Gj87QquYstOY ngk4fxZunTFYKXwL4qNP1kJ00W8c0Oa0r2x16NdhEqJhZAjcso/5k4KykCqr0lCxQk8O O4+uf1JZ/fH0hs267e3eZXiIqh2DissZDACg2W8aan4f9KBPMCfExIm2b2ZbSpZMLZFS omCLAB0+bw1wmDT6r4fOKWRSFUltBdjhjrghI2qFSMR5wL4zYshbwM4AI/KXek1dWVsw H/awB+2QHmMlxe11M8fa8tw+GQ6iSaZ3FpZ4K9aFTYNGSvNqOwMuXAvhrpi8zHpklA6F imwA== X-Gm-Message-State: AOJu0YzO6oWuwkxDMxrOyMrLcpa3zh9oh8XlPi3ieYGeq9mFOz1FwaDv CfvggFEZGb0nBab1eV4RILMXSw== X-Google-Smtp-Source: AGHT+IHnOiUcy8JXKcoEvGEFJjBuKV8KQLk7xv3UY4lyz6ACLBnBr+ZIXmzvc3YVmB2uAO7FfkCoEw== X-Received: by 2002:a05:600c:a49:b0:409:5d7d:b26d with SMTP id c9-20020a05600c0a4900b004095d7db26dmr3556372wmq.15.1699524892326; Thu, 09 Nov 2023 02:14:52 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:51 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 3/7] cpufreq/schedutil: Use a fixed reference frequency Date: Thu, 9 Nov 2023 11:14:34 +0100 Message-Id: <20231109101438.1139696-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Viresh Kumar Tested-by: Pierre Gondois --- 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_schedu= til.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) } } =20 +/** + * 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 =3D 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 =3D sg_policy->policy; - unsigned int freq =3D arch_scale_freq_invariant() ? - policy->cpuinfo.max_freq : policy->cur; + unsigned int freq; =20 util =3D map_util_perf(util); + freq =3D get_capacity_ref_freq(policy); freq =3D map_util_freq(util, freq, max); =20 if (freq =3D=3D sg_policy->cached_raw_freq && !sg_policy->need_freq_updat= e) --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADC61C4167B for ; Thu, 9 Nov 2023 10:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233954AbjKIKPO (ORCPT ); Thu, 9 Nov 2023 05:15:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbjKIKPI (ORCPT ); Thu, 9 Nov 2023 05:15:08 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84BB130C5 for ; Thu, 9 Nov 2023 02:14:55 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4083f613275so4555865e9.2 for ; Thu, 09 Nov 2023 02:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524894; x=1700129694; 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=aduCSyHEYIhu+IO52anhhUtjmJcDS68d0TTkBLTxAgE=; b=B2XoNOc/UvEkRo9hxP5p1Y+/rylqTlP3mpJpsnqcRVhqXeUBHOrpDAr/QbiG4v0gac KbITUVpfPRbT7B2PCPJpKJ44jFCcIwxQr6IiwXs2MLAScSMyildYvBopvyezCP1E0q9m BGDj7nYrYa+dWF7na8dtTgGOBic5lJpmdxpY2oDmjYv7l7W4GYLUMZ0nd6mqII+t7GZi yIzwyAnQHmLIqZ88AuJvLuyknLFegie3phbl4pVTE7JKnCIqhFUZ0y3hb+ckUwyzt1h8 Ip6Fwb5153oFvDGCmBa03thse64naSSLLxF2YV5nZdxlcK+vOqBZNZKAvAMgXK4a2JyP xNwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524894; x=1700129694; 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=aduCSyHEYIhu+IO52anhhUtjmJcDS68d0TTkBLTxAgE=; b=CyeaD/tSed5ULDuOPMxr9DYTezgKrig00P/dTNNrxLINaSYyZF+yv7+nK7p77EMvJq k41tjIY30Yb2TWvzQ2iiWbfbrBX4wjl+6UQjVlCPacfnNcf6Ecw0Rs+R82QnTYA5ebYf yx48gZjfbJwFyps+1LSQyqVhorOqSbr0RlaiUzsEgRJs4ScaDJV9m723xZ6RWyV/q1Mf 5owYD5a2tvI2FIB5CWLCB8HtMQSlNcXEKlR4S5ajUV1N3tIwI5EtzxbtOtPtXCr6tB+G tQ3Ey+4rC+7SOjz5x0Q5+VFQ0AA5PxEIG4RF0WF1+b0E7RVDUKC2NpMmOnALz8p1Ha1f hv3A== X-Gm-Message-State: AOJu0YwhqmH55W0m9oSdKh6lNg4IfUuup4r5fXwiJWZH4yH88j2jPsiL rchNw3EZicB2dP+EHMepukOhCQ== X-Google-Smtp-Source: AGHT+IEYIB6ScZWDEgpcZ/S2cHjVchJEeCFHQxgRNVNplqpr7l/I6Xe67qLyHn6zzj6QW+TyS8tvqg== X-Received: by 2002:a1c:7516:0:b0:40a:28b1:70f8 with SMTP id o22-20020a1c7516000000b0040a28b170f8mr3876852wmc.21.1699524893988; Thu, 09 Nov 2023 02:14:53 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:53 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 4/7] energy_model: Use a fixed reference frequency Date: Thu, 9 Nov 2023 11:14:35 +0100 Message-Id: <20231109101438.1139696-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The last item of a performance domain is not always the performance point that has been used to compute CPU's capacity. This can lead to different target frequency compared with other part of the system like schedutil and would result in wrong energy estimation. A new arch_scale_freq_ref() is available to return a fixed and coherent frequency reference that can be used when computing the CPU's frequency for an level of utilization. Use this function to get this reference frequency. Energy model is never used without defining arch_scale_freq_ref() but can be compiled. Define a default arch_scale_freq_ref() returning 0 in such case. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Tested-by: Pierre Gondois --- include/linux/energy_model.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b9caa01dfac4..c19e7effe764 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -224,7 +224,7 @@ static inline unsigned long em_cpu_energy(struct em_per= f_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) { - unsigned long freq, scale_cpu; + unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; int cpu; =20 @@ -241,11 +241,11 @@ static inline unsigned long em_cpu_energy(struct em_p= erf_domain *pd, */ cpu =3D cpumask_first(to_cpumask(pd->cpus)); scale_cpu =3D arch_scale_cpu_capacity(cpu); - ps =3D &pd->table[pd->nr_perf_states - 1]; + ref_freq =3D arch_scale_freq_ref(cpu); =20 max_util =3D map_util_perf(max_util); max_util =3D min(max_util, allowed_cpu_cap); - freq =3D map_util_freq(max_util, ps->frequency, scale_cpu); + freq =3D map_util_freq(max_util, ref_freq, scale_cpu); =20 /* * Find the lowest performance state of the Energy Model above the --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1739C0018C for ; Thu, 9 Nov 2023 10:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233424AbjKIKPR (ORCPT ); Thu, 9 Nov 2023 05:15:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbjKIKPJ (ORCPT ); Thu, 9 Nov 2023 05:15:09 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1CD030D6 for ; Thu, 9 Nov 2023 02:14:57 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c50fbc218bso7567391fa.3 for ; Thu, 09 Nov 2023 02:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524896; x=1700129696; 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=lCeYYy5Thhb4RKaz86QJRj36sMkWMn4qr/sGF6e6Ivs=; b=kbfkzvGIy0XV98Yug5f3V7lYFzZsegoBdaRMmVgOvbtOBbeLdaeNgOMRJDcTPU4ke0 PmW/QV/HRNKTYn3stmzQxdmqRYRCb5vcLiz+jT4qGAxuU9M5aCxMcckfS9CM99Ybbpqe DgHqMKzODAQAqcJdKu4yoI+S4PWeWXN87rskhQCN/P3n4IUHFpCPxCO35sgeOAdaoNRb Oy46Cuww4T9NnUOPKbhtXV3Pqp7sukksT/+H9KIlgufk2XJN0khloLnUEsYqp+4/nRb7 22u6xY+yFo4eQU4na8UnvvfbGGWW24hcBfSHGoiSOAfYDyzGFw91dGsk8uhlYy+N+yMJ g2SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524896; x=1700129696; 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=lCeYYy5Thhb4RKaz86QJRj36sMkWMn4qr/sGF6e6Ivs=; b=DSqlOcWKcAfLmw83RHUa4Kh5+G9wcaTsbCB2qgdiJdtnDfBqtp3h5na2X9ZfDkf8QL dzx4NbIU9bwdBcPWaaLW9Vq1ep1016JMpwfElJR3mecMzRnkSb0lYbkSet0W+D9qrJ/4 EV5gRi0O1lSklcIXmsciShM9eMIlzaJ7ga9YjiYsH4pA4S+Up2quRuU84X2Y5Ldr8MZ/ PSup9bTkDER57hoDv2B6s7lS2Q+n/AfBhJiLOu1TqZRt1h7Efb+zKDehA+3uEHlzHvoI lom9iqlUyU4XV418PBrFWSILGYmOXi1j396BSPbtFCnoMWUHDg4qH52uvrt2SOji2hc5 DDtA== X-Gm-Message-State: AOJu0Yw5OiyYBPgmGpbPXdCl89GRrfR2dgXKN08KcbyjCxFkEjxzF0FS e9aC6IP6GnVU84JICrCV5X7Iyw== X-Google-Smtp-Source: AGHT+IGBoDudDQnmYAYbAg3sS2vQkxa5GehMipEZK1fFGMpvUqjDW36EmW0lVGcIfkmF004wnyx9zQ== X-Received: by 2002:a2e:9441:0:b0:2bc:dab2:c7dc with SMTP id o1-20020a2e9441000000b002bcdab2c7dcmr3558708ljh.47.1699524895768; Thu, 09 Nov 2023 02:14:55 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:55 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 5/7] cpufreq/cppc: Move and rename cppc_cpufreq_{perf_to_khz|khz_to_perf} Date: Thu, 9 Nov 2023 11:14:36 +0100 Message-Id: <20231109101438.1139696-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move and rename cppc_cpufreq_perf_to_khz and cppc_cpufreq_khz_to_perf to use them outside cppc_cpufreq in topology_init_cpu_capacity_cppc(). Modify the interface to use struct cppc_perf_caps *caps instead of struct cppc_cpudata *cpu_data as we only use the fields of cppc_perf_caps. cppc_cpufreq was converting the lowest and nominal freq from MHz to kHz before using them. We move this conversion inside cppc_perf_to_khz and cppc_khz_to_perf to make them generic and usable outside cppc_cpufreq. No functional change Signed-off-by: Vincent Guittot Acked-by: Rafael J. Wysocki Acked-by: Viresh Kumar Tested-by: Pierre Gondois --- drivers/acpi/cppc_acpi.c | 104 ++++++++++++++++++++++++ drivers/cpufreq/cppc_cpufreq.c | 139 ++++----------------------------- include/acpi/cppc_acpi.h | 2 + 3 files changed, 123 insertions(+), 122 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7ff269a78c20..d155a86a8614 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -39,6 +39,9 @@ #include #include #include +#include +#include +#include =20 #include =20 @@ -1760,3 +1763,104 @@ unsigned int cppc_get_transition_latency(int cpu_nu= m) return latency_ns; } EXPORT_SYMBOL_GPL(cppc_get_transition_latency); + +/* Minimum struct length needed for the DMI processor entry we want */ +#define DMI_ENTRY_PROCESSOR_MIN_LENGTH 48 + +/* Offset in the DMI processor structure for the max frequency */ +#define DMI_PROCESSOR_MAX_SPEED 0x14 + +/* Callback function used to retrieve the max frequency from DMI */ +static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private) +{ + const u8 *dmi_data =3D (const u8 *)dm; + u16 *mhz =3D (u16 *)private; + + if (dm->type =3D=3D DMI_ENTRY_PROCESSOR && + dm->length >=3D DMI_ENTRY_PROCESSOR_MIN_LENGTH) { + u16 val =3D (u16)get_unaligned((const u16 *) + (dmi_data + DMI_PROCESSOR_MAX_SPEED)); + *mhz =3D val > *mhz ? val : *mhz; + } +} + +/* Look up the max frequency in DMI */ +static u64 cppc_get_dmi_max_khz(void) +{ + u16 mhz =3D 0; + + dmi_walk(cppc_find_dmi_mhz, &mhz); + + /* + * Real stupid fallback value, just in case there is no + * actual value set. + */ + mhz =3D mhz ? mhz : 1; + + return KHZ_PER_MHZ * mhz; +} + +/* + * If CPPC lowest_freq and nominal_freq registers are exposed then we can + * use them to convert perf to freq and vice versa. The conversion is + * extrapolated as an affine function passing by the 2 points: + * - (Low perf, Low freq) + * - (Nominal perf, Nominal freq) + */ +unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int pe= rf) +{ + s64 retval, offset =3D 0; + static u64 max_khz; + u64 mul, div; + + if (caps->lowest_freq && caps->nominal_freq) { + mul =3D caps->nominal_freq - caps->lowest_freq; + mul *=3D KHZ_PER_MHZ; + div =3D caps->nominal_perf - caps->lowest_perf; + offset =3D caps->nominal_freq * KHZ_PER_MHZ - + div64_u64(caps->nominal_perf * mul, div); + } else { + if (!max_khz) + max_khz =3D cppc_get_dmi_max_khz(); + mul =3D max_khz; + div =3D caps->highest_perf; + } + + retval =3D offset + div64_u64(perf * mul, div); + if (retval >=3D 0) + return retval; + return 0; +} +EXPORT_SYMBOL_GPL(cppc_perf_to_khz); + +unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int fr= eq) +{ + s64 retval, offset =3D 0; + static u64 max_khz; + u64 mul, div; + + if (caps->lowest_freq && caps->nominal_freq) { + mul =3D caps->nominal_perf - caps->lowest_perf; + div =3D caps->nominal_freq - caps->lowest_freq; + /* + * We don't need to convert to kHz for computing offset and can + * directly use nominal_freq and lowest_freq as the div64_u64 + * will remove the frequency unit. + */ + offset =3D caps->nominal_perf - + div64_u64(caps->nominal_freq * mul, div); + /* But we need it for computing the perf level. */ + div *=3D KHZ_PER_MHZ; + } else { + if (!max_khz) + max_khz =3D cppc_get_dmi_max_khz(); + mul =3D caps->highest_perf; + div =3D max_khz; + } + + retval =3D offset + div64_u64(freq * mul, div); + if (retval >=3D 0) + return retval; + return 0; +} +EXPORT_SYMBOL_GPL(cppc_khz_to_perf); diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index fe08ca419b3d..64420d9cfd1e 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -27,12 +26,6 @@ =20 #include =20 -/* Minimum struct length needed for the DMI processor entry we want */ -#define DMI_ENTRY_PROCESSOR_MIN_LENGTH 48 - -/* Offset in the DMI processor structure for the max frequency */ -#define DMI_PROCESSOR_MAX_SPEED 0x14 - /* * This list contains information parsed from per CPU ACPI _CPC and _PSD * structures: e.g. the highest and lowest supported performance, capabili= ties, @@ -291,97 +284,9 @@ static inline void cppc_freq_invariance_exit(void) } #endif /* CONFIG_ACPI_CPPC_CPUFREQ_FIE */ =20 -/* Callback function used to retrieve the max frequency from DMI */ -static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private) -{ - const u8 *dmi_data =3D (const u8 *)dm; - u16 *mhz =3D (u16 *)private; - - if (dm->type =3D=3D DMI_ENTRY_PROCESSOR && - dm->length >=3D DMI_ENTRY_PROCESSOR_MIN_LENGTH) { - u16 val =3D (u16)get_unaligned((const u16 *) - (dmi_data + DMI_PROCESSOR_MAX_SPEED)); - *mhz =3D val > *mhz ? val : *mhz; - } -} - -/* Look up the max frequency in DMI */ -static u64 cppc_get_dmi_max_khz(void) -{ - u16 mhz =3D 0; - - dmi_walk(cppc_find_dmi_mhz, &mhz); - - /* - * Real stupid fallback value, just in case there is no - * actual value set. - */ - mhz =3D mhz ? mhz : 1; - - return (1000 * mhz); -} - -/* - * If CPPC lowest_freq and nominal_freq registers are exposed then we can - * use them to convert perf to freq and vice versa. The conversion is - * extrapolated as an affine function passing by the 2 points: - * - (Low perf, Low freq) - * - (Nominal perf, Nominal perf) - */ -static unsigned int cppc_cpufreq_perf_to_khz(struct cppc_cpudata *cpu_data, - unsigned int perf) -{ - struct cppc_perf_caps *caps =3D &cpu_data->perf_caps; - s64 retval, offset =3D 0; - static u64 max_khz; - u64 mul, div; - - if (caps->lowest_freq && caps->nominal_freq) { - mul =3D caps->nominal_freq - caps->lowest_freq; - div =3D caps->nominal_perf - caps->lowest_perf; - offset =3D caps->nominal_freq - div64_u64(caps->nominal_perf * mul, div); - } else { - if (!max_khz) - max_khz =3D cppc_get_dmi_max_khz(); - mul =3D max_khz; - div =3D caps->highest_perf; - } - - retval =3D offset + div64_u64(perf * mul, div); - if (retval >=3D 0) - return retval; - return 0; -} - -static unsigned int cppc_cpufreq_khz_to_perf(struct cppc_cpudata *cpu_data, - unsigned int freq) -{ - struct cppc_perf_caps *caps =3D &cpu_data->perf_caps; - s64 retval, offset =3D 0; - static u64 max_khz; - u64 mul, div; - - if (caps->lowest_freq && caps->nominal_freq) { - mul =3D caps->nominal_perf - caps->lowest_perf; - div =3D caps->nominal_freq - caps->lowest_freq; - offset =3D caps->nominal_perf - div64_u64(caps->nominal_freq * mul, div); - } else { - if (!max_khz) - max_khz =3D cppc_get_dmi_max_khz(); - mul =3D caps->highest_perf; - div =3D max_khz; - } - - retval =3D offset + div64_u64(freq * mul, div); - if (retval >=3D 0) - return retval; - return 0; -} - static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) - { struct cppc_cpudata *cpu_data =3D policy->driver_data; unsigned int cpu =3D policy->cpu; @@ -389,7 +294,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_polic= y *policy, u32 desired_perf; int ret =3D 0; =20 - desired_perf =3D cppc_cpufreq_khz_to_perf(cpu_data, target_freq); + desired_perf =3D cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); /* Return if it is exactly the same perf */ if (desired_perf =3D=3D cpu_data->perf_ctrls.desired_perf) return ret; @@ -417,7 +322,7 @@ static unsigned int cppc_cpufreq_fast_switch(struct cpu= freq_policy *policy, u32 desired_perf; int ret; =20 - desired_perf =3D cppc_cpufreq_khz_to_perf(cpu_data, target_freq); + desired_perf =3D cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); cpu_data->perf_ctrls.desired_perf =3D desired_perf; ret =3D cppc_set_perf(cpu, &cpu_data->perf_ctrls); =20 @@ -530,7 +435,7 @@ static int cppc_get_cpu_power(struct device *cpu_dev, min_step =3D min_cap / CPPC_EM_CAP_STEP; max_step =3D max_cap / CPPC_EM_CAP_STEP; =20 - perf_prev =3D cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + perf_prev =3D cppc_khz_to_perf(perf_caps, *KHz); step =3D perf_prev / perf_step; =20 if (step > max_step) @@ -550,8 +455,8 @@ static int cppc_get_cpu_power(struct device *cpu_dev, perf =3D step * perf_step; } =20 - *KHz =3D cppc_cpufreq_perf_to_khz(cpu_data, perf); - perf_check =3D cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + *KHz =3D cppc_perf_to_khz(perf_caps, perf); + perf_check =3D cppc_khz_to_perf(perf_caps, *KHz); step_check =3D perf_check / perf_step; =20 /* @@ -561,8 +466,8 @@ static int cppc_get_cpu_power(struct device *cpu_dev, */ while ((*KHz =3D=3D prev_freq) || (step_check !=3D step)) { perf++; - *KHz =3D cppc_cpufreq_perf_to_khz(cpu_data, perf); - perf_check =3D cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + *KHz =3D cppc_perf_to_khz(perf_caps, perf); + perf_check =3D cppc_khz_to_perf(perf_caps, *KHz); step_check =3D perf_check / perf_step; } =20 @@ -591,7 +496,7 @@ static int cppc_get_cpu_cost(struct device *cpu_dev, un= signed long KHz, perf_caps =3D &cpu_data->perf_caps; max_cap =3D arch_scale_cpu_capacity(cpu_dev->id); =20 - perf_prev =3D cppc_cpufreq_khz_to_perf(cpu_data, KHz); + perf_prev =3D cppc_khz_to_perf(perf_caps, KHz); perf_step =3D CPPC_EM_CAP_STEP * perf_caps->highest_perf / max_cap; step =3D perf_prev / perf_step; =20 @@ -679,10 +584,6 @@ static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(= unsigned int cpu) goto free_mask; } =20 - /* Convert the lowest and nominal freq from MHz to KHz */ - cpu_data->perf_caps.lowest_freq *=3D 1000; - cpu_data->perf_caps.nominal_freq *=3D 1000; - list_add(&cpu_data->node, &cpu_data_list); =20 return cpu_data; @@ -724,20 +625,16 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_polic= y *policy) * Set min to lowest nonlinear perf to avoid any efficiency penalty (see * Section 8.4.7.1.1.5 of ACPI 6.1 spec) */ - policy->min =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->lowest_nonlinear_perf); - policy->max =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->min =3D cppc_perf_to_khz(caps, caps->lowest_nonlinear_perf); + policy->max =3D cppc_perf_to_khz(caps, caps->nominal_perf); =20 /* * Set cpuinfo.min_freq to Lowest to make the full range of performance * available if userspace wants to use any perf between lowest & lowest * nonlinear perf */ - policy->cpuinfo.min_freq =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->lowest_perf); - policy->cpuinfo.max_freq =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->cpuinfo.min_freq =3D cppc_perf_to_khz(caps, caps->lowest_perf); + policy->cpuinfo.max_freq =3D cppc_perf_to_khz(caps, caps->nominal_perf); =20 policy->transition_delay_us =3D cppc_cpufreq_get_transition_delay_us(cpu); policy->shared_type =3D cpu_data->shared_type; @@ -773,7 +670,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy = *policy) boost_supported =3D true; =20 /* Set policy->cur to max now. The governors will adjust later. */ - policy->cur =3D cppc_cpufreq_perf_to_khz(cpu_data, caps->highest_perf); + policy->cur =3D cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf =3D caps->highest_perf; =20 ret =3D cppc_set_perf(cpu, &cpu_data->perf_ctrls); @@ -863,7 +760,7 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int = cpu) delivered_perf =3D cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0, &fb_ctrs_t1); =20 - return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf); + return cppc_perf_to_khz(&cpu_data->perf_caps, delivered_perf); } =20 static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) @@ -878,11 +775,9 @@ static int cppc_cpufreq_set_boost(struct cpufreq_polic= y *policy, int state) } =20 if (state) - policy->max =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->highest_perf); + policy->max =3D cppc_perf_to_khz(caps, caps->highest_perf); else - policy->max =3D cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->max =3D cppc_perf_to_khz(caps, caps->nominal_perf); policy->cpuinfo.max_freq =3D policy->max; =20 ret =3D freq_qos_update_request(policy->max_freq_req, policy->max); @@ -937,7 +832,7 @@ static unsigned int hisi_cppc_cpufreq_get_rate(unsigned= int cpu) if (ret < 0) return -EIO; =20 - return cppc_cpufreq_perf_to_khz(cpu_data, desired_perf); + return cppc_perf_to_khz(&cpu_data->perf_caps, desired_perf); } =20 static void cppc_check_hisi_workaround(void) diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 6126c977ece0..3a0995f8bce8 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -144,6 +144,8 @@ extern int cppc_set_perf(int cpu, struct cppc_perf_ctrl= s *perf_ctrls); extern int cppc_set_enable(int cpu, bool enable); extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); extern bool cppc_perf_ctrs_in_pcc(void); +extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned= int perf); +extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned= int freq); extern bool acpi_cpc_valid(void); extern bool cppc_allow_fast_switch(void); extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_dat= a); --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3430C05022 for ; Thu, 9 Nov 2023 10:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234149AbjKIKPT (ORCPT ); Thu, 9 Nov 2023 05:15:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232918AbjKIKPK (ORCPT ); Thu, 9 Nov 2023 05:15:10 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27A9B30E7 for ; Thu, 9 Nov 2023 02:14:59 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4083f613272so4798565e9.1 for ; Thu, 09 Nov 2023 02:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524897; x=1700129697; 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=PRZuGgttIdjMzTtOY1KLieaDHjYgH97fC7jzr+fvVqo=; b=gBsWdZ++s0+LbDVr6pkTEDUcxoNovypRYVpvgDcsB2PaAFhT4bGmgI866JjQnZbZqL kXIdaKl1KymtebNa3pakFi5d5BDfcB0BW4wtCL8C+6wkV1VbKgNWhbhbQYaI+F2zEKoi FNuODtaNQ9p9sLxo1EhL/UdusZfedmzToInJ9JDcq8c87vRtd3mmilrQFB7U5Yg3ltjF xWF6NhOopvSjKhiVV4GzU3bMHctjkZe1xabLr6duAJUj8Ch05mz3gBT+dcL8uWJ4MK8W /5eHFmXq7GWJ1Q/8UtmT1HBQ4s7x6QqkfS0VQoRXjfcdtp5n7trE55apN+XJvRtPLlfm 6Zvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524897; x=1700129697; 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=PRZuGgttIdjMzTtOY1KLieaDHjYgH97fC7jzr+fvVqo=; b=I+NGtOwSly1LvyCPoukyurSvu68f3X2Tf6gC77u/mH5Jq3K0JALj8vPP9mveyV5WBQ BP/aPBtHv3yiJ5a8/QSc944DnhT98OAHHgwfOJNUZzfTZ2ZEcRgvLpc3dsV+x+4hWxyN PMEy0lzgYo/wjNyq9/30C8KIDxGzq/i/nyTW4qTNTFFxqT+uWKoqtLJ1DnNOkdzUfg7X iI2bkfJCvn66Ch8ZEYTFtOXGOCgbcx6NdQ87x7QZWUZ1GyL7F4Vr353hkdpMg7Sr42lQ CqfxZP97f2YAWEKUjJPKccqf3yAT41llzsG5+VMPMwjheaGymFsSPGNi5+hLjvqVTw1L 0xwQ== X-Gm-Message-State: AOJu0YwjzuWqa4aqDwnktMmxm6tYn0kUoOukC1F3FDb0YQMRTYOrCg1i qpqFJY8EK8jQ0TikVHytu12RWg== X-Google-Smtp-Source: AGHT+IFErHhK3dv93vXA3skdZjBc12KSv8yFV05cQNNZGn5wIgqPMa1zCHFgcuaqbLUWzLMBHHtZSA== X-Received: by 2002:a05:600c:138b:b0:407:5b7c:2f6a with SMTP id u11-20020a05600c138b00b004075b7c2f6amr3739930wmf.0.1699524897543; Thu, 09 Nov 2023 02:14:57 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:57 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 6/7] cpufreq/cppc: Set the frequency used for computing the capacity Date: Thu, 9 Nov 2023 11:14:37 +0100 Message-Id: <20231109101438.1139696-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Save the frequency associated to the performance that has been used when initializing the capacity of CPUs. Also, cppc cpufreq driver can register an artificial energy model. In such case, it needs the frequency for this compute capacity. Signed-off-by: Vincent Guittot Acked-by: Sudeep Holla Acked-by: Viresh Kumar Tested-by: Pierre Gondois --- drivers/base/arch_topology.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index e8d1cdf1f761..0a2e43728286 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -349,6 +349,7 @@ bool __init topology_parse_cpu_capacity(struct device_n= ode *cpu_node, int cpu) =20 void topology_init_cpu_capacity_cppc(void) { + u64 capacity, capacity_scale =3D 0; struct cppc_perf_caps perf_caps; int cpu; =20 @@ -365,6 +366,10 @@ void topology_init_cpu_capacity_cppc(void) (perf_caps.highest_perf >=3D perf_caps.nominal_perf) && (perf_caps.highest_perf >=3D perf_caps.lowest_perf)) { raw_capacity[cpu] =3D perf_caps.highest_perf; + capacity_scale =3D max_t(u64, capacity_scale, raw_capacity[cpu]); + + per_cpu(capacity_freq_ref, cpu) =3D cppc_perf_to_khz(&perf_caps, raw_ca= pacity[cpu]); + pr_debug("cpu_capacity: CPU%d cpu_capacity=3D%u (raw).\n", cpu, raw_capacity[cpu]); continue; @@ -375,7 +380,15 @@ void topology_init_cpu_capacity_cppc(void) goto exit; } =20 - topology_normalize_cpu_scale(); + for_each_possible_cpu(cpu) { + capacity =3D raw_capacity[cpu]; + capacity =3D div64_u64(capacity << SCHED_CAPACITY_SHIFT, + capacity_scale); + topology_set_cpu_scale(cpu, capacity); + pr_debug("cpu_capacity: CPU%d cpu_capacity=3D%lu\n", + cpu, topology_get_cpu_scale(cpu)); + } + schedule_work(&update_topology_flags_work); pr_debug("cpu_capacity: cpu_capacity initialization done\n"); =20 --=20 2.34.1 From nobody Mon Dec 15 21:25:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3AA9C4167D for ; Thu, 9 Nov 2023 10:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234168AbjKIKPX (ORCPT ); Thu, 9 Nov 2023 05:15:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233475AbjKIKPL (ORCPT ); Thu, 9 Nov 2023 05:15:11 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D798F30D5 for ; Thu, 9 Nov 2023 02:15:00 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40839807e82so4048495e9.0 for ; Thu, 09 Nov 2023 02:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699524899; x=1700129699; 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=Yeh/ejHIslK7GUpigz7eOxRJ5nIZNkForzOfukaDKm0=; b=r4t1ibiOa66uJtVLUNjZ3X3zQsZ+Awg425wX7LcAY4Gp69+CEFUXdMvAXkATcWePZV z6QefD6qL6CVN1gv+m98Iv3uI7FrDkQvkitUMY0DFCOH3E+S6+7/5emJ6AbU2dmizGJQ MsqwOrxVLF5txOevqS3x6rUch5ueEQQX4bL68f2BJTbrkktV780i1vHpnDXXF3kTEBS5 U0T0Mnps+4l7tUy42gS+cjQJupK3LXlcLTvDtkJnjW2WoH/hsRQN9bfuuorncUFZFWt9 vRnx/cblg67XdV08PQJuqCGUCB7ZwR9sGxOFZqV/3Y4zk/C6vJya22lvSWapEgwIeraN mPNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524899; x=1700129699; 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=Yeh/ejHIslK7GUpigz7eOxRJ5nIZNkForzOfukaDKm0=; b=aesLyRgmwUj4JveO2PoVB8RsNsq1e/ar25uiLAB7YH9xvPQeBybjgoAaeiu49XZXnh 9xNZl9ej9v9xJM/jjpi8gka7pjXWz1M80RuoG0N+uaQrezcCwb9RNToMhbI7mHiIBND9 qUL3Q4g4ZArS0eMV657pklSTYSTWL67wa7mNdSlLmMqzOo6QLEa+9ezWnveKbTHnOhgn dytl48lYg0b0gnvskXWaHxgn1bOsD2w2m3byOtfx8ZGk57DCS/6Ecq2RQ6gXrQqlur4L baIn12Hyg/x/Fd+ttKSUArhecgD6xqqMfCDLRkDmCapnK3rUAsbEJ1v47pYEifFzUU1d ecdw== X-Gm-Message-State: AOJu0YyGEu6L4pn6jSiFOtq4AaxLKO1CqxLBJqvWIu3eIxq35Xq1+hqo SGCly7moC1lvgCu8k+2mjgkcFg== X-Google-Smtp-Source: AGHT+IGlIQP4ExpYKEcJPouG3NAgRbcbvugwDfKHk5La7RKyXTFl7Z52+KMescuL7ihHOYDKBftYUA== X-Received: by 2002:a05:600c:3c97:b0:406:5a14:5c1e with SMTP id bg23-20020a05600c3c9700b004065a145c1emr10570874wmb.1.1699524899315; Thu, 09 Nov 2023 02:14:59 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:26e5:c6da:63bc:dd99]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b003fefb94ccc9sm1611816wmq.11.2023.11.09.02.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:14:58 -0800 (PST) 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, beata.michalska@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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v6 7/7] arm64/amu: Use capacity_ref_freq to set AMU ratio Date: Thu, 9 Nov 2023 11:14:38 +0100 Message-Id: <20231109101438.1139696-8-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109101438.1139696-1-vincent.guittot@linaro.org> References: <20231109101438.1139696-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the new capacity_ref_freq to set the ratio that is used by AMU for computing the arch_scale_freq_capacity(). This helps to keep everything aligned using the same reference for computing CPUs capacity. The default value of the ratio (stored in per_cpu(arch_max_freq_scale)) ensures that arch_scale_freq_capacity() returns max capacity until it is set to its correct value with the cpu capacity and capacity_ref_freq. Signed-off-by: Vincent Guittot Acked-by: Sudeep Holla Acked-by: Will Deacon Tested-by: Pierre Gondois --- arch/arm64/kernel/topology.c | 26 +++++++++++++------------- drivers/base/arch_topology.c | 12 +++++++++++- include/linux/arch_topology.h | 1 + 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 817d788cd866..1a2c72f3e7f8 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -82,7 +82,12 @@ int __init parse_acpi_topology(void) #undef pr_fmt #define pr_fmt(fmt) "AMU: " fmt =20 -static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, arch_max_freq_scale); +/* + * Ensure that amu_scale_freq_tick() will return SCHED_CAPACITY_SCALE until + * the CPU capacity and its associated frequency have been correctly + * initialized. + */ +static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, arch_max_freq_scale) =3D = 1UL << (2 * SCHED_CAPACITY_SHIFT); static DEFINE_PER_CPU(u64, arch_const_cycles_prev); static DEFINE_PER_CPU(u64, arch_core_cycles_prev); static cpumask_var_t amu_fie_cpus; @@ -112,14 +117,14 @@ static inline bool freq_counters_valid(int cpu) return true; } =20 -static int freq_inv_set_max_ratio(int cpu, u64 max_rate, u64 ref_rate) +void freq_inv_set_max_ratio(int cpu, u64 max_rate) { - u64 ratio; + u64 ratio, ref_rate =3D arch_timer_get_rate(); =20 if (unlikely(!max_rate || !ref_rate)) { - pr_debug("CPU%d: invalid maximum or reference frequency.\n", + WARN_ONCE(1, "CPU%d: invalid maximum or reference frequency.\n", cpu); - return -EINVAL; + return; } =20 /* @@ -139,12 +144,10 @@ static int freq_inv_set_max_ratio(int cpu, u64 max_ra= te, u64 ref_rate) ratio =3D div64_u64(ratio, max_rate); if (!ratio) { WARN_ONCE(1, "Reference frequency too low.\n"); - return -EINVAL; + return; } =20 - per_cpu(arch_max_freq_scale, cpu) =3D (unsigned long)ratio; - - return 0; + WRITE_ONCE(per_cpu(arch_max_freq_scale, cpu), (unsigned long)ratio); } =20 static void amu_scale_freq_tick(void) @@ -195,10 +198,7 @@ static void amu_fie_setup(const struct cpumask *cpus) return; =20 for_each_cpu(cpu, cpus) { - if (!freq_counters_valid(cpu) || - freq_inv_set_max_ratio(cpu, - cpufreq_get_hw_max_freq(cpu) * 1000ULL, - arch_timer_get_rate())) + if (!freq_counters_valid(cpu)) return; } =20 diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 0a2e43728286..0906114963ff 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -344,6 +344,10 @@ bool __init topology_parse_cpu_capacity(struct device_= node *cpu_node, int cpu) return !ret; } =20 +void __weak freq_inv_set_max_ratio(int cpu, u64 max_rate) +{ +} + #ifdef CONFIG_ACPI_CPPC_LIB #include =20 @@ -381,6 +385,9 @@ void topology_init_cpu_capacity_cppc(void) } =20 for_each_possible_cpu(cpu) { + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); + capacity =3D raw_capacity[cpu]; capacity =3D div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity_scale); @@ -422,8 +429,11 @@ init_cpu_capacity_callback(struct notifier_block *nb, =20 cpumask_andnot(cpus_to_visit, cpus_to_visit, policy->related_cpus); =20 - for_each_cpu(cpu, policy->related_cpus) + for_each_cpu(cpu, policy->related_cpus) { per_cpu(capacity_freq_ref, cpu) =3D policy->cpuinfo.max_freq; + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); + } =20 if (cpumask_empty(cpus_to_visit)) { topology_normalize_cpu_scale(); diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 32c24ff4f2a8..a63d61ca55af 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -99,6 +99,7 @@ void update_siblings_masks(unsigned int cpu); void remove_cpu_topology(unsigned int cpuid); void reset_cpu_topology(void); int parse_acpi_topology(void); +void freq_inv_set_max_ratio(int cpu, u64 max_rate); #endif =20 #endif /* _LINUX_ARCH_TOPOLOGY_H_ */ --=20 2.34.1