From patchwork Tue Feb 26 14:54:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159215 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3303917jad; Tue, 26 Feb 2019 06:54:33 -0800 (PST) X-Received: by 2002:a19:294d:: with SMTP id p74mr9344516lfp.101.1551192873374; Tue, 26 Feb 2019 06:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192873; cv=none; d=google.com; s=arc-20160816; b=Z+uYg65r/Ad+KweI8v/qbn3hQSqDG2S4PTNAVM0mtA7DO0TL8YZWROBRuiMu+u1Vjw SCGTRuQs7f1joat/53AucySOG9EF0C1vsdBTzODND98KBdUn9KQWTTmVSDSYI6HtdZaP evKb5QcN21RwCdjd5dDuLhsg3U76UztOZWXwgqNXGTNB3dL5Fedi93W7e0j7Wrs4ipx0 qr2f0b2NW29tSc+IoGnGLh14g0DpE4TrIai9knA7KezPPnPFjk+5Z7AKesbqonzLG0tL gvbR9iWoSrBA1/9Nw1tUQcTmPauElhqdHmxZGOJzDonXGoxRE87/nmDD65jzfUYXIU5m GhPg== 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; bh=4olRHrO4OGLzrA6TD5Q8IXYA3EOf33sfuFLg1Ze1+T8=; b=nvNFE3Xji3ERJCNp+Z6zjyY0/w8M9+a7PB0jupYMjUiD2FdntLb8otvqgO+yi4WZVJ nnISjtA7WWXu18Ft6ZpTK8463y49mSjtlW0N/WhV8232a0Q0X6WMpq7YmwJVfBZDyGCZ u4aoBRWZa29dCrm+gAL3Xq6akKtgEVL9kTIQCjdWk0vC0AtAmHwmf1LwYKhtNjSMIs4f IFfmdESimwZq307DYTW+vY6dqMAiHcBQ/lVSrGVXmePWK+uN/m6iBY/0Dk6LPtnFzIQT xSF4BpwI8qzl/4coRKLjzsqZlLuGOjC4VcNX7+t8U2f6sq4bPTAstMVx8QDTZJCropiN 5DuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UpiV1C7X; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 i26sor7051300ljj.17.2019.02.26.06.54.33 for (Google Transport Security); Tue, 26 Feb 2019 06:54:33 -0800 (PST) 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=UpiV1C7X; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=4olRHrO4OGLzrA6TD5Q8IXYA3EOf33sfuFLg1Ze1+T8=; b=UpiV1C7XUoRlE7eOlCQ7dZ0FXppFbUeWVKE+mS8DyVTrfoC9wQDiLrkZaRPQsDkffg 7LmpX1qQeqw7pZ4AGLlqSYJuLMPQL08U8CWEQRAzNONsI4X0V9xyDVzPq8sh0WB4flM1 esuF0lZLmPD4DVxaFMIq1+6Wc29pnSH+8Dkuhnz8A0Be9Wg7PKAiatg7BMtzX4BoINze +uZ4OPlROTt/bcxixY1D8S0MKU4u5tchRwXrsbPR5KkeD5uTBeH7HE6rueq/yA4Bnf6o 4giH0pEncr3VbdMzT1AqQ2na2sJZ2g7M9VVfBr+gsFBFrcJbgHblsvCVf/AUAccBFciE Kkjg== 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=4olRHrO4OGLzrA6TD5Q8IXYA3EOf33sfuFLg1Ze1+T8=; b=lU5azA7LHh2T2rjzZmAdYGqo4x9TqDRb9e0B7qy7GXZZ/kDpALZz9UdQW3LLRmrrvW SHPJIC1ZZuWEx3gCusAzzWe0V9apoDSUxJPBESDDEIGUr3z57k2sqcRNU1eyXkNptV66 WMJEVtXe2p6eRlLCaHQ77L8Zq5Yzasce+NLRddjjX9nNXLnhJhiWDpXOtr/8nLewxGUB dqCQvBD8uJ5qR8n/U32rst13DenigiorDYUJvuqskgJFJBZ73ZYF/kUTq5LoDZODrRO1 C0UgeloF2z7JBm5rwbgMjg6HtnL8NXLKRJgLzkaU/gkXWMIwe7ya13Tmmzuz2ELj69Tv 5Xkg== X-Gm-Message-State: AHQUAuangwlmls3c78ZQstym0+PGdwteZySwwoFVyTTMxouICk2Cnr9c QgP9h8llGQRNL/Pxi70Al1PjLbH7 X-Google-Smtp-Source: AHgI3IYhRgfMci2gWG7XJv/qsPRrrRxzcro7TN2Y9E2w5Y3G0gGzKJM7bcSXjPp5ZRxr+TyG33XsbQ== X-Received: by 2002:a2e:9916:: with SMTP id v22mr13192461lji.68.1551192872994; Tue, 26 Feb 2019 06:54:32 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:32 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 1/8] PM / Domains: Add a generic data pointer to the genpd_power_state struct Date: Tue, 26 Feb 2019 15:54:08 +0100 Message-Id: <20190226145415.19411-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> Let's add a data pointer to the genpd_power_state struct, to allow a genpd backend driver to store per state specific data. To introduce the pointer, we need to change the way genpd deals with freeing of the corresponding allocated data. More precisely, let's clarify the responsibility of whom that shall free the data, by adding a ->free_states() callback to the struct generic_pm_domain. The one allocating the data shall assign the callback, to allow genpd to invoke it from genpd_remove(). Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- Changes in v11: - Add a callback for freeing allocated power states. --- drivers/base/power/domain.c | 12 ++++++++++-- include/linux/pm_domain.h | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 2c334c01fc43..03885c003c6a 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1685,6 +1685,12 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, } EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); +static void genpd_free_default_power_state(struct genpd_power_state *states, + unsigned int state_count) +{ + kfree(states); +} + static int genpd_set_default_power_state(struct generic_pm_domain *genpd) { struct genpd_power_state *state; @@ -1695,7 +1701,7 @@ static int genpd_set_default_power_state(struct generic_pm_domain *genpd) genpd->states = state; genpd->state_count = 1; - genpd->free = state; + genpd->free_states = genpd_free_default_power_state; return 0; } @@ -1811,7 +1817,9 @@ static int genpd_remove(struct generic_pm_domain *genpd) list_del(&genpd->gpd_list_node); genpd_unlock(genpd); cancel_work_sync(&genpd->power_off_work); - kfree(genpd->free); + if (genpd->free_states) + genpd->free_states(genpd->states, genpd->state_count); + pr_debug("%s: removed %s\n", __func__, genpd->name); return 0; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 1ed5874bcee0..8e1399231753 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -69,6 +69,7 @@ struct genpd_power_state { s64 residency_ns; struct fwnode_handle *fwnode; ktime_t idle_time; + void *data; }; struct genpd_lock_ops; @@ -110,9 +111,10 @@ struct generic_pm_domain { struct device *dev); unsigned int flags; /* Bit field of configs for genpd */ struct genpd_power_state *states; + void (*free_states)(struct genpd_power_state *states, + unsigned int state_count); unsigned int state_count; /* number of states */ unsigned int state_idx; /* state that genpd will go to when off */ - void *free; /* Free the state that was allocated for default */ ktime_t on_time; ktime_t accounting_time; const struct genpd_lock_ops *lock_ops; From patchwork Tue Feb 26 14:54:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159216 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3303941jad; Tue, 26 Feb 2019 06:54:35 -0800 (PST) X-Received: by 2002:a19:ae0b:: with SMTP id f11mr14518838lfc.104.1551192874944; Tue, 26 Feb 2019 06:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192874; cv=none; d=google.com; s=arc-20160816; b=wPpZv3Qf3NwnLwC3hp94sCnreeqwitLCV1gMlCUW6gWRu0LTvmkbl0DakGlm4OGxkZ HIL4ucFGyZ28HG4LhCEveaWUlDVwY1XitBIDrXFx5XK6btg69pkV0BxQyFGO0d75AKsb D0sHVPasIrpKcopJHIlQi4G3L3BftFg3wONIa9xFnt/HewWD2j7ol2tedXWV1T1rpnwy Adv6qHyr3DNMF2NGEqa3jraG7VvtcR1d+4bGRtRPwWGiRlzRcW4d0KievQ8ToGDYjKP+ z1XGUbEcjalCtCuQbANkCLmCcWcNNDQRv6kVJfXCh2j4V5v7CFRp6QQKH6wExNtEisCC SbwQ== 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; bh=lS99QcFML7dLoSt8lbXdQh9xfwG03Z7ZZ1t/PX5xDuw=; b=mJELo2rRxWRG0/iQqv4qNga9WdyAxtrnR6hUbV1XEgjZ3yxLAO+46lC8+2JQWIl3c2 F4o2kFfNFSes143je0FnMQ07UfUeS7LQaNSSsGrmH9nfa3t1tz8mPSDH2zwSxD8Ix/fB toVBexJc0SB+jDqaK/iW7276d9mPWxCov9oVsPsB8PZ/DXO7VKnGtAZt71DqIPdBfKPR Q12Vx0KuEcmK3tDUCdu9Nw4bsFV3/0doW6kwfoDrwN07wd2JhyEp9aN2r9sgmhtQSMkl jqVgMNj6Q+8Hz//74fIvkZw72H56i0PTPbX2vZep7Sf3kj2eEnJQZyWXg7lD1oKnQngK s01A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=frjy6udQ; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 k13sor7377718lji.32.2019.02.26.06.54.34 for (Google Transport Security); Tue, 26 Feb 2019 06:54:34 -0800 (PST) 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=frjy6udQ; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=lS99QcFML7dLoSt8lbXdQh9xfwG03Z7ZZ1t/PX5xDuw=; b=frjy6udQ0V45QAlGWn2RK3H4Qay0Dq+k1iLA9pvVtEOGvBZCfN60TFwRiT+YU2SxLu ozUVLsugwcY7ngfHpTJ4PwxYhEfL90HWT+cGtTXd6zplHUVZpeIy4GFUP1jOOA35iD+6 JydHeDM6KJ4ozjrCjQq5V+82FtAv96rciaaKZvbbxNLkKlUT9qXNy1VUbXobZ1bLKAIP GTCl3rXYTnHQSHmmAd/v4j4QaTSpdT4efyPqQNURA9tOqjkuHaCLN01+QeFrQNlu0S8i JsWN2u/aSHSzwJEPHdnzDnfFsSMisvbXCqepOSYnEV9aTOkO8Sdm54rRJWOSOkBrd1Dn MP8w== 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=lS99QcFML7dLoSt8lbXdQh9xfwG03Z7ZZ1t/PX5xDuw=; b=f3S4PVLUqz/DCshTxKfQBAkp9X8ltKwpmd59+m6hjyD7jltvT9SCSds7LwU6g+3eoN HJLDK876uMFzRclJfErvPTbZFOGVuFlwNVll2IHrN/HOkPxICT7Mmm9HR6g9T38LO+sn ZcaE75lvAEipC+oisAYJ5pf8CDM8GPbLxNvEk4SlzOe2KzaqDF2/5Zl0Jh2DlvwR+WI6 bjcUlU2YqftzYeP9/vvZgeVqWFa7+v45A1UiB7ObclwS6ZkJM7vX9yG+Yz8f/YrFHP7C NbNyq5HK4Yx0eegmJhTdt93UdmXCW4+I2X5on3SRYVzLOjk6dGuAZ7++BA+h3ObqzF75 0rHw== X-Gm-Message-State: AHQUAuYntkIVVJShe1wCgEp+RJE//4ehD+xpnc3m+oDJsEdAbLcBZJdQ Eqomz8SunyBd80blHan3v+AxOG/F X-Google-Smtp-Source: AHgI3IbQK6g/GHqoYKUC0IMwAjwvECcgXrr3eJfo/5LQs+2DB3SME1ZCcMMQEZY8/vc+STbIWIx3oQ== X-Received: by 2002:a2e:6801:: with SMTP id c1mr14658227lja.81.1551192874484; Tue, 26 Feb 2019 06:54:34 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:33 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 2/8] PM / Domains: Add support for CPU devices to genpd Date: Tue, 26 Feb 2019 15:54:09 +0100 Message-Id: <20190226145415.19411-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> To enable a device belonging to a CPU to be attached to a PM domain managed by genpd, let's do a few changes to it, as to make it convenient to manage the specifics around CPUs. To be able to quickly find out what CPUs that are attached to a genpd, which typically becomes useful from a genpd governor as following changes is about to show, let's add a cpumask to the struct generic_pm_domain. At the point when a CPU device gets attached to a genpd, let's update the genpd's cpumask. Moreover, let's also propagate changes to the cpumask upwards in the topology to the master PM domains. In this way, the cpumask for a genpd hierarchically reflects all CPUs attached to the topology below it. Finally, let's make this an opt-in feature, to avoid having to manage CPUs and the cpumask for a genpd that doesn't need it. For that reason, let's add a new genpd configuration bit, GENPD_FLAG_CPU_DOMAIN. Cc: Lina Iyer Co-developed-by: Lina Iyer Acked-by: Rafael J. Wysocki Signed-off-by: Ulf Hansson --- Changes in v11: - None. --- drivers/base/power/domain.c | 66 ++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 13 ++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 03885c003c6a..da10052e6427 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "power.h" @@ -126,6 +127,7 @@ static const struct genpd_lock_ops genpd_spin_ops = { #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON) #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP) +#define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN) static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, const struct generic_pm_domain *genpd) @@ -1452,6 +1454,56 @@ static void genpd_free_dev_data(struct device *dev, dev_pm_put_subsys_data(dev); } +static void __genpd_update_cpumask(struct generic_pm_domain *genpd, + int cpu, bool set, unsigned int depth) +{ + struct gpd_link *link; + + if (!genpd_is_cpu_domain(genpd)) + return; + + list_for_each_entry(link, &genpd->slave_links, slave_node) { + struct generic_pm_domain *master = link->master; + + genpd_lock_nested(master, depth + 1); + __genpd_update_cpumask(master, cpu, set, depth + 1); + genpd_unlock(master); + } + + if (set) + cpumask_set_cpu(cpu, genpd->cpus); + else + cpumask_clear_cpu(cpu, genpd->cpus); +} + +static void genpd_update_cpumask(struct generic_pm_domain *genpd, + struct device *dev, bool set) +{ + int cpu; + + if (!genpd_is_cpu_domain(genpd)) + return; + + for_each_possible_cpu(cpu) { + if (get_cpu_device(cpu) == dev) { + __genpd_update_cpumask(genpd, cpu, set, 0); + return; + } + } +} + +static void genpd_set_cpumask(struct generic_pm_domain *genpd, + struct device *dev) +{ + genpd_update_cpumask(genpd, dev, true); +} + +static void genpd_clear_cpumask(struct generic_pm_domain *genpd, + struct device *dev) +{ + genpd_update_cpumask(genpd, dev, false); +} + static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, struct gpd_timing_data *td) { @@ -1473,6 +1525,8 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (ret) goto out; + genpd_set_cpumask(genpd, dev); + dev_pm_domain_set(dev, &genpd->domain); genpd->device_count++; @@ -1534,6 +1588,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, if (genpd->detach_dev) genpd->detach_dev(genpd, dev); + genpd_clear_cpumask(genpd, dev); dev_pm_domain_set(dev, NULL); list_del_init(&pdd->list_node); @@ -1767,11 +1822,18 @@ int pm_genpd_init(struct generic_pm_domain *genpd, if (genpd_is_always_on(genpd) && !genpd_status_on(genpd)) return -EINVAL; + if (genpd_is_cpu_domain(genpd) && + !zalloc_cpumask_var(&genpd->cpus, GFP_KERNEL)) + return -ENOMEM; + /* Use only one "off" state if there were no states declared */ if (genpd->state_count == 0) { ret = genpd_set_default_power_state(genpd); - if (ret) + if (ret) { + if (genpd_is_cpu_domain(genpd)) + free_cpumask_var(genpd->cpus); return ret; + } } else if (!gov) { pr_warn("%s : no governor for states\n", genpd->name); } @@ -1817,6 +1879,8 @@ static int genpd_remove(struct generic_pm_domain *genpd) list_del(&genpd->gpd_list_node); genpd_unlock(genpd); cancel_work_sync(&genpd->power_off_work); + if (genpd_is_cpu_domain(genpd)) + free_cpumask_var(genpd->cpus); if (genpd->free_states) genpd->free_states(genpd->states, genpd->state_count); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 8e1399231753..a6e251fe9deb 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -16,6 +16,7 @@ #include #include #include +#include /* * Flags to control the behaviour of a genpd. @@ -42,11 +43,22 @@ * GENPD_FLAG_ACTIVE_WAKEUP: Instructs genpd to keep the PM domain powered * on, in case any of its attached devices is used * in the wakeup path to serve system wakeups. + * + * GENPD_FLAG_CPU_DOMAIN: Instructs genpd that it should expect to get + * devices attached, which may belong to CPUs or + * possibly have subdomains with CPUs attached. + * This flag enables the genpd backend driver to + * deploy idle power management support for CPUs + * and groups of CPUs. Note that, the backend + * driver must then comply with the so called, + * last-man-standing algorithm, for the CPUs in the + * PM domain. */ #define GENPD_FLAG_PM_CLK (1U << 0) #define GENPD_FLAG_IRQ_SAFE (1U << 1) #define GENPD_FLAG_ALWAYS_ON (1U << 2) #define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) +#define GENPD_FLAG_CPU_DOMAIN (1U << 4) enum gpd_status { GPD_STATE_ACTIVE = 0, /* PM domain is active */ @@ -94,6 +106,7 @@ struct generic_pm_domain { unsigned int suspended_count; /* System suspend device counter */ unsigned int prepared_count; /* Suspend counter of prepared devices */ unsigned int performance_state; /* Aggregated max performance state */ + cpumask_var_t cpus; /* A cpumask of the attached CPUs */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); struct opp_table *opp_table; /* OPP table of the genpd */ From patchwork Tue Feb 26 14:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159217 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3303965jad; Tue, 26 Feb 2019 06:54:36 -0800 (PST) X-Received: by 2002:a2e:805a:: with SMTP id p26mr13447410ljg.179.1551192876415; Tue, 26 Feb 2019 06:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192876; cv=none; d=google.com; s=arc-20160816; b=fAzaTFApv2LRik5MDJ2voE9+xRn09PbDFtku3qvALf/y9hMLq7CXOPbHfjmxCcPK6u 6k7x0R+n8MdR3lBWgZE+JKWVphAD1FngjLXPq7xnXhSXb1Hz4DbyI2ZOohhrwl2FZz9T P4qsFU4FG1nRb8F+1HBgwdQzB3zZVgfDqJHAJjuq1cRP5t8ybfbU77s3p1XhUMkujP0y 3JQ+65Ru5P9m141sR8oDd6eLktEiO+aEZqSfHhM/rITEmqQq+tvFQEm/ijzOJlPbatR5 3C+kyWU3locdWp9FmbNZqpOsIXJ4vqHku3tQrlW3wb64ZVbS4nl7Hy4Y8k//gi6+naGU t9+A== 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; bh=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=0VWfaOr7rPxZJoMDl5ITj1FCAJi1LaLGbyhkk8P3CUvPDyw1o5/TNL38iWW7ycONHv KNuFP2S6kR+SD0L8hTzRRWDJZmOgK9iHag3+OI7rQWhmFFHrqxBsEgJFSHOobGDu5oU7 3GrlhVPwKOrEMwvpMzmAQWpQ7Aj0bGypfcVkjRblqLx/BrQyMGqAO2Tn1ls6XPJevbHs vVSKb96D/O1s5AgruBKqGFTWK2Oi6c1WR1O52mFtBryGhYQ3nh40knxem+ECxUjN72R4 7M27VHdQY8DjUv5ZjVcPNZ+LCnMLOzHCmIQjNVrCKgcE8+VYPeHIt+sj4LlOL6C8CRTC 93yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XADwoXr/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 h18sor7402253lja.11.2019.02.26.06.54.36 for (Google Transport Security); Tue, 26 Feb 2019 06:54:36 -0800 (PST) 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="XADwoXr/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=XADwoXr/kyyiMCzb9CS6DjwET0munxhbMQIwQFME2w8OCXzBvaWMH170NRncocFNPW X3IwkYXquWtD2FqzjNypn1QvdA7rhC0Sg2pfd2tAB07t2GK1sz4eeSlPq1ZSMerouLB/ yL8xYGa3C8T1+P97PJKc85J9n3JhT1JffBZg2gW80U8pJoFeRkcqssL4pm6zAMO2NeE+ yW0k2bLLZTbWiRsTJBgR0SZMbYTMLrLTASulOBpc7SS6P+0jyFj3qeCrkahnJLbwzeXv xrqwjvn5VSxFLH+8WtQk+CDKV2LnJKl/bQFJ2FpE6XkLYTYAMtvFOu6hw1idcP0G7FXW w8bQ== 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=cHcnRnu2FIgTWtisqlvCscC0vHLrnc1MItOKTfTvXoU=; b=lULZH8N1RxnfT96Z8BOFAmNmh5GinjexgAWP8Tsxzmh9orhztGXRKHau/DdIhEMTc1 HYHQZsVJGb8TDtxljosgdfX1XcYHIMn4MxAQeG9Udtc/NYs/voP2YZ5kfsioejd5d1IW /XC5JM0UASZUbaCzFRFeEAoeA2Z6xVlHfKT6isckOka9mBAeO2FzjAQUozX1lLf+f3jh rVO6rxkY6c0QC/r8dg+NLqXsz4NB4e3HAyCOXbAWQHof9gSMxZUWgian87Vxu3wlEqBQ ZIyzM4sLA+c62ZvKZ2SCr/aAw2YXBpfWHFHgJyQ04bAEvr2i2EdlPhwaVd5fhkP7EYLE q2fA== X-Gm-Message-State: AHQUAuZdrRm4O08tJMp1hg6pCLmesHnjfSKtfr5yG6v0H+N9E88RbdgB qLugQfl58u6E9uwB8JmLsblXYBDo X-Google-Smtp-Source: AHgI3IauEHmxkM6+fHc/XlZ7fBCCsrlb0JVEuV8nYLBMNV+/1LXzmHXaNCoZrVoDUKDl+bDaD0aZRg== X-Received: by 2002:a2e:6c09:: with SMTP id h9mr13631068ljc.139.1551192875997; Tue, 26 Feb 2019 06:54:35 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:35 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 3/8] time: tick-sched: Provide helpers to get the next timer expiration Date: Tue, 26 Feb 2019 15:54:10 +0100 Message-Id: <20190226145415.19411-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> From: Daniel Lezcano In the power control path with the interrupts disabled, cpuidle governors calls tick_nohz_get_sleep_length() to get the duration until the next timer expires. This is not always convenient when going forward, as the duration is a relative time to "now". To make it more flexible, let's instead provide two new functions tick_nohz_get_next_timer|hrtimer(), which provides the actual time for when the next timer is about to expire. The computation of the duration can then be done by the caller. For now, leave tick_nohz_get_sleep_length() as is. When users of it has converted to the new APIs, then we can remove it. Signed-off-by: Daniel Lezcano [Ulf: Clarified information in changelog] Signed-off-by: Ulf Hansson --- Changes in v11: - New patch, replace "timer: Export next wakeup time of a CPU" from v10. --- include/linux/tick.h | 7 +++++ kernel/time/tick-sched.c | 68 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/include/linux/tick.h b/include/linux/tick.h index 55388ab45fd4..5b10a0e4acbb 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -111,6 +111,8 @@ enum tick_dep_bits { #define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED) #define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE) +extern ktime_t tick_nohz_get_next_hrtimer(void); + #ifdef CONFIG_NO_HZ_COMMON extern bool tick_nohz_enabled; extern bool tick_nohz_tick_stopped(void); @@ -123,6 +125,7 @@ extern void tick_nohz_idle_exit(void); extern void tick_nohz_irq_exit(void); extern bool tick_nohz_idle_got_tick(void); extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); +extern ktime_t tick_nohz_get_next_timer(void); extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); @@ -145,6 +148,10 @@ static inline void tick_nohz_idle_restart_tick(void) { } static inline void tick_nohz_idle_enter(void) { } static inline void tick_nohz_idle_exit(void) { } static inline bool tick_nohz_idle_got_tick(void) { return false; } +static inline ktime_t tick_nohz_get_next_timer(void) +{ + return tick_nohz_get_next_hrtimer(); +} static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) { diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 6fa52cd6df0b..9966be665074 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -443,6 +443,20 @@ void __init tick_nohz_init(void) } #endif +/** + * tick_nohz_get_next_hrtimer - return the expected deadline for the + * next hrtimer + * + * Called from power state control code with interrupts disabled + * + * Returns a ktime_t based value giving the next deadline for the tick + * or an earlier hrtimer + */ +ktime_t tick_nohz_get_next_hrtimer(void) +{ + return __this_cpu_read(tick_cpu_device.evtdev)->next_event; +} + /* * NOHZ - aka dynamic tick functionality */ @@ -918,7 +932,7 @@ static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) int cpu = smp_processor_id(); /* - * If tick_nohz_get_sleep_length() ran tick_nohz_next_event(), the + * If tick_nohz_get_next_timer() ran tick_nohz_next_event(), the * tick timer expiration time is known already. */ if (ts->timer_expires_base) @@ -1022,6 +1036,58 @@ bool tick_nohz_idle_got_tick(void) return false; } +/** + * tick_nohz_get_next_timer - return the earliest timer deadline + * + * Called from power state control code with interrupts disabled + * + * Returns a ktime_t based value giving the earliest timer + */ +ktime_t tick_nohz_get_next_timer(void) +{ + + struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + ktime_t next_tick, next_timer, next_hrtimer; + int cpu = smp_processor_id(); + + /* + * Actually the function returns the next hrtimer which can + * be the next tick or another hrtimer expiring before the tick. + */ + next_tick = tick_nohz_get_next_hrtimer(); + + /* + * If we can not stop the tick, then in any case the next + * timer is the earliest one expiring with the hrtimer. + */ + if (!can_stop_idle_tick(cpu, ts)) + return next_tick; + + /* + * Get the next low resolution timer led by the hrtimer. If + * there is no timer in this case, then we can rely on the + * hrtimer next event only coming from the call above. + */ + next_timer = tick_nohz_next_event(ts, cpu); + if (!next_timer) + return next_tick; + + /* + * This function will return the next timer after the + * sched_timer aka the tick. We know there is another hrtimer + * because the tick_nohz_next_event() returned a non zero + * deadline and we need a tick to make the lowres to expire. + */ + next_hrtimer = hrtimer_next_event_without(&ts->sched_timer); + + /* + * At this point, we have the next lowres timer and the next + * hrtimer which is not the tick. We need to figure out which + * one expires first. + */ + return min_t(u64, next_hrtimer, next_timer); +} + /** * tick_nohz_get_sleep_length - return the expected length of the current sleep * @delta_next: duration until the next event if the tick cannot be stopped From patchwork Tue Feb 26 14:54:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159219 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3303992jad; Tue, 26 Feb 2019 06:54:38 -0800 (PST) X-Received: by 2002:a2e:9105:: with SMTP id m5mr13903696ljg.100.1551192877911; Tue, 26 Feb 2019 06:54:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192877; cv=none; d=google.com; s=arc-20160816; b=naZg9OiU+kBI5rwdAMh4A4xF0O5xBv+EN7jyna6KMNFx5fA9XBRJFWhFLUDucoRZ/H 5ZLRbVbLjCJRo+K0qkEamqzx+4nW7gNAoYRCodmbW6zk+psMJr0UF0fzgEcydcDgVHwj z9j4CHVGYzbQ9msnPSKQHmJsifZ/2rEegvzqdOOe/XEsNBFDaKrf3AjDI/+2Zq9b7qba ajhQyXy4GP8qd55HcGBRqnQkg2YbPkmWoN8tcx7euNian6XNdOZHgd2hNs7Oxhz5u/Fg LuhqFc/Bx3EzhLWqEqsuux55FqQ8rvLBY8aHV76M+Lnfoz74jmWst9MA0bymKMAWuK7H nvRA== 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; bh=CizRMe2YmHoMDQUcJ8913XbNFEFzGgJHDQtzao5WKiM=; b=Qbd84DNJFfehpCmDNtoflDJS/VKxAApu7I1eve2NUNLTmLzmw9Yo6Kt4rPNJIplFAo smQ/Rm6SbHVryjLYmvBIPU55PPilVrs1f7MT9CPFdx8+wlW/lCq6zHQj6nJipBrj61B5 OcZ3RNDuYseSVqSDO0qdkCI0nPfuahSQlvt2ickt4qRWStvsFNy/Lj6ikJz3U+R3Y3XO byVFJU3/N8Fg1CtQ7stB/c/q9CZCzduOu6ZTMCkwff7VzNgIW3gUMHZauTOUGixs6ln9 9l9leEae0DInM3V3C8bn7Zhws72q2qRXwa8NQgygq7rVfnRLVlsWg1veGlBNcoIfxIex +efw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kfhQSPA9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 n4sor244395lfl.57.2019.02.26.06.54.37 for (Google Transport Security); Tue, 26 Feb 2019 06:54:37 -0800 (PST) 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=kfhQSPA9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=CizRMe2YmHoMDQUcJ8913XbNFEFzGgJHDQtzao5WKiM=; b=kfhQSPA9AMik5mPi+zuWznWRU+Lb20kx5Yl1pd6vQyrPRfnG2ZYWVm4Hs9i5AjRK0b GnRrB3iYlXym2YsokbhWJCIunemOZzuO9vuqHFOLcbCrDm3wSn0ZApSiB3kPmMZT4ZVe dmDlZ3gGNBUQRE0rvOZn3OW2DWmlz6edcGX8vVCXxzAE2yqcdM3MZffJJb7PJBdYLj5l 5oQcGO+AlfUyq47Vsk9LJnj3r6W/fZpU73n4kFJDER7GNwbFFwflAQ8+q7a+UCe6ax7Z 8ZJPmf7ugZk/AuUGSuMdngYkcUPATcadWzlgy7bJo/HoChaXuWSMnkbwXRIT90W6tXrv Rugg== 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=CizRMe2YmHoMDQUcJ8913XbNFEFzGgJHDQtzao5WKiM=; b=KuF8UFMpndsmW/I+S7TYK+g+6IIoDNBeM1aRkodFJbLys40sVTeIgB/QQpdX7TYayz 7GE4b9leKjJTDeSvkeqaKbG6fFiYYuCzw8bgk6/rBs2enVEjLKdpg6n2iIggduyRo27G L7m/e3JxwhyXKWw2AfV5cOJVxufsnqSF4aNwkhtXOlIOz4E+xjCliHqpMpoPr3rAFhBI PtwYMdmXb01J2xpOX6ggLBry23Ue2JZXMedSm6kMdtX2wJAcDh/H62GrUpXPb3M+vuqq +EUMPwaQy1d1U4hK1zlEXkXtxbdxjpVjYQySZ0qnsHQwTl216ek3wAZT05KWAX/oOXxF EETg== X-Gm-Message-State: AHQUAuZp/F8ikxlzNWT1xYdILEXg4jzBPt/bu0zteVtstqpBmQCNjYGE 6mm5CCk/4+IjRbHLyCx6d9y59VkI X-Google-Smtp-Source: AHgI3Iaxn87jYxFUqbmB5XhLkCIJqJ/F1RTwFyjp9WrstSdbqh+lc5QmyHlpoFkyjdolp9R2+2X54Q== X-Received: by 2002:ac2:4154:: with SMTP id c20mr1623972lfi.74.1551192877411; Tue, 26 Feb 2019 06:54:37 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:36 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 4/8] cpuidle: menu: Convert to tick_nohz_get_next_timer|hrtimer() Date: Tue, 26 Feb 2019 15:54:11 +0100 Message-Id: <20190226145415.19411-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> From: Daniel Lezcano Rather than using tick_nohz_get_sleep_length(), let's convert to use the more flexible tick_nohz_get_next_timer|hrtimer() APIs. This should have no functional change, but allows following changes to later drop the tick_nohz_get_sleep_length() API. Signed-off-by: Daniel Lezcano [Ulf: Clarified information in changelog] Signed-off-by: Ulf Hansson --- Changes in v11: - New patch. --- drivers/cpuidle/governors/menu.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 61316fc51548..95e9122d6047 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -286,14 +286,26 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, unsigned int predicted_us; unsigned long nr_iowaiters; ktime_t delta_next; + ktime_t now = ktime_get(); + ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); + ktime_t next_timer = tick_nohz_get_next_timer(); if (data->needs_update) { menu_update(drv, dev); data->needs_update = 0; } - /* determine the expected residency time, round up */ - data->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length(&delta_next)); + /* + * Compute the duration before the next timer, whatever the origin + */ + delta_next = ktime_sub(next_timer, now); + data->next_timer_us = ktime_to_us(delta_next); + + /* + * Compute the duration before next hrtimer which is the tick + * or an earliest hrtimer + */ + delta_next = ktime_sub(next_hrtimer, now); nr_iowaiters = nr_iowait_cpu(dev->cpu); data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); From patchwork Tue Feb 26 14:54:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159218 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3304017jad; Tue, 26 Feb 2019 06:54:39 -0800 (PST) X-Received: by 2002:a2e:424f:: with SMTP id p76mr13427097lja.140.1551192879305; Tue, 26 Feb 2019 06:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192879; cv=none; d=google.com; s=arc-20160816; b=XT9rQFtVmASPzsPniyV5q6rAIGLb+wxVKjyX3gPG7TpycdmJ7azuiEr18NwL66QoQd 6JePQdVaYWZ7oQpbqWkXzR8WrLDq7RayPpAop670xVmOM6rEC5y5yWh7na7L9n9zagY/ sqlOpvQ177RfdV7X2tcWLGDq6P3JXnzfXuFcDLmjRl+lXcud3B5AKNEwk4iGZk3UvCsx G901Jz2Fcd0g0mkasqvtFYfgG3L2yFlrVF6MPCL4q3QkUP3mqV3gZj2YAv8+QQdPsbJk 5gzyShp1xTMe1kdLEC9lRPirPipn0jmDHC/EBlEycMQUvhaQMhoPxitouJSPW13C8Y+7 CLlA== 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; bh=QFP37LMPbDEXb2WSHVoMAA8Lx3svlyaybruT2DgQlU0=; b=c0qEA5Hy6dLmQpJVsQE0co+lEgQrNpVm105gSBsqrQEAxNDLpnFLwQs/dgkk2NH3HU iq5woXhbbxjMWci92r94oRHWVLLqC9QEP8EmfP/nMG5UlXiGNq9IeaMTevOLp4nTrmOf wLKEqmLZZWUKbbWTjDywBYx7J6IoGHqIqWznEY2F/Ejy3nBbEZqXf576oGDgUTLgAGU2 jn0piFMSoATLg9sF03tjdoNwUWWt2q+Y4txj0GTEQ1IoAkeKZM8Tz0nBEpaF0jQAaYQu mT3dz2aa4NmbbvtNHqOY8iulc/f6CdE8+2ZrxNCwRt70c7jBrNYOV8CdrM31mlJY60ZK KlKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fJhdwSZT; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 4sor7363182ljs.30.2019.02.26.06.54.39 for (Google Transport Security); Tue, 26 Feb 2019 06:54:39 -0800 (PST) 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=fJhdwSZT; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=QFP37LMPbDEXb2WSHVoMAA8Lx3svlyaybruT2DgQlU0=; b=fJhdwSZT64oym87C1NPWYsxIEnup9PjcSrF5GkbD0dEkILjToBgGvkqSO1yuzAVcuY IwBVw3Zw38so85Mizik5Mbqonnymp5nRCUSAeVjgZe95R69zBRpRgVtL24+ppEzUedoB NpydwEpWMQecOd+BSrS93JvO1fV6wtFgLmZWITK7ROpK+jMaic+PXJolJziV/BwlXTzX 46B54oWIwMLMFkGtSgKTYVr9lZwnOlZciD2cQ2YKRrdsNPOE3vDQUKLzNfiAsaxGEY0K d4e3kfGe1XkyNlfUhSKLa0rGM+V8qMLWduf0o4coYslRwFKe7cLZOi2CAdNUg62Of95u 7oag== 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=QFP37LMPbDEXb2WSHVoMAA8Lx3svlyaybruT2DgQlU0=; b=PQRPBLxOpNvqIhhmRkKROHOuXhFp+xO6XOpsT8xqF67iic24+FofKSXWwY5hVsJSbQ BzIiYKl6RMLlPliv4YnnpYZapc+grrwQez5kOq7Ccw8dwEOL/5QY5dhbCsqCwFrJW7RJ zDGItI/UcgK7TQh4Jz1RB4VCPO501Ki/ljxOiBeV1wPw/Y84em/rH0pf5k0xS3OTFoqf LeiGraJAZD8MBEkeW1qtRynjY4oaglEOFsMk8D50oo4vnuTtJPamGCeukf2IAIkOcKHG 00gUODNGRalap5Tcti4W4miMayUQVTEh4fDR1IEOrhsPnQQo1LP41iE+2gHnHHmlrnkL vdrQ== X-Gm-Message-State: AHQUAua1biwj2bkESgq/sNLavq9077S7HK+eJBHBA1InTps5Y94AsYYM TJEEl7cLM7QXdSK/ZImUOr0uM5Dr X-Google-Smtp-Source: AHgI3IZoxyPbTSnljzQM1jRy5kabLjUHxsOiMNs290/aMYRRyMHraw0tJ9QXBiD8tu67oy3ls34hDA== X-Received: by 2002:a2e:9e03:: with SMTP id e3mr9516998ljk.92.1551192878914; Tue, 26 Feb 2019 06:54:38 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:38 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 5/8] cpuidle: teo: Convert to tick_nohz_get_next_timer() Date: Tue, 26 Feb 2019 15:54:12 +0100 Message-Id: <20190226145415.19411-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> From: Daniel Lezcano Rather than using tick_nohz_get_sleep_length(), let's convert to use the more flexible tick_nohz_get_next_timer|hrtimer() APIs. This should have no functional change, but allows following changes to later drop the tick_nohz_get_sleep_length() API. Signed-off-by: Daniel Lezcano [Ulf: Clarified information in changelog] Signed-off-by: Ulf Hansson --- Changes in v11: - New patch. --- drivers/cpuidle/governors/teo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c index 7d05efdbd3c6..bef1e95c597e 100644 --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -244,6 +244,9 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, unsigned int duration_us, count; int max_early_idx, idx, i; ktime_t delta_tick; + ktime_t now = ktime_get(); + ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); + ktime_t next_timer = tick_nohz_get_next_timer(); if (cpu_data->last_state >= 0) { teo_update(drv, dev); @@ -252,7 +255,8 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, cpu_data->time_span_ns = local_clock(); - cpu_data->sleep_length_ns = tick_nohz_get_sleep_length(&delta_tick); + cpu_data->sleep_length_ns = ktime_sub(next_timer, now); + delta_tick = ktime_sub(next_hrtimer, now); duration_us = ktime_to_us(cpu_data->sleep_length_ns); count = 0; From patchwork Tue Feb 26 14:54:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159220 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3304036jad; Tue, 26 Feb 2019 06:54:41 -0800 (PST) X-Received: by 2002:a19:e05e:: with SMTP id g30mr1651222lfj.167.1551192880743; Tue, 26 Feb 2019 06:54:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192880; cv=none; d=google.com; s=arc-20160816; b=itM5JOG7cD1EnmU51tme2mRYikSxiui002D4M66ErR7XMc7iGo7AB6bkfDpV0FGeJJ CEQRXOjOqcHLaYeOmF1eU0azmHx/u7Uvua6FBH6T9P85K6gD2XNpQIf9jIL9xAHpnJhX dhTtjii2fJdLqrLUTsqe7x5c55nfN4Wqjj2chRo7kvg0X8ekoSDy8Y/9SHzjkkhjIIdt P0qStD+44geDwSe04y2lfz9ISex/OSnkN7vanEIog1tPDLsX46ZcC+dEgQhx1uRpsTNX SckiOXoGYV2Y5eG/Qx7NDJaWHb7PWxa4NVb36rAvK40jKikcysVaMicZT8cg7IJjIGcr /3Ig== 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; bh=7Kl3KIsTbVNnLIJETkqUkswPckk4QEkcaiOEMLrmE0U=; b=r2dkb8Bk/A9uBwac3jPHAGyJE8cC1aNQEieLF/jBBmLDHHBz2425RLLyT+w5cMtvja RakhDvRWjqi1JyjNZXwgeiUkFOO/PtICiw1C0ylCFOR/gXWoza7SCNdfeINtGP1LAznj y2v8lidz9tbRTuDRDC0EFXiOQlgn7MaW/8KSpxGGd9TNjmXD1KE03ohvCNwVaB/46J/m fqLmoYl6JGac0HrQUuV5J2Te16RWZpuCGSEf3yEt4c/Qcu4NA+5gVPvqFU1yTb7LzvwX OiaVg0VpAQCJj2D9mzXN7sdI94jLu26EdRxDfcJz8tT8y0E41QU7g9xulAah7+lotdHc +2/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n7uIvug2; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 4sor7363224ljs.30.2019.02.26.06.54.40 for (Google Transport Security); Tue, 26 Feb 2019 06:54:40 -0800 (PST) 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=n7uIvug2; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=7Kl3KIsTbVNnLIJETkqUkswPckk4QEkcaiOEMLrmE0U=; b=n7uIvug2vs/kr0RJhQcdk7BSHrob5nvRXyL0xNSxYnHFnnMKjuMDRuby6EvZhP8bIQ sEYAZFh2urn9DNVCLN5raj4+lCcuGxSZHrQSdsISgzZi+LnkU7Y9EAiAT0yLLDsNv/91 yJK71O7bWyCWWNnL5495Puaw0fpepx6aL4venBxoepro1Y72A1ytEOBcfjDqI48F+zmU Oh1P6GO0N+LiCwNlB7ssEj9oyJ9A9Oa1ROLwtEV+BbUuGmXb+kMWjx22hoV7q+XLdaOA 3CjmUKkM6RiMFGcf6nXNVb/hmr2vZCCmETUMiDFJ59GXm/VtpI8sEPIBPKj33vsL/sPW sPTg== 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=7Kl3KIsTbVNnLIJETkqUkswPckk4QEkcaiOEMLrmE0U=; b=FLMzElQvqMWjXMTlaKSmWNBqC1yELYWxvcDaVVVfyuOurc+BRebXAJBHzb9i/Kr+eY tlWM63TUp62GYuc3/2eBZuXuLZd/5McZbYKIdibXfz9Tca6G11osxekJAERKe8xyMPD8 DtT/dC7dV7LNaP0ryPQ0PK8SzAZqqNey9V2xZWpWWz7h4Xqlhy5QCcNe9ETjEezul/IG j6oN2KrXMfVXatC450+2eZm404ywPchRSVWyw6rvNs1lhobX7ebOrD5dAPrLbGw1kUIo hCb5LtqN79VgSw+ggHDwDgZ3f5KtYWZYbrNyv/kUERXU9AlFaRX8oInKjIEPuYKPu0Mj 9Q1g== X-Gm-Message-State: AHQUAuajCowWqbR3sPrbOTj7Qdq0XSSksciuDDolVTRR2rgtKy6btv81 uWrFjZVvXCDPdlCgI9hYb3YFihx5 X-Google-Smtp-Source: AHgI3IatimNXxbZ0UlAUMjP41vSG7rroGtk09LV0giyDGyOxLDbucKAoH6kRcU7fitCx8KE+Ma61NQ== X-Received: by 2002:a2e:4285:: with SMTP id h5mr13819746ljf.32.1551192880350; Tue, 26 Feb 2019 06:54:40 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:39 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 6/8] time: tick-sched: Remove tick_nohz_get_sleep_length() Date: Tue, 26 Feb 2019 15:54:13 +0100 Message-Id: <20190226145415.19411-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> From: Daniel Lezcano There are no longer any users of tick_nohz_get_sleep_length(), so let's drop it. Signed-off-by: Daniel Lezcano [Ulf: Clarified information in changelog] Signed-off-by: Ulf Hansson --- Changes in v11: - New patch. --- include/linux/tick.h | 6 ------ kernel/time/tick-sched.c | 39 --------------------------------------- 2 files changed, 45 deletions(-) -- 2.17.1 diff --git a/include/linux/tick.h b/include/linux/tick.h index 5b10a0e4acbb..1a0158736072 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -124,7 +124,6 @@ extern void tick_nohz_idle_enter(void); extern void tick_nohz_idle_exit(void); extern void tick_nohz_irq_exit(void); extern bool tick_nohz_idle_got_tick(void); -extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); extern ktime_t tick_nohz_get_next_timer(void); extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); @@ -153,11 +152,6 @@ static inline ktime_t tick_nohz_get_next_timer(void) return tick_nohz_get_next_hrtimer(); } -static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) -{ - *delta_next = TICK_NSEC; - return *delta_next; -} static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 9966be665074..a376c7db26ce 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1088,45 +1088,6 @@ ktime_t tick_nohz_get_next_timer(void) return min_t(u64, next_hrtimer, next_timer); } -/** - * tick_nohz_get_sleep_length - return the expected length of the current sleep - * @delta_next: duration until the next event if the tick cannot be stopped - * - * Called from power state control code with interrupts disabled - */ -ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) -{ - struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); - struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - int cpu = smp_processor_id(); - /* - * The idle entry time is expected to be a sufficient approximation of - * the current time at this point. - */ - ktime_t now = ts->idle_entrytime; - ktime_t next_event; - - WARN_ON_ONCE(!ts->inidle); - - *delta_next = ktime_sub(dev->next_event, now); - - if (!can_stop_idle_tick(cpu, ts)) - return *delta_next; - - next_event = tick_nohz_next_event(ts, cpu); - if (!next_event) - return *delta_next; - - /* - * If the next highres timer to expire is earlier than next_event, the - * idle governor needs to know that. - */ - next_event = min_t(u64, next_event, - hrtimer_next_event_without(&ts->sched_timer)); - - return ktime_sub(next_event, now); -} - /** * tick_nohz_get_idle_calls_cpu - return the current idle calls counter value * for a particular CPU. From patchwork Tue Feb 26 14:54:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159221 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3304051jad; Tue, 26 Feb 2019 06:54:42 -0800 (PST) X-Received: by 2002:a2e:965a:: with SMTP id z26mr12065512ljh.59.1551192882417; Tue, 26 Feb 2019 06:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192882; cv=none; d=google.com; s=arc-20160816; b=xDRrF/2mte4hG09YS7cgtNwrwaGd1/+NhZ/U+QSUMpYmq2alXEfMteRizeq1Vjaw1+ HJXa9t3+QejOFKZ3NTEOxr+vOd/VjFmWlX+ENBisrataUmcXdyYcrcnQ+eDY6Vui5OJ0 tthzlaDf7+Bwp1TbG84eCPU7dusn+/LKrH74bM1QqZB5Ndb758cUHlk4tSSdOp60b5dd vBVFXXGJhAcpy1Za9ZIBbKeIfFn9GQCJ9E7UZEMIO/W+wDwaz5TJKVUg2YQdpqmhhOot x8qxh8qyDwPeOINEGWYBEyOw/z5/q2ZnrmNiPjOCA6hd2dzuVb2pTAXhtrzSfWZ4+3zY DPYg== 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; bh=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=Aw2aAYmSNftJN/MT3ULLbZdum1Lilju+1vNmr3eqLVfg5EBSa2ajq/mtAwiGL9jKCl T4sL24HIQJR+NYyChTcU44J5P8GkxfYOd6yDRsEZM7Tk2fD6Dt+Z/FD/ZuwJayrbxd6H /KOjSX9k+VNPCY/0pe75YrEwGzi9SNQ6JLnpMv9VWfsxcofbQnf+0c4BM0SAzfLHPBjt xKbWxGXFSmXxWBLcyAkB37MtiHP8SM6csCN0leksoIUK6fehgwsrevv7c6tt7awF868+ +jzkC4Qp/WHsYMbJ5+gFVBGHHD0h0NxrMklxgFtXqLRK2D395ybwdiRVM0TijqGINhqG un6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WXbnVH1b; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 f18sor583397lfc.11.2019.02.26.06.54.42 for (Google Transport Security); Tue, 26 Feb 2019 06:54:42 -0800 (PST) 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=WXbnVH1b; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=WXbnVH1bnHlmFW3O8yFUbl6Uw3ZNLM4we+2msBhbMMZoJTPSnF7TyZVvnUuqKPCXpx V1+/lFSM8P0nVXxaNK7jld1v/1f5rPMP1nUihV6qSwvNUskToK5HM7OvZFJZ6QyXD8B/ X3XdzTBVLG+TGrdb9bpWwV6YdS7dUoi9AEZKmGa1m7AOFq+rqYkZMX4erNtlKmkiu4Ld PHX76Ti+FlXmTILcikEJSWJcoTZh/Hu52AVe7t3KkL5eJM1//lF4ZvF0lt+CkXZWNNMO ECX5oXpDzSw7kqPYIDSZH4kzNlYhbt4LafqJAdFzNtkcUXJInTkeNx5CDxOTL8gcOmwk USXQ== 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=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=gqavUw0BQvkugjNHH1hDGQGC+bJv1pMnnN6PKn7NN/oqmUEZHuGtCQzuUe5TDbBCAI pdbt6SzfXtfvOwFmQB4OgJ1Yj2P1mX39k26H8k6aJsL3QgCUm3g1pe1MqC90NX3fHQsd w/ZuGW5PThCdJJFlb6oQGMtbjQCLSBWH8fu2LCXCGHQrhG30h1MeaLDBVHIiNiZEPPaN XSsO3V3G7IfIhEByVKjgMKnzaDFwR5uK3mjX7n31hW8LqGPgbkRsD5cUOkjDJ4s70H1d hhBbM6ykfmH8qLGlkVLQdrmJFiJ4UXQMOy9D2bBAy9BpVI47taPt+AsGJj67sUuSuSkl zp7w== X-Gm-Message-State: AHQUAuY5Zo/h+HJrkHKqNjG1NOxRGY6A0s8UeGhoPccrI6/nS9UK8jTG uU+zfWQ+kCaKy1RLxspFFi3C+LOS X-Google-Smtp-Source: AHgI3IaNV91xIKeFyKjyyZRkFvds0amqlzky1w/KDmal/FUD1TWohEu1I+qqz3hzqvkCZV5Je/GfQw== X-Received: by 2002:a19:9a47:: with SMTP id c68mr7984024lfe.139.1551192881912; Tue, 26 Feb 2019 06:54:41 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:41 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 7/8] cpuidle: Pre-store next timer/tick before selecting an idle state Date: Tue, 26 Feb 2019 15:54:14 +0100 Message-Id: <20190226145415.19411-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> A common piece of data used by cpuidle governors, is the information about when the next timer/tick is going to fire. Rather than having each governor calling tick_nohz_get_next_timer|hrtimer() separately, let's consolidate the code by calling these functions before invoking the ->select() callback of the governor - and store the output data in the struct cpuidle_device. Besides the consolidation benefit, the purpose of this change is also to make the information about the next timer/tick, available outside the cpuidle framework. Following changes that implements a new genpd governor, makes use of this. Signed-off-by: Ulf Hansson --- Changes in v11: - New patch. --- drivers/cpuidle/cpuidle.c | 2 ++ drivers/cpuidle/governors/menu.c | 6 ++---- drivers/cpuidle/governors/teo.c | 6 ++---- include/linux/cpuidle.h | 2 ++ 4 files changed, 8 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 7f108309e871..3b148253036b 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -312,6 +312,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, bool *stop_tick) { + dev->next_timer = tick_nohz_get_next_timer(); + dev->next_hrtimer = tick_nohz_get_next_hrtimer(); return cpuidle_curr_governor->select(drv, dev, stop_tick); } diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 95e9122d6047..cdbe434e783d 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -287,8 +287,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, unsigned long nr_iowaiters; ktime_t delta_next; ktime_t now = ktime_get(); - ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); - ktime_t next_timer = tick_nohz_get_next_timer(); if (data->needs_update) { menu_update(drv, dev); @@ -298,14 +296,14 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, /* * Compute the duration before the next timer, whatever the origin */ - delta_next = ktime_sub(next_timer, now); + delta_next = ktime_sub(dev->next_timer, now); data->next_timer_us = ktime_to_us(delta_next); /* * Compute the duration before next hrtimer which is the tick * or an earliest hrtimer */ - delta_next = ktime_sub(next_hrtimer, now); + delta_next = ktime_sub(dev->next_hrtimer, now); nr_iowaiters = nr_iowait_cpu(dev->cpu); data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c index bef1e95c597e..7af9851d9d40 100644 --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -245,8 +245,6 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, int max_early_idx, idx, i; ktime_t delta_tick; ktime_t now = ktime_get(); - ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); - ktime_t next_timer = tick_nohz_get_next_timer(); if (cpu_data->last_state >= 0) { teo_update(drv, dev); @@ -255,8 +253,8 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, cpu_data->time_span_ns = local_clock(); - cpu_data->sleep_length_ns = ktime_sub(next_timer, now); - delta_tick = ktime_sub(next_hrtimer, now); + cpu_data->sleep_length_ns = ktime_sub(dev->next_timer, now); + delta_tick = ktime_sub(dev->next_hrtimer, now); duration_us = ktime_to_us(cpu_data->sleep_length_ns); count = 0; diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 3b39472324a3..81ec924206f0 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -83,6 +83,8 @@ struct cpuidle_device { unsigned int use_deepest_state:1; unsigned int poll_time_limit:1; unsigned int cpu; + ktime_t next_timer; + ktime_t next_hrtimer; int last_residency; struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX]; From patchwork Tue Feb 26 14:54:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159222 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3304067jad; Tue, 26 Feb 2019 06:54:43 -0800 (PST) X-Received: by 2002:a2e:8847:: with SMTP id z7mr12283866ljj.99.1551192883682; Tue, 26 Feb 2019 06:54:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192883; cv=none; d=google.com; s=arc-20160816; b=CpVrYROB9K6Yu0pB5EbF/aLczCsGMiRaCCrjzVcl+XRrjuS54Qbn+1xnWuAHb5vqQu HoKTyfBMb7n10vR16iOKvD4GJlR3eJzDFGAkukA0BKyhL0F5pSgW/2X/DGqQG3oWsubA TDSmktsMJ02PztI4HgKwDnNFZtSbsfeZbI5qBLgwHRY6DJQ1mUL+6jXj0Ux2hV2jEM0Y Wc5zcAoC+vTGc4R67k3iVyDsXX6QAtMrXJqR0PJGGrrt9L54CxNk522u9h1QHT2b3MAN brovlDSTSozjdVJ4qtZ43XLIBjOYd1eWNP1iGgAXL73VW3PAV2yxCWoWctLUMpWuyaVm 70yg== 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; bh=yH4pjF02915u7o7IIseXUbpxw7HKHFLB85eZ2Pu4HjQ=; b=F/nU5kN4GedigJbuluyQTjOkoaDZywuisymKttiJ/kzYHdofK4KFtHZCEW+TT2rD7o FAhKT39BTW2GKse05KCtBx/4NPNqbLpkWDD/a6L/qZCqNXO4WoLyYZLGj/HD1weFr0TM NA05dzUpMJXIs6AsQ5dsiPYezzXtF+f3rk1RND4UiNlshIT2Y4penZGcon5TZqfHQl4Z kooZ0K6yKaZUkKb5S+Zmv62O4O/S50ldgm8bd2iyq8jTbMLYb78LaLYgwWcNBMGuD84p vRgeB8H6HqAydYXu9dV8hDkLTKRdT5Vv3kwdqHwfW1AzAdj2G6rjoCB8470vWqqWYnGq ekKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LcfqNnOP; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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 t25sor1356596lfb.18.2019.02.26.06.54.43 for (Google Transport Security); Tue, 26 Feb 2019 06:54:43 -0800 (PST) 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=LcfqNnOP; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@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=yH4pjF02915u7o7IIseXUbpxw7HKHFLB85eZ2Pu4HjQ=; b=LcfqNnOPimrzqobeUbqhTtKZ1YN1ejQMSpxKzAFD9I+5AHFqLvX9WTAorjPQH2Pgf7 R2STDsz2lwqog2F/WWcF4LHVfD8Mf/Njvu6dfMmgpoYwhuGGZQA402/oOsbBFGf4223F pkyRbiC7EZwV6bLwFgnuuskyI1X5hYnS+bo0SNpHjVzHfEg7JAyhxbAtAEnYEKdTScsH p4SP1K4+GwVeNtefCEb97Hq2CYW50QS1xIVd/QOHePoTGqocjgxhKnopL0SGUMSUMW9/ bHrFADb4TDZGr9aqyBBLiEEZ0xbNqTT63ofOfrjUJJwgVq754UrTtDLd40erGj7ou4ao og5A== 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=yH4pjF02915u7o7IIseXUbpxw7HKHFLB85eZ2Pu4HjQ=; b=UqEQ6QhuvmqoK8Os/RF3XMk0T52BNY5JKAUitZBaFcRI57F34YnWPx8u6ZEbP3V+8t REa+bWwK5jBo7ocW4JGEXqGdr57UxKa/CHCZQaf74GgUN+L6jwrK+Ouq5CraFu3DS4dt 726CxM3DrdSb8dhSvxiIoELNdnRzPu+Ok/ThOtllmf6eNDLaGGKcAhOQYt9WhBuSggVi yDMTMF90vVkkVmJ2fiCD36Vvhz8bYsQKFJEOr3IyYJUO1n4ax0ox+hROPN74OcPNCB0W rcu2yyMlE7UC7PEKlkgrC53vhVabeE8XkUil1SDfGwDZf5rHWNx3BndMeEHLdfUsiBz7 zcRA== X-Gm-Message-State: AHQUAuZQ5LiFNpnGoNxzUWSCs7K0T9UxbYtg1DS74QGxb6ZBVC8pp6oO B2YTnP3029OnVX3+u1XPMSf7Jibe X-Google-Smtp-Source: AHgI3IYVI3uMWxE1NkMGYvg/8bPIENwiMsuV5I0+KkNgjN4De5RbbW1SRU+01hAgWVNknehZ+xn3vg== X-Received: by 2002:ac2:411a:: with SMTP id b26mr14677379lfi.169.1551192883264; Tue, 26 Feb 2019 06:54:43 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:42 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 8/8] PM / Domains: Add genpd governor for CPUs Date: Tue, 26 Feb 2019 15:54:15 +0100 Message-Id: <20190226145415.19411-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-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 about the next timer/tick that is stored in the per CPU variable, cpuidle_devices, for the related CPUs. Future wise, this deserves to be improved, as there are obviously more reasons to why a CPU may be woken up from idle. Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- Changes in v11: - Updated to use the data about the next timer/tick, pre-stored in the per CPU variable, cpuidle_devices. --- drivers/base/power/domain_governor.c | 62 +++++++++++++++++++++++++++- include/linux/pm_domain.h | 3 ++ 2 files changed, 64 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index 99896fbf18e4..d950ec24ed0e 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,55 @@ 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); + struct cpuidle_device *dev; + ktime_t domain_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; + + /* + * 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) { + dev = per_cpu(cpuidle_devices, cpu); + if (dev && ktime_before(dev->next_timer, domain_wakeup)) + domain_wakeup = dev->next_timer; + } + + /* 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 +312,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 a6e251fe9deb..ae7061556a26 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -118,6 +118,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, @@ -202,6 +203,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) @@ -245,6 +247,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