]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: sleep: stats: Define suspend_stats next to the code using it
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 29 Jan 2024 16:30:44 +0000 (17:30 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 5 Feb 2024 13:28:19 +0000 (14:28 +0100)
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>
drivers/base/power/main.c
include/linux/suspend.h
kernel/power/main.c
kernel/power/power.h
kernel/power/suspend.c

index 896450503d0d5615c49c802a98214a3bf10e0940..761b03b4edb1ec425892ce3d2ab36cbe1b063ef0 100644 (file)
@@ -60,7 +60,6 @@ static LIST_HEAD(dpm_suspended_list);
 static LIST_HEAD(dpm_late_early_list);
 static LIST_HEAD(dpm_noirq_list);
 
-struct suspend_stats suspend_stats;
 static DEFINE_MUTEX(dpm_list_mtx);
 static pm_message_t pm_transition;
 
index 216bae9895357ecebb61dc8ddbebeb6a52e30aef..da6ebca3ff774c8bf59353aac08fe17106682b6d 100644 (file)
@@ -40,62 +40,6 @@ typedef int __bitwise suspend_state_t;
 #define PM_SUSPEND_MIN         PM_SUSPEND_TO_IDLE
 #define PM_SUSPEND_MAX         ((__force suspend_state_t) 4)
 
-enum suspend_stat_step {
-       SUSPEND_WORKING = 0,
-       SUSPEND_FREEZE,
-       SUSPEND_PREPARE,
-       SUSPEND_SUSPEND,
-       SUSPEND_SUSPEND_LATE,
-       SUSPEND_SUSPEND_NOIRQ,
-       SUSPEND_RESUME_NOIRQ,
-       SUSPEND_RESUME_EARLY,
-       SUSPEND_RESUME
-};
-
-#define SUSPEND_NR_STEPS       SUSPEND_RESUME
-
-struct suspend_stats {
-       unsigned int step_failures[SUSPEND_NR_STEPS];
-       unsigned int success;
-       unsigned int fail;
-#define        REC_FAILED_NUM  2
-       int     last_failed_dev;
-       char    failed_devs[REC_FAILED_NUM][40];
-       int     last_failed_errno;
-       int     errno[REC_FAILED_NUM];
-       int     last_failed_step;
-       u64     last_hw_sleep;
-       u64     total_hw_sleep;
-       u64     max_hw_sleep;
-       enum suspend_stat_step  failed_steps[REC_FAILED_NUM];
-};
-
-extern struct suspend_stats suspend_stats;
-
-static inline void dpm_save_failed_dev(const char *name)
-{
-       strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
-               name,
-               sizeof(suspend_stats.failed_devs[0]));
-       suspend_stats.last_failed_dev++;
-       suspend_stats.last_failed_dev %= REC_FAILED_NUM;
-}
-
-static inline void dpm_save_failed_errno(int err)
-{
-       suspend_stats.errno[suspend_stats.last_failed_errno] = err;
-       suspend_stats.last_failed_errno++;
-       suspend_stats.last_failed_errno %= REC_FAILED_NUM;
-}
-
-static inline void dpm_save_failed_step(enum suspend_stat_step step)
-{
-       suspend_stats.step_failures[step-1]++;
-       suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
-       suspend_stats.last_failed_step++;
-       suspend_stats.last_failed_step %= REC_FAILED_NUM;
-}
-
 /**
  * struct platform_suspend_ops - Callbacks for managing platform dependent
  *     system sleep states.
@@ -623,4 +567,19 @@ static inline void queue_up_suspend_work(void) {}
 
 #endif /* !CONFIG_PM_AUTOSLEEP */
 
+enum suspend_stat_step {
+       SUSPEND_WORKING = 0,
+       SUSPEND_FREEZE,
+       SUSPEND_PREPARE,
+       SUSPEND_SUSPEND,
+       SUSPEND_SUSPEND_LATE,
+       SUSPEND_SUSPEND_NOIRQ,
+       SUSPEND_RESUME_NOIRQ,
+       SUSPEND_RESUME_EARLY,
+       SUSPEND_RESUME
+};
+
+void dpm_save_failed_dev(const char *name);
+void dpm_save_failed_step(enum suspend_stat_step step);
+
 #endif /* _LINUX_SUSPEND_H */
