linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM/sleep: Expose suspend stats in sysfs
@ 2019-07-30 22:52 Kalesh Singh
  2019-07-31  5:05 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Kalesh Singh @ 2019-07-30 22:52 UTC (permalink / raw)
  To: rjw, gregkh
  Cc: trong, trong, sspatil, hridya, linux-kernel, linux-pm, Kalesh Singh

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] PM/sleep: Expose suspend stats in sysfs
  2019-07-30 22:52 [PATCH] PM/sleep: Expose suspend stats in sysfs Kalesh Singh
@ 2019-07-31  5:05 ` Greg KH
  2019-07-31 21:29   ` [PATCH v2] " Kalesh Singh
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2019-07-31  5:05 UTC (permalink / raw)
  To: Kalesh Singh; +Cc: rjw, trong, trong, sspatil, hridya, linux-kernel, linux-pm

On Tue, Jul 30, 2019 at 03:52:28PM -0700, Kalesh Singh wrote:
> +#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]);\
> +	}								\

For these 3 "special" ones, just have your own show function, no need to
cram it into this macro, making a bunch of unused code be generated all
the time.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] PM/sleep: Expose suspend stats in sysfs
  2019-07-31  5:05 ` Greg KH
@ 2019-07-31 21:29   ` Kalesh Singh
  2019-08-01  6:19     ` Greg KH
  2019-08-26  9:14     ` Rafael J. Wysocki
  0 siblings, 2 replies; 7+ messages in thread
From: Kalesh Singh @ 2019-07-31 21:29 UTC (permalink / raw)
  To: rjw, gregkh
  Cc: trong, trong, sspatil, hridya, kernel-team, linux-kernel,
	linux-pm, Kalesh Singh

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>
---
Changes in v2:
  - Added separate show functions for last_failed_* stats, as per Greg
  - Updated ABI Documentation

 Documentation/ABI/testing/sysfs-power | 106 ++++++++++++++++++++++++++
 kernel/power/main.c                   |  97 ++++++++++++++++++++++-
 2 files changed, 201 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index 3c5130355011..6f87b9dd384b 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -301,3 +301,109 @@ Description:
 
 		Using this sysfs file will override any values that were
 		set using the kernel command line for disk offset.
