From patchwork Tue Oct 20 13:26:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Haslam X-Patchwork-Id: 7447331 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 89F36BEEA4 for ; Tue, 20 Oct 2015 13:26:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8576A2089D for ; Tue, 20 Oct 2015 13:26:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72BB620867 for ; Tue, 20 Oct 2015 13:26:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752320AbbJTN0x (ORCPT ); Tue, 20 Oct 2015 09:26:53 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:32920 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752835AbbJTN0q (ORCPT ); Tue, 20 Oct 2015 09:26:46 -0400 Received: by wijp11 with SMTP id p11so47441375wij.0 for ; Tue, 20 Oct 2015 06:26:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fxn7uFvi0amR4pZV+03M/0pI+4CbLIxP0xtj6IN5hs0=; b=NmZ8s1/Au8wMHFcb1xqSgPX1cH4dtvCMU20XxnxPCic5e0IrN47DZbaW2CB2NmC23u MPzp6dxgZO0D7a9yuj0wZ+E+RduXjZliICdqUTzAifi6/v/n5S6sxpC/Y52GO6dPUQVV xa54P2Jy/ExV88y7cCxx5AHOijrEbI/LzWed2nhP0g9SltTpzQzvR6FcFVgl/fTk+GRo O/dQoy9h+0ZoCbDOrIAniA395YFF20IxpBa7kKmipRSa4HaChCUjt1uVuPUfuQGGk6w8 N5s5P5l+8SL42p8IKmqkkE710XAEnXeUYMLiQdkKNmkwnB1NIVdoRGg+fvjLOqTfzPkU m7Eg== X-Gm-Message-State: ALoCoQm/biJW1mXzJEU+nXMolYbEsTImsMfEPv6aJvB8nCH4eameeuL6F9jp/cZ6On3+zglclWv2 X-Received: by 10.194.204.195 with SMTP id la3mr4062104wjc.77.1445347605340; Tue, 20 Oct 2015 06:26:45 -0700 (PDT) Received: from localhost.localdomain (cag06-6-78-235-100-105.fbx.proxad.net. [78.235.100.105]) by smtp.gmail.com with ESMTPSA id uq5sm3905098wjc.3.2015.10.20.06.26.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Oct 2015 06:26:44 -0700 (PDT) From: ahaslam@baylibre.com To: khilman@linaro.org, ulf.hansson@linaro.org, lina.iyer@linaro.org, geert@glider.be, k.kozlowski.k@gmail.com, rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bcousson@baylibre.com, mturquette@baylibre.com, Axel Haslam Subject: [PATCH v10 3/6] PM / Domains: make governor select deepest state Date: Tue, 20 Oct 2015 15:26:26 +0200 Message-Id: <1445347589-5626-4-git-send-email-ahaslam@baylibre.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: <1445347589-5626-1-git-send-email-ahaslam@baylibre.com> References: <1445347589-5626-1-git-send-email-ahaslam@baylibre.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Axel Haslam Now that the structures of genpd can support multiple state definitions, add the logic in the governor to select the deepest possible state when powering down. For this, create the new function power_down_ok_for_state which will test if a particular state will not violate the devices and sub-domains constraints. default_power_down_ok is modified to try each state starting from the deepest until a valid state is found or there are no more states to test. the resulting state will be valid until there are latency or constraint changes, thus, we can avoid looping every power_down, and use the cached results instead. Signed-off-by: Axel Haslam --- drivers/base/power/domain_governor.c | 75 +++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index bf3ac68..aab2b32 100644 --- a/drivers/base/power/domain_governor.c +++ b/drivers/base/power/domain_governor.c @@ -100,7 +100,8 @@ static bool default_stop_ok(struct device *dev) * * This routine must be executed under the PM domain's lock. */ -static bool default_power_down_ok(struct dev_pm_domain *pd) +static bool power_down_ok_for_state(struct dev_pm_domain *pd, + unsigned int state) { struct generic_pm_domain *genpd = pd_to_genpd(pd); struct gpd_link *link; @@ -108,31 +109,9 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) s64 min_off_time_ns; s64 off_on_time_ns; - if (genpd->max_off_time_changed) { - struct gpd_link *link; + off_on_time_ns = genpd->states[state].power_off_latency_ns + + genpd->states[state].power_on_latency_ns; - /* - * We have to invalidate the cached results for the masters, so - * use the observation that default_power_down_ok() is not - * going to be called for any master until this instance - * returns. - */ - list_for_each_entry(link, &genpd->slave_links, slave_node) - link->master->max_off_time_changed = true; - - genpd->max_off_time_changed = false; - genpd->cached_power_down_ok = false; - genpd->max_off_time_ns = -1; - } else { - return genpd->cached_power_down_ok; - } - - /* - * Use the only available state, until multiple state support is added - * to the governor. - */ - off_on_time_ns = genpd->states[0].power_off_latency_ns + - genpd->states[0].power_on_latency_ns; min_off_time_ns = -1; /* @@ -195,8 +174,6 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) min_off_time_ns = constraint_ns; } - genpd->cached_power_down_ok = true; - /* * If the computed minimum device off time is negative, there are no * latency constraints, so the domain can spend arbitrary time in the @@ -209,14 +186,52 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) * The difference between the computed minimum subdomain or device off * time and the time needed to turn the domain on is the maximum * theoretical time this domain can spend in the "off" state. - * Use the only available state, until multiple state support is added - * to the governor. */ genpd->max_off_time_ns = min_off_time_ns - - genpd->states[0].power_on_latency_ns; + genpd->states[state].power_on_latency_ns; return true; } +static bool default_power_down_ok(struct dev_pm_domain *pd) +{ + struct generic_pm_domain *genpd = pd_to_genpd(pd); + unsigned int last_state_idx = genpd->state_count - 1; + struct gpd_link *link; + bool retval = false; + unsigned int i; + + /* + * if there was no change on max_off_time, we can return the + * cached value and we dont need to find a new target_state + */ + if (!genpd->max_off_time_changed) + return genpd->cached_power_down_ok; + + /* + * We have to invalidate the cached results for the masters, so + * use the observation that default_power_down_ok() is not + * going to be called for any master until this instance + * returns. + */ + list_for_each_entry(link, &genpd->slave_links, slave_node) + link->master->max_off_time_changed = true; + + genpd->max_off_time_ns = -1; + genpd->max_off_time_changed = false; + + /* find a state to power down to, starting from the deepest */ + for (i = 0; i < genpd->state_count; i++) { + if (power_down_ok_for_state(pd, last_state_idx - i)) { + genpd->state_idx = last_state_idx - i; + retval = true; + break; + } + } + + genpd->cached_power_down_ok = retval; + return retval; +} + static bool always_on_power_down_ok(struct dev_pm_domain *domain) { return false;