From patchwork Tue Jun 13 20:27:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 105417 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp589484qgd; Tue, 13 Jun 2017 13:27:54 -0700 (PDT) X-Received: by 10.107.142.136 with SMTP id q130mr2160978iod.225.1497385674324; Tue, 13 Jun 2017 13:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497385674; cv=none; d=google.com; s=arc-20160816; b=IhLHHvKGhnYLpCv8WZL8z4o1VYP+Dlffi0urFegAIoLljPsPrzSZ9zH21LSowGqZAb 6isCQiXehRdu1/pX/CClKUv6CJX/xOB56TQC5dLzGAGubJvIvylHwylCiVPAN//UtjdO FOS8x69cFiLpPPrXh7L5aCeb28vZnpxxFFuLidya1/R6usjetPdF0T1RL8fD3BeDm4T1 qHf1pdqFcAMJYb8GWSizaqhfkgrrzMA1vEx7uJ0aSpW/l0EaeolV875sIpl8T7g84sgv muvjrzrBJtMSn8a8ol9PxBah8A+TjsCv0MBvaNcg5KFVSy9GOJJr13YeI7ZTieh6j2Mt CNUg== 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=anZlNqsHhUzndDQC2SSAHbJmGDGOll5vlzeY3iVS6O8=; b=RZMG1++N3cRYqz84kIOmUEkltpewRDDWH/ej3Mvo8mVgnF0lCGRv1IthVTqzlAqYwl OruSCbUncE0hNSIw9B7pwZ91CgLZcmiZURQJpEA5QuVXf2Zdx5inP5BJSsrAvYO8iLjC SG6QQr413lUKMf2+ih64TONkLbBowc6npsX8SYDn1Fn29h6csTz3EEHjD6BL5xE86GKL 43E7xSosRpYRkoJKH6S6syLzt7NY1MRwgfBBI+mTiGU86SrGGN0RrqvcLkDkHHUgfXa+ /ndOzPwyWJeDPoJz/JdTE1l2FyBsu7R0C9fsJOtTs2U6+3ZUYrY1H5Akwi7KGCC4SV6A lvxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=ZXY58A6c; 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 p141si7743160itp.89.2017.06.13.13.27.54; Tue, 13 Jun 2017 13:27:54 -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 header.b=ZXY58A6c; 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 S1753853AbdFMU1x (ORCPT + 14 others); Tue, 13 Jun 2017 16:27:53 -0400 Received: from mail-qt0-f178.google.com ([209.85.216.178]:34903 "EHLO mail-qt0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753845AbdFMU1w (ORCPT ); Tue, 13 Jun 2017 16:27:52 -0400 Received: by mail-qt0-f178.google.com with SMTP id w1so187990928qtg.2 for ; Tue, 13 Jun 2017 13:27:51 -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=anZlNqsHhUzndDQC2SSAHbJmGDGOll5vlzeY3iVS6O8=; b=ZXY58A6c2gJh9IR9/HcuiZxPLMgF8wJWRX20+N0mLnHAcuqQKvsEnmSYEPZV8b9hw2 dWjbg7i9IPCoL+x9uL9jhyA2cmlxmyYURDHeFKOcxCHSdWVaKH2cd7W34SjXiag43xRw 6DyiD5VeYGoFNctSM2EorLf6H5M3NkSynMEzI= 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=anZlNqsHhUzndDQC2SSAHbJmGDGOll5vlzeY3iVS6O8=; b=if6+Z3Tm7CLAiin8otjPHRV165DFu1ljtG0jjAguV45RWRfg8N3Ja6Nhrh+ClHqoj0 Kgslrl0MfdM8z2FjqD8ngQil7pWRFl0y4Vq7Kd/2PoLMy/uDOdVzYvWDL70wuuGBbXNL IXYlXDbPx9jyDJQ3A00c4ddahs2h8AVgHHghQ3LJfrXM9wwFGvyKOsmyfsc9IQq711Wa /jN2AgY+0WtxdinIiQICXE/zdBfnEvHR3daK/5f8KzOMzU9Q7sCle3S/VCWibTH0ax7k /5xew5eexF877uKaMvV3D0IZVDLtosyF4nn0ufV0kVB0K96XrraFsoDDf/2orGx2S44X wgyg== X-Gm-Message-State: AKS2vOz1q9lziXsGxCD4LmA3NB8O7T8AjguDWsior1ofkHVpmcwvrW7L q1L+vFY5Ztz7J2rP5Bk5zg== X-Received: by 10.55.24.232 with SMTP id 101mr115352qky.203.1497385666292; Tue, 13 Jun 2017 13:27:46 -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 z40sm10101515qth.64.2017.06.13.13.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 13:27:44 -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 V2 2/2] PM / Domains: Extend generic power domain debugfs. Date: Tue, 13 Jun 2017 16:27:39 -0400 Message-Id: <1497385659-2356-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1497385659-2356-1-git-send-email-thara.gopinath@linaro.org> References: <1497385659-2356-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 - 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. - sub_domains - Displays the sub power domains. - active_time - Displays the time the domain was in active state in ms. - total_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 | 203 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 195 insertions(+), 8 deletions(-) -- 2.1.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 33b4632..c1a0cd1 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2322,21 +2322,189 @@ static int pm_genpd_summary_show(struct seq_file *s, void *data) return ret; } -static int pm_genpd_summary_open(struct inode *inode, struct file *file) +static int pm_genpd_status_show(struct seq_file *s, void *data) { - return single_open(file, pm_genpd_summary_show, NULL); + static const char * const status_lookup[] = { + [GPD_STATE_ACTIVE] = "on", + [GPD_STATE_POWER_OFF] = "off" + }; + + 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; } -static const struct file_operations pm_genpd_summary_fops = { - .open = pm_genpd_summary_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +static int pm_genpd_sub_domains_show(struct seq_file *s, void *data) +{ + struct generic_pm_domain *genpd = s->private; + struct gpd_link *link; + int ret = 0; + + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + 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"); + + genpd_unlock(genpd); + return ret; +} + +static int pm_genpd_idle_states_show(struct seq_file *s, void *data) +{ + 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].idle_time, delta)); + seq_printf(s, "S%-15i %lld\n", i, msecs); + } + + genpd_unlock(genpd); + return ret; +} + +static int pm_genpd_active_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_total_idle_time_show(struct seq_file *s, void *data) +{ + struct generic_pm_domain *genpd = s->private; + ktime_t delta = 0, total = 0; + int i, ret = 0; + + ret = genpd_lock_interruptible(genpd); + if (ret) + return -ERESTARTSYS; + + for (i = 0; i < genpd->state_count; i++) { + + if ((genpd->status == GPD_STATE_POWER_OFF) && + (genpd->state_idx == i)) + delta = ktime_sub(ktime_get(), genpd->accounting_time); + + total = ktime_add(total, genpd->states[i].idle_time); + } + total = ktime_add(total, delta); + + seq_printf(s, "%lld ms\n", ktime_to_ms(total)); + + 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(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); + } + + genpd_unlock(genpd); + return ret; +} + +#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); \ +} + +define_pm_genpd_open_function(summary); +define_pm_genpd_open_function(status); +define_pm_genpd_open_function(sub_domains); +define_pm_genpd_open_function(idle_states); +define_pm_genpd_open_function(active_time); +define_pm_genpd_open_function(total_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(summary); +define_pm_genpd_debugfs_fops(status); +define_pm_genpd_debugfs_fops(sub_domains); +define_pm_genpd_debugfs_fops(idle_states); +define_pm_genpd_debugfs_fops(active_time); +define_pm_genpd_debugfs_fops(total_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); @@ -2348,6 +2516,25 @@ static int __init pm_genpd_debug_init(void) 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("sub_domains", 0444, + d, genpd, &pm_genpd_sub_domains_fops); + debugfs_create_file("idle_states", 0444, + d, genpd, &pm_genpd_idle_states_fops); + debugfs_create_file("active_time", 0444, + d, genpd, &pm_genpd_active_time_fops); + debugfs_create_file("total_idle_time", 0444, + d, genpd, &pm_genpd_total_idle_time_fops); + debugfs_create_file("devices", 0444, + d, genpd, &pm_genpd_devices_fops); + } + return 0; } late_initcall(pm_genpd_debug_init);