diff mbox series

[v2] PM: sleep: Expose last succeeded resumed timestamp in sysfs

Message ID 169845668624.1319505.1097714089024984847.stgit@mhiramat.roam.corp.google.com
State Superseded
Headers show
Series [v2] PM: sleep: Expose last succeeded resumed timestamp in sysfs | expand

Commit Message

Masami Hiramatsu (Google) Oct. 28, 2023, 1:31 a.m. UTC
From: Masami Hiramatsu <mhiramat@kernel.org>

Expose last succeeded resumed timestamp as last_success_resume_time
attribute of suspend_stats in sysfs. This timestamp is recorded in
CLOCK_MONOTONIC. So user can find the actual resumed time and
measure the elapsed time from the time when the kernel finished
the resume to the user-space action (e.g. display the UI).

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 Changes in v2:
  - Use %llu instead of %lu for printing u64 value.
  - Remove unneeded indent spaces from the last_success_resume_time
    line in the debugfs suspend_stat file.
---
 Documentation/ABI/testing/sysfs-power |   10 ++++++++++
 include/linux/suspend.h               |    2 ++
 kernel/power/main.c                   |   14 ++++++++++++++
 kernel/power/suspend.c                |    1 +
 4 files changed, 27 insertions(+)

Comments

kernel test robot Oct. 28, 2023, 11:26 a.m. UTC | #1
Hi Masami,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.6-rc7 next-20231027]
[cannot apply to pavel-leds/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/PM-sleep-Expose-last-succeeded-resumed-timestamp-in-sysfs/20231028-093251
base:   linus/master
patch link:    https://lore.kernel.org/r/169845668624.1319505.1097714089024984847.stgit%40mhiramat.roam.corp.google.com
patch subject: [PATCH v2] PM: sleep: Expose last succeeded resumed timestamp in sysfs
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20231028/202310281942.ZwkSMsVB-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231028/202310281942.ZwkSMsVB-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310281942.ZwkSMsVB-lkp@intel.com/

All warnings (new ones prefixed by >>):

   kernel/power/main.c: In function 'last_success_resume_time_show':
>> kernel/power/main.c:427:38: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'long int' [-Wformat=]
     427 |         return sprintf(buf, "%llu.%llu\n",
         |                                   ~~~^
         |                                      |
         |                                      long long unsigned int
         |                                   %lu
     428 |                        suspend_stats.last_success_resume_time.tv_sec,
     429 |                        suspend_stats.last_success_resume_time.tv_nsec);
         |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                                              |
         |                                                              long int
   kernel/power/main.c: In function 'suspend_stats_show':
   kernel/power/main.c:528:62: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'long int' [-Wformat=]
     528 |         seq_printf(s,   "last_success_resume_time:\t%-llu.%llu\n",
         |                                                           ~~~^
         |                                                              |
         |                                                              long long unsigned int
         |                                                           %lu
     529 |                    suspend_stats.last_success_resume_time.tv_sec,
     530 |                    suspend_stats.last_success_resume_time.tv_nsec);
         |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                                          |
         |                                                          long int


vim +427 kernel/power/main.c

   423	
   424	static ssize_t last_success_resume_time_show(struct kobject *kobj,
   425			struct kobj_attribute *attr, char *buf)
   426	{
 > 427		return sprintf(buf, "%llu.%llu\n",
   428			       suspend_stats.last_success_resume_time.tv_sec,
   429			       suspend_stats.last_success_resume_time.tv_nsec);
   430	}
   431	static struct kobj_attribute last_success_resume_time =
   432				__ATTR_RO(last_success_resume_time);
   433
Masami Hiramatsu (Google) Oct. 28, 2023, 12:37 p.m. UTC | #2
On Sat, 28 Oct 2023 19:26:10 +0800
kernel test robot <lkp@intel.com> wrote:

> Hi Masami,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on linus/master]
> [also build test WARNING on v6.6-rc7 next-20231027]
> [cannot apply to pavel-leds/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/PM-sleep-Expose-last-succeeded-resumed-timestamp-in-sysfs/20231028-093251
> base:   linus/master
> patch link:    https://lore.kernel.org/r/169845668624.1319505.1097714089024984847.stgit%40mhiramat.roam.corp.google.com
> patch subject: [PATCH v2] PM: sleep: Expose last succeeded resumed timestamp in sysfs
> config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20231028/202310281942.ZwkSMsVB-lkp@intel.com/config)
> compiler: mips-linux-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231028/202310281942.ZwkSMsVB-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202310281942.ZwkSMsVB-lkp@intel.com/

Oops, I missed casting. Let me fix it.

Thanks,

> 
> All warnings (new ones prefixed by >>):
> 
>    kernel/power/main.c: In function 'last_success_resume_time_show':
> >> kernel/power/main.c:427:38: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'long int' [-Wformat=]
>      427 |         return sprintf(buf, "%llu.%llu\n",
>          |                                   ~~~^
>          |                                      |
>          |                                      long long unsigned int
>          |                                   %lu
>      428 |                        suspend_stats.last_success_resume_time.tv_sec,
>      429 |                        suspend_stats.last_success_resume_time.tv_nsec);
>          |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          |                                                              |
>          |                                                              long int
>    kernel/power/main.c: In function 'suspend_stats_show':
>    kernel/power/main.c:528:62: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'long int' [-Wformat=]
>      528 |         seq_printf(s,   "last_success_resume_time:\t%-llu.%llu\n",
>          |                                                           ~~~^
>          |                                                              |
>          |                                                              long long unsigned int
>          |                                                           %lu
>      529 |                    suspend_stats.last_success_resume_time.tv_sec,
>      530 |                    suspend_stats.last_success_resume_time.tv_nsec);
>          |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          |                                                          |
>          |                                                          long int
> 
> 
> vim +427 kernel/power/main.c
> 
>    423	
>    424	static ssize_t last_success_resume_time_show(struct kobject *kobj,
>    425			struct kobj_attribute *attr, char *buf)
>    426	{
>  > 427		return sprintf(buf, "%llu.%llu\n",
>    428			       suspend_stats.last_success_resume_time.tv_sec,
>    429			       suspend_stats.last_success_resume_time.tv_nsec);
>    430	}
>    431	static struct kobj_attribute last_success_resume_time =
>    432				__ATTR_RO(last_success_resume_time);
>    433	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index a3942b1036e2..63659765dee1 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -442,6 +442,16 @@  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:		Oct 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 from suspend/hibernate.
+		This floating number is measured in seconds by monotonic
+		clock.
+
 What:		/sys/power/sync_on_suspend
 Date:		October 2019
 Contact:	Jonas Meurer <jonas@freesources.org>
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index ef503088942d..ddd789044960 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -8,6 +8,7 @@ 
 #include <linux/pm.h>
 #include <linux/mm.h>
 #include <linux/freezer.h>
+#include <linux/timekeeping.h>
 #include <asm/errno.h>
 
 #ifdef CONFIG_VT
@@ -71,6 +72,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];
 };
 
diff --git a/kernel/power/main.c b/kernel/power/main.c
index f6425ae3e8b0..5803f6f2a2c2 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -421,6 +421,16 @@  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",
+		       suspend_stats.last_success_resume_time.tv_sec,
+		       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,
@@ -438,6 +448,7 @@  static struct attribute *suspend_attrs[] = {
 	&last_hw_sleep.attr,
 	&total_hw_sleep.attr,
 	&max_hw_sleep.attr,
+	&last_success_resume_time.attr,
 	NULL,
 };
 
@@ -514,6 +525,9 @@  static int suspend_stats_show(struct seq_file *s, void *unused)
 			suspend_step_name(
 				suspend_stats.failed_steps[index]));
 	}
+	seq_printf(s,	"last_success_resume_time:\t%-llu.%llu\n",
+		   suspend_stats.last_success_resume_time.tv_sec,
+		   suspend_stats.last_success_resume_time.tv_nsec);
 
 	return 0;
 }
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index fa3bf161d13f..33334565d5a6 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -622,6 +622,7 @@  int pm_suspend(suspend_state_t state)
 		dpm_save_failed_errno(error);
 	} else {
 		suspend_stats.success++;
+		ktime_get_ts64(&suspend_stats.last_success_resume_time);
 	}
 	pr_info("suspend exit\n");
 	return error;