Skip to content

Commit 9ff544f

Browse files
committed
PM: sleep: stats: Define suspend_stats next to the code using it
It is not necessary to define struct suspend_stats in a header file and the suspend_stats variable in the core device system-wide PM code. They both can be defined in kernel/power/main.c, next to the sysfs and debugfs code accessing suspend_stats, which can be static. Modify the code in question in accordance with the above observation and replace the static inline functions manipulating suspend_stats with regular ones defined in kernel/power/main.c. While at it, move the enum suspend_stat_step to the end of suspend.h which is a more suitable place for it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 2231f78 commit 9ff544f

5 files changed

Lines changed: 81 additions & 76 deletions

File tree

drivers/base/power/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static LIST_HEAD(dpm_suspended_list);
6060
static LIST_HEAD(dpm_late_early_list);
6161
static LIST_HEAD(dpm_noirq_list);
6262

63-
struct suspend_stats suspend_stats;
6463
static DEFINE_MUTEX(dpm_list_mtx);
6564
static pm_message_t pm_transition;
6665

include/linux/suspend.h

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,62 +40,6 @@ typedef int __bitwise suspend_state_t;
4040
#define PM_SUSPEND_MIN PM_SUSPEND_TO_IDLE
4141
#define PM_SUSPEND_MAX ((__force suspend_state_t) 4)
4242

43-
enum suspend_stat_step {
44-
SUSPEND_WORKING = 0,
45-
SUSPEND_FREEZE,
46-
SUSPEND_PREPARE,
47-
SUSPEND_SUSPEND,
48-
SUSPEND_SUSPEND_LATE,
49-
SUSPEND_SUSPEND_NOIRQ,
50-
SUSPEND_RESUME_NOIRQ,
51-
SUSPEND_RESUME_EARLY,
52-
SUSPEND_RESUME
53-
};
54-
55-
#define SUSPEND_NR_STEPS SUSPEND_RESUME
56-
57-
struct suspend_stats {
58-
unsigned int step_failures[SUSPEND_NR_STEPS];
59-
unsigned int success;
60-
unsigned int fail;
61-
#define REC_FAILED_NUM 2
62-
int last_failed_dev;
63-
char failed_devs[REC_FAILED_NUM][40];
64-
int last_failed_errno;
65-
int errno[REC_FAILED_NUM];
66-
int last_failed_step;
67-
u64 last_hw_sleep;
68-
u64 total_hw_sleep;
69-
u64 max_hw_sleep;
70-
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
71-
};
72-
73-
extern struct suspend_stats suspend_stats;
74-
75-
static inline void dpm_save_failed_dev(const char *name)
76-
{
77-
strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
78-
name,
79-
sizeof(suspend_stats.failed_devs[0]));
80-
suspend_stats.last_failed_dev++;
81-
suspend_stats.last_failed_dev %= REC_FAILED_NUM;
82-
}
83-
84-
static inline void dpm_save_failed_errno(int err)
85-
{
86-
suspend_stats.errno[suspend_stats.last_failed_errno] = err;
87-
suspend_stats.last_failed_errno++;
88-
suspend_stats.last_failed_errno %= REC_FAILED_NUM;
89-
}
90-
91-
static inline void dpm_save_failed_step(enum suspend_stat_step step)
92-
{
93-
suspend_stats.step_failures[step-1]++;
94-
suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
95-
suspend_stats.last_failed_step++;
96-
suspend_stats.last_failed_step %= REC_FAILED_NUM;
97-
}
98-
9943
/**
10044
* struct platform_suspend_ops - Callbacks for managing platform dependent
10145
* system sleep states.
@@ -623,4 +567,19 @@ static inline void queue_up_suspend_work(void) {}
623567

624568
#endif /* !CONFIG_PM_AUTOSLEEP */
625569

570+
enum suspend_stat_step {
571+
SUSPEND_WORKING = 0,
572+
SUSPEND_FREEZE,
573+
SUSPEND_PREPARE,
574+
SUSPEND_SUSPEND,
575+
SUSPEND_SUSPEND_LATE,
576+
SUSPEND_SUSPEND_NOIRQ,
577+
SUSPEND_RESUME_NOIRQ,
578+
SUSPEND_RESUME_EARLY,
579+
SUSPEND_RESUME
580+
};
581+
582+
void dpm_save_failed_dev(const char *name);
583+
void dpm_save_failed_step(enum suspend_stat_step step);
584+
626585
#endif /* _LINUX_SUSPEND_H */