+
+What:		/sys/power/suspend_stats
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats directory contains suspend related
+		statistics.
+
+What:		/sys/power/suspend_stats/success
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/success file contains the number
+		of times entering system sleep state succeeded.
+
+What:		/sys/power/suspend_stats/fail
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/fail file contains the number
+		of times entering system sleep state failed.
+
+What:		/sys/power/suspend_stats/failed_freeze
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_freeze file contains the
+		number of times freezing processes failed.
+
+What:		/sys/power/suspend_stats/failed_prepare
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_prepare file contains the
+		number of times preparing all non-sysdev devices for
+		a system PM transition failed.
+
+What:		/sys/power/suspend_stats/failed_resume
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_resume file contains the
+		number of times executing "resume" callbacks of
+		non-sysdev devices failed.
+
+What:		/sys/power/suspend_stats/failed_resume_early
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_resume_early file contains
+		the number of times executing "early resume" callbacks
+		of devices failed.
+
+What:		/sys/power/suspend_stats/failed_resume_noirq
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_resume_noirq file contains
+		the number of times executing "noirq resume" callbacks
+		of devices failed.
+
+What:		/sys/power/suspend_stats/failed_suspend
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_suspend file contains
+		the number of times executing "suspend" callbacks
+		of all non-sysdev devices failed.
+
+What:		/sys/power/suspend_stats/failed_suspend_late
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_suspend_late file contains
+		the number of times executing "late suspend" callbacks
+		of all devices failed.
+
+What:		/sys/power/suspend_stats/failed_suspend_noirq
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/failed_suspend_noirq file contains
+		the number of times executing "noirq suspend" callbacks
+		of all devices failed.
+
+What:		/sys/power/suspend_stats/last_failed_dev
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/last_failed_dev file contains
+		the last device for which a suspend/resume callback failed.
+
+What:		/sys/power/suspend_stats/last_failed_errno
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/last_failed_errno file contains
+		the errno of the last failed attempt at entering
+		system sleep state.
+
+What:		/sys/power/suspend_stats/last_failed_step
+Date:		July 2019
+Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
+Description:
+		The /sys/power/suspend_stats/last_failed_step file contains
+		the last failed step in the suspend/resume path.
diff --git a/kernel/power/main.c b/kernel/power/main.c
index bdbd605c4215..938dc53a8b94 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,92 @@ 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)		\
+{								\
+	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);
+
+static ssize_t last_failed_dev_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	int index;
+	char *last_failed_dev = NULL;
+
+	index = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
+	index %= REC_FAILED_NUM;
+	last_failed_dev = suspend_stats.failed_devs[index];
+
+	return sprintf(buf, "%s\n", last_failed_dev);
+}
+static struct kobj_attribute last_failed_dev = __ATTR_RO(last_failed_dev);
+
+static ssize_t last_failed_errno_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	int index;
+	int last_failed_errno;
+
+	index = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
+	index %= REC_FAILED_NUM;
+	last_failed_errno = suspend_stats.errno[index];
+
+	return sprintf(buf, "%d\n", last_failed_errno);
+}
+static struct kobj_attribute last_failed_errno = __ATTR_RO(last_failed_errno);
+
+static ssize_t last_failed_step_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	int index;
+	enum suspend_stat_step step;
+	char *last_failed_step = NULL;
+
+	index = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
+	index %= REC_FAILED_NUM;
+	step = suspend_stats.failed_steps[index];
+	last_failed_step = suspend_step_name(step);
+
+	return sprintf(buf, "%s\n", last_failed_step);
+}
+static struct kobj_attribute last_failed_step = __ATTR_RO(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 +879,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 +908,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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PM/sleep: Expose suspend stats in sysfs
  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-26  9:14     ` Rafael J. Wysocki
  1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2019-08-01  6:19 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: rjw, trong, trong, sspatil, hridya, kernel-team, linux-kernel, linux-pm

On Wed, Jul 31, 2019 at 02:29:33PM -0700, Kalesh Singh wrote:
> 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>
> ---
> Changes in v2:
>   - Added separate show functions for last_failed_* stats, as per Greg
>   - Updated ABI Documentation

This is nice, I didn't even know some of these were in the debugfs
entries, so this should be more helpful to people.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PM/sleep: Expose suspend stats in sysfs
  2019-08-01  6:19     ` Greg KH
@ 2019-08-01 16:34       ` Kalesh Singh
  2019-08-05 18:29         ` Tri Vo
  0 siblings, 1 reply; 7+ messages in thread
From: Kalesh Singh @ 2019-08-01 16:34 UTC (permalink / raw)
  To: Greg KH
  Cc: rjw, Tri Vo, trong, Sandeep Patil, Hridya Valsaraju, kernel-team,
	linux-kernel, linux-pm

On Wed, Jul 31, 2019 at 11:19 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Jul 31, 2019 at 02:29:33PM -0700, Kalesh Singh wrote:
> > 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>
> > ---
> > Changes in v2:
> >   - Added separate show functions for last_failed_* stats, as per Greg
> >   - Updated ABI Documentation
>
> This is nice, I didn't even know some of these were in the debugfs
> entries, so this should be more helpful to people.
>
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks for the review Greg :)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PM/sleep: Expose suspend stats in sysfs
  2019-08-01 16:34       ` Kalesh Singh
@ 2019-08-05 18:29         ` Tri Vo
  0 siblings, 0 replies; 7+ messages in thread
From: Tri Vo @ 2019-08-05 18:29 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: Greg KH, Rafael J. Wysocki, Tri Vo, Sandeep Patil,
	Hridya Valsaraju, Cc: Android Kernel, LKML, Linux PM

On Thu, Aug 1, 2019 at 9:34 AM Kalesh Singh <kaleshsingh@google.com> wrote:
>
> On Wed, Jul 31, 2019 at 11:19 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Wed, Jul 31, 2019 at 02:29:33PM -0700, Kalesh Singh wrote:
> > > 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>
> > > ---
> > > Changes in v2:
> > >   - Added separate show functions for last_failed_* stats, as per Greg
> > >   - Updated ABI Documentation
> >
> > This is nice, I didn't even know some of these were in the debugfs
> > entries, so this should be more helpful to people.
> >
> > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Tri Vo <trong@android.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PM/sleep: Expose suspend stats in sysfs
  2019-07-31 21:29   ` [PATCH v2] " Kalesh Singh
  2019-08-01  6:19     ` Greg KH
