From patchwork Fri Jun 23 16:32:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 9806885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E9DC6089D for ; Fri, 23 Jun 2017 16:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E9242869B for ; Fri, 23 Jun 2017 16:32:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 839C928792; Fri, 23 Jun 2017 16:32:39 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE518287A1 for ; Fri, 23 Jun 2017 16:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754414AbdFWQc3 (ORCPT ); Fri, 23 Jun 2017 12:32:29 -0400 Received: from mail-qk0-f175.google.com ([209.85.220.175]:35029 "EHLO mail-qk0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753893AbdFWQc2 (ORCPT ); Fri, 23 Jun 2017 12:32:28 -0400 Received: by mail-qk0-f175.google.com with SMTP id 16so39761359qkg.2 for ; Fri, 23 Jun 2017 09:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=z9p39rabsXDkusSVPrHLdNDHcW65FBN1ZaJdskjDCVk=; b=fQED9y3kXqJqAUBbnAETTCNoLpd6+1aJaj3duLFAkzcD6qPlleSngjMLj1o2WWpXfq GjvbCiwxmSjKxdQvMSFijW5MAixWFi/Sk0HTD1nh+dI+3pHtwrckGuRhQ9zRciK6yFlq xyIS0OUmJW06IOQ+UA5kxI4CzdDkMWP3I+tPk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=z9p39rabsXDkusSVPrHLdNDHcW65FBN1ZaJdskjDCVk=; b=D/8rrW1FskCdp9CySrHsj7bVtTSqjIoTW4WbZM534ZHNt4Tj26cnbpT01s7GRI3+LL Cn9ylqjLLSfebVx5mWMrRNwZQ/PI2MmOUtx2J8+k78iny9TXvjt/lXJiHqMWNzn4cuHT ADMcZrgOH/TcAvaBzBUNVo46W+9OUDux8tMgDjHlkwK3/gPDjuHZVQ7ITf+L7JZkQKmD RJw4g9+85ZUDhSkhbUnuI0h7BP6SAoyRXNw8A+yfyxeFfoh07lnQ3j3TqfhWsFBuiuYT g4sIimSTC4zKUFQljaFK/hVtxKfUJMfvxNiM6OKsnNtt58S3/OjNUID7F+dNGlHmi6yF D26A== X-Gm-Message-State: AKS2vOwnx8ElY/5ObXs7xHS9FUbbDiZoakfcIDmzjcvcm3f3q2RuUD08 SDV1SIariGh3EryQbX+mNQ== X-Received: by 10.55.99.76 with SMTP id x73mr9659638qkb.219.1498235547600; Fri, 23 Jun 2017 09:32:27 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-167.washdc.fios.verizon.net. [71.255.245.167]) by smtp.googlemail.com with ESMTPSA id c26sm1620720qte.63.2017.06.23.09.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Jun 2017 09:32:26 -0700 (PDT) From: Thara Gopinath To: ulf.hansson@linaro.org, khilman@kernel.org, rjw@rjwysocki.net, gregkh@linuxfoundation.org, linux-pm@vger.kernel.org Subject: [PATCH V3 1/2] PM / Domains: Add time accounting to various genpd states. Date: Fri, 23 Jun 2017 12:32:22 -0400 Message-Id: <1498235543-30064-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1498235543-30064-1-git-send-email-thara.gopinath@linaro.org> References: <1498235543-30064-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support to calculate the time spent by the generic power domains in on and various idle states. Signed-off-by: Thara Gopinath Acked-by: Ulf Hansson --- drivers/base/power/domain.c | 32 ++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index da49a83..40768cc 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -207,6 +207,34 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd) smp_mb__after_atomic(); } +#ifdef CONFIG_DEBUG_FS +static void genpd_update_accounting(struct generic_pm_domain *genpd) +{ + ktime_t delta, now; + + now = ktime_get(); + delta = ktime_sub(now, genpd->accounting_time); + + /* + * If genpd->status is active, it means we are just + * out of off and so update the idle time and vice + * versa. + */ + if (genpd->status == GPD_STATE_ACTIVE) { + int state_idx = genpd->state_idx; + + genpd->states[state_idx].idle_time = + ktime_add(genpd->states[state_idx].idle_time, delta); + } else { + genpd->on_time = ktime_add(genpd->on_time, delta); + } + + genpd->accounting_time = now; +} +#else +static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {} +#endif + static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { unsigned int state_idx = genpd->state_idx; @@ -359,6 +387,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, } genpd->status = GPD_STATE_POWER_OFF; + genpd_update_accounting(genpd); list_for_each_entry(link, &genpd->slave_links, slave_node) { genpd_sd_counter_dec(link->master); @@ -411,6 +440,8 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) goto err; genpd->status = GPD_STATE_ACTIVE; + genpd_update_accounting(genpd); + return 0; err: @@ -1486,6 +1517,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, genpd->max_off_time_changed = true; genpd->provider = NULL; genpd->has_provider = false; + genpd->accounting_time = ktime_get(); genpd->domain.ops.runtime_suspend = genpd_runtime_suspend; genpd->domain.ops.runtime_resume = genpd_runtime_resume; genpd->domain.ops.prepare = pm_genpd_prepare; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index b7803a2..9c8b334 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -43,6 +43,7 @@ struct genpd_power_state { s64 power_on_latency_ns; s64 residency_ns; struct fwnode_handle *fwnode; + ktime_t idle_time; }; struct genpd_lock_ops; @@ -78,6 +79,8 @@ struct generic_pm_domain { 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; union { struct mutex mlock;