From nobody Fri Dec 26 19:27:31 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24AAF328CA; Thu, 4 Jan 2024 17:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 B86DC153B; Thu, 4 Jan 2024 09:16:28 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4D5393F64C; Thu, 4 Jan 2024 09:15:40 -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 v6 19/23] drivers/thermal/devfreq_cooling: Use new Energy Model interface Date: Thu, 4 Jan 2024 17:15:49 +0000 Message-Id: <20240104171553.2080674-20-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-1-lukasz.luba@arm.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" 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/devfreq_cooling.c | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_co= oling.c index 262e62ab6cf2..b7aed5a3810e 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -87,6 +87,7 @@ static int devfreq_cooling_set_cur_state(struct thermal_c= ooling_device *cdev, struct devfreq_cooling_device *dfc =3D cdev->devdata; struct devfreq *df =3D dfc->devfreq; struct device *dev =3D df->dev.parent; + struct em_perf_state *table; unsigned long freq; int perf_idx; =20 @@ -100,7 +101,10 @@ static int devfreq_cooling_set_cur_state(struct therma= l_cooling_device *cdev, =20 if (dfc->em_pd) { perf_idx =3D dfc->max_state - state; - freq =3D dfc->em_pd->table[perf_idx].frequency * 1000; + + table =3D em_get_table(dfc->em_pd); + freq =3D table[perf_idx].frequency * 1000; + em_put_table(); } else { freq =3D dfc->freq_table[state]; } @@ -123,14 +127,20 @@ static int devfreq_cooling_set_cur_state(struct therm= al_cooling_device *cdev, */ static int get_perf_idx(struct em_perf_domain *em_pd, unsigned long freq) { - int i; + struct em_perf_state *table; + int i, idx =3D -EINVAL; =20 + table =3D em_get_table(em_pd); for (i =3D 0; i < em_pd->nr_perf_states; i++) { - if (em_pd->table[i].frequency =3D=3D freq) - return i; + if (table[i].frequency !=3D freq) + continue; + + idx =3D i; + break; } + em_put_table(); =20 - return -EINVAL; + return idx; } =20 static unsigned long get_voltage(struct devfreq *df, unsigned long freq) @@ -181,6 +191,7 @@ static int devfreq_cooling_get_requested_power(struct t= hermal_cooling_device *cd struct devfreq_cooling_device *dfc =3D cdev->devdata; struct devfreq *df =3D dfc->devfreq; struct devfreq_dev_status status; + struct em_perf_state *table; unsigned long state; unsigned long freq; unsigned long voltage; @@ -204,7 +215,10 @@ static int devfreq_cooling_get_requested_power(struct = thermal_cooling_device *cd state =3D dfc->capped_state; =20 /* Convert EM power into milli-Watts first */ - dfc->res_util =3D dfc->em_pd->table[state].power; + table =3D em_get_table(dfc->em_pd); + dfc->res_util =3D table[state].power; + em_put_table(); + dfc->res_util /=3D MICROWATT_PER_MILLIWATT; =20 dfc->res_util *=3D SCALE_ERROR_MITIGATION; @@ -225,7 +239,10 @@ static int devfreq_cooling_get_requested_power(struct = thermal_cooling_device *cd _normalize_load(&status); =20 /* Convert EM power into milli-Watts first */ - *power =3D dfc->em_pd->table[perf_idx].power; + table =3D em_get_table(dfc->em_pd); + *power =3D table[perf_idx].power; + em_put_table(); + *power /=3D MICROWATT_PER_MILLIWATT; /* Scale power for utilization */ *power *=3D status.busy_time; @@ -245,13 +262,18 @@ static int devfreq_cooling_state2power(struct thermal= _cooling_device *cdev, unsigned long state, u32 *power) { struct devfreq_cooling_device *dfc =3D cdev->devdata; + struct em_perf_state *table; int perf_idx; =20 if (state > dfc->max_state) return -EINVAL; =20 perf_idx =3D dfc->max_state - state; - *power =3D dfc->em_pd->table[perf_idx].power; + + table =3D em_get_table(dfc->em_pd); + *power =3D table[perf_idx].power; + em_put_table(); + *power /=3D MICROWATT_PER_MILLIWATT; =20 return 0; @@ -264,6 +286,7 @@ static int devfreq_cooling_power2state(struct thermal_c= ooling_device *cdev, struct devfreq *df =3D dfc->devfreq; struct devfreq_dev_status status; unsigned long freq, em_power_mw; + struct em_perf_state *table; s32 est_power; int i; =20 @@ -288,13 +311,15 @@ static int devfreq_cooling_power2state(struct thermal= _cooling_device *cdev, * Find the first cooling state that is within the power * budget. The EM power table is sorted ascending. */ + table =3D em_get_table(dfc->em_pd); for (i =3D dfc->max_state; i > 0; i--) { /* Convert EM power to milli-Watts to make safe comparison */ - em_power_mw =3D dfc->em_pd->table[i].power; + em_power_mw =3D table[i].power; em_power_mw /=3D MICROWATT_PER_MILLIWATT; if (est_power >=3D em_power_mw) break; } + em_put_table(); =20 *state =3D dfc->max_state - i; dfc->capped_state =3D *state; --=20 2.25.1