From patchwork Mon Apr 20 15:02:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Haslam X-Patchwork-Id: 6242711 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 6A7B5BF4A6 for ; Mon, 20 Apr 2015 15:02:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CE5820459 for ; Mon, 20 Apr 2015 15:02:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2849620458 for ; Mon, 20 Apr 2015 15:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753475AbbDTPCT (ORCPT ); Mon, 20 Apr 2015 11:02:19 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:37981 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753179AbbDTPCT (ORCPT ); Mon, 20 Apr 2015 11:02:19 -0400 Received: by wiun10 with SMTP id n10so95166221wiu.1 for ; Mon, 20 Apr 2015 08:02:17 -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=76Mm6MBnYY/kiLJRDSjOk6QDqCoeEU3y0Mt5EULeXfE=; b=m4SepLghgJaffsLFiNBrO5a2MWU7fGMHmbMIsG/OnE9j3UUnr2+0XeRcgMEVk59P9u axuMlJfETa3yPIYnMElVhIWFrPGRy/C2e7+89VITLVLmd01njF9lnVh4pizO7yj/xQgR 9/72+f/wkkrIOpg7jvYqTorSycDfZO73IrV1vUOTdL0eCUQyyKgd1+mODkbU4cHIGhHZ LNDC0RzNalGQ2o7Az4KZ8GnCcbd0+64f3yRDlQjUJyd/EXifL06fmX8XDapX7b3M4Csb +IoXePH+q3DYpZeillINusMwZJ0O9cTt6KLlAxqRvZ6krH/tzty/28yba7R5HHJKn3YM g6Ng== X-Gm-Message-State: ALoCoQlyN4jRoxFMrOEI9KA/LFzpsd7Ry5ad1CaDgfthm98MUHJfn9BNQV8K9c/uAtQPMkv5zH0S X-Received: by 10.180.102.34 with SMTP id fl2mr25725908wib.73.1429542137538; Mon, 20 Apr 2015 08:02:17 -0700 (PDT) Received: from axelh-ThinkPad-T440s.home (LPoitiers-656-1-62-228.w90-63.abo.wanadoo.fr. [90.63.143.228]) by mx.google.com with ESMTPSA id fm8sm11119190wib.9.2015.04.20.08.02.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Apr 2015 08:02:16 -0700 (PDT) From: ahaslam@baylibre.com To: ulf.hansson@linaro.org, khilman@linaro.org, rjw@rjwysocki.net Cc: bcousson@baylibre.com, linux-pm@vger.kernel.org, Axel Haslam Subject: [RFC v3 2/7] PM / Domains: select deepest state Date: Mon, 20 Apr 2015 17:02:03 +0200 Message-Id: <1429542128-21021-3-git-send-email-ahaslam@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429542128-21021-1-git-send-email-ahaslam@baylibre.com> References: <1429542128-21021-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, T_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 target 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 | 71 ++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index 8630fce..ab7b925 100644 --- a/drivers/base/power/domain_governor.c +++ b/drivers/base/power/domain_governor.c @@ -97,33 +97,13 @@ 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, int state) { struct generic_pm_domain *genpd = pd_to_genpd(pd); struct gpd_link *link; struct pm_domain_data *pdd; s64 min_off_time_ns; s64 off_on_time_ns; - int state = 0; - - if (genpd->max_off_time_changed) { - struct gpd_link *link; - - /* - * 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; - } off_on_time_ns = genpd->states[state].power_off_latency_ns + genpd->states[state].power_on_latency_ns; @@ -202,8 +182,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 @@ -222,6 +200,53 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) return true; } +/* + * Loop into all the possible low power states + * and find the deepest state that does not violate any + * constraints. If device constraints did not change, + * we can return the cached value and use the target_state + * calculated previously. + */ +static bool default_power_down_ok(struct dev_pm_domain *pd) +{ + struct generic_pm_domain *genpd = pd_to_genpd(pd); + int last_state_idx = genpd->state_count - 1; + struct gpd_link *link; + bool retval = false; + 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->target_state = 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;