From patchwork Wed Jun 20 17:22:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 139375 Delivered-To: patches@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1050539lji; Wed, 20 Jun 2018 10:22:47 -0700 (PDT) X-Received: by 2002:a19:1c8d:: with SMTP id c135-v6mr1701527lfc.92.1529515367891; Wed, 20 Jun 2018 10:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529515367; cv=none; d=google.com; s=arc-20160816; b=DyHpTCNDw6b6SNKvcXfPRq4k++HOXwhL7ntAvRd+ObBfLJO9OanCvXnQpxoaYeO5Tm UzN7OdQC+LEGPX3FroEeGd2ANlEw7s0hPn45kslWHU+VVR2hd5bJntxz2r0aN2S+GYzl wnTSjwoYtdn4FesR3I1UHCFRhaN1nxfneezpmpedfH7gbJAuNF8i+kODWpBUi1nmvqw4 W78zitP0psGDLA+B5+3bpieOLVroCm+UQsIfVD9O3rFjpBn8HAQ0WhTgWOB2Gez7ZoQ+ V1Ig4pbxtAPP5VR7681NUJKbMkI+ZzG6Jp1Wfm8AT2roFFhSJlmMHAicJjWTrv3TwVWS IHng== 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=LFPzDs1JucyTyUU9q3YaT4OD/JzXpPsipsDpCqXWAns=; b=wqisTyTPDN272Op322Wh0TU95oP5lYYmieAMgWhe1hJAIm6R64EdVu/hgqRqQDnpmr aq2tSdg5rJ2hB+kE5M8Qjhm20hPglL1AjIczFw23+ifn45Ae6zllOy6lqYtV61LlzePC 9yR6sBkwChUfDm0I1QTVTSrULC4h0mjYtZY2rDU3RP6XErn5jZs7vYC4VI2C9j2eJASR 7Gazu/kY/8xbAP0MbKlNpkfsxY+SsoJZGPTYxTQk3+gqdm/QdbWsPOVC67UCX+jikONz 6WzhigNoBKwhNoRSN4K56DyNima6FblkGOyuvFo1nHs+xVuPhmMOw1G99b1ecz7Tb6aW LIBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Pd+AU57/"; 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 a3-v6sor736167ljh.38.2018.06.20.10.22.47 for (Google Transport Security); Wed, 20 Jun 2018 10:22:47 -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="Pd+AU57/"; 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=LFPzDs1JucyTyUU9q3YaT4OD/JzXpPsipsDpCqXWAns=; b=Pd+AU57/ZbU9iVlM9eRTAuOn9GTqB6ot50bON6VCr0QtZEowyR6sePRKbj4JPhWgzu mTOhEKCczfF/p3cFIkRwIpRAdYi31j2ESbGBOYI7oXPX/eWp4DodDrcwp4lYr8MK2T8y mgxz3z+CuQXdsccOPAKsbsuwrNIXRQjLEj4F0= 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=LFPzDs1JucyTyUU9q3YaT4OD/JzXpPsipsDpCqXWAns=; b=BGljlrSlXgzZf2UuIFQT0NfFKdyaJ3TIjiwKfoRnRNsbAbSmLjp+X7Q7iJdkbwbVqV RwFT5zzdkvoTWckAhFEiK3eWKU6njNAbkDr7Kxb8H661j9/KODKH8bRy6BAwMYVM45sI aq0VCYcQUP59OHUQHnINKtRNmV00VI9VfpIcRTCmqIys8SZPW6gHEvjqLbZcPm1h/MDq vXnnRNfKSyzK0UawjtCA2+tuWx8MHKgvb9IINiTx9owqWQkd1EwchCZ1R6uZHfp26Sev 1mLXmOCdh0rjmVKa5LkVt5K39w9CzTmfNJkSvJg05v67/P+VKemxTpo7iBFzlms3kyeX AMlA== X-Gm-Message-State: APt69E1GW+ae3ZGGeTo3NxzGcF93tQ1PMBdfwAdegQ3+7TMn9Ktyi462 uNCNKM45VGLOMjBRIYWvLfynQkP1 X-Google-Smtp-Source: ADUXVKIXzbzMOEIVwbTkD347j4lM5kxIzlrYLKIeVYq/rh6c3durBgY/IosyfyDugqxJq+GurWA87w== X-Received: by 2002:a2e:c52:: with SMTP id o18-v6mr14820774ljd.72.1529515367664; Wed, 20 Jun 2018 10:22:47 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b2-v6sm514441lji.85.2018.06.20.10.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:22:46 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , 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, Frederic Weisbecker , Ingo Molnar Subject: [PATCH v8 07/26] PM / Domains: Add genpd governor for CPUs Date: Wed, 20 Jun 2018 19:22:07 +0200 Message-Id: <20180620172226.15012-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180620172226.15012-1-ulf.hansson@linaro.org> References: <20180620172226.15012-1-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 Cc: Frederic Weisbecker Cc: Ingo Molnar Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/base/power/domain_governor.c | 58 ++++++++++++++++++++++++++++ include/linux/pm_domain.h | 2 + 2 files changed, 60 insertions(+) -- 2.17.1 diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index 99896fbf18e4..1aad55719537 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,56 @@ 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 + * and by also taking into account the power off latency for the state. + * 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 + + genpd->states[i].power_off_latency_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 +310,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 2c09cf80b285..97901c833108 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -160,6 +160,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) @@ -203,6 +204,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