index d6b4a925828894cf2dec32261050a500594d62be..8c4bf5a548055c6b6abb7e37a46cd06fadc24c99 100644 (file)
@@ -95,19 +95,6 @@ int unregister_pm_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL_GPL(unregister_pm_notifier);
 
-void pm_report_hw_sleep_time(u64 t)
-{
-       suspend_stats.last_hw_sleep = t;
-       suspend_stats.total_hw_sleep += t;
-}
-EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
-
-void pm_report_max_hw_sleep(u64 t)
-{
-       suspend_stats.max_hw_sleep = t;
-}
-EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
-
 int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
 {
        int ret;
@@ -319,6 +306,69 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
 power_attr(pm_test);
 #endif /* CONFIG_PM_SLEEP_DEBUG */
 
+#define SUSPEND_NR_STEPS       SUSPEND_RESUME
+#define REC_FAILED_NUM         2
+
+struct suspend_stats {
+       unsigned int step_failures[SUSPEND_NR_STEPS];
+       unsigned int success;
+       unsigned int fail;
+       int last_failed_dev;
+       char failed_devs[REC_FAILED_NUM][40];
+       int last_failed_errno;
+       int errno[REC_FAILED_NUM];
+       int last_failed_step;
+       u64 last_hw_sleep;
+       u64 total_hw_sleep;
+       u64 max_hw_sleep;
+       enum suspend_stat_step failed_steps[REC_FAILED_NUM];
+};
+
+static struct suspend_stats suspend_stats;
+
+void dpm_save_failed_dev(const char *name)
+{
+       strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
+               name, sizeof(suspend_stats.failed_devs[0]));
+       suspend_stats.last_failed_dev++;
+       suspend_stats.last_failed_dev %= REC_FAILED_NUM;
+}
+
+void dpm_save_failed_step(enum suspend_stat_step step)
+{
+       suspend_stats.step_failures[step-1]++;
+       suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
+       suspend_stats.last_failed_step++;
+       suspend_stats.last_failed_step %= REC_FAILED_NUM;
+}
+
+void dpm_save_errno(int err)
+{
+       if (!err) {
+               suspend_stats.success++;
+               return;
+       }
+
+       suspend_stats.fail++;
+
+       suspend_stats.errno[suspend_stats.last_failed_errno] = err;
+       suspend_stats.last_failed_errno++;
+       suspend_stats.last_failed_errno %= REC_FAILED_NUM;
+}
+
+void pm_report_hw_sleep_time(u64 t)
+{
+       suspend_stats.last_hw_sleep = t;
+       suspend_stats.total_hw_sleep += t;
+}
+EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
+
+void pm_report_max_hw_sleep(u64 t)
+{
+       suspend_stats.max_hw_sleep = t;
+}
+EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
+
 static const char * const suspend_step_names[] = {
        [SUSPEND_WORKING] = "",
        [SUSPEND_FREEZE] = "freeze",
index 8499a39c62f4b002f2126ac4f3602227577e1305..4e03046b9c4d44864098408ced71f09316abb39d 100644 (file)
@@ -327,3 +327,5 @@ static inline void pm_sleep_enable_secondary_cpus(void)
        suspend_enable_secondary_cpus();
        cpuidle_resume();
 }
+
+void dpm_save_errno(int err);
index 07bde5bba49ea174bdcc3700d3d8bf9e8eea65da..742eb26618ccb1b612859c26423c0ca9361c8b07 100644 (file)
@@ -616,12 +616,7 @@ int pm_suspend(suspend_state_t state)
 
        pr_info("suspend entry (%s)\n", mem_sleep_labels[state]);
        error = enter_state(state);
-       if (error) {
-               suspend_stats.fail++;
-               dpm_save_failed_errno(error);
-       } else {
-               suspend_stats.success++;
-       }
+       dpm_save_errno(error);
        pr_info("suspend exit\n");
        return error;
 }