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: 10830397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDDE51399 for ; Tue, 26 Feb 2019 14:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 490652C7A0 for ; Tue, 26 Feb 2019 14:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C2292C7AA; Tue, 26 Feb 2019 14:54:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C35BD2C7A0 for ; Tue, 26 Feb 2019 14:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=u7eutKaHc+DoU+KTP5zxhR7TQiZqRCAH7VZDPDoKHdk=; b=g9S7lSgFLNfngJjO6owfBSvFSy A4ootn8wMa5Do9cHPfJ/rDDP+SwOwV8wtZEZj/FHmZz2kQZNiLh0394/9A2NNwVV6FBwbjkFK5uiL 1o9RdWnd9uoBKUO9Eu41q08QsEqbumGqPG+H0jzRf1TKSvVfpCBcMDxFvY4upAKafa+UHdKula99I Fmzzl1xCLQ2L/CdHn+vI7hIiKVowDaaFnKlA1G+v2RWW30jdMgcnV0BIUCASUawNHIscbYucd9aH/ gAUpJvPUKjwWkBtmI5PSxyyT0aD1RlNBca7A4GUGBjb/6/tMHJ6DutF3iqmkgebYSH/GwW8pYOGCc H2+qg/DA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye7z-0005Pe-Ol; Tue, 26 Feb 2019 14:54:39 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye7w-0005Ng-1A for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:37 +0000 Received: by mail-lj1-x243.google.com with SMTP id z20so11005050ljj.10 for ; Tue, 26 Feb 2019 06:54:34 -0800 (PST) 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=dJjpAFdpmcT0rLGHtYBlLYRMpb+fsFlPA+DxWsf/2Jnl4EpmjIEJA2uhQkvIYj7wZh i3telZ39Nyrc8okg7iRGmlXVWClK8nkSz1fQrLBsxU3YSEUz1+hpZqN36LorWm1uBH6g 37eKxiJUJonei4jymLB6LmdhIy6zIJao6ScFYxLjADW07POpsPNKVgfbdr6gpWG63BZB b2HuQCVlWiClu7cP2AzMHR2ahHqphDpqVCyiOJElRB6DapdNofLEoVjlJg6ChjQFZnWs DZpQHzfcJkyNWuuZpQmzITxWKA8SbyWFzYFp9x5g5zgjVSbPkdszfTUYmeIJtWndGQT7 Bnhg== X-Gm-Message-State: AHQUAubnMdWx+3nqu8jAZaFDtJchpWEYXmDBi5zYJd5pl85MnBt0J6ox vEohmPJbkOTGmlWJPUIoiTFung== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065436_068301_1F339085 X-CRM114-Status: GOOD ( 19.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4789F1805 for ; Tue, 26 Feb 2019 14:55:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31DD82C7C5 for ; Tue, 26 Feb 2019 14:55:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 256E12C8F6; Tue, 26 Feb 2019 14:55:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CAC02C7C5 for ; Tue, 26 Feb 2019 14:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=aMh3tBPr+FO3roApq4kz+jiwadnIR/+AdWghY2RYFHA=; b=t25gyqeQVxJ8PAx1KIwqtGTdX+ IAl+jQa9CFjaoIyg4vIDJAX1K81JuKxkgipdwK30y+VnYj3yOF3vVCzb6ltq58B7VbPIJyT2GY73S a+NZq7Yh7GUCQCkro6WEZjghPt+XkBFF8L9ICAI+p3dvU9aIVVio7wHRV7iY3xd+e5Quivick6/xR FBFphMz3iADWfS9tQE82RnMIN8XjXDIWhaRM0rPe9LnHZzlhAQ51hTOHQhM3AxwGHr/CmbmmnEGTN 99wDBUPGuMkpL+AGN2136EeDltORScWqxTihBZdOj3MmwmeKZDAKjcOlDWw2sPS7QwxwcKmq3SjgX u2vZK+wQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye8m-0007Nq-ND; Tue, 26 Feb 2019 14:55:28 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye7w-0005Nm-JZ for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:39 +0000 Received: by mail-lj1-x241.google.com with SMTP id j19so11024053ljg.5 for ; Tue, 26 Feb 2019 06:54:36 -0800 (PST) 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=Pe6MCN3b+6GdkyTnu3c2Se42IiGY5K68qRClYIHcR8DPWtRt+hSvt+KLuLTWhYSUhX 9HMSsy2ZqyARPf7axjxIqaZXl90xBhMwNo9MlYiYAgTu9421nFNGviN4KtaxwgHQGOaa w3ddnLaqkD3t6n4NEerIWv75m6lVFt3zWo0II5fOtnZkTSrk4IW0TAtYmIsxGr9hCMej 5CuGZoGa32QdU6MK6NyQu8AQGa1AM9/KPLkH2NK9jWNgqn1WTJlKVByWK5Kk8tB07rn9 SDkMdTbF4XtWtBh47gQ4l4Ujq8pToXc4nFr4SdsmmVqEKfVtcGCVF4H26pZBTwQcQXCt tvMA== X-Gm-Message-State: AHQUAuaCZNt7YTI+wWd1AT0Q9ZR7sfW6FfkYjfcNjWUR/Q0lNrdwB3Xj K8uF3XiNGrsEjEI2YdZCszjWBQ== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065436_641985_5D029704 X-CRM114-Status: GOOD ( 24.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37E3B1399 for ; Tue, 26 Feb 2019 14:55:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21EDD2C8EA for ; Tue, 26 Feb 2019 14:55:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 163552C8F6; Tue, 26 Feb 2019 14:55:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9F3482C8EA for ; Tue, 26 Feb 2019 14:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NZJC7yTcoo9tsYV7+YUTK7x4Og4icgZD+oPtBAcZkj8=; b=fAOjxlSn8Fq2+cxuFvPwgBSkAU mPyWXlNsHmYhViCfHr/EVJuzJ9Rnff7mzNw1obKPAuaTKj/w9OezVXJdV/waV40vedwteIp8SxfKS OaDvsT0EPnZZeHVz8nuKOmemifsisolLOUkb1N0fcDWIGEi8uRr4EKT5X3g9HpSMICHwhtBzLOyBW Us/SrLrfOTPLrJOVTsYZE6MHCB9jnd5Gk2J6Zfo3uuSla3NILt93T42IxynfF7g4RXw+3g21tW90S 1ZL9+92/KXSJHoX/ztdjQFDtxRsIDjoIcqKy+fVTfCrgt7W+2JFiroe5TNU7IO7lNzoVOEtqR4Deo zGprKjkQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye8y-0007f9-En; Tue, 26 Feb 2019 14:55:40 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye7x-0005OE-JX for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:39 +0000 Received: by mail-lj1-x244.google.com with SMTP id w6so11024847ljd.7 for ; Tue, 26 Feb 2019 06:54:37 -0800 (PST) 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=XBC7weaQuqnxi3lJANQI+r/xZfJ/AngJT+Jnkggc540mQyYLJfzJUeEY4FyKFm4G/F dm3L3Mk9TxoKNITwLpEKsb0CkLf2JjwW84Ktr5aJmoen9rUh6vq1IYV7ngibWIvxbtJX K3WiL5SN1pQP5z5Q7lVyCubTaBhRw92hVDu02DjilH/320AQHJD3WituZRN01akbi+6m TXq1ePl1GZfnHKdKeZXaBboX8I5HP20DwYqnkWMoTECVr8WrUiP6S06z6iXPF7hWO9IV ltkvcq5HkFSWgqmwIGA8r7TvYun1FpotorNG7sb0Lg90x2i6rh3mxXj0dSU/07FleTnt yvJw== X-Gm-Message-State: AHQUAuarWXjrmWfHvPmCmHGKMX1s56nFvYZj9ECM5YJrDjLviOuoksrL FB2VVvqKthgN011nnZUBtIx5yQ== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065437_918277_48202F2D X-CRM114-Status: GOOD ( 23.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B2D41399 for ; Tue, 26 Feb 2019 14:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A83FF2C848 for ; Tue, 26 Feb 2019 14:55:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C41D2C878; Tue, 26 Feb 2019 14:55:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48F372C8B6 for ; Tue, 26 Feb 2019 14:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B1Dpm1PAh8KonVOLj2lyEeghbEaIvkx09hwu1/gGsa8=; b=I3gWaKChIC48UkwELb/tl6dB6/ IiixiGlceDfihSXYtJh8YzIpRVSYmCg2d4YDQBqVDa4bNqu81cMsqeti1ggRScv6wpT07tkG7kkaw uvOsNmUnsyjneI3ewuDz7ybboacEGFlfox2PWL2Ae9qIsCRDGgEcokZKuPX1Arr+sO9rXFV3oi5xH gmp9RD08sARIaGGLzDP4tQLm8nABKy2KWB95QsRlmKCHtEVv0ydVNiccRt0jKJZIlhWkPH+WWLAVG l7IkHVG/LsP7HF4fAP3gVmPYkdcQhcNchktwxQlQ57Bin6svKiZtCe1yKoh4mtbwsy5eLwNF4l+Zh tu6sYlpw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye8e-0007Ce-0a; Tue, 26 Feb 2019 14:55:20 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye7z-0005Os-HD for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:42 +0000 Received: by mail-lf1-x143.google.com with SMTP id a8so4044072lfi.7 for ; Tue, 26 Feb 2019 06:54:39 -0800 (PST) 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=X/8oTbMNHddgExo/VKBaWpKCd1GZISI/DXJO5s0mXADLDiaMuAQnVx+UZzREojP3R+ fZkiPOLZtNpqweODqdCtCwZr8iwok5TzzN84Fp/d55Vl8IuCeeJaqup0ohsYvk14Ve7o f4ARcTg7rIjCOoZ+i6BCiRb/aml8tocDvqJhlkX4eZzFRPQJP9GByZGUBLK0z/MNoD95 9hvtDTsA7CUYdM3K0TBf7veU4mwF+WZAddVrapV8CpYPqM3nm9+hFZDAfNH5+VT2VYyq 1l5vH2nqxiYExvx0KACgv0y3SYrMkl/9Gy9f5EM1Mni/7Io+FYFmf5Pniu8JvEnx4J5Y 4v0w== X-Gm-Message-State: AHQUAuaNWJxT03yYHmy8Hgy1k9jEWILB0Ik/OaR4wh6VcTQLv1RWsZvq /1Tnz/3uYxYj/r0tAGY3YKRB+A== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065439_836377_3AF41373 X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08E211399 for ; Tue, 26 Feb 2019 14:56:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C102C87D for ; Tue, 26 Feb 2019 14:56:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBD772C8F6; Tue, 26 Feb 2019 14:56:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 888052C87D for ; Tue, 26 Feb 2019 14:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=b0MWrpu4Dy4df8GBNhuUQL7vQovMCIu0bxUcMm7GTeo=; b=W24BqrS+tdHSuG44kO3JXWJw9F kVKoL1g0eGg/N29M8cWjJ1/vsNGX5AfjJ3U/lfFGVApYETswU8dd7gzDb6Kw12zIIUxz0JqdMrfdO 5rdQXNI8jVp3+fIt3ymt9GA0UHjy1HrNdPWPVoLBq3ZcRcasga6GHpsedPyHmYKuZe0fSvmIw/He9 NCP+/9kXsW8/6Bff/xeeATPDL//RWIVseWyvomr9TRQzamyItvmLiaGZWoZsTwJ0hDkjJnENVaRCp N8/UxqoR8NsaG8v5XqEQRzTrR2kg3DaEH4AOtmb0TmaeF61FgWN8hRxMQBeNDpKbDoNlWkwBk7jmG qF7bxiBg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye98-0007tb-NB; Tue, 26 Feb 2019 14:55:50 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye80-0005Pc-G6 for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:44 +0000 Received: by mail-lj1-x241.google.com with SMTP id z20so11005325ljj.10 for ; Tue, 26 Feb 2019 06:54:40 -0800 (PST) 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=TYosv/DA13NFkIsP08hzaR4yTWga1LHJNVhj63kWo2IX+NhCfwtsnwl1V3dBDojuoO IGmRWVdKLLr7nO2BSo8P6tSGlD7WsVgkIHSHkeFVkxKBicV4CzTpoy5mzVZojrmFQfS+ kEb3NxIw57FAgp8OWnJdXwP8taHu6kgGHbfs3iu1z7a9DAse5jeDX166vdLrCPczTlIM OVAX6QvOpeGlSs1v/Np8WiSjPOtBQks8QHgWbcigJEB2q9bCOkPVxTFdnvOgM8VBqNYg ga8PKw1eNOmsGpW8OWjugyc34PvYp/W/ewecvXFPW8qb/3eMfPTlqlB1TXV+Mu1wP0cm nNZQ== X-Gm-Message-State: AHQUAubR2YbdEwkNmfeB/RS0eZnpllB1GTuz+9J/rCP4GW75Uh4C56mh nLfVpoVQo05SU2mf0ZSqKSOs6g== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065440_612308_26275959 X-CRM114-Status: GOOD ( 14.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B6DC1399 for ; Tue, 26 Feb 2019 14:56:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 129392C8CA for ; Tue, 26 Feb 2019 14:56:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06DA72C8F6; Tue, 26 Feb 2019 14:56:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B8522C8CA for ; Tue, 26 Feb 2019 14:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nAtAZpm4ZNTrNrNSGbGBJ0UP5V4rzKoldHcboHkoPro=; b=nsR5y/QwRWptw4aC2MbPkthmCt 8ldPw/HTMfCviJ8wTBLRcnlcO9UIjfdeh3GOZk6LuOnLMRZeCN0f+Ow+AZhZya6l1LRd1rrGQwbIT jDXmvw0w2/22mcfQ007Ah9Vkyr6XXS91yda4u0nEvpBLFwG9Qsbpg9fbQPsPZRGlLk3paIb1QDbJM XKyCuYcwFLR7PaFstxpSiuRRKhfAY+pREcRKMQ3BcwzoSkOChJYZckaTAdJySERiRBpizE0tPO+PT Y5axgwe4ip9uNRwjJMzdc7pbf/eSkFYUdO+jFgbgUUahymoztaiF+UpRax/MGN1do0DQ2oUFfVS+J +Xnp/04Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye9J-00088n-FG; Tue, 26 Feb 2019 14:56:01 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye81-0005RA-W3 for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:48 +0000 Received: by mail-lj1-x241.google.com with SMTP id z25so11019713ljk.8 for ; Tue, 26 Feb 2019 06:54:41 -0800 (PST) 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=O+GZDoSSHACEuLpV0rROr+RQLmka1/WFhOZs7pvqPB74R1o5ZPHyysZXHyiUfwcuOO 7/ELkiFmYkkl/OrLAyGyDgkEypZvm8w1Q/qk+J1tH0MZc3KDuFdWgdBS9dYfU4zqeX5r e44XHu/ilTG4L3e7YXrwgSVDiQdMqR6GgqPKL1F499J3z360gIsnCD+ZHRdw/b1sYdhA Hz3G+yb3krf7A9v+w4ueNkT0NgtVre8FKconRfAzHeEZrrzGV6MxZo00YJClJ4uDeQMN uXLDJetN4ekTbyG1qHoRXZuVcNI7SdljitPGIt1NmbsgIaZX49zcvU8jjLM01od+rjJF /Ycg== X-Gm-Message-State: AHQUAuYBOONNeYZAXVb01/zR4I0xlpGu5qEN3Tar/t2EtEi2/SHcSeZj KHQLvyTtDj7Ozl2wQnAcJTW9Ag== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065442_371079_1A351EBB X-CRM114-Status: GOOD ( 14.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1FE41575 for ; Tue, 26 Feb 2019 14:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD57E2C87D for ; Tue, 26 Feb 2019 14:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0D1C2C90C; Tue, 26 Feb 2019 14:56:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B1062C87D for ; Tue, 26 Feb 2019 14:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Wt+b5LsmlXwIxAsuF3oXhnfH5hixL6xnxk2iUBZXLWU=; b=IsbpxhrQq/mMeAv8tnELLZrnDn Y/qNIQ/56LszuH6c2gEiCrmeV1JlJ9qJgUDgYjuaVhTJJSuOv++2LG3HMqgPFtxnYxIP7jq9PUdXm nVCiOEvsb/R+6SeQApWaGOmJxqrHHDKqww7RsOmLGSeMizwBLGVtfk8Lgs3aSIac7ZdfDdIuCQgmZ FkUIhDCjbD8QlHcw0rGZfS5S11XpNaQvj3wWPc1MpVibjyEjFxqjqBLBdSmg3+ruHchUuVwamd9LZ 8o/wizBYJNr6IoOw75ZcDXB0JppfUQu+NeN19pxgxUJERPNe+BvEj4UeIDtcUCBCttHQ8pxO+HzCq B3H73h8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye9T-0008NJ-Ul; Tue, 26 Feb 2019 14:56:11 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye84-0005TI-0P for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:50 +0000 Received: by mail-lf1-x144.google.com with SMTP id q12so9864490lfm.0 for ; Tue, 26 Feb 2019 06:54:43 -0800 (PST) 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=DYYTbSxEKLW3kZpGNTsO6ww9XWWkV3LpD2Ua22aHJnnd8BbSDfMsego+ZSdeqDqLF2 /M2OUYH+eF7TrFuyCMwI+pG5dQqxMA0OZp0liIUAv/aTSxo8RCrAqewN1W4V1QG9iKgB /3cxufBl6mASW5ZEVnDQhDpPZKmrms0YZbueAgDHbBrQEVqLXp+hXu+1O6blh/SDdSi7 F4qyrOoDYUEkHRIW2cZp/pAE/r3U6ys7onbURx68iXx7Ry/ceWT5Q3UnJY+HJDjwU3qS 92Eh11OERWkiIVjW9scE3j0y5wuGPZqpP0ggDWLFHPQOuoMN3YtxiK0ILiL4GpKlEeyv S7+w== X-Gm-Message-State: AHQUAubgThjga7C7aWENOBV7giWnHnHdWFpPeyWgiGVd16LW9I6hoBs8 2ZkU2M2uiFZq5nY5cwW9KA1l0Ky31Ck= 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065444_630152_F4A321BE X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10830447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83E871575 for ; Tue, 26 Feb 2019 14:56:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AFE92C87D for ; Tue, 26 Feb 2019 14:56:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D4262C90C; Tue, 26 Feb 2019 14:56:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D5F8F2C87D for ; Tue, 26 Feb 2019 14:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hn71MhHZL6KXERpbmrvjC2W/qzDZPPb8OTSb0oO9BiM=; b=hULDaMJoXtjGqyY95MuJyLlh0M YiZPnMZU9mnQcMkEfWTJ1k0rhFpwg8TiSbzPGoYyJuTObDjT2avIxvcFcUM47GL9sZkK6dLyIvBrm hL4zQ1UsqpJH5KSyWCoVdeXJlKlfdxn72+6o4B6tCqF3oVToWDzm5XI9t9kGkDNVlfgV06V4rJFVc S62VaC+Gpp5p7jBmkIChpJfiOZI1acYaUKbnXk5X5gGONqLA3SWCeeuqSu5mv5XZI3Y/PIODAoItd m8rT0xV9eld7bX8ZgbGW7VDaY3Sk5enffGMQwgwgm5286wajvzg8lT5lecVPPJ/KcA08zRGOdEj2E nonEvWIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye9f-0000Ak-Df; Tue, 26 Feb 2019 14:56:23 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gye85-0005Ux-3C for linux-arm-kernel@lists.infradead.org; Tue, 26 Feb 2019 14:54:50 +0000 Received: by mail-lf1-x144.google.com with SMTP id x206so1827447lff.3 for ; Tue, 26 Feb 2019 06:54:44 -0800 (PST) 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=NMsGyTvl3yAoZ1nP6NeB1izjLtE8lPao97ugW7NF136fVGs2E3/IEw4u1zRp+Th+H9 e8XjjgMykgiO/8DrmFOlGzvS9re/FJKFQz/Z2uyt9R0dC5xLGTrwCg6ZDVaYJH5xdoGS 0f2K+VmQxkqEyZezeVsmCf5dJNCyjCDJH0wMKii08MIO4tB7eb9P9iVcPKeJuz2LIx3V IVkaP75ubN8OdzHHGyLjJUFgbOkFiYuDvhkuNy5thQm8zrk+nvGKIJKmMtpQOJFGgez5 HpvUCOx33PsfqLabdwkmhLtOvsII/r9y9lOYUeioQpCKBen4RZ2cC3fbAPQh1hMGNQXr mU6w== X-Gm-Message-State: AHQUAubb+JyLnhw5yze8JlYqDhOZy+TU9IpyjSR9NxmnlpdGCXSEQtdI V+XkP+9dgGO75mLVZ3xBnxR6zg== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190226_065445_768544_A1797882 X-CRM114-Status: GOOD ( 23.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , Frederic Weisbecker , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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