All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Donnefort <vincent.donnefort@arm.com>
To: peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org,
	vincent.guittot@linaro.org, qperret@google.com
Cc: linux-pm@vger.kernel.org, ionela.voinescu@arm.com,
	lukasz.luba@arm.com, dietmar.eggemann@arm.com, mka@chromium.org,
	Vincent Donnefort <vincent.donnefort@arm.com>
Subject: [PATCH v6 7/7] PM / EM: Mark inefficiencies in CPUFreq
Date: Tue, 31 Aug 2021 11:24:13 +0100	[thread overview]
Message-ID: <1630405453-275784-8-git-send-email-vincent.donnefort@arm.com> (raw)
In-Reply-To: <1630405453-275784-1-git-send-email-vincent.donnefort@arm.com>

The Energy Model has a 1:1 mapping between OPPs and performance states
(em_perf_state). If a CPUFreq driver registers an Energy Model,
inefficiencies found by the latter can be applied to CPUFreq.

Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>

diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index cb09afbf01e2..153ddc7b0506 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -1121,7 +1121,6 @@ void cpufreq_generic_init(struct cpufreq_policy *policy,
 
 static inline void cpufreq_register_em_with_opp(struct cpufreq_policy *policy)
 {
-	dev_pm_opp_of_register_em(get_cpu_device(policy->cpu),
-				  policy->related_cpus);
+	dev_pm_opp_of_register_em(get_cpu_device(policy->cpu), policy->related_cpus);
 }
 #endif /* _LINUX_CPUFREQ_H */
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index d353ef29e37f..dfcbb2deb794 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -10,6 +10,7 @@
 #define pr_fmt(fmt) "energy_model: " fmt
 
 #include <linux/cpu.h>
+#include <linux/cpufreq.h>
 #include <linux/cpumask.h>
 #include <linux/debugfs.h>
 #include <linux/energy_model.h>
@@ -231,6 +232,46 @@ static int em_create_pd(struct device *dev, int nr_states,
 	return 0;
 }
 
+static void em_cpufreq_update_efficiencies(struct device *dev)
+{
+	struct em_perf_domain *pd = dev->em_pd;
+	struct em_perf_state *table;
+	struct cpufreq_policy *policy;
+	bool found = false;
+	int i;
+
+	if (!_is_cpu_device(dev) || !pd)
+		return;
+
+	policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd)));
+	if (!policy) {
+		dev_warn(dev, "EM: Access to CPUFreq policy failed");
+		return;
+	}
+
+	table = pd->table;
+
+	for (i = 0; i < pd->nr_perf_states; i++) {
+		if (!(table[i].flags & EM_PERF_STATE_INEFFICIENT))
+			continue;
+
+		cpufreq_table_set_inefficient(policy, table[i].frequency);
+		found = true;
+	}
+
+	if (!found)
+		return;
+
+	if (cpufreq_table_update_efficiencies(policy))
+		return;
+
+	/*
+	 * Efficiencies have been installed in CPUFreq, inefficient frequencies
+	 * will be skipped. The EM can do the same.
+	 */
+	pd->flags |= EM_PERF_DOMAIN_SKIP_INEFFICIENCIES;
+}
+
 /**
  * em_pd_get() - Return the performance domain for a device
  * @dev : Device to find the performance domain for
@@ -347,6 +388,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
 	if (milliwatts)
 		dev->em_pd->flags |= EM_PERF_DOMAIN_MILLIWATTS;
 
+	em_cpufreq_update_efficiencies(dev);
+
 	em_debug_create_pd(dev);
 	dev_info(dev, "EM: created perf domain\n");
 
-- 
2.7.4


  parent reply	other threads:[~2021-08-31 10:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 10:24 [PATCH v6 0/7] Inefficient OPPs Vincent Donnefort
2021-08-31 10:24 ` [PATCH v6 1/7] PM / EM: Fix inefficient states detection Vincent Donnefort
2021-08-31 10:24 ` [PATCH v6 2/7] PM / EM: Mark inefficient states Vincent Donnefort
2021-08-31 10:24 ` [PATCH v6 3/7] PM / EM: Extend em_perf_domain with a flag field Vincent Donnefort
2021-08-31 10:24 ` [PATCH v6 4/7] PM / EM: Allow skipping inefficient states Vincent Donnefort
2021-08-31 10:24 ` [PATCH v6 5/7] cpufreq: Add an interface to mark inefficient frequencies Vincent Donnefort
2021-09-01  4:55   ` Viresh Kumar
2021-09-01 17:25   ` Rafael J. Wysocki
2021-08-31 10:24 ` [PATCH v6 6/7] cpufreq: Skip " Vincent Donnefort
2021-09-01  5:30   ` Viresh Kumar
2021-09-01 18:13   ` Rafael J. Wysocki
2021-09-02 10:50     ` Vincent Donnefort
2021-09-02 13:09       ` Rafael J. Wysocki
2021-09-02 13:49         ` Vincent Donnefort
2021-09-03 18:14           ` Rafael J. Wysocki
2021-09-06  8:17             ` Vincent Donnefort
2021-09-06 12:08               ` Rafael J. Wysocki
2021-09-06 12:53                 ` Vincent Donnefort
2021-09-06 15:16                   ` Rafael J. Wysocki
2021-09-06 15:32                     ` Rafael J. Wysocki
2021-09-06 15:38                     ` Vincent Donnefort
2021-09-06 16:04                       ` Rafael J. Wysocki
2021-08-31 10:24 ` Vincent Donnefort [this message]
2021-09-01  5:31   ` [PATCH v6 7/7] PM / EM: Mark inefficiencies in CPUFreq Viresh Kumar

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=1630405453-275784-8-git-send-email-vincent.donnefort@arm.com \
    --to=vincent.donnefort@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=ionela.voinescu@arm.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=mka@chromium.org \
    --cc=peterz@infradead.org \
    --cc=qperret@google.com \
    --cc=rjw@rjwysocki.net \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    /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.