From patchwork Wed Mar 14 16:58:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 131676 Delivered-To: patches@linaro.org Received: by 10.80.210.197 with SMTP id q5csp410385edg; Wed, 14 Mar 2018 09:59:15 -0700 (PDT) X-Received: by 2002:a19:e59d:: with SMTP id i29-v6mr4252251lfk.66.1521046755317; Wed, 14 Mar 2018 09:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521046755; cv=none; d=google.com; s=arc-20160816; b=OMURVzKP1rXeBWMKXl5smgDDuFlvIlUAaDCz4C0mggPLf+DskBF0Xjc4ZdyKasOX/w oytBl7GkTAQjLBnjwefYcg5vZw16f3UKGJiDXfvI+nIUJ7M0AgngAhVeaZ1WwmErqqLT 1uEzUcjk9qYmde1zirOhK6wB0ProNwRR90jP5ZIyfJH2N2ZyerrfbYXJR54dgRS5EQTX +MopCVh7iyJ7WT7BX0naenb5elBdDBEmWhZ9vV5LOiK9GV+h3hepk9M0wpWM7/OgVHd0 CrqSRdQZwwYMssgjtkV+sINMPUKmpXoOh5V6je7nxeiaq8VMip3oORW6CMQt1UnjbJBT UNng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=01VUm08eQQhxupMLWKqsGfmqGDt6OKm4OXTCGEljJ30=; b=P8CJ7hwV+lOBRDF9vC15AZrtAO1NPzWFoKGWD7j87bu9ZF4OXYzF/q1xvD6cwUuM4f 3sq0KClj3RHj3wh52kgP4ZZX7NzLQmG30YF8B24JBOR3uc6Co3FPVd11At/4s0Pw0rd6 8gik8gq2KVcrGyLkXXibceJhRhQFQ6HtxOGPg9bz5t50C/WoSJQ7b+cPTMUPt7TymnFt gI/VNxujm98aWX7IPuWSUCKHDCS3IehiC/OexVezViCHjQcp8Oo6outP2okHB2X49FLR uVxDwG6JUgINpg1+AENrNy6yUVR+s6A+/hIIR5hFeuLY1PzV/l6+cIVSxzr0DBbcVh9Z W9qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jRoZ38D9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d202-v6sor862400lfg.51.2018.03.14.09.59.15 for (Google Transport Security); Wed, 14 Mar 2018 09:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jRoZ38D9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=01VUm08eQQhxupMLWKqsGfmqGDt6OKm4OXTCGEljJ30=; b=jRoZ38D9HpPRHeBcADqrCG3WPFYk6M7wFlk/XuO7+Yi6lNB98S47ZCWhQHFExukspF XyaxdIa6jl5P5y7/T9EtLIzp8NV7WKA+Mk4SxLnIBgmeEXW6xevaQC+/wLmCBioDb/40 vV4jRYegxNegvDFar8sJFicJAz/gixn30CKEg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=01VUm08eQQhxupMLWKqsGfmqGDt6OKm4OXTCGEljJ30=; b=qypaXKjR97dcoq9K3tF6O2xLN2OAcZAph7ySMxeRrjJMwDHQ5DZ/gNbHWW+G/hikBl ELuY2/I/+IFvnAKPslnOMBtOg4eRFIxO00LmBlc24kPxoW7GJuP7JFPJQIge/KEkjTA7 /npG3UqHeW/qrPVJmFKaHeurefkAS1D7O3RhmVWhgOwS3JgyfUd+R5fRDCra2e3KqLbA n8bf31EvuSDAND+S3ZkVSp8Iz9LSf+Ej8AQzhyrT6mkQL6vUIPVR3XxHuQXPlNonjBb+ 8+t3OqL/+up45iQxyaH3OfZ77cefdOygckc0zogWFhS2BrlyVw7mVQbfSHgXW9NFS80U DRnQ== X-Gm-Message-State: AElRT7Glizgxb3nxU8KLu/NOjlqPSNMWDGIGsZlavkz27VzbA4ddXO1M 6+3BrVXP2nDmOF+/ot9ZWHj8C+90 X-Google-Smtp-Source: AG47ELs/RDCKZ4OvMKXyMvmsGYrv6A27Wj+EihblUhR5Wr4e8/We9ZLGX9W1457J0PRoGUUd80q4gA== X-Received: by 2002:a19:cd4c:: with SMTP id d73-v6mr3838508lfg.12.1521046754984; Wed, 14 Mar 2018 09:59:14 -0700 (PDT) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t24-v6sm724849lfi.30.2018.03.14.09.59.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 09:59:14 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Kevin Hilman , Lina Iyer , Lina Iyer , Ulf Hansson , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 07/25] PM / Domains: Add genpd governor for CPUs Date: Wed, 14 Mar 2018 17:58:17 +0100 Message-Id: <1521046715-30683-8-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> References: <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 Cc: Daniel Lezcano Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/base/power/domain_governor.c | 56 ++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 2 ++ 2 files changed, 58 insertions(+) -- 2.7.4 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 #include #include +#include +#include +#include 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,