From nobody Thu Dec 18 15:08:27 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 EA36DC4167B for ; Wed, 29 Nov 2023 11:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231741AbjK2LKT (ORCPT ); Wed, 29 Nov 2023 06:10:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjK2LJh (ORCPT ); Wed, 29 Nov 2023 06:09:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95E121FCE; Wed, 29 Nov 2023 03:08:50 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D4CFC15; Wed, 29 Nov 2023 03:09:37 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BA4E83F5A1; Wed, 29 Nov 2023 03:08:47 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v5 18/23] drivers/thermal/cpufreq_cooling: Use new Energy Model interface Date: Wed, 29 Nov 2023 11:08:48 +0000 Message-Id: <20231129110853.94344-19-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-1-lukasz.luba@arm.com> 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" Energy Model framework support modifications at runtime of the power values. Use the new EM table API which is protected with RCU. Align the code so that this RCU read section is short. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/cpufreq_cooling.c | 40 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_co= oling.c index e2cc7bd30862..c32d8dfa4fff 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -91,12 +91,15 @@ struct cpufreq_cooling_device { static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { + struct em_perf_state *table; int i; =20 + table =3D em_get_table(cpufreq_cdev->em); for (i =3D cpufreq_cdev->max_level - 1; i >=3D 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } + em_put_table(); =20 return cpufreq_cdev->max_level - i - 1; } @@ -104,16 +107,19 @@ static unsigned long get_level(struct cpufreq_cooling= _device *cpufreq_cdev, static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, u32 freq) { + struct em_perf_state *table; unsigned long power_mw; int i; =20 + table =3D em_get_table(cpufreq_cdev->em); for (i =3D cpufreq_cdev->max_level - 1; i >=3D 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } =20 - power_mw =3D cpufreq_cdev->em->table[i + 1].power; + power_mw =3D table[i + 1].power; power_mw /=3D MICROWATT_PER_MILLIWATT; + em_put_table(); =20 return power_mw; } @@ -121,18 +127,23 @@ static u32 cpu_freq_to_power(struct cpufreq_cooling_d= evice *cpufreq_cdev, static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, u32 power) { + struct em_perf_state *table; unsigned long em_power_mw; + u32 freq; int i; =20 + table =3D em_get_table(cpufreq_cdev->em); for (i =3D cpufreq_cdev->max_level; i > 0; i--) { /* Convert EM power to milli-Watts to make safe comparison */ - em_power_mw =3D cpufreq_cdev->em->table[i].power; + em_power_mw =3D table[i].power; em_power_mw /=3D MICROWATT_PER_MILLIWATT; if (power >=3D em_power_mw) break; } + freq =3D table[i].frequency; + em_put_table(); =20 - return cpufreq_cdev->em->table[i].frequency; + return freq; } =20 /** @@ -262,8 +273,9 @@ static int cpufreq_get_requested_power(struct thermal_c= ooling_device *cdev, static int cpufreq_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { - unsigned int freq, num_cpus, idx; struct cpufreq_cooling_device *cpufreq_cdev =3D cdev->devdata; + unsigned int freq, num_cpus, idx; + struct em_perf_state *table; =20 /* Request state should be less than max_level */ if (state > cpufreq_cdev->max_level) @@ -272,7 +284,11 @@ static int cpufreq_state2power(struct thermal_cooling_= device *cdev, num_cpus =3D cpumask_weight(cpufreq_cdev->policy->cpus); =20 idx =3D cpufreq_cdev->max_level - state; - freq =3D cpufreq_cdev->em->table[idx].frequency; + + table =3D em_get_table(cpufreq_cdev->em); + freq =3D table[idx].frequency; + em_put_table(); + *power =3D cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; =20 return 0; @@ -378,8 +394,16 @@ static unsigned int get_state_freq(struct cpufreq_cool= ing_device *cpufreq_cdev, #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR /* Use the Energy Model table if available */ if (cpufreq_cdev->em) { + struct em_perf_state *table; + unsigned int freq; + idx =3D cpufreq_cdev->max_level - state; - return cpufreq_cdev->em->table[idx].frequency; + + table =3D em_get_table(cpufreq_cdev->em); + freq =3D table[idx].frequency; + em_put_table(); + + return freq; } #endif =20 --=20 2.25.1