From patchwork Thu May 25 23:51:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 100535 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp10555qge; Thu, 25 May 2017 16:51:46 -0700 (PDT) X-Received: by 10.84.193.3 with SMTP id e3mr54989458pld.21.1495756306496; Thu, 25 May 2017 16:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495756306; cv=none; d=google.com; s=arc-20160816; b=xjCEGg8rEgqcY2Yh14Gw+6lgBKeJtA7iGaIHt8f9VYVmSFDUmnk+jE1PuIJx+j3ihY xT2ltYyNKRkh5ZTX5ALREz+HuyOoLV9cFz+3Ei85flTChe3h+3TtWOrqjQxHKwfhL8yG J/4a3Kyvlr/f7gjiAOwTpyifRD1mX8IKvIIqPDNDkHi4Uts51zSN59NmIAs6FygdbZ4J wOr/50BuuExjQLhtEkOr1njEKqFlVFcFPidWSO2lJslzJZAXp3qwrL6W4J352AjWIROH OL4xolj3gXEDcQWIJ1t+mgAZGvtdmkuT25lGQ6fDtibQUbOV++RuxSIv3FqNv2j/4jpS ecTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=6ewEnKQzEAH+/CFU0lVNP/X81F4oXH9wBHUTbvWHGeA=; b=Vc8yJ60UgnP73kSrYfQlt+2VMF+PNP70Vm1oDlo/yjlRuKke5PXOSudDr5v90XdkU2 FsgZWc7BdeJ0LKSl8OdOUSKRBOPfAfUUiGHFJM4qn5Y+TIdtd9xW6eukoArU5Q6vyrE/ hXwWzpGFee2QfHjaCuQtf1YHe2LmoU1J2Z93cuD6CLg8fLJ9HDkZ/F5Lo4Dy0ylPYyYc baDLId3v4cTkATnfir7krWmev119zcnIHldGE3X5K9lAJOUetWtdIu46v8Bjw3yVj71X kUrGsKUBdU547r9ftUAoADXGbqmPWk2TLsgtRiaLO0O5d/SU5HbnZ4aMiZwGm5/+6nUc ZkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si29568498plb.236.2017.05.25.16.51.46; Thu, 25 May 2017 16:51:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162730AbdEYXvp (ORCPT + 14 others); Thu, 25 May 2017 19:51:45 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:34694 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161779AbdEYXvo (ORCPT ); Thu, 25 May 2017 19:51:44 -0400 Received: by mail-pf0-f177.google.com with SMTP id 9so180724631pfj.1 for ; Thu, 25 May 2017 16:51:43 -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=6ewEnKQzEAH+/CFU0lVNP/X81F4oXH9wBHUTbvWHGeA=; b=KodsqBwLV618nDmpca8gy0QZEBfGeXgSWe99fyXmH9bazld7hHhhUCEnEc4G1Qboju tcUu4NFmGN03WQHdvTShlvvku3rjKhSdOaWUfSZfsqy51VeD7CIyLiSQf6fLI1bSj78q 0sCNrzwUSP17w2Ydn15c+Uj4X8NnKfcFul0e0= 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=6ewEnKQzEAH+/CFU0lVNP/X81F4oXH9wBHUTbvWHGeA=; b=eIVINBdQKEOlnWPcj3I2avXrfE+2uDqwxIGx3LAdWo39Knv59Igyq0YzM4Wid0GR8L t06S7LrpkcRFbtYuJM4Nfb1ePIO9CF3gw5wWf0IUqwINSiCtyU0twnBxxMukD7I8J7sM 2crXLKeXRqRJzIHe+dV4ROQjJsPY1nCgtGS7v7JuIKyvwoVIc5clDnyxeYb3KJ0yeB56 X/p4UNos+iEOkNmT9VMCgI97zG6OtET62M+NKgWT6XQLgjaN0In1WFk7Tdoz32t8KQGo ct/d2WQ6lcBKuzkbaD/qQWQ4suAaC/qMByFCQp07HCyPcc637LMb789tPOoiH3dNE8qq CaDw== X-Gm-Message-State: AODbwcAzuPq3beVAijBFqll4DYtPf8i1SwTNPr4QkqoR7dOfNulHTmHG 2WbvNFmPI5tPNIBX X-Received: by 10.98.70.198 with SMTP id o67mr46576382pfi.79.1495756303414; Thu, 25 May 2017 16:51:43 -0700 (PDT) Received: from Thara-Work-Ubuntu.domain.name ([117.213.2.159]) by smtp.googlemail.com with ESMTPSA id h71sm14684220pfe.85.2017.05.25.16.51.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 May 2017 16:51:42 -0700 (PDT) From: Thara Gopinath To: linux-pm@vger.kernel.org, ulf.hansson@linaro.org, khilman@baylibre.com Subject: [PATCH 1/2] PM / Domains: Add time accounting to various genpd states. Date: Thu, 25 May 2017 19:51:32 -0400 Message-Id: <1495756293-29534-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495756293-29534-1-git-send-email-thara.gopinath@linaro.org> References: <1495756293-29534-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 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 --- drivers/base/power/domain.c | 24 ++++++++++++++++++++++++ include/linux/pm_domain.h | 4 ++++ 2 files changed, 28 insertions(+) -- 2.1.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index da49a83..e733796 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -207,6 +207,25 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd) smp_mb__after_atomic(); } +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 == GPD_STATE_ACTIVE) { + genpd->on_time = ktime_add(genpd->on_time, delta); + } else { + int state_idx = genpd->state_idx; + + genpd->states[state_idx].active_time = + ktime_add(genpd->states[state_idx].active_time, delta); + genpd->off_time = ktime_add(genpd->off_time, delta); + } + genpd->accounting_time = now; +} + static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { unsigned int state_idx = genpd->state_idx; @@ -358,6 +377,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, return ret; } + genpd_update_accounting(genpd); genpd->status = GPD_STATE_POWER_OFF; list_for_each_entry(link, &genpd->slave_links, slave_node) { @@ -410,6 +430,7 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) if (ret) goto err; + genpd_update_accounting(genpd); genpd->status = GPD_STATE_ACTIVE; return 0; @@ -774,6 +795,7 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, if (_genpd_power_off(genpd, false)) return; + genpd_update_accounting(genpd); genpd->status = GPD_STATE_POWER_OFF; list_for_each_entry(link, &genpd->slave_links, slave_node) { @@ -821,6 +843,7 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, _genpd_power_on(genpd, false); + genpd_update_accounting(genpd); genpd->status = GPD_STATE_ACTIVE; } @@ -1486,6 +1509,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..8bee0e3 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 active_time; }; struct genpd_lock_ops; @@ -78,6 +79,9 @@ 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 off_time; + ktime_t accounting_time; const struct genpd_lock_ops *lock_ops; union { struct mutex mlock; From patchwork Thu May 25 23:51:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 100536 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp10576qge; Thu, 25 May 2017 16:51:50 -0700 (PDT) X-Received: by 10.99.184.2 with SMTP id p2mr49311717pge.126.1495756310044; Thu, 25 May 2017 16:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495756310; cv=none; d=google.com; s=arc-20160816; b=HIG97IJR986V8fDX4KYAa3MpOuy/wZJsUc/KMkjHKeQZxV2fNHSFP7bY3D7AnVNT+U 542MyNFd2kXStboVyEw78QheiY58cvFglhZpXME5aDi6GSb4GwCR0t5kCCUxnJruerpG cElnMMosk6ph1DB2q2YyA9p0JXRJvULSjVK5i/3/iFNtNiEyUuZ5EjDuHtp4D39HR/WB dSqkuAlsZ4hy+dAr/7Ak8leYf7HSNQ22PBBFdTcaTTn+OLGq05IjomJLvvr8WGIvjDIE lCA2w6XahCa5LTtwRq/4fE6Nly8sPNobelsND2ePIEFeygEtqPY0O2OyL0kX/hUVjGaF Doxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=sSVvCAMmWTde5kRNq8/1+LAquC0nz69Sv5vVyPuKji0=; b=ZVBFtklyuMY88zMO1cyhztYtX/HPoAbP/GEnqi2iVdvmxp9ymW5kyRrZzTVLs1mbzz SI6cm8UM4c4qSjONakLcjqUtKA8/w+C6fYgY1cE9a2AAwvqxvg7+ZRtbVinUv2OH62ej adJGGhUG1xzM8mYWVJpyrYbD9vn+YtY93+V1DsUILp35fco/CmcsW+JUQsO+nK5+n4gG SGfa2SHqdIxrNuH7ksMqFz7O7/9iQsVvtk5ufcoTfrGbNIQmr1YM2dSyt2sEC1VDEqJ2 j60x4b4jUpD9GZrvgBNQruCLb/TIqCrUaGBfOHMLCFzRVtnG/ZW1eXnOco5LEbxr9m8X NisQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si29568498plb.236.2017.05.25.16.51.49; Thu, 25 May 2017 16:51:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163171AbdEYXvt (ORCPT + 14 others); Thu, 25 May 2017 19:51:49 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:32802 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161779AbdEYXvr (ORCPT ); Thu, 25 May 2017 19:51:47 -0400 Received: by mail-pf0-f178.google.com with SMTP id e193so180987194pfh.0 for ; Thu, 25 May 2017 16:51:47 -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=sSVvCAMmWTde5kRNq8/1+LAquC0nz69Sv5vVyPuKji0=; b=AzeN1+OM58Hf+YJhz5lXmO5O7Lv0LHxSCwdmokOQdOXnFxTcGLEyz1a51zoQZqwjR2 Y3n7j6VKybBcI4LTksUyKHN629EE8HfSDTcp5uIgbJWDli2ZRXanSMFTeAtZ5unHAxL2 kAQPwKhNkCNI2hDuHUVKlGsA3dMK28we1MCcE= 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=sSVvCAMmWTde5kRNq8/1+LAquC0nz69Sv5vVyPuKji0=; b=TerWSv4pcNByUok+fjw7RC1Y7ZHqmmngiHoMx25RUMipTDBcgnNXufrlwpXbRe8CXq Vk3rWrrdgi5pWZqq+J3Iut4V6EHZ0oDg4AvAnYytejkKu0aV/ddDm5oYoMST6qFqqvuR gibFq71nUtbOWxyfnvsibvlsX0G6RdY2Zj5BPcyPObX0uNDYnlkTlXWeI4TmSWukmk9N 3jY1PnUUGyIx/ShN3T3bIzdyJan7mlal2p23cLYKHYBNhTldgaM67ApHzzRHrO0ds5ES Hi3g8U47Sl3Fs/JM8SkdCSp3DpTzN+OoDGVhfEYwWmf2FOXfSVLelXzj/gJsI9GyO/xE AwMQ== X-Gm-Message-State: AODbwcBCp4k1SlWxPfrRqispEy+wjE1zPKuXIKpLxPZqDtiWEYAMeXz3 hPKOpf2O9rNC0vgH X-Received: by 10.99.102.7 with SMTP id a7mr47577729pgc.216.1495756307026; Thu, 25 May 2017 16:51:47 -0700 (PDT) Received: from Thara-Work-Ubuntu.domain.name ([117.213.2.159]) by smtp.googlemail.com with ESMTPSA id h71sm14684220pfe.85.2017.05.25.16.51.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 May 2017 16:51:45 -0700 (PDT) From: Thara Gopinath To: linux-pm@vger.kernel.org, ulf.hansson@linaro.org, khilman@baylibre.com Subject: [PATCH 2/2] PM / Domains: Extend generic power domain debugfs. Date: Thu, 25 May 2017 19:51:33 -0400 Message-Id: <1495756293-29534-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495756293-29534-1-git-send-email-thara.gopinath@linaro.org> References: <1495756293-29534-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 This patch extends the existing generic power domain debugfs. Changes involve the following - Remove the current flat format of displaying generic power domain summary. - Introduce a unique debugfs entry for each generic power domain with the following attributes - current_state - Displays current state of the domain. - devices - Displays the devices associated with this domain. - slaves - Displays the sub power domains. - on_time - Displays the time the domain was in on state in ms. - idle_time - Displays the time the domain was in any of the idle states in ms. - idle_states - Displays the various idle states and the time spent in each idle state in ms. Signed-off-by: Thara Gopinath --- drivers/base/power/domain.c | 233 ++++++++++++++++++++++++++++---------------- 1 file changed, 150 insertions(+), 83 deletions(-) -- 2.1.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index e733796..3c06e33 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2214,137 +2214,204 @@ EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); #include static struct dentry *pm_genpd_debugfs_dir; -/* - * TODO: This function is a slightly modified version of rtpm_status_show - * from sysfs.c, so generalize it. - */ -static void rtpm_status_str(struct seq_file *s, struct device *dev) +static int pm_genpd_idle_states_show(struct seq_file *s, void *data) { - static const char * const status_lookup[] = { - [RPM_ACTIVE] = "active", - [RPM_RESUMING] = "resuming", - [RPM_SUSPENDED] = "suspended", - [RPM_SUSPENDING] = "suspending" - }; - const char *p = ""; - - if (dev->power.runtime_error) - p = "error"; - else if (dev->power.disable_depth) - p = "unsupported"; - else if (dev->power.runtime_status < ARRAY_SIZE(status_lookup)) - p = status_lookup[dev->power.runtime_status]; - else - WARN_ON(1); + struct generic_pm_domain *genpd = s->private; + int i, ret = 0; + + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + seq_puts(s, "State Time Spent(ms)\n"); + + for (i = 0; i < genpd->state_count; i++) { + ktime_t delta = 0; + s64 msecs; + + if ((genpd->status == GPD_STATE_POWER_OFF) && + (genpd->state_idx == i)) + delta = ktime_sub(ktime_get(), genpd->accounting_time); + + msecs = ktime_to_ms( + ktime_add(genpd->states[i].active_time, delta)); + seq_printf(s, "S%-15i %lld\n", i, msecs); + } - seq_puts(s, p); + genpd_unlock(genpd); + return ret; } -static int pm_genpd_summary_one(struct seq_file *s, - struct generic_pm_domain *genpd) +static int pm_genpd_slaves_show(struct seq_file *s, void *data) { - static const char * const status_lookup[] = { - [GPD_STATE_ACTIVE] = "on", - [GPD_STATE_POWER_OFF] = "off" - }; - struct pm_domain_data *pm_data; - const char *kobj_path; + struct generic_pm_domain *genpd = s->private; struct gpd_link *link; - char state[16]; - int ret; + int ret = 0; ret = genpd_lock_interruptible(genpd); if (ret) return -ERESTARTSYS; - if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup))) - goto exit; - if (!genpd_status_on(genpd)) - snprintf(state, sizeof(state), "%s-%u", - status_lookup[genpd->status], genpd->state_idx); - else - snprintf(state, sizeof(state), "%s", - status_lookup[genpd->status]); - seq_printf(s, "%-30s %-15s ", genpd->name, state); - - /* - * Modifications on the list require holding locks on both - * master and slave, so we are safe. - * Also genpd->name is immutable. - */ list_for_each_entry(link, &genpd->master_links, master_node) { seq_printf(s, "%s", link->slave->name); if (!list_is_last(&link->master_node, &genpd->master_links)) seq_puts(s, ", "); } + seq_puts(s, "\n"); - list_for_each_entry(pm_data, &genpd->dev_list, list_node) { - kobj_path = kobject_get_path(&pm_data->dev->kobj, - genpd_is_irq_safe(genpd) ? - GFP_ATOMIC : GFP_KERNEL); - if (kobj_path == NULL) - continue; + genpd_unlock(genpd); + return ret; +} - seq_printf(s, "\n %-50s ", kobj_path); - rtpm_status_str(s, pm_data->dev); - kfree(kobj_path); - } +static int pm_genpd_status_show(struct seq_file *s, void *data) +{ + static const char * const status_lookup[] = { + [GPD_STATE_ACTIVE] = "on", + [GPD_STATE_POWER_OFF] = "off" + }; - seq_puts(s, "\n"); + struct generic_pm_domain *genpd = s->private; + int ret = 0; + + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup))) + goto exit; + + if (genpd->status == GPD_STATE_POWER_OFF) + seq_printf(s, "%s-%u\n", status_lookup[genpd->status], + genpd->state_idx); + else + seq_printf(s, "%s\n", status_lookup[genpd->status]); exit: genpd_unlock(genpd); + return ret; +} - return 0; +static int pm_genpd_on_time_show(struct seq_file *s, void *data) +{ + struct generic_pm_domain *genpd = s->private; + ktime_t delta = 0; + int ret = 0; + + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + if (genpd->status == GPD_STATE_ACTIVE) + delta = ktime_sub(ktime_get(), genpd->accounting_time); + + seq_printf(s, "%lld ms\n", ktime_to_ms( + ktime_add(genpd->on_time, delta))); + + genpd_unlock(genpd); + return ret; } -static int pm_genpd_summary_show(struct seq_file *s, void *data) +static int pm_genpd_idle_time_show(struct seq_file *s, void *data) { - struct generic_pm_domain *genpd; + struct generic_pm_domain *genpd = s->private; + ktime_t delta = 0; int ret = 0; - seq_puts(s, "domain status slaves\n"); - seq_puts(s, " /device runtime status\n"); - seq_puts(s, "----------------------------------------------------------------------\n"); + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + if (genpd->status == GPD_STATE_POWER_OFF) + delta = ktime_sub(ktime_get(), genpd->accounting_time); + + seq_printf(s, "%lld ms\n", + ktime_to_ms(ktime_add(genpd->off_time, delta))); - ret = mutex_lock_interruptible(&gpd_list_lock); + genpd_unlock(genpd); + return ret; +} + +static int pm_genpd_devices_show(struct seq_file *s, void *data) +{ + struct generic_pm_domain *genpd = s->private; + struct pm_domain_data *pm_data; + const char *kobj_path; + int ret = 0; + + ret = genpd_lock_interruptible(genpd); if (ret) return -ERESTARTSYS; - list_for_each_entry(genpd, &gpd_list, gpd_list_node) { - ret = pm_genpd_summary_one(s, genpd); - if (ret) - break; + list_for_each_entry(pm_data, &genpd->dev_list, list_node) { + kobj_path = kobject_get_path(&pm_data->dev->kobj, + genpd_is_irq_safe(genpd) ? + GFP_ATOMIC : GFP_KERNEL); + if (kobj_path == NULL) + continue; + + seq_printf(s, "%s\n", kobj_path); + kfree(kobj_path); } - mutex_unlock(&gpd_list_lock); + genpd_unlock(genpd); return ret; } -static int pm_genpd_summary_open(struct inode *inode, struct file *file) -{ - return single_open(file, pm_genpd_summary_show, NULL); +#define define_pm_genpd_open_function(name) \ +static int pm_genpd_##name##_open(struct inode *inode, struct file *file) \ +{ \ + return single_open(file, pm_genpd_##name##_show, inode->i_private); \ } -static const struct file_operations pm_genpd_summary_fops = { - .open = pm_genpd_summary_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +define_pm_genpd_open_function(status); +define_pm_genpd_open_function(slaves); +define_pm_genpd_open_function(idle_states); +define_pm_genpd_open_function(on_time); +define_pm_genpd_open_function(idle_time); +define_pm_genpd_open_function(devices); + +#define define_pm_genpd_debugfs_fops(name) \ +static const struct file_operations pm_genpd_##name##_fops = { \ + .open = pm_genpd_##name##_open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ +} + +define_pm_genpd_debugfs_fops(status); +define_pm_genpd_debugfs_fops(slaves); +define_pm_genpd_debugfs_fops(idle_states); +define_pm_genpd_debugfs_fops(on_time); +define_pm_genpd_debugfs_fops(idle_time); +define_pm_genpd_debugfs_fops(devices); static int __init pm_genpd_debug_init(void) { struct dentry *d; + struct generic_pm_domain *genpd; pm_genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL); if (!pm_genpd_debugfs_dir) return -ENOMEM; - d = debugfs_create_file("pm_genpd_summary", S_IRUGO, - pm_genpd_debugfs_dir, NULL, &pm_genpd_summary_fops); - if (!d) - return -ENOMEM; + list_for_each_entry(genpd, &gpd_list, gpd_list_node) { + d = debugfs_create_dir(genpd->name, pm_genpd_debugfs_dir); + if (!d) + return -ENOMEM; + + debugfs_create_file("current_state", 0444, + d, genpd, &pm_genpd_status_fops); + debugfs_create_file("slaves", 0444, + d, genpd, &pm_genpd_slaves_fops); + debugfs_create_file("idle_states", 0444, + d, genpd, &pm_genpd_idle_states_fops); + debugfs_create_file("on_time", 0444, + d, genpd, &pm_genpd_on_time_fops); + debugfs_create_file("idle_time", 0444, + d, genpd, &pm_genpd_idle_time_fops); + debugfs_create_file("devices", 0444, + d, genpd, &pm_genpd_devices_fops); + } return 0; }