kernel/power/main.c

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,6 @@ int unregister_pm_notifier(struct notifier_block *nb)
9595
}
9696
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
9797

98-
void pm_report_hw_sleep_time(u64 t)
99-
{
100-
suspend_stats.last_hw_sleep = t;
101-
suspend_stats.total_hw_sleep += t;
102-
}
103-
EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
104-
105-
void pm_report_max_hw_sleep(u64 t)
106-
{
107-
suspend_stats.max_hw_sleep = t;
108-
}
109-
EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
110-
11198
int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
11299
{
113100
int ret;
@@ -319,6 +306,69 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
319306
power_attr(pm_test);
320307
#endif /* CONFIG_PM_SLEEP_DEBUG */
321308

309+
#define SUSPEND_NR_STEPS SUSPEND_RESUME
310+
#define REC_FAILED_NUM 2
311+
312+
struct suspend_stats {
313+
unsigned int step_failures[SUSPEND_NR_STEPS];
314+
unsigned int success;
315+
unsigned int fail;
316+
int last_failed_dev;
317+
char failed_devs[REC_FAILED_NUM][40];
318+
int last_failed_errno;
319+
int errno[REC_FAILED_NUM];
320+
int last_failed_step;
321+
u64 last_hw_sleep;
322+
u64 total_hw_sleep;
323+
u64 max_hw_sleep;
324+
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
325+
};
326+
327+
static struct suspend_stats suspend_stats;
328+
329+
void dpm_save_failed_dev(const char *name)
330+
{
331+
strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
332+
name, sizeof(suspend_stats.failed_devs[0]));
333+
suspend_stats.last_failed_dev++;
334+
suspend_stats.last_failed_dev %= REC_FAILED_NUM;
335+
}
336+
337+
void dpm_save_failed_step(enum suspend_stat_step step)
338+
{
339+
suspend_stats.step_failures[step-1]++;
340+
suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
341+
suspend_stats.last_failed_step++;
342+
suspend_stats.last_failed_step %= REC_FAILED_NUM;
343+
}
344+
345+
void dpm_save_errno(int err)
346+
{
347+
if (!err) {
348+
suspend_stats.success++;
349+
return;
350+
}
351+
352+
suspend_stats.fail++;
353+
354+
suspend_stats.errno[suspend_stats.last_failed_errno] = err;
355+
suspend_stats.last_failed_errno++;
356+
suspend_stats.last_failed_errno %= REC_FAILED_NUM;
357+
}
358+
359+
void pm_report_hw_sleep_time(u64 t)
360+
{
361+
suspend_stats.last_hw_sleep = t;
362+
suspend_stats.total_hw_sleep += t;
363+
}
364+
EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
365+
366+
void pm_report_max_hw_sleep(u64 t)
367+
{
368+
suspend_stats.max_hw_sleep = t;
369+
}
370+
EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
371+
322372
static const char * const suspend_step_names[] = {
323373
[SUSPEND_WORKING] = "",
324374
[SUSPEND_FREEZE] = "freeze",

kernel/power/power.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,5 @@ static inline void pm_sleep_enable_secondary_cpus(void)
327327
suspend_enable_secondary_cpus();
328328
cpuidle_resume();
329329
}
330+
331+
void dpm_save_errno(int err);

kernel/power/suspend.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,7 @@ int pm_suspend(suspend_state_t state)
616616

617617
pr_info("suspend entry (%s)\n", mem_sleep_labels[state]);
618618
error = enter_state(state);
619-
if (error) {
620-
suspend_stats.fail++;
621-
dpm_save_failed_errno(error);
622-
} else {
623-
suspend_stats.success++;
624-
}
619+
dpm_save_errno(error);
625620
pr_info("suspend exit\n");
626621
return error;
627622
}

0 commit comments

Comments
 (0)