Skip to content

Commit 2c8db5b

Browse files
Kalesh Singhrafaeljw
authored andcommitted
PM/sleep: Expose suspend stats in sysfs
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> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e21a712 commit 2c8db5b

2 files changed

Lines changed: 201 additions & 2 deletions

File tree

‎Documentation/ABI/testing/sysfs-power‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,109 @@ Description:
301301

302302
Using this sysfs file will override any values that were
303303
set using the kernel command line for disk offset.
304+
305+
What: /sys/power/suspend_stats
306+
Date: July 2019
307+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
308+
Description:
309+
The /sys/power/suspend_stats directory contains suspend related
310+
statistics.
311+
312+
What: /sys/power/suspend_stats/success
313+
Date: July 2019
314+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
315+
Description:
316+
The /sys/power/suspend_stats/success file contains the number
317+
of times entering system sleep state succeeded.
318+
319+
What: /sys/power/suspend_stats/fail
320+
Date: July 2019
321+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
322+
Description:
323+
The /sys/power/suspend_stats/fail file contains the number
324+
of times entering system sleep state failed.
325+
326+
What: /sys/power/suspend_stats/failed_freeze
327+
Date: July 2019
328+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
329+
Description:
330+
The /sys/power/suspend_stats/failed_freeze file contains the
331+
number of times freezing processes failed.
332+
333+
What: /sys/power/suspend_stats/failed_prepare
334+
Date: July 2019
335+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
336+
Description:
337+
The /sys/power/suspend_stats/failed_prepare file contains the
338+
number of times preparing all non-sysdev devices for
339+
a system PM transition failed.
340+
341+
What: /sys/power/suspend_stats/failed_resume
342+
Date: July 2019
343+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
344+
Description:
345+
The /sys/power/suspend_stats/failed_resume file contains the
346+
number of times executing "resume" callbacks of
347+
non-sysdev devices failed.
348+
349+
What: /sys/power/suspend_stats/failed_resume_early
350+
Date: July 2019
351+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
352+
Description:
353+
The /sys/power/suspend_stats/failed_resume_early file contains
354+
the number of times executing "early resume" callbacks
355+
of devices failed.
356+
357+
What: /sys/power/suspend_stats/failed_resume_noirq
358+
Date: July 2019
359+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
360+
Description:
361+
The /sys/power/suspend_stats/failed_resume_noirq file contains
362+
the number of times executing "noirq resume" callbacks
363+
of devices failed.
364+
365+
What: /sys/power/suspend_stats/failed_suspend
366+
Date: July 2019
367+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
368+
Description:
369+
The /sys/power/suspend_stats/failed_suspend file contains
370+
the number of times executing "suspend" callbacks
371+
of all non-sysdev devices failed.
372+
373+
What: /sys/power/suspend_stats/failed_suspend_late
374+
Date: July 2019
375+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
376+
Description:
377+
The /sys/power/suspend_stats/failed_suspend_late file contains
378+
the number of times executing "late suspend" callbacks
379+
of all devices failed.
380+
381+
What: /sys/power/suspend_stats/failed_suspend_noirq
382+
Date: July 2019
383+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
384+
Description:
385+
The /sys/power/suspend_stats/failed_suspend_noirq file contains
386+
the number of times executing "noirq suspend" callbacks
387+
of all devices failed.
388+
389+
What: /sys/power/suspend_stats/last_failed_dev
390+
Date: July 2019
391+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
392+
Description:
393+
The /sys/power/suspend_stats/last_failed_dev file contains
394+
the last device for which a suspend/resume callback failed.
395+
396+
What: /sys/power/suspend_stats/last_failed_errno
397+
Date: July 2019
398+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
399+
Description:
400+
The /sys/power/suspend_stats/last_failed_errno file contains
401+
the errno of the last failed attempt at entering
402+
system sleep state.
403+
404+
What: /sys/power/suspend_stats/last_failed_step
405+
Date: July 2019
406+
Contact: Kalesh Singh <kaleshsingh96@gmail.com>
407+
Description:
408+
The /sys/power/suspend_stats/last_failed_step file contains
409+
the last failed step in the suspend/resume path.

‎kernel/power/main.c‎

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
254254
power_attr(pm_test);
255255
#endif /* CONFIG_PM_SLEEP_DEBUG */
256256

257-
#ifdef CONFIG_DEBUG_FS
258257
static char *suspend_step_name(enum suspend_stat_step step)
259258
{
260259
switch (step) {
@@ -275,6 +274,92 @@ static char *suspend_step_name(enum suspend_stat_step step)
275274
}
276275
}
277276

