@@ -442,6 +442,17 @@ Description:
'total_hw_sleep' and 'last_hw_sleep' may not be accurate.
This number is measured in microseconds.
+What: /sys/power/suspend_stats/last_success_resume_time
+Date: Dec 2023
+Contact: Masami Hiramatsu <mhiramat@kernel.org>
+Description:
+ The /sys/power/suspend_stats/last_success_resume_time file
+ contains the timestamp of when the kernel successfully
+ resumed drivers/subsystems from suspend/hibernate. This is
+ just before thawing the user processes.
+ This floating point number is measured in seconds by monotonic
+ clock.
+
What: /sys/power/sync_on_suspend
Date: October 2019
Contact: Jonas Meurer <jonas@freesources.org>
@@ -16,6 +16,7 @@
#include <linux/seq_file.h>
#include <linux/suspend.h>
#include <linux/syscalls.h>
+#include <linux/timekeeping.h>
#include <linux/pm_runtime.h>
#include "power.h"
@@ -321,6 +322,7 @@ struct suspend_stats {
u64 last_hw_sleep;
u64 total_hw_sleep;
u64 max_hw_sleep;
+ struct timespec64 last_success_resume_time;
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
};
@@ -361,6 +363,17 @@ void dpm_save_errno(int err)
suspend_stats.last_failed_errno %= REC_FAILED_NUM;
}
+void dpm_save_success_time(int err)
+{
+ /*
+ * Record last succeeded resume timestamp just before thawing processes.
+ * This is for helping users to measure user-space resume performance
+ * for improving their programs or finding regressions.
+ */
+ if (!err)
+ ktime_get_ts64(&suspend_stats.last_success_resume_time);
+}
+
void pm_report_hw_sleep_time(u64 t)
{
suspend_stats.last_hw_sleep = t;
@@ -460,6 +473,17 @@ static ssize_t last_failed_step_show(struct kobject *kobj,
}
static struct kobj_attribute last_failed_step = __ATTR_RO(last_failed_step);
+static ssize_t last_success_resume_time_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%llu.%llu\n",
+ (unsigned long long)suspend_stats.last_success_resume_time.tv_sec,
+ (unsigned long long)suspend_stats.last_success_resume_time.tv_nsec);
+}
+
+static struct kobj_attribute last_success_resume_time =
+ __ATTR_RO(last_success_resume_time);
+
static struct attribute *suspend_attrs[] = {
&success.attr,
&fail.attr,
@@ -477,6 +501,7 @@ static struct attribute *suspend_attrs[] = {
&last_hw_sleep.attr,
&total_hw_sleep.attr,
&max_hw_sleep.attr,
+ &last_success_resume_time.attr,
NULL,
};
@@ -542,6 +567,9 @@ static int suspend_stats_show(struct seq_file *s, void *unused)
seq_printf(s, "\t\t\t%-s\n",
suspend_step_names[suspend_stats.failed_steps[index]]);
}
+ seq_printf(s, "last_success_resume_time:\t%-llu.%llu\n",
+ (unsigned long long)suspend_stats.last_success_resume_time.tv_sec,
+ (unsigned long long)suspend_stats.last_success_resume_time.tv_nsec);
return 0;
}
@@ -348,3 +348,4 @@ static inline void pm_sleep_enable_secondary_cpus(void)
}
void dpm_save_errno(int err);
+void dpm_save_success_time(int err);
@@ -601,6 +601,7 @@ static int enter_state(suspend_state_t state)
Finish:
events_check_enabled = false;
pm_pr_dbg("Finishing wakeup.\n");
+ dpm_save_success_time(error);
suspend_finish();
Unlock:
mutex_unlock(&system_transition_mutex);