Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1036745imm; Wed, 20 Jun 2018 10:29:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkjeVxEV1xa4eUH3lGGCHhLe3fEyyPLcIIb/SAzT+jv2aLGqAPEsrKBx2TTAML2Azw52qU X-Received: by 2002:a17:902:a715:: with SMTP id w21-v6mr9523537plq.111.1529515767522; Wed, 20 Jun 2018 10:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529515767; cv=none; d=google.com; s=arc-20160816; b=Ga8AeMGwWIkCSHo4C/BcjBRv1zSjwen5cqt7MsONGDC+xWvpgGJigAt4iwUyxmNrOt CMEbntQ2jtgf9mwLFogZnJYE+8KuFHqT/ULaJ1QQcpoQ3Nht6Z7v1UbaRj8wjdthXQxk H+Hz0/1aSu1qQXjR1d1J2Yfl1T71XZclBuGMaWe0C9VBV5B1heZ+6LUnMYxl8QuFnbYd rRYDvdCMsom7+T1dnVqQRVAiDX8rQJnvwt/aRnc9puV1M7yzhEJd4zLuZwSq/FYV2GV9 oGl6akTS2Bbz5F24nGcJUm9S8DED5AVROosHIkqPclVnNIgaZk1NahyJu6j0JvxD6YkA FRZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LFPzDs1JucyTyUU9q3YaT4OD/JzXpPsipsDpCqXWAns=; b=xV8d3OrNvaLBC5l8+34ZmhluT3jSwcmF3gmtsDAwqx6EhiQ4P1vPGxDLs+Ke3PpOeO oWzLD5Tq3834Okm0i6xFPL6bsLNc1ogTMMmMT2KUenubtlLmtsRETcknj9k7/8aF+cDx t/PJKoZC65z/xONYtO9B0p+08XLw1Ola278oDmn9XoUqCh8tnVIeGZatAIHba56aAvts M6g8iCCnjqZjBmmHz6LFSGT28n4lDqo2UGimDgxueAV5EQMclEaouNlkZnUxbWCtBlj4 z7jqvCvCKMj2/ZaFYLTyshmFKgc5zmDKrP/oasOm7taJ12REAVWDUrqsFHPR/S71hzL6 A3Xg== 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: 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 bc12-v6si2723554plb.373.2018.06.20.10.29.13; Wed, 20 Jun 2018 10:29:27 -0700 (PDT) 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="Pd+AU57/"; 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 S932743AbeFTR2F (ORCPT + 99 others); Wed, 20 Jun 2018 13:28:05 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36812 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754519AbeFTRWt (ORCPT ); Wed, 20 Jun 2018 13:22:49 -0400 Received: by mail-lf0-f67.google.com with SMTP id n24-v6so485982lfh.3 for ; Wed, 20 Jun 2018 10:22:48 -0700 (PDT) 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=GS86ZgdJaAU3I44WzuKCSOPgfseZRhc+KSjtJMklZ317exbnTgTVaEx6RB+fHkRVBy 7E45JPTff23D6iu8WjN6WMJj+xFh3xHwbvVFw7NJZT2UzEix1V3rW6TBfeVGVOckb9SV JOobP4/McBC3sCwqvUOzOt4MDMCcScyKQ/xss+2JljIfV6CBrAxphfiQPqKDBPsqnxhd YYbnxKCH18qtBOw4P+SrOwYcKSRzknUQeLSWFLJf/q1IfIcNJIgfe4mqvNhKqt/Zodpk dfE0Wi+B7b0K77uJj7m70YI2g1fuGNin5h7EvY1VvjxAF5TihPNWObKClg+v0yOLsywP OztQ== X-Gm-Message-State: APt69E1tnqiEigtP77+ip+OfrCBpmSo3jg9RibI607ZJjwhzutqyL5r5 0L6yxgQbGa2G3pBWpGfFlSVCiw== X-Received: by 2002:a2e:c52:: with SMTP id o18-v6mr14820774ljd.72.1529515367664; Wed, 20 Jun 2018 10:22:47 -0700 (PDT) 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(+) 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 -- 2.17.1