277+
#define suspend_attr(_name) \
278+
static ssize_t _name##_show(struct kobject *kobj, \
279+
struct kobj_attribute *attr, char *buf) \
280+
{ \
281+
return sprintf(buf, "%d\n", suspend_stats._name); \
282+
} \
283+
static struct kobj_attribute _name = __ATTR_RO(_name)
284+
285+
suspend_attr(success);
286+
suspend_attr(fail);
287+
suspend_attr(failed_freeze);
288+
suspend_attr(failed_prepare);
289+
suspend_attr(failed_suspend);
290+
suspend_attr(failed_suspend_late);
291+
suspend_attr(failed_suspend_noirq);
292+
suspend_attr(failed_resume);
293+
suspend_attr(failed_resume_early);
294+
suspend_attr(failed_resume_noirq);
295+
296+
static ssize_t last_failed_dev_show(struct kobject *kobj,
297+
struct kobj_attribute *attr, char *buf)
298+
{
299+
int index;
300+
char *last_failed_dev = NULL;
301+
302+
index = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
303+
index %= REC_FAILED_NUM;
304+
last_failed_dev = suspend_stats.failed_devs[index];
305+
306+
return sprintf(buf, "%s\n", last_failed_dev);
307+
}
308+
static struct kobj_attribute last_failed_dev = __ATTR_RO(last_failed_dev);
309+
310+
static ssize_t last_failed_errno_show(struct kobject *kobj,
311+
struct kobj_attribute *attr, char *buf)
312+
{
313+
int index;
314+
int last_failed_errno;
315+
316+
index = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
317+
index %= REC_FAILED_NUM;
318+
last_failed_errno = suspend_stats.errno[index];
319+
320+
return sprintf(buf, "%d\n", last_failed_errno);
321+
}
322+
static struct kobj_attribute last_failed_errno = __ATTR_RO(last_failed_errno);
323+
324+
static ssize_t last_failed_step_show(struct kobject *kobj,
325+
struct kobj_attribute *attr, char *buf)
326+
{
327+
int index;
328+
enum suspend_stat_step step;
329+
char *last_failed_step = NULL;
330+
331+
index = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
332+
index %= REC_FAILED_NUM;
333+
step = suspend_stats.failed_steps[index];
334+
last_failed_step = suspend_step_name(step);
335+
336+
return sprintf(buf, "%s\n", last_failed_step);
337+
}
338+
static struct kobj_attribute last_failed_step = __ATTR_RO(last_failed_step);
339+
340+
static struct attribute *suspend_attrs[] = {
341+
&success.attr,
342+
&fail.attr,
343+
&failed_freeze.attr,
344+
&failed_prepare.attr,
345+
&failed_suspend.attr,
346+
&failed_suspend_late.attr,
347+
&failed_suspend_noirq.attr,
348+
&failed_resume.attr,
349+
&failed_resume_early.attr,
350+
&failed_resume_noirq.attr,
351+
&last_failed_dev.attr,
352+
&last_failed_errno.attr,
353+
&last_failed_step.attr,
354+
NULL,
355+
};
356+
357+
static struct attribute_group suspend_attr_group = {
358+
.name = "suspend_stats",
359+
.attrs = suspend_attrs,
360+
};
361+
362+
#ifdef CONFIG_DEBUG_FS
278363
static int suspend_stats_show(struct seq_file *s, void *unused)
279364
{
280365
int i, index, last_dev, last_errno, last_step;
@@ -794,6 +879,14 @@ static const struct attribute_group attr_group = {
794879
.attrs = g,
795880
};
796881

882+
static const struct attribute_group *attr_groups[] = {
883+
&attr_group,
884+
#ifdef CONFIG_PM_SLEEP
885+
&suspend_attr_group,
886+
#endif
887+
NULL,
888+
};
889+
797890
struct workqueue_struct *pm_wq;
798891
EXPORT_SYMBOL_GPL(pm_wq);
799892

@@ -815,7 +908,7 @@ static int __init pm_init(void)
815908
power_kobj = kobject_create_and_add("power", NULL);
816909
if (!power_kobj)
817910
return -ENOMEM;
818-
error = sysfs_create_group(power_kobj, &attr_group);
911+
error = sysfs_create_groups(power_kobj, attr_groups);
819912
if (error)
820913
return error;
821914
pm_print_times_init();

0 commit comments

Comments
 (0)