From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>,
Randy Dunlap <rdunlap@infradead.org>,
suleiman@google.com, briannorris@google.com,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v7] PM: sleep: Expose last succeeded resumed timestamp in sysfs
Date: Wed, 17 Jan 2024 09:07:06 +0900 [thread overview]
Message-ID: <20240117090706.3522d23763fab9dcea21aee1@kernel.org> (raw)
In-Reply-To: <170359669607.1864392.5078004271237566637.stgit@mhiramat.roam.corp.google.com>
Gently ping,
I would like to know this is enough or I should add more info/update.
Thank you,
On Tue, 26 Dec 2023 22:18:16 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu <mhiramat@kernel.org>
>
> Expose last succeeded resumed timestamp as last_success_resume_time
> attribute of suspend_stats in sysfs so that user can use this time
> stamp as a reference point of resuming user space.
>
> On some system like the ChromeOS, the system suspend and resume are
> controlled by a power management process. The user-space tasks will be
> noticed the suspend and the resume signal from it.
> To improve the suspend/resume performance and/or to find regressions,
> we would like to know how long the resume processes are taken in kernel
> and in user-space.
> For this purpose, expose the accarate time when the kernel is finished
> to resume so that we can distinguish the duration of kernel resume and
> user space resume.
>
> This suspend_stats attribute is easy to access and only expose the
> timestamp in CLOCK_MONOTONIC. User can find the accarate time when the
> kernel finished to resume its drivers/subsystems and start thawing, and
> measure the elapsed time from the time when the kernel finished the
> resume to a user-space action (e.g. displaying the UI).
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> Changes in v7:
> - Update patch description.
> - Update sysfs documentation to say the exact timing.
> - Update the comment.
> Changes in v6:
> - Fix to record resume time before thawing user processes.
> Changes in v5:
> - Just updated for v6.7-rc3.
> Changes in v4.1:
> - Fix document typo (again).
> Changes in v4:
> - Update description to add why.
> - Fix document typo.
> Changes in v3:
> - Add (unsigned long long) casting for %llu.
> - Add a line after last_success_resume_time_show().
> 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 | 11 +++++++++++
> include/linux/suspend.h | 2 ++
> kernel/power/main.c | 15 +++++++++++++++
> kernel/power/suspend.c | 9 +++++++++
> 4 files changed, 37 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
> index a3942b1036e2..ee567e7e9d4a 100644
> --- a/Documentation/ABI/testing/sysfs-power
> +++ b/Documentation/ABI/testing/sysfs-power
> @@ -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>
> 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..2ab23fd3daac 100644
> --- a/kernel/power/main.c
> +++ b/kernel/power/main.c
> @@ -421,6 +421,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,
> @@ -438,6 +449,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 +526,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",
> + (unsigned long long)suspend_stats.last_success_resume_time.tv_sec,
> + (unsigned long long)suspend_stats.last_success_resume_time.tv_nsec);
>
> return 0;
> }
> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
> index fa3bf161d13f..2d0f46b4d0cf 100644
> --- a/kernel/power/suspend.c
> +++ b/kernel/power/suspend.c
> @@ -595,6 +595,15 @@ static int enter_state(suspend_state_t state)
> Finish:
> events_check_enabled = false;
> pm_pr_dbg("Finishing wakeup.\n");
> +
> + /*
> + * 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 (!error)
> + ktime_get_ts64(&suspend_stats.last_success_resume_time);
> +
> suspend_finish();
> Unlock:
> mutex_unlock(&system_transition_mutex);
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-01-17 0:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-26 13:18 [PATCH v7 0/1] PM: sleep: Expose last succeeded resumed timestamp in sysfs Masami Hiramatsu (Google)
2023-12-26 13:18 ` [PATCH v7] " Masami Hiramatsu (Google)
2024-01-17 0:07 ` Masami Hiramatsu [this message]
2024-01-19 21:07 ` Rafael J. Wysocki
2024-01-23 2:08 ` Brian Norris
2024-01-25 0:43 ` Masami Hiramatsu
2024-01-25 20:19 ` Rafael J. Wysocki
2024-01-30 14:51 ` Masami Hiramatsu
2024-01-09 15:04 ` [PATCH v7 0/1] " Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240117090706.3522d23763fab9dcea21aee1@kernel.org \
--to=mhiramat@kernel.org \
--cc=briannorris@google.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=suleiman@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox