All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
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,
	xuewen.yan94@gmail.com
Subject: [PATCH v8 16/23] powercap/dtpm_cpu: Use new Energy Model interface to get table
Date: Thu,  8 Feb 2024 11:55:50 +0000	[thread overview]
Message-ID: <20240208115557.1273962-17-lukasz.luba@arm.com> (raw)
In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com>

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.

Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/powercap/dtpm_cpu.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index 9193c3b8edeb..ee0d1aa3e023 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -42,6 +42,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
 {
 	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
 	struct em_perf_domain *pd = em_cpu_get(dtpm_cpu->cpu);
+	struct em_perf_state *table;
 	struct cpumask cpus;
 	unsigned long freq;
 	u64 power;
@@ -50,20 +51,22 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
 	cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus));
 	nr_cpus = cpumask_weight(&cpus);
 
+	rcu_read_lock();
+	table = em_perf_state_from_pd(pd);
 	for (i = 0; i < pd->nr_perf_states; i++) {
 
-		power = pd->table[i].power * nr_cpus;
+		power = table[i].power * nr_cpus;
 
 		if (power > power_limit)
 			break;
 	}
 
-	freq = pd->table[i - 1].frequency;
+	freq = table[i - 1].frequency;
+	power_limit = table[i - 1].power * nr_cpus;
+	rcu_read_unlock();
 
 	freq_qos_update_request(&dtpm_cpu->qos_req, freq);
 
-	power_limit = pd->table[i - 1].power * nr_cpus;
-
 	return power_limit;
 }
 
@@ -87,9 +90,11 @@ static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power)
 static u64 get_pd_power_uw(struct dtpm *dtpm)
 {
 	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
+	struct em_perf_state *table;
 	struct em_perf_domain *pd;
 	struct cpumask *pd_mask;
 	unsigned long freq;
+	u64 power = 0;
 	int i;
 
 	pd = em_cpu_get(dtpm_cpu->cpu);
@@ -98,33 +103,43 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
 
 	freq = cpufreq_quick_get(dtpm_cpu->cpu);
 
+	rcu_read_lock();
+	table = em_perf_state_from_pd(pd);
 	for (i = 0; i < pd->nr_perf_states; i++) {
 
-		if (pd->table[i].frequency < freq)
+		if (table[i].frequency < freq)
 			continue;
 
-		return scale_pd_power_uw(pd_mask, pd->table[i].power);
+		power = scale_pd_power_uw(pd_mask, table[i].power);
+		break;
 	}
+	rcu_read_unlock();
 
-	return 0;
+	return power;
 }
 
 static int update_pd_power_uw(struct dtpm *dtpm)
 {
 	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
 	struct em_perf_domain *em = em_cpu_get(dtpm_cpu->cpu);
+	struct em_perf_state *table;
 	struct cpumask cpus;
 	int nr_cpus;
 
 	cpumask_and(&cpus, cpu_online_mask, to_cpumask(em->cpus));
 	nr_cpus = cpumask_weight(&cpus);
 
-	dtpm->power_min = em->table[0].power;
+	rcu_read_lock();
+	table = em_perf_state_from_pd(em);
+
+	dtpm->power_min = table[0].power;
 	dtpm->power_min *= nr_cpus;
 
-	dtpm->power_max = em->table[em->nr_perf_states - 1].power;
+	dtpm->power_max = table[em->nr_perf_states - 1].power;
 	dtpm->power_max *= nr_cpus;
 
+	rcu_read_unlock();
+
 	return 0;
 }
 
@@ -180,6 +195,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 {
 	struct dtpm_cpu *dtpm_cpu;
 	struct cpufreq_policy *policy;
+	struct em_perf_state *table;
 	struct em_perf_domain *pd;
 	char name[CPUFREQ_NAME_LEN];
 	int ret = -ENOMEM;
@@ -216,9 +232,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 	if (ret)
 		goto out_kfree_dtpm_cpu;
 
+	rcu_read_lock();
+	table = em_perf_state_from_pd(pd);
 	ret = freq_qos_add_request(&policy->constraints,
 				   &dtpm_cpu->qos_req, FREQ_QOS_MAX,
-				   pd->table[pd->nr_perf_states - 1].frequency);
+				   table[pd->nr_perf_states - 1].frequency);
+	rcu_read_unlock();
 	if (ret)
 		goto out_dtpm_unregister;
 
-- 
2.25.1


  parent reply	other threads:[~2024-02-08 11:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08 11:55 [PATCH v8 00/23] Introduce runtime modifiable Energy Model Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 01/23] PM: EM: Add missing newline for the message log Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 02/23] PM: EM: Extend em_cpufreq_update_efficiencies() argument list Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 03/23] PM: EM: Find first CPU active while updating OPP efficiency Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 05/23] PM: EM: Introduce em_compute_costs() Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 06/23] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 07/23] PM: EM: Split the allocation and initialization of the EM table Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 08/23] PM: EM: Introduce runtime modifiable table Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 09/23] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 10/23] PM: EM: Add functions for memory allocations for new EM tables Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 11/23] PM: EM: Introduce em_dev_update_perf_domain() for EM updates Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 12/23] PM: EM: Add em_perf_state_from_pd() to get performance states table Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 13/23] PM: EM: Add performance field to struct em_perf_state and optimize Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 14/23] PM: EM: Support late CPUs booting and capacity adjustment Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 15/23] PM: EM: Optimize em_cpu_energy() and remove division Lukasz Luba
2024-02-08 11:55 ` Lukasz Luba [this message]
2024-02-08 11:55 ` [PATCH v8 17/23] powercap/dtpm_devfreq: Use new Energy Model interface to get table Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 18/23] drivers/thermal/cpufreq_cooling: Use new Energy Model interface Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 19/23] drivers/thermal/devfreq_cooling: " Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 21/23] PM: EM: Remove old table Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 22/23] PM: EM: Add em_dev_compute_costs() Lukasz Luba
2024-02-08 11:55 ` [PATCH v8 23/23] Documentation: EM: Update with runtime modification design Lukasz Luba
2024-02-08 14:01 ` [PATCH v8 00/23] Introduce runtime modifiable Energy Model Rafael J. Wysocki
2024-02-08 15:00   ` Lukasz Luba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240208115557.1273962-17-lukasz.luba@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=amit.kachhap@gmail.com \
    --cc=amit.kucheria@verdurent.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=qyousef@layalina.io \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wvw@google.com \
    --cc=xuewen.yan94@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.