@ 2019-08-26  9:14     ` Rafael J. Wysocki
  1 sibling, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-08-26  9:14 UTC (permalink / raw)
  To: Kalesh Singh
  Cc: gregkh, trong, trong, sspatil, hridya, kernel-team, linux-kernel,
	linux-pm

On Wednesday, July 31, 2019 11:29:33 PM CEST Kalesh Singh wrote:
> 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>
> ---
> Changes in v2:
>   - Added separate show functions for last_failed_* stats, as per Greg
>   - Updated ABI Documentation
> 
>  Documentation/ABI/testing/sysfs-power | 106 ++++++++++++++++++++++++++
>  kernel/power/main.c                   |  97 ++++++++++++++++++++++-
>  2 files changed, 201 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
> index 3c5130355011..6f87b9dd384b 100644
> --- a/Documentation/ABI/testing/sysfs-power
> +++ b/Documentation/ABI/testing/sysfs-power
> @@ -301,3 +301,109 @@ Description:
>  
>  		Using this sysfs file will override any values that were
>  		set using the kernel command line for disk offset.
> +
> +What:		/sys/power/suspend_stats
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats directory contains suspend related
> +		statistics.
> +
> +What:		/sys/power/suspend_stats/success
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/success file contains the number
> +		of times entering system sleep state succeeded.
> +
> +What:		/sys/power/suspend_stats/fail
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/fail file contains the number
> +		of times entering system sleep state failed.
> +
> +What:		/sys/power/suspend_stats/failed_freeze
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_freeze file contains the
> +		number of times freezing processes failed.
> +
> +What:		/sys/power/suspend_stats/failed_prepare
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_prepare file contains the
> +		number of times preparing all non-sysdev devices for
> +		a system PM transition failed.
> +
> +What:		/sys/power/suspend_stats/failed_resume
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_resume file contains the
> +		number of times executing "resume" callbacks of
> +		non-sysdev devices failed.
> +
> +What:		/sys/power/suspend_stats/failed_resume_early
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_resume_early file contains
> +		the number of times executing "early resume" callbacks
> +		of devices failed.
> +
> +What:		/sys/power/suspend_stats/failed_resume_noirq
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_resume_noirq file contains
> +		the number of times executing "noirq resume" callbacks
> +		of devices failed.
> +
> +What:		/sys/power/suspend_stats/failed_suspend
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_suspend file contains
> +		the number of times executing "suspend" callbacks
> +		of all non-sysdev devices failed.
> +
> +What:		/sys/power/suspend_stats/failed_suspend_late
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_suspend_late file contains
> +		the number of times executing "late suspend" callbacks
> +		of all devices failed.
> +
> +What:		/sys/power/suspend_stats/failed_suspend_noirq
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/failed_suspend_noirq file contains
> +		the number of times executing "noirq suspend" callbacks
> +		of all devices failed.
> +
> +What:		/sys/power/suspend_stats/last_failed_dev
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/last_failed_dev file contains
> +		the last device for which a suspend/resume callback failed.
> +
> +What:		/sys/power/suspend_stats/last_failed_errno
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/last_failed_errno file contains
> +		the errno of the last failed attempt at entering
> +		system sleep state.
> +
> +What:		/sys/power/suspend_stats/last_failed_step
> +Date:		July 2019
> +Contact:	Kalesh Singh <kaleshsingh96@gmail.com>
> +Description:
> +		The /sys/power/suspend_stats/last_failed_step file contains
> +		the last failed step in the suspend/resume path.
> diff --git a/kernel/power/main.c b/kernel/power/main.c
> index bdbd605c4215..938dc53a8b94 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,92 @@ 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)		\
> +{								\
> +	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);
> +
> +static ssize_t last_failed_dev_show(struct kobject *kobj,
> +		struct kobj_attribute *attr, char *buf)
> +{
> +	int index;
> +	char *last_failed_dev = NULL;
> +
> +	index = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
> +	index %= REC_FAILED_NUM;
> +	last_failed_dev = suspend_stats.failed_devs[index];
> +
> +	return sprintf(buf, "%s\n", last_failed_dev);
> +}
> +static struct kobj_attribute last_failed_dev = __ATTR_RO(last_failed_dev);
> +
> +static ssize_t last_failed_errno_show(struct kobject *kobj,
> +		struct kobj_attribute *attr, char *buf)
> +{
> +	int index;
> +	int last_failed_errno;
> +
> +	index = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
> +	index %= REC_FAILED_NUM;
> +	last_failed_errno = suspend_stats.errno[index];
> +
> +	return sprintf(buf, "%d\n", last_failed_errno);
> +}
> +static struct kobj_attribute last_failed_errno = __ATTR_RO(last_failed_errno);
> +
> +static ssize_t last_failed_step_show(struct kobject *kobj,
> +		struct kobj_attribute *attr, char *buf)
> +{
> +	int index;
> +	enum suspend_stat_step step;
> +	char *last_failed_step = NULL;
> +
> +	index = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
> +	index %= REC_FAILED_NUM;
> +	step = suspend_stats.failed_steps[index];
> +	last_failed_step = suspend_step_name(step);
> +
> +	return sprintf(buf, "%s\n", last_failed_step);
> +}
> +static struct kobj_attribute last_failed_step = __ATTR_RO(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 +879,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 +908,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();
> 

Applied with the Greg's R-by, thanks!




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-08-26  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30 22:52 [PATCH] PM/sleep: Expose suspend stats in sysfs Kalesh Singh
2019-07-31  5:05 ` 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

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).