From: ulf.hansson@linaro.org (Ulf Hansson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 07/25] PM / Domains: Add genpd governor for CPUs
Date: Wed, 14 Mar 2018 17:58:17 +0100 [thread overview]
Message-ID: <1521046715-30683-8-git-send-email-ulf.hansson@linaro.org> (raw)
In-Reply-To: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org>
As it's now perfectly possible that a PM domain managed by genpd contains
devices belonging to CPUs, we should start to take into account the
residency values for the idle states during the state selection process.
The residency value specifies the minimum duration of time, the CPU or a
group of CPUs, needs to spend in an idle state to not waste energy entering
it.
To deal with this, let's add a new genpd governor, pm_domain_cpu_gov, that
may be used for a PM domain that have CPU devices attached or if the CPUs
are attached through subdomains.
The new governor computes the minimum expected idle duration time for the
online CPUs being attached to the PM domain and its subdomains. Then in the
state selection process, trying the deepest state first, it verifies that
the idle duration time satisfies the state's residency value.
It should be noted that, when computing the minimum expected idle duration
time, we use the information from tick_nohz_get_next_wakeup(), to find the
next wakeup for the related CPUs. Future wise, this may deserve to be
improved, as there are more reasons to why a CPU may be woken up from idle.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Lina Iyer <ilina@codeaurora.org>
Co-developed-by: Lina Iyer <lina.iyer@linaro.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/base/power/domain_governor.c | 56 ++++++++++++++++++++++++++++++++++++
include/linux/pm_domain.h | 2 ++
2 files changed, 58 insertions(+)
diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c
index 99896fb..70565a8 100644
--- a/drivers/base/power/domain_governor.c
+++ b/drivers/base/power/domain_governor.c
@@ -10,6 +10,9 @@
#include <linux/pm_domain.h>
#include <linux/pm_qos.h>
#include <linux/hrtimer.h>
+#include <linux/cpumask.h>
+#include <linux/ktime.h>
+#include <linux/tick.h>
static int dev_update_qos_constraint(struct device *dev, void *data)
{
@@ -245,6 +248,54 @@ static bool always_on_power_down_ok(struct dev_pm_domain *domain)
return false;
}
+static bool cpu_power_down_ok(struct dev_pm_domain *pd)
+{
+ struct generic_pm_domain *genpd = pd_to_genpd(pd);
+ ktime_t domain_wakeup, cpu_wakeup;
+ s64 idle_duration_ns;
+ int cpu, i;
+
+ if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN))
+ return true;
+
+ /*
+ * Find the next wakeup for any of the online CPUs within the PM domain
+ * and its subdomains. Note, we only need the genpd->cpus, as it already
+ * contains a mask of all CPUs from subdomains.
+ */
+ domain_wakeup = ktime_set(KTIME_SEC_MAX, 0);
+ for_each_cpu_and(cpu, genpd->cpus, cpu_online_mask) {
+ cpu_wakeup = tick_nohz_get_next_wakeup(cpu);
+ if (ktime_before(cpu_wakeup, domain_wakeup))
+ domain_wakeup = cpu_wakeup;
+ }
+
+ /* The minimum idle duration is from now - until the next wakeup. */
+ idle_duration_ns = ktime_to_ns(ktime_sub(domain_wakeup, ktime_get()));
+
+ /*
+ * Find the deepest idle state, that has its residency value satisfied.
+ * Start at the deepest supported state.
+ */
+ i = genpd->state_count - 1;
+ do {
+ if (!genpd->states[i].residency_ns)
+ break;
+
+ /* Check idle_duration_ns >= 0 to compare signed/unsigned. */
+ if (idle_duration_ns >= 0 &&
+ idle_duration_ns >= genpd->states[i].residency_ns)
+ break;
+ i--;
+ } while (i >= 0);
+
+ if (i < 0)
+ return false;
+
+ genpd->state_idx = i;
+ return true;
+}
+
struct dev_power_governor simple_qos_governor = {
.suspend_ok = default_suspend_ok,
.power_down_ok = default_power_down_ok,
@@ -257,3 +308,8 @@ struct dev_power_governor pm_domain_always_on_gov = {
.power_down_ok = always_on_power_down_ok,
.suspend_ok = default_suspend_ok,
};
+
+struct dev_power_governor pm_domain_cpu_gov = {
+ .suspend_ok = NULL,
+ .power_down_ok = cpu_power_down_ok,
+};
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ccd7c94..8f60181 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -161,6 +161,7 @@ extern int dev_pm_genpd_set_performance_state(struct device *dev,
extern struct dev_power_governor simple_qos_governor;
extern struct dev_power_governor pm_domain_always_on_gov;
+extern struct dev_power_governor pm_domain_cpu_gov;
#else
static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
@@ -206,6 +207,7 @@ static inline int dev_pm_genpd_set_performance_state(struct device *dev,
#define simple_qos_governor (*(struct dev_power_governor *)(NULL))
#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
+#define pm_domain_cpu_gov (*(struct dev_power_governor *)(NULL))
#endif
static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
--
2.7.4
next prev parent reply other threads:[~2018-03-14 16:58 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-14 16:58 [PATCH v6 00/25] PM / Domains: Support hierarchical CPU arrangement (PSCI/ARM) Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 01/25] PM / Domains: Don't treat zero found compatible idle states as an error Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 02/25] PM / Domains: Deal with multiple states but no governor in genpd Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 03/25] PM / Domains: Add generic data pointer to genpd_power_state struct Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 04/25] PM / Domains: Add support for CPU devices to genpd Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 05/25] PM / Domains: Add helper functions to attach/detach CPUs to/from genpd Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 06/25] timer: Export next wakeup time of a CPU Ulf Hansson
2018-03-14 17:19 ` Mark Rutland
2018-03-14 16:58 ` Ulf Hansson [this message]
2018-03-14 16:58 ` [PATCH v6 08/25] PM / Domains: Extend genpd CPU governor to cope with QoS constraints Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 09/25] kernel/cpu_pm: Manage runtime PM in the idle path for CPUs Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 10/25] dt: psci: Update DT bindings to support hierarchical PSCI states Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 11/25] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Ulf Hansson
2018-03-18 12:51 ` Rob Herring
2018-03-14 16:58 ` [PATCH v6 12/25] cpuidle: dt: Support hierarchical CPU idle states Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 13/25] drivers: firmware: psci: Split psci_dt_cpu_init_idle() Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 14/25] drivers: firmware: psci: Support hierarchical CPU idle states Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 15/25] drivers: firmware: psci: Simplify error path of psci_dt_init() Ulf Hansson
2018-03-14 17:25 ` Mark Rutland
2018-03-14 16:58 ` [PATCH v6 16/25] drivers: firmware: psci: Announce support for OS initiated suspend mode Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 17/25] drivers: firmware: psci: Prepare to use " Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 18/25] drivers: firmware: psci: Share a few internal PSCI functions Ulf Hansson
2018-03-14 17:30 ` Mark Rutland
2018-03-14 16:58 ` [PATCH v6 19/25] drivers: firmware: psci: Add support for PM domains using genpd Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 20/25] drivers: firmware: psci: Introduce psci_dt_topology_init() Ulf Hansson
2018-03-14 17:38 ` Mark Rutland
2018-04-10 7:19 ` Ulf Hansson
2018-04-10 11:10 ` Mark Rutland
2018-04-10 12:25 ` Ulf Hansson
2018-04-18 11:32 ` Mark Rutland
2018-03-14 16:58 ` [PATCH v6 21/25] drivers: firmware: psci: Try to attach CPU devices to their PM domains Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 22/25] drivers: firmware: psci: Deal with CPU hotplug when using OSI mode Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 23/25] MAINTAINERS: Update files for PSCI Ulf Hansson
2018-03-14 17:40 ` Mark Rutland
2018-03-14 16:58 ` [PATCH v6 24/25] arm64: kernel: Respect the hierarchical CPU topology in DT " Ulf Hansson
2018-03-14 16:58 ` [PATCH v6 25/25] arm64: dts: Convert to the hierarchical CPU topology layout for MSM8916 Ulf Hansson
2018-03-14 17:19 ` [PATCH v6 00/25] PM / Domains: Support hierarchical CPU arrangement (PSCI/ARM) Mark Rutland
2018-03-15 14:19 ` Ulf Hansson
2018-03-15 11:00 ` Geert Uytterhoeven
2018-03-15 13:14 ` Ulf Hansson
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=1521046715-30683-8-git-send-email-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).