Skip to content

Commit 2a77c46

Browse files
ShuoX Liurjwysocki
authored andcommitted
PM / Suspend: Add statistics debugfs file for suspend to RAM
Record S3 failure time about each reason and the latest two failed devices' names in S3 progress. We can check it through 'suspend_stats' entry in debugfs. The motivation of the patch: We are enabling power features on Medfield. Comparing with PC/notebook, a mobile enters/exits suspend-2-ram (we call it s3 on Medfield) far more frequently. If it can't enter suspend-2-ram in time, the power might be used up soon. We often find sometimes, a device suspend fails. Then, system retries s3 over and over again. As display is off, testers and developers don't know what happens. Some testers and developers complain they don't know if system tries suspend-2-ram, and what device fails to suspend. They need such info for a quick check. The patch adds suspend_stats under debugfs for users to check suspend to RAM statistics quickly. If not using this patch, we have other methods to get info about what device fails. One is to turn on CONFIG_PM_DEBUG, but users would get too much info and testers need recompile the system. In addition, dynamic debug is another good tool to dump debug info. But it still doesn't match our utilization scenario closely. 1) user need write a user space parser to process the syslog output; 2) Our testing scenario is we leave the mobile for at least hours. Then, check its status. No serial console available during the testing. One is because console would be suspended, and the other is serial console connecting with spi or HSU devices would consume power. These devices are powered off at suspend-2-ram. Signed-off-by: ShuoX Liu <shuox.liu@intel.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
1 parent 9bd717c commit 2a77c46

5 files changed

Lines changed: 218 additions & 8 deletions

File tree

‎Documentation/power/basic-pm-debugging.txt‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,27 @@ case, you may be able to search for failing drivers by following the procedure
201201
analogous to the one described in section 1. If you find some failing drivers,
202202
you will have to unload them every time before an STR transition (ie. before
203203
you run s2ram), and please report the problems with them.
204+
205+
There is a debugfs entry which shows the suspend to RAM statistics. Here is an
206+
example of its output.
207+
# mount -t debugfs none /sys/kernel/debug
208+
# cat /sys/kernel/debug/suspend_stats
209+
success: 20
210+
fail: 5
211+
failed_freeze: 0
212+
failed_prepare: 0
213+
failed_suspend: 5
214+
failed_suspend_noirq: 0
215+
failed_resume: 0
216+
failed_resume_noirq: 0
217+
failures:
218+
last_failed_dev: alarm
219+
adc
220+
last_failed_errno: -16
221+
-16
222+
last_failed_step: suspend
223+
suspend
224+
Field success means the success number of suspend to RAM, and field fail means
225+
the failure number. Others are the failure number of different steps of suspend
226+
to RAM. suspend_stats just lists the last 2 failed devices, error number and
227+
failed step of suspend.

‎drivers/base/power/main.c‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ LIST_HEAD(dpm_prepared_list);
4646
LIST_HEAD(dpm_suspended_list);
4747
LIST_HEAD(dpm_noirq_list);
4848

49+
struct suspend_stats suspend_stats;
4950
static DEFINE_MUTEX(dpm_list_mtx);
5051
static pm_message_t pm_transition;
5152

@@ -467,8 +468,12 @@ void dpm_resume_noirq(pm_message_t state)
467468
mutex_unlock(&dpm_list_mtx);
468469

469470
error = device_resume_noirq(dev, state);
470-
if (error)
471+
if (error) {
472+
suspend_stats.failed_resume_noirq++;
473+
dpm_save_failed_step(SUSPEND_RESUME_NOIRQ);
474+
dpm_save_failed_dev(dev_name(dev));
471475
pm_dev_err(dev, state, " early", error);
476+
}
472477

473478
mutex_lock(&dpm_list_mtx);
474479
put_device(dev);
@@ -629,8 +634,12 @@ void dpm_resume(pm_message_t state)
629634
mutex_unlock(&dpm_list_mtx);
630635

631636
error = device_resume(dev, state, false);
632-
if (error)
637+
if (error) {
638+
suspend_stats.failed_resume++;
639+
dpm_save_failed_step(SUSPEND_RESUME);
640+
dpm_save_failed_dev(dev_name(dev));
633641
pm_dev_err(dev, state, "", error);
642+
}
634643

635644
mutex_lock(&dpm_list_mtx);
636645
}
@@ -805,6 +814,9 @@ int dpm_suspend_noirq(pm_message_t state)
805814
mutex_lock(&dpm_list_mtx);
806815
if (error) {
807816
pm_dev_err(dev, state, " late", error);
817+
suspend_stats.failed_suspend_noirq++;
818+
dpm_save_failed_step(SUSPEND_SUSPEND_NOIRQ);
819+
dpm_save_failed_dev(dev_name(dev));
808820
put_device(dev);
809821
break;
810822
}
@@ -926,8 +938,10 @@ static void async_suspend(void *data, async_cookie_t cookie)
926938
int error;
927939

928940
error = __device_suspend(dev, pm_transition, true);
929-
if (error)
941+
if (error) {
942+
dpm_save_failed_dev(dev_name(dev));
930943
pm_dev_err(dev, pm_transition, " async", error);
944+
}
931945

932946
put_device(dev);
933947
}
@@ -970,6 +984,7 @@ int dpm_suspend(pm_message_t state)
970984
mutex_lock(&dpm_list_mtx);
971985
if (error) {
972986
pm_dev_err(dev, state, "", error);
987+
dpm_save_failed_dev(dev_name(dev));
973988
put_device(dev);
974989
break;
975990
}
@@ -983,7 +998,10 @@ int dpm_suspend(pm_message_t state)
983998
async_synchronize_full();
984999
if (!error)
9851000
error = async_error;
986-
if (!error)
1001+
if (error) {
1002+
suspend_stats.failed_suspend++;
1003+
dpm_save_failed_step(SUSPEND_SUSPEND);
1004+
} else
9871005
dpm_show_time(starttime, state, NULL);
9881006
return error;
9891007
}
@@ -1091,7 +1109,10 @@ int dpm_suspend_start(pm_message_t state)
10911109
int error;
10921110

10931111
error = dpm_prepare(state);
1094-
if (!error)
1112+
if (error) {
1113+
suspend_stats.failed_prepare++;
1114+
dpm_save_failed_step(SUSPEND_PREPARE);
1115+
} else
10951116
error = dpm_suspend(state);
10961117
return error;
10971118
}

‎include/linux/suspend.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,58 @@ typedef int __bitwise suspend_state_t;
3434
#define PM_SUSPEND_MEM ((__force suspend_state_t) 3)
3535
#define PM_SUSPEND_MAX ((__force suspend_state_t) 4)
3636

37+
enum suspend_stat_step {
38+
SUSPEND_FREEZE = 1,
39+
SUSPEND_PREPARE,
40+
SUSPEND_SUSPEND,
41+
SUSPEND_SUSPEND_NOIRQ,
42+
SUSPEND_RESUME_NOIRQ,
43+
SUSPEND_RESUME
44+
};
45+
46+
struct suspend_stats {
47+
int success;
48+
int fail;
49+
int failed_freeze;
50+
int failed_prepare;
51+
int failed_suspend;
52+
int failed_suspend_noirq;
53+
int failed_resume;
54+
int failed_resume_noirq;
55+
#define REC_FAILED_NUM 2
56+
int last_failed_dev;
57+
char failed_devs[REC_FAILED_NUM][40];
58+
int last_failed_errno;
59+
int errno[REC_FAILED_NUM];
60+
int last_failed_step;
61+
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
62+
};
63+
64+
extern struct suspend_stats suspend_stats;
65+
66+
static inline void dpm_save_failed_dev(const char *name)
67+
{
68+
strlcpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
69+
name,
70+
sizeof(suspend_stats.failed_devs[0]));
71+
suspend_stats.last_failed_dev++;
72+
suspend_stats.last_failed_dev %= REC_FAILED_NUM;
73+
}
74+
75+
static inline void dpm_save_failed_errno(int err)
76+
{
77+
suspend_stats.errno[suspend_stats.last_failed_errno] = err;
78+
suspend_stats.last_failed_errno++;
79+
suspend_stats.last_failed_errno %= REC_FAILED_NUM;
80+
}
81+
82+
static inline void dpm_save_failed_step(enum suspend_stat_step step)
83+
{
84+
suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
85+
suspend_stats.last_failed_step++;
86+
suspend_stats.last_failed_step %= REC_FAILED_NUM;
87+
}
88+
3789
/**
3890
* struct platform_suspend_ops - Callbacks for managing platform dependent
3991
* system sleep states.

‎kernel/power/main.c‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <linux/string.h>
1313
#include <linux/resume-trace.h>
1414
#include <linux/workqueue.h>
15+
#include <linux/debugfs.h>
16+
#include <linux/seq_file.h>
1517

1618
#include "power.h"
1719

@@ -133,6 +135,101 @@ power_attr(pm_test);
133135

134136
#endif /* CONFIG_PM_SLEEP */
135137

138+
#ifdef CONFIG_DEBUG_FS
139+
static char *suspend_step_name(enum suspend_stat_step step)
140+
{
141+
switch (step) {
142+
case SUSPEND_FREEZE:
143+
return "freeze";
144+
case SUSPEND_PREPARE:
145+
return "prepare";
146+
case SUSPEND_SUSPEND:
147+
return "suspend";
148+
case SUSPEND_SUSPEND_NOIRQ:
149+
return "suspend_noirq";
150+
case SUSPEND_RESUME_NOIRQ:
151+
return "resume_noirq";
152+
case SUSPEND_RESUME:
153+
return "resume";
154+
default:
155+
return "";
156+
}
157+
}
158+
159+
static int suspend_stats_show(struct seq_file *s, void *unused)
160+
{
161+
int i, index, last_dev, last_errno, last_step;
162+
163+
last_dev = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
164+
last_dev %= REC_FAILED_NUM;
165+
last_errno = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
166+
last_errno %= REC_FAILED_NUM;
167+
last_step = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
168+
last_step %= REC_FAILED_NUM;
169+
seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
170+
"%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
171+
"success", suspend_stats.success,
172+
"fail", suspend_stats.fail,
173+
"failed_freeze", suspend_stats.failed_freeze,
174+
"failed_prepare", suspend_stats.failed_prepare,
175+
"failed_suspend", suspend_stats.failed_suspend,
176+
"failed_suspend_noirq",
177+
suspend_stats.failed_suspend_noirq,
178+
"failed_resume", suspend_stats.failed_resume,
179+
"failed_resume_noirq",
180+
suspend_stats.failed_resume_noirq);
181+
seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
182+
suspend_stats.failed_devs[last_dev]);
183+
for (i = 1; i < REC_FAILED_NUM; i++) {
184+
index = last_dev + REC_FAILED_NUM - i;
185+
index %= REC_FAILED_NUM;
186+
seq_printf(s, "\t\t\t%-s\n",
187+
suspend_stats.failed_devs[index]);
188+
}
189+
seq_printf(s, " last_failed_errno:\t%-d\n",
190+
suspend_stats.errno[last_errno]);
191+
for (i = 1; i < REC_FAILED_NUM; i++) {
192+
index = last_errno + REC_FAILED_NUM - i;
193+
index %= REC_FAILED_NUM;
194+
seq_printf(s, "\t\t\t%-d\n",
195+
suspend_stats.errno[index]);
196+
}
197+
seq_printf(s, " last_failed_step:\t%-s\n",
198+
suspend_step_name(
199+
suspend_stats.failed_steps[last_step]));
200+
for (i = 1; i < REC_FAILED_NUM; i++) {
201+
index = last_step + REC_FAILED_NUM - i;
202+
index %= REC_FAILED_NUM;
203+
seq_printf(s, "\t\t\t%-s\n",
204+
suspend_step_name(
205+
suspend_stats.failed_steps[index]));
206+
}
207+
208+
return 0;
209+
}
210+
211+
static int suspend_stats_open(struct inode *inode, struct file *file)
212+
{
213+
return single_open(file, suspend_stats_show, NULL);
214+
}
215+
216+
static const struct file_operations suspend_stats_operations = {
217+
.open = suspend_stats_open,
218+
.read = seq_read,
219+
.llseek = seq_lseek,
220+
.release = single_release,
221+
};
222+
223+
static int __init pm_debugfs_init(void)
224+
{
225+
debugfs_create_file("suspend_stats", S_IFREG | S_IRUGO,
226+
NULL, NULL, &suspend_stats_operations);
227+
return 0;
228+
}
229+
230+
late_initcall(pm_debugfs_init);
231+
#endif /* CONFIG_DEBUG_FS */
232+
136233
struct kobject *power_kobj;
137234

138235
/**
@@ -194,6 +291,11 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
194291
}
195292
if (state < PM_SUSPEND_MAX && *s)
196293
error = enter_state(state);
294+
if (error) {
295+
suspend_stats.fail++;
296+
dpm_save_failed_errno(error);
297+
} else
298+
suspend_stats.success++;
197299
#endif
198300

199301
Exit:

‎kernel/power/suspend.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ static int suspend_prepare(void)
104104
goto Finish;
105105

106106
error = suspend_freeze_processes();
107-
if (!error)
107+
if (error) {
108+
suspend_stats.failed_freeze++;
109+
dpm_save_failed_step(SUSPEND_FREEZE);
110+
} else
108111
return 0;
109112

110113
suspend_thaw_processes();
@@ -315,8 +318,16 @@ int enter_state(suspend_state_t state)
315318
*/
316319
int pm_suspend(suspend_state_t state)
317320
{
318-
if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX)
319-
return enter_state(state);
321+
int ret;
322+
if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX) {
323+
ret = enter_state(state);
324+
if (ret) {
325+
suspend_stats.fail++;
326+
dpm_save_failed_errno(ret);
327+
} else
328+
suspend_stats.success++;
329+
return ret;
330+
}
320331
return -EINVAL;
321332
}
322333
EXPORT_SYMBOL(pm_suspend);

0 commit comments

Comments
 (0)