Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4991317imu; Wed, 19 Dec 2018 03:53:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/WW1uBZg1zFmyFIBjhvcSW1cOMfgx+oU42BvGiM3oVeYTAbA86P7rvaM6BSEhjOZ5ShaGXz X-Received: by 2002:a63:504d:: with SMTP id q13mr2733398pgl.319.1545220405870; Wed, 19 Dec 2018 03:53:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545220405; cv=none; d=google.com; s=arc-20160816; b=VioJQPDue7kkOn62bWgmXBlns5kH5srUGWjPAhZmCj4I+/FE7+1mhmineU8EKVdPmc La4+ZaOpusLaqiHn01StIcmmvKgqNBqv2gdgfxSe5cMR74L7cy7iyRZFDXPAEtICJUSc OQEldycigkSzVgO4hPdtfwj1T1ZIoLmQVjhZyvSXmkw6/k0wW0O+kSMzp1j13df9AQWO n4Ty/x0sntcwHU4osxx2JXV9zt6lHoZJ2yIKvkBijwmLZvw1Do1Q1Nbag5tDjWKr2p7t y5AG3sF/5lq7ywH3m/Pd1lURILfN/zLx6MSVjV5u64+pR+W/9D9ukWGc4rTi1LcnCeGB TiqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=O0vouEdLzSS4mYarCHOwZC3GUarLRhIXtaaYdhIDtVM=; b=U+tXxAwjv5+k8ooMVuMZdOqZFpgS2Ujw8oaeN5i8b4yO0OiIXp1yAnX8rVpmCYv0FG naL1ZIsT6Oskxd8CY7WK1kk0hoaB+ljjEsgnMmbY0rHzCfYdWgyMybvkpkFs1+HpCOKm HVaH0W+mTkXmKwisDs9tqpbcol3H3cDFL9hbuWH4Qy//sF+Vh2xPfqXxVa8rTiLYef47 YoXqMthpmvZeHvNDtVKOB9RcD4ldhU3U1cLYbuqQBN2oJbqFnT870x2AZvRbswb1ttIo Oqt1V9z7U9+wGXmSeQ9iJJ1VsWCkKAWNrE1ecjGX8q8QjgfiSQoUQXGO3zvfkyO+kygs QjnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X6fdH8md; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si15606662pfl.279.2018.12.19.03.53.10; Wed, 19 Dec 2018 03:53:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X6fdH8md; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728726AbeLSJye (ORCPT + 99 others); Wed, 19 Dec 2018 04:54:34 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50767 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728660AbeLSJyc (ORCPT ); Wed, 19 Dec 2018 04:54:32 -0500 Received: by mail-wm1-f65.google.com with SMTP id n190so5427420wmd.0 for ; Wed, 19 Dec 2018 01:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=O0vouEdLzSS4mYarCHOwZC3GUarLRhIXtaaYdhIDtVM=; b=X6fdH8mdSlxrkG1pj85BRjgGnSoKRwoO9XBbPTOuC6nazNYpoiDhHS17AL6qGvNa52 6IHanetEy+71QtnUahHrQO8YgCkoJpRlndEe5mY5ldKcdEdEKxvCnas54zu7HCE3m/A+ DwPZP9GlVL0+s2a9GJDReI7yVSXYIbV++SCeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=O0vouEdLzSS4mYarCHOwZC3GUarLRhIXtaaYdhIDtVM=; b=ppif9CjnAezDaUA47Ls4fHjOOo0sLumnggGFJkK7aZEAG2ypob7/x860gLP73HfoP7 YI+7cTsPUo919wHFyCN11H49UAHA2VlF4zWYW1q9Lbg7XLU1DwwTrPTPRdgFS5BqUEfT F5r4c2WQsvGCJqydjC3orOq2KKCY+r2be1NLA4jxF2bKsTq50t4JHu+G/kg+0M0VNy5J 114ITYEgITho4deKKdkCbwY5MmzM6mZ+Hd+r9deqyj+EFHloWjhbgB52LR3arbjWv5lT FuUCe1zJYF2SsS9/BuWnlKV/jr7rbj28uaXekCNluV5b4VomO//lGApNyIvLMEZcviso bosg== X-Gm-Message-State: AA+aEWasufecmwbA41C3MPDLm07EH93lzFQGhdlSdKs+Zcym+2K9bWZw k9TbWs9ZbweobWJ58d49C+4mWQ== X-Received: by 2002:a1c:e1d5:: with SMTP id y204mr6419457wmg.65.1545213268868; Wed, 19 Dec 2018 01:54:28 -0800 (PST) Received: from [192.168.0.40] (105.50.92.92.rev.sfr.net. [92.92.50.105]) by smtp.googlemail.com with ESMTPSA id q3sm8599214wrn.84.2018.12.19.01.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 01:54:28 -0800 (PST) Subject: Re: [PATCH v10 04/27] PM / Domains: Add genpd governor for CPUs To: Ulf Hansson , "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-pm@vger.kernel.org Cc: "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Frederic Weisbecker , Ingo Molnar References: <20181129174700.16585-1-ulf.hansson@linaro.org> <20181129174700.16585-5-ulf.hansson@linaro.org> From: Daniel Lezcano Message-ID: <5529fc0a-af96-b10a-ca4a-f1417598f4ee@linaro.org> Date: Wed, 19 Dec 2018 10:54:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181129174700.16585-5-ulf.hansson@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/11/2018 18:46, Ulf Hansson wrote: > 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 > Cc: Frederic Weisbecker > Cc: Ingo Molnar > Co-developed-by: Lina Iyer > Signed-off-by: Ulf Hansson > --- > > Changes in v10: > - Fold in patch that extended the new genpd CPU governor to cope with > QoS constraints, as to avoid confusion. > - Simplified the code according to suggestions from Rafael. > > --- > drivers/base/power/domain_governor.c | 61 +++++++++++++++++++++++++++- > include/linux/pm_domain.h | 3 ++ > 2 files changed, 63 insertions(+), 1 deletion(-) > > diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c > index 99896fbf18e4..61a7c3c03c98 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) > { > @@ -211,8 +214,10 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) > struct generic_pm_domain *genpd = pd_to_genpd(pd); > struct gpd_link *link; > > - if (!genpd->max_off_time_changed) > + if (!genpd->max_off_time_changed) { > + genpd->state_idx = genpd->cached_power_down_state_idx; > return genpd->cached_power_down_ok; > + } > > /* > * We have to invalidate the cached results for the masters, so > @@ -237,6 +242,7 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) > genpd->state_idx--; > } > > + genpd->cached_power_down_state_idx = genpd->state_idx; > return genpd->cached_power_down_ok; > } > > @@ -245,6 +251,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; > + > + /* Validate dev PM QoS constraints. */ > + if (!default_power_down_ok(pd)) > + return false; > + > + if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN)) > + return true; Is it possible to have this function called without the GENPD_FLAG_CPU_DOMAIN flag set in the genpd? > + /* > + * 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())); > + if (idle_duration_ns <= 0) > + return false; > + > + /* > + * Find the deepest idle state that has its residency value satisfied > + * and by also taking into account the power off latency for the state. > + * Start at the state picked by the dev PM QoS constraint validation. > + */ > + i = genpd->state_idx; > + do { > + if (idle_duration_ns >= (genpd->states[i].residency_ns + > + genpd->states[i].power_off_latency_ns)) { > + genpd->state_idx = i; > + return true; > + } > + } while (--i >= 0); > + > + return false; > +} > + > struct dev_power_governor simple_qos_governor = { > .suspend_ok = default_suspend_ok, > .power_down_ok = default_power_down_ok, > @@ -257,3 +311,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 = default_suspend_ok, > + .power_down_ok = cpu_power_down_ok, > +}; > diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h > index 5a4673605d22..969a9b36c0db 100644 > --- a/include/linux/pm_domain.h > +++ b/include/linux/pm_domain.h > @@ -116,6 +116,7 @@ struct generic_pm_domain { > s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ > bool max_off_time_changed; > bool cached_power_down_ok; > + bool cached_power_down_state_idx; > int (*attach_dev)(struct generic_pm_domain *domain, > struct device *dev); > void (*detach_dev)(struct generic_pm_domain *domain, > @@ -195,6 +196,7 @@ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); > > 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) > @@ -238,6 +240,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 > > #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog