From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC492C4167B for ; Mon, 30 Oct 2023 13:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231483AbjJ3Nh3 (ORCPT ); Mon, 30 Oct 2023 09:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjJ3Nh1 (ORCPT ); Mon, 30 Oct 2023 09:37:27 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E187AA2; Mon, 30 Oct 2023 06:37:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F53C433C8; Mon, 30 Oct 2023 13:37:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698673044; bh=xgrSUtzCIyimkvkqPcm5cQu355vBStn8Nf7zgaVsVaA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=K0ioALA5b54Lxhs760+Z08LF52iDAIOaAwaEFE8MqGokajFVuxUfpndwg0vmszEYe 4NTSLSs0s7EKha3L/NoNeJwrMcLJXKOWaM+NwlXXn42X3DU+A6PjaHrKFOO7Q8ZrGi EJfy0z2pgQT66oUG5rW7Xt+h6Kfih/WkhrUqT64oUlDTZ4H2qnT4crBoAGrG+N8ROh wmgUHoiLaqwogjyb1Z72qkHQJ7yF1WA49BZ0QNyWknfaf1Wj+7g456YdzMNLM41xCi U72ICET9pSXgOKHzasljgdNDFOt/Wof4iAvaKytjZAVl3+n1Tcn9pDXBQ2h9asjHsV Y8+g0ng+mdmlw== Date: Mon, 30 Oct 2023 22:37:20 +0900 From: Masami Hiramatsu (Google) To: "Masami Hiramatsu (Google)" Cc: "Rafael J . Wysocki" , Pavel Machek , Len Brown , Randy Dunlap , suleiman@google.com, briannorris@google.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH v4] PM: sleep: Expose last succeeded resumed timestamp in sysfs Message-Id: <20231030223720.30c95dbe73c2c8c6b455b5e4@kernel.org> In-Reply-To: <169865271630.102723.17346936890436522603.stgit@mhiramat.roam.corp.google.com> References: <169865271630.102723.17346936890436522603.stgit@mhiramat.roam.corp.google.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry, please ignore this v4, because I found this does not typo fix. I sent v4.1. in https://lore.kernel.org/all/169865961255.107850.9724026775256278587.stgit@mhiramat.roam.corp.google.com/ Thanks, On Mon, 30 Oct 2023 16:58:36 +0900 "Masami Hiramatsu (Google)" wrote: > From: Masami Hiramatsu > > Expose last succeeded resumed timestamp as last_success_resume_time > attribute of suspend_stats in sysfs. > > There are some printk()s for printing the similar resume timing to > dmesg, but those are recorded with local_clock(), and user can not > compare it with current time. We also have tracing events but it > requires CAP_SYS_ADMIN to use it. > > This suspend_stats attribute is easy to access and only expose the > timestamp 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) > --- > 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 | 10 ++++++++++ > include/linux/suspend.h | 2 ++ > kernel/power/main.c | 15 +++++++++++++++ > kernel/power/suspend.c | 1 + > 4 files changed, 28 insertions(+) > > 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 > +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 > 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 > #include > #include > +#include > #include > > #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..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; > -- Masami Hiramatsu (Google)