From: Kalesh Singh <kaleshsingh@google.com>
To: rjw@rjwysocki.net, gregkh@linuxfoundation.org
Cc: trong@google.com, trong@android.com, sspatil@google.com,
hridya@google.com, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, Kalesh Singh <kaleshsingh@google.com>
Subject: [PATCH] PM/sleep: Expose suspend stats in sysfs
Date: Tue, 30 Jul 2019 15:52:28 -0700 [thread overview]
Message-ID: <20190730225228.126044-1-kaleshsingh@google.com> (raw)
Userspace can get suspend stats from the suspend stats debugfs node.
Since debugfs doesn't have stable ABI, expose suspend stats in
sysfs under /sys/power/suspend_stats.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
kernel/power/main.c | 77 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 75 insertions(+), 2 deletions(-)
diff --git a/kernel/power/main.c b/kernel/power/main.c
index bdbd605c4215..2a0edfcd50dc 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -254,7 +254,6 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
power_attr(pm_test);
#endif /* CONFIG_PM_SLEEP_DEBUG */
-#ifdef CONFIG_DEBUG_FS
static char *suspend_step_name(enum suspend_stat_step step)
{
switch (step) {
@@ -275,6 +274,72 @@ static char *suspend_step_name(enum suspend_stat_step step)
}
}
+#define suspend_attr(_name) \
+static ssize_t _name##_show(struct kobject *kobj, \
+ struct kobj_attribute *attr, char *buf) \
+{ \
+ int index; \
+ enum suspend_stat_step step; \
+ char *last_failed_stat = NULL; \
+ \
+ if (strcmp(attr->attr.name, "last_failed_dev") == 0) { \
+ index = suspend_stats._name + REC_FAILED_NUM - 1; \
+ index %= REC_FAILED_NUM; \
+ last_failed_stat = suspend_stats.failed_devs[index]; \
+ return sprintf(buf, "%s\n", last_failed_stat); \
+ } else if (strcmp(attr->attr.name, "last_failed_step") == 0) { \
+ index = suspend_stats._name + REC_FAILED_NUM - 1; \
+ index %= REC_FAILED_NUM; \
+ step = suspend_stats.failed_steps[index]; \
+ last_failed_stat = suspend_step_name(step); \
+ return sprintf(buf, "%s\n", last_failed_stat); \
+ } else if (strcmp(attr->attr.name, "last_failed_errno") == 0) { \
+ index = suspend_stats._name + REC_FAILED_NUM - 1; \
+ index %= REC_FAILED_NUM; \
+ return sprintf(buf, "%d\n", suspend_stats.errno[index]);\
+ } \
+ \
+ return sprintf(buf, "%d\n", suspend_stats._name); \
+} \
+static struct kobj_attribute _name = __ATTR_RO(_name)
+
+suspend_attr(success);
+suspend_attr(fail);
+suspend_attr(failed_freeze);
+suspend_attr(failed_prepare);
+suspend_attr(failed_suspend);
+suspend_attr(failed_suspend_late);
+suspend_attr(failed_suspend_noirq);
+suspend_attr(failed_resume);
+suspend_attr(failed_resume_early);
+suspend_attr(failed_resume_noirq);
+suspend_attr(last_failed_dev);
+suspend_attr(last_failed_errno);
+suspend_attr(last_failed_step);
+
+static struct attribute *suspend_attrs[] = {
+ &success.attr,
+ &fail.attr,
+ &failed_freeze.attr,
+ &failed_prepare.attr,
+ &failed_suspend.attr,
+ &failed_suspend_late.attr,
+ &failed_suspend_noirq.attr,
+ &failed_resume.attr,
+ &failed_resume_early.attr,
+ &failed_resume_noirq.attr,
+ &last_failed_dev.attr,
+ &last_failed_errno.attr,
+ &last_failed_step.attr,
+ NULL,
+};
+
+static struct attribute_group suspend_attr_group = {
+ .name = "suspend_stats",
+ .attrs = suspend_attrs,
+};
+
+#ifdef CONFIG_DEBUG_FS
static int suspend_stats_show(struct seq_file *s, void *unused)
{
int i, index, last_dev, last_errno, last_step;
@@ -794,6 +859,14 @@ static const struct attribute_group attr_group = {
.attrs = g,
};
+static const struct attribute_group *attr_groups[] = {
+ &attr_group,
+#ifdef CONFIG_PM_SLEEP
+ &suspend_attr_group,
+#endif
+ NULL,
+};
+
struct workqueue_struct *pm_wq;
EXPORT_SYMBOL_GPL(pm_wq);
@@ -815,7 +888,7 @@ static int __init pm_init(void)
power_kobj = kobject_create_and_add("power", NULL);
if (!power_kobj)
return -ENOMEM;
- error = sysfs_create_group(power_kobj, &attr_group);
+ error = sysfs_create_groups(power_kobj, attr_groups);
if (error)
return error;
pm_print_times_init();
--
2.22.0.770.g0f2c4a37fd-goog
next reply other threads:[~2019-07-30 22:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 22:52 Kalesh Singh [this message]
2019-07-31 5:05 ` [PATCH] PM/sleep: Expose suspend stats in sysfs Greg KH
2019-07-31 21:29 ` [PATCH v2] " Kalesh Singh
2019-08-01 6:19 ` Greg KH
2019-08-01 16:34 ` Kalesh Singh
2019-08-05 18:29 ` Tri Vo
2019-08-26 9:14 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190730225228.126044-1-kaleshsingh@google.com \
--to=kaleshsingh@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hridya@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=sspatil@google.com \
--cc=trong@android.com \
--cc=trong@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).