From patchwork Wed Mar 27 14:35:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 161261 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp6561526jan; Wed, 27 Mar 2019 07:35:57 -0700 (PDT) X-Received: by 2002:a2e:8693:: with SMTP id l19mr9051335lji.47.1553697357129; Wed, 27 Mar 2019 07:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553697357; cv=none; d=google.com; s=arc-20160816; b=a8iVPEM2QZZwAqHUZrKr8YOrTrzhTWMnyaWt8Ix0KWfXog133Vw1zFmw2zigWhuLM4 dQKFJSywxSnsV7DbwqkTz2XZftkToTfAtovfHLpqPi+j/EP3EYEd49bkBFhj5JozgiIH wuCy+KVgMEZIOIp15+TSMHs16ayCKnWPOCBkJyPwmw17NasgR9ybKGy/hD2M38a7AtCz oVFQAIg75kh/B+bKZZcUwhqF3aOi7zO1emj8xPYsR0ftN/pGxbRq4JuRHnFKIziINv8w RsyjwHx9LH2PKZE051xaC+8P29RPvGSToZLXYoTWLOoWzJOYIBpuZdOlHakwWfax1Y+d qq8g== 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=xqDhXSTUJNklRs7Nsz2EsWlg0IJVd5TtQANghzoIj6Y=; b=ECu8dz4P1py7Du7IVxLUQdHiZO3XbAinNPNPz5Ef2rl2RhZh33qXyl54kW0qOsxl40 xOtSZark6aLUIPat/fFpY55S8E4/HwYsxE1FHZGKfWir2wCTjW+yurL7kLjsrtJAOaf+ gwaFalXTpUbKeq9tiwhqYEHK1HCpBIWWLDeoul76+RvQ1tmZhByv86Q9z3w9I5kkqiE6 Avyg3DxBCbG3R5iuZYJIyYIXz3OFwzXNqPrAazz79iIchg2JFv3O5Ntvt33Fiq21P6vk zumQvH/YtgbnT1HaVZsjUI+6bNY1tjlyrZDxrY7MD3VLnB6y3BUKamh2e0hF0xVBF8Cb 0w1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vUdTcIfa; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k5sor6198657lfm.7.2019.03.27.07.35.56 for (Google Transport Security); Wed, 27 Mar 2019 07:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vUdTcIfa; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xqDhXSTUJNklRs7Nsz2EsWlg0IJVd5TtQANghzoIj6Y=; b=vUdTcIfazo4TkG+buldam+PhyFFNuDthLSslrkpqwoNrYsu9WlNlKvCd+BtFpo5FYh 89eb2KqV9okg5JSqhPhLjyra4l3GTxsGzD17RUxkhr+oB4xNyS+EKB9yX1/Vib1G4qjV kelNtpBQgdCNT31xGRERRrVn/akwMUFsyT193BRZqUMiOFFEBy4T1lHJLhgAB10PDnkf 8q0oG8j60vwlTk0DPt+SCObhXi0ferjtdFQkmBy6EIcmEG0VgMXI+JS9ls6pnKl3PgnR 0pOR0NYNy9SkPTqPIUaMH3BCAe9q6a8sH3awjerhjj642XPPRHMLwUhHddsNk8uq8KKn jkww== 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=xqDhXSTUJNklRs7Nsz2EsWlg0IJVd5TtQANghzoIj6Y=; b=gF6xseyHDlwnNVWOFDlo/KJkGBLyyttIuo3oh4dIGGQCML5xT7eW4oEN94Pa02o1S0 inTsdYugGmaE71U+cttFOwrGi7+AHJuT67r8ovg4ihmDFgqy89gsiOjfgy02fLPUZ5uF 0Xjj2zpJh6Gu9xmAn1h/89qe3sBXvy09WWbHFI4KjBHlbVKZstF29lYfZpmadm4uJD+4 0uHCYdGPHWcZV3SKj3h34XTG/EzMlj1FIMLmMsHj5puneAZbqbAS5JZnrAlkCdCUox8B CVvN78CNeHfIIiHP/FNhlF54o+O030Jg3ZXwcgZX+gC+bLn3PwSCkaIMQ8P4/9MghkxY 2ecA== X-Gm-Message-State: APjAAAVoUPI55Exj6DcRKrPFmfoxAGnPEYePdGIuImEVp189OFzxIxou SvGn+1+wCwJkjkzg7W0hNXKszeSJ X-Google-Smtp-Source: APXvYqzEgmGdFWFkPc93PX7NAm6POm61bIL9xLa3T0OreH/UQDLKrqrYmy0xCbUzxhqvX5C9ZJv03g== X-Received: by 2002:a19:d144:: with SMTP id i65mr17047487lfg.52.1553697356770; Wed, 27 Mar 2019 07:35:56 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q2sm4548789lfj.58.2019.03.27.07.35.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 07:35:55 -0700 (PDT) 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 v13 1/4] PM / Domains: Add a generic data pointer to the genpd_power_state struct Date: Wed, 27 Mar 2019 15:35:45 +0100 Message-Id: <20190327143548.25305-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190327143548.25305-1-ulf.hansson@linaro.org> References: <20190327143548.25305-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 Acked-by: Daniel Lezcano Signed-off-by: Ulf Hansson --- Changes in v13: - None (re-based). --- 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 96a6dc9d305c..ff6f992f7a1d 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1686,6 +1686,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; @@ -1696,7 +1702,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; } @@ -1812,7 +1818,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 Wed Mar 27 14:35:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 161262 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp6561560jan; Wed, 27 Mar 2019 07:35:59 -0700 (PDT) X-Received: by 2002:a19:954b:: with SMTP id x72mr18698796lfd.67.1553697358892; Wed, 27 Mar 2019 07:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553697358; cv=none; d=google.com; s=arc-20160816; b=SQ+2Vo3Hisr3oWuznYW7OogavD+SSwicXEIooFNf8fJCS34cqbcIvMGvTpSvbUna+V YUTiah2Gq/8iMtxGxnO7PMtdzTV7U6Cw8nQfZwOQ94G1Ni5futHnWqRJFoxru7IBjqRc oTU66GrQ3jhaXGDfA5JPtc89hZ7libCoR1d5IP8GWnzvt/ijdNi3hwG7LnphtdAPQwpV HqkuyfqLYoDjDTNoIRdOXsC7Mz9RqjhW+T18FBKRilpHn+1+9WpChsfhcwaVNIQQMZs/ +yh8sovSx6MBGXwNPr3qPOrdWb9EokdLVewrLKwYVwO4uch4wM/3NUQyhkLklb93Ztw/ I6BQ== 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=Do62RarFZKiaJHchChMBUqt67JhmdRrqCmB3BM4qNsk=; b=sH9ao24tP0Pa4mcXqIk2/YjWtNt4b6NsaNxfP9Seby2eAWcGvSvEnWT22VC2cytnNy NQFayH17nshw/hQwsJfIHKUc/i4KXiBbFWcNHGIxBqCYkOHQn/y77bnnIIuqMa+OdRxV jrs2NIZrEiQ7yCE6NH2EjDLzg3xxFCcA1n14lhG2X9T2dOryQX9yu9VW6EPm28SlZC9A ZERF1uUNr1ToT1rHrFn0MALGjeiOjdy6JHG6ZHmHyzGsmjiUiN700Q9Ss3X1btjjzo9R xv7TaE9BISqUtp9vsMToxe68+evKgSAvo0gy3VCJoe160iwpq9XeteX7L68ikK33xt01 b6iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KhP79mrR; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f7sor8688933ljk.41.2019.03.27.07.35.58 for (Google Transport Security); Wed, 27 Mar 2019 07:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KhP79mrR; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Do62RarFZKiaJHchChMBUqt67JhmdRrqCmB3BM4qNsk=; b=KhP79mrRfRrsAir3ZbeLkpEDaUFnZcXgy4dlrUVtV8lML0eWBceZEwB0ezuPNHY+1c Iq1UJXV7GcgXCRg/xcAcpI4MhRAeR3Ll0LQKwPPgj60Xt3muNyAxwTK+WKwMYlApbkgr n1Uw3OLTWqi7HbQxkCZv5Fn+3qOjlxbAkU+B8B4RFb9qShGuTC9ad27zlG+1UQX8V94E jSqOGJW7wKzMSL5V5W0vVquYRSVmMwnr26ysFcHMGWO7oFAh99YyGCYSFX7tHqcUMzFf +dUJ0EdnCraD5KLu2v/H3sruhCmV+Vdk60NEBJLauuw+MGHLv/90O098+wvCCkGT1cur jrJQ== 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=Do62RarFZKiaJHchChMBUqt67JhmdRrqCmB3BM4qNsk=; b=NyAxUpud+KSskmdIxmLrZA5j+rC59BpcmlTuuJ7aHex0I/SQczgZIoJCsTrZcydUeC yN3lIEiKksuCdNLupqDm9PuqIbA75DFgjPkz6HGbIGhDZtG28fBIGG7WEo7QUT7hqvmZ mrgJ77/7JNuj/fjgdNS7w36RCKOFCYyua/n9m0FQZJQ8cVY37Ol5aLPaapY5tMIxhf9d 4rXVcgiU+hATUSD3quokX92zjUqYn8+MCJctOqNpHektliUGXxV3DTn0yz9JGL8n8mXW uhrb53HMnTw8yz3w+iRRDxSCcPZRO/vIXJBgZlV5o66gYgwBzS4zMzBw9o3rzjpUHiwv ki3w== X-Gm-Message-State: APjAAAVqftj6BzAGRmT0zcm/o2eWhAqKOvozm49pl6+W9JwvgFFXSD9h T8pcd8JlPVmJgcOMmqcbEiZhR5yV X-Google-Smtp-Source: APXvYqxvJpHzjkikSC9P794Ufie27oyHGtWUvApWjshRK2vNSuvPv1H/ixxVqHnz+Ufj42EuSVQ5aQ== X-Received: by 2002:a2e:5d94:: with SMTP id v20mr18347734lje.138.1553697358467; Wed, 27 Mar 2019 07:35:58 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q2sm4548789lfj.58.2019.03.27.07.35.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 07:35:57 -0700 (PDT) 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 2/4] PM / Domains: Add support for CPU devices to genpd Date: Wed, 27 Mar 2019 15:35:46 +0100 Message-Id: <20190327143548.25305-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190327143548.25305-1-ulf.hansson@linaro.org> References: <20190327143548.25305-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 Acked-by: Daniel Lezcano Signed-off-by: Ulf Hansson --- Changes in v13: - None (re-based). --- drivers/base/power/domain.c | 65 ++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 13 ++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index ff6f992f7a1d..ecac03dcc9b2 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "power.h" @@ -128,6 +129,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) @@ -1454,6 +1456,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) { @@ -1475,6 +1527,7 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, genpd_lock(genpd); + genpd_set_cpumask(genpd, dev); dev_pm_domain_set(dev, &genpd->domain); genpd->device_count++; @@ -1532,6 +1585,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd->device_count--; genpd->max_off_time_changed = true; + genpd_clear_cpumask(genpd, dev); dev_pm_domain_set(dev, NULL); list_del_init(&pdd->list_node); @@ -1768,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 && genpd->state_count > 1) { pr_warn("%s: no governor for states\n", genpd->name); } @@ -1818,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 Wed Mar 27 14:35:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 161263 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp6561610jan; Wed, 27 Mar 2019 07:36:01 -0700 (PDT) X-Received: by 2002:ac2:4825:: with SMTP id 5mr18776561lft.64.1553697361537; Wed, 27 Mar 2019 07:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553697361; cv=none; d=google.com; s=arc-20160816; b=xXIWrpeZX/POvg8F/AurjaSiE8zO0xttPVuwK6d4jimXSeTB/UTqvYkEkc2lKcK/ny rLJF+bntOhJ43ZFbE47WRrgSIV95vwbI03Ye0fmzfN3ACNMfBOcGcrApQ9oOe7T0aEME XgmNB1nM+kvHDY9VMc7kXcJFwdIe2CWpdiyeXe46ImbUlNvul82ewaAm7MjuAuxo7+aT aejtv02BRyeVWxLyG5p4aO9l3polP5VIuLJg9jtad+JafVHqvX4PVx7F5MuEScR664Yg feAh0uN5NHjtCTSwUlEKyltAi+JN8KHFx3jZxKEVXNt/p5PV1yEDmVk7TH4NB72c5uux GE/g== 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=5vc0Fh7WVBEgxYINTNsSBAHF75OIY/EqVtxxKOnOMeU=; b=yJa6Ibtv4JtZF2Yye3DaQSsTVlPqvdEEZ4kPFUvRlkljv0sY04+x9ssua9aWyYFqH1 9SJ4FE6VptAHEgy1LMN6uLAJF914Q4b3/U7cACJ6in57ZR9u/7qX93npQFNhkSBCynut bhO7K/0Mr0bXntiB1SIoMD5AJIFSEwAx5z5w6yU6jxvQpdF+c1KVYkZrkoS9o7OgXFQi 6LnapF8LxTp2g+YTQjQpEepV3znP6qgONNCkWHhMWLG7Sgb7s+WUUXG6tyHP4MI+2YDx VW3W46HqiMd3Z/UPAEPSSayjFFHxIDEktDFsv740qCiQ54n0aFZwHvA6BLf7dI4Fr1Sj 352w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MTrdssA0; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y9sor8753742ljj.19.2019.03.27.07.36.01 for (Google Transport Security); Wed, 27 Mar 2019 07:36:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MTrdssA0; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5vc0Fh7WVBEgxYINTNsSBAHF75OIY/EqVtxxKOnOMeU=; b=MTrdssA0TPWQa4lNDrtuZYmFjZtQEp9NuJXqUFJnOAP0JcSMEATBgM9kPNKibwinXU +Hd+Ht+XFjZr69eWzu/wdFQb1oaxzSM3Vqkz2IVL2dBjBEZ7pHDVPXOsOEBvd6DNWL7w SJzA23Z7Y/BhudD2sfsUomqLtvK9Id1KfkATcOD1992bWeZAI6VG41atqyO8lZll5aL2 7Mnp0mO3oM5kMbeq09mfXN+TdBg07KXEhJJ4V/z3osDE3X1S5YKv9uHpBJDHbWCoLxQx IYNKfg0a9BAn7WvEBCeEtFW4Jyh4sJGadUhX0hKXJtA4jJT9G1pIQZ7nvHwFWmBJvO6Z tbcA== 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=5vc0Fh7WVBEgxYINTNsSBAHF75OIY/EqVtxxKOnOMeU=; b=hqiK6cC/9gnghf64/X0/xedexAk1kuYISjcrObhfTNkiZ3PwBNSI95TwpU/xoXK2du LSyMjMkPPGwOUvb60slYPZ8dKGGx3BA/KEvZIOsV5nMIT2e/SslkAR8H8ozp9IgXQP/X aVx/SvJjJhsRbM15wNQmqdsUlQQaeR1tHIGTH3nydOhhqiiIu6K2dDlLYzN2r0gWTYxL UwoMEvpvGPednrCSHuq5igvn7kYzBrVFC3YUjZWcumzi6xyTpvywvXt6gwiZmB1UNY0/ lj/B80q9A9/smEGCcgGK1K/kgNj3TA1x0HyHA+BkZDYkkPFJT9VRn+YGZXl1tX8AwLkZ WBKQ== X-Gm-Message-State: APjAAAWaA4ulpxL2NIljGbkYCAhTpZ4rijeNghSK7nT1LIJNNWhUqaYv vSlxtr4OtpZzu/Il2IhzFJsY2wEL X-Google-Smtp-Source: APXvYqxM6qi/XDrPHpLp+RXLlmfNtCXJbY2FGNByAhSqp/7Ums1A1rJ2C5zXW0rMIhKX2jVXPoZkDA== X-Received: by 2002:a2e:6c0f:: with SMTP id h15mr19630105ljc.155.1553697361156; Wed, 27 Mar 2019 07:36:01 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q2sm4548789lfj.58.2019.03.27.07.35.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 07:35:59 -0700 (PDT) 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 v13 3/4] cpuidle: Export the next timer/tick expiration for a CPU Date: Wed, 27 Mar 2019 15:35:47 +0100 Message-Id: <20190327143548.25305-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190327143548.25305-1-ulf.hansson@linaro.org> References: <20190327143548.25305-1-ulf.hansson@linaro.org> To be able to predict the sleep duration for a CPU that is entering idle, knowing when the next timer/tick is going to expire, is extremely useful. Both the teo and the menu cpuidle governors already makes use of this information, while selecting an idle state. Moving forward, the similar prediction needs to be done, but for a group of idle CPUs rather than for a single idle CPU. Following changes implements a new genpd governor, which needs this. Support this, by sharing a new function called tick_nohz_get_next_hrtimer(), which returns the next hrtimer or the next tick, whatever that expires first. Additionally, when cpuidle is about to invoke the ->enter() callback, then call tick_nohz_get_next_hrtimer() and store its return value in the per CPU struct cpuidle_device, as to make it available outside cpuidle. Do note, at the point when cpuidle calls tick_nohz_get_next_hrtimer(), the governor's ->select() callback has already made a decision whether to stop the tick or not. In this way, tick_nohz_get_next_hrtimer() actually returns the next timer expiration, whatever origin. Cc: Lina Iyer Co-developed-by: Lina Iyer Co-developed-by: Daniel Lezcano Acked-by: Daniel Lezcano Signed-off-by: Ulf Hansson --- Changes in v13: - As suggested by Rafael, use WRITE|READ_ONCE when writing/reading the next_hrtimer variable and also avoid it from containing a stale value. --- drivers/cpuidle/cpuidle.c | 19 +++++++++++++++++-- include/linux/cpuidle.h | 1 + include/linux/tick.h | 7 ++++++- kernel/time/tick-sched.c | 12 ++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 7f108309e871..0f4b7c45df3e 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -328,9 +328,23 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev, int index) { + int ret = 0; + + /* + * Store the next hrtimer, which becomes either next tick or the next + * timer event, whatever expires first. Additionally, to make this data + * useful for consumers outside cpuidle, we rely on that the governor's + * ->select() callback have decided, whether to stop the tick or not. + */ + WRITE_ONCE(dev->next_hrtimer, tick_nohz_get_next_hrtimer()); + if (cpuidle_state_is_coupled(drv, index)) - return cpuidle_enter_state_coupled(dev, drv, index); - return cpuidle_enter_state(dev, drv, index); + ret = cpuidle_enter_state_coupled(dev, drv, index); + else + ret = cpuidle_enter_state(dev, drv, index); + + WRITE_ONCE(dev->next_hrtimer, 0); + return ret; } /** @@ -511,6 +525,7 @@ static void __cpuidle_device_init(struct cpuidle_device *dev) { memset(dev->states_usage, 0, sizeof(dev->states_usage)); dev->last_residency = 0; + dev->next_hrtimer = 0; } /** diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 3b39472324a3..bb9a0db89f1a 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -83,6 +83,7 @@ struct cpuidle_device { unsigned int use_deepest_state:1; unsigned int poll_time_limit:1; unsigned int cpu; + ktime_t next_hrtimer; int last_residency; struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX]; diff --git a/include/linux/tick.h b/include/linux/tick.h index 55388ab45fd4..8891b5ac3e40 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -122,6 +122,7 @@ 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_next_hrtimer(void); extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); @@ -145,7 +146,11 @@ 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_hrtimer(void) +{ + /* Next wake up is the tick period, assume it starts now */ + return ktime_add(ktime_get(), TICK_NSEC); +} static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) { *delta_next = TICK_NSEC; diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 6fa52cd6df0b..8d18e03124ff 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1022,6 +1022,18 @@ bool tick_nohz_idle_got_tick(void) return false; } +/** + * tick_nohz_get_next_hrtimer - return the next expiration time for the hrtimer + * or the tick, whatever that expires first. Note that, if the tick has been + * stopped, it returns the next hrtimer. + * + * Called from power state control code with interrupts disabled + */ +ktime_t tick_nohz_get_next_hrtimer(void) +{ + return __this_cpu_read(tick_cpu_device.evtdev)->next_event; +} + /** * 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 Wed Mar 27 14:35:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 161264 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp6561659jan; Wed, 27 Mar 2019 07:36:03 -0700 (PDT) X-Received: by 2002:a2e:8316:: with SMTP id a22mr20039555ljh.171.1553697363383; Wed, 27 Mar 2019 07:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553697363; cv=none; d=google.com; s=arc-20160816; b=wCE1G+xmfg/AvUdTsSAofluxYxpR2klmYqC5Wu/m0QE+Id56Y/gK4J+E4HNucEveXV zkmf+0mXo65Hh+nUpETMg/hT5hG9cAP5P1Hy5KCDYNPpvwPjZdSdHK2RTJkcjiPUevrD 8YVaxrFGfx0R3cdl8Bb6NOrm+Sv4E5G4IFGQ1+939NcQ7zcmXj8ru5+JH6lDWsQofkSM txj8TfChANi87nYXn5kDehEmgi8IC34QoNtazrsEyrrM+c0rWPpkmqq7ZCCjl/84F2VK CN9VsT43CRS91NyM9Ypalc+hRMCY2e3h6x+v0DwSODQbdTueFnEBZ8E8cUPqr+e3bsqx 9nfw== 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=U/DRGI4bD5hxWQz0RfripmToZCqku1wrBoz6VqQCAxM=; b=hI+QMa8/9dVWqjJAFe6kC041zHTtBh6hVepC+2c9IUuRbbYfzFRiBWRZeMjyOmyqEt t6O60NzWt1Kdj4KPXuPvqDVGIl/Q3IwXyhAeS0yy5bzHwTNPL618GcHI79dj2ToMxPqm 45TjHcpTLdT9VN7UwLi7XRG885fr7rsZujOQeq8Rl3bmrjGYtonz/JK64dIUxSKZ3QJm tyYHlYE7tqRtMj0LaYQ6T1NJPo87ULOmTxFRZq9u+WaB+nBishkWKTuHNou3vn6AplGI 5laYv5p8aCBqsOtDZdnml4RAF84uHWtnn1a5ITlkccdw/cgd0chDu2oSfBbWqyDT8ciO X+Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AoB0C/P6"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 11sor6199348lfr.68.2019.03.27.07.36.03 for (Google Transport Security); Wed, 27 Mar 2019 07:36:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AoB0C/P6"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U/DRGI4bD5hxWQz0RfripmToZCqku1wrBoz6VqQCAxM=; b=AoB0C/P6/wN599c40fA7FnfEHKiR7xeJ7iQmmglTyYj5F7TdqnpFwOiPVkri1hG8sp ARptOc6fXizzOnP4L5FQuk5esopJcWQ+JW8LnKxDNbXzcZ+IAjOG+346RpopY45y7NCv XN9qFMtVdnzZ1twakoIFLSjUOCID5QPM6ZL2TdIVgshdDxw2edfQ5xZpKXu2/bJUNsr6 WujH02a4iLbZyLLKr303Cd/xcwky2IRKn1/FPMIauCLVndH7lwpAi2Cd+OHZjqdPEyrO I01box3+bUsmQsyzJF/nigg3kCfs6jS8swImNBcEH7LbM0wZ5+SJTm1TwdTIr0KUsHSV PstA== 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=U/DRGI4bD5hxWQz0RfripmToZCqku1wrBoz6VqQCAxM=; b=mJu3rqU6LrX7SsPmZMMCFhGZ8SWhdhXGZ3HHjkfF+TkFBDFxcZhtpG98Byo38GWbYM zIgp1jilFeMzJUnYm+x8ONEZdKsSyLB2vRUbQJFOgV1euuBFH6EfB+gJCP+hB68LlXSk 27RBl1qmFhIEfd3gUSpqeJWLXy3wVBXNAAu3hRXWSnycrHF0fiUOqolhSUKQlx4bdjx9 4ic5e+oCt9QmFKmbuE5KU4gnG403MZwtKg87A9xBFQ+J1fnbuFoHUXK0F6DfZOrAIEA3 PbxnjK861huco+rAk+jsFA2UWrqZLRGV9IL7B3Mc5OWI9FltdJx1TVNGDVSNND2WkAev T2AQ== X-Gm-Message-State: APjAAAXi8uxUqwu9oROjxO2mrB+WF9WEz0qrPFPBd1SrF0BneXZ8vmhJ NRBd2x+TiaHWbBC37/fnN5OWvO2E X-Google-Smtp-Source: APXvYqwVSECMJDyPtKk3qdNVbNspLWl8YfiJbJb0coBO8l42U3F7Cr7jGh2Pwe9hzNBWHEBxdliY8A== X-Received: by 2002:a19:4b53:: with SMTP id y80mr20608817lfa.146.1553697362971; Wed, 27 Mar 2019 07:36:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q2sm4548789lfj.58.2019.03.27.07.36.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 07:36:02 -0700 (PDT) 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 v13 4/4] PM / Domains: Add genpd governor for CPUs Date: Wed, 27 Mar 2019 15:35:48 +0100 Message-Id: <20190327143548.25305-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190327143548.25305-1-ulf.hansson@linaro.org> References: <20190327143548.25305-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 Acked-by: Daniel Lezcano Signed-off-by: Ulf Hansson --- Changes in v13: - As suggested by Rafael, use READ_ONCE when reading the next_hrtimer variable. --- drivers/base/power/domain_governor.c | 65 +++++++++++++++++++++++++++- include/linux/pm_domain.h | 3 ++ 2 files changed, 67 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index 4d07e38a8247..7f9b80f46b3a 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) { @@ -210,8 +213,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 @@ -236,6 +241,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; } @@ -244,6 +250,58 @@ 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, next_hrtimer; + 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) { + next_hrtimer = READ_ONCE(dev->next_hrtimer); + if (ktime_before(next_hrtimer, domain_wakeup)) + domain_wakeup = next_hrtimer; + } + } + + /* 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, @@ -256,3 +314,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