linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Limonciello, Mario" <mario.limonciello@amd.com>
To: Raul Rangel <rrangel@chromium.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Sven van Ashbrook <svenva@chromium.org>,
	linux-pm@vger.kernel.org, platform-driver-x86@vger.kernel.org,
	Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>,
	John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	Rajneesh Bhardwaj <irenic.rajneesh@gmail.com>,
	S-k Shyam-sundar <Shyam-sundar.S-k@amd.com>,
	Rajat Jain <rajatja@google.com>,
	David E Box <david.e.box@intel.com>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC v2 1/3] PM: Add a sysfs files to represent sleep duration
Date: Tue, 15 Nov 2022 11:26:55 -0600	[thread overview]
Message-ID: <bb86ba1f-c0cd-ae71-520c-b94d4d71b261@amd.com> (raw)
In-Reply-To: <CAHQZ30BCXtyJ9qqHHX5eztXbgA_A8yH48+AQVMCB64CXjqE+hQ@mail.gmail.com>

On 11/15/2022 11:20, Raul Rangel wrote:
> 
> 
> On Tue, Nov 15, 2022 at 9:35 AM Rafael J. Wysocki <rafael@kernel.org 
> <mailto:rafael@kernel.org>> wrote:
> 
>     On Tue, Nov 15, 2022 at 4:17 PM Limonciello, Mario
>     <mario.limonciello@amd.com <mailto:mario.limonciello@amd.com>> wrote:
>      >
>      > On 11/15/2022 08:45, Rafael J. Wysocki wrote:
>      > > On Thu, Nov 10, 2022 at 7:49 AM Mario Limonciello
>      > > <mario.limonciello@amd.com <mailto:mario.limonciello@amd.com>>
>     wrote:
>      > >>
>      > >> Both AMD and Intel SoCs have a concept of reporting whether
>     the hardware
>      > >> reached a hardware sleep state over s2idle as well as how much
>      > >> time was spent in such a state.
>      > >>
>      > >> This information is valuable to both chip designers and system
>     designers
>      > >> as it helps to identify when there are problems with power
>     consumption
>      > >> over an s2idle cycle.
>      > >>
>      > >> To make the information discoverable, create a new sysfs file
>     and a symbol
>      > >> that drivers from supported manufacturers can use to advertise
>     this
>      > >> information. This file will only be exported when the system
>     supports low
>      > >> power idle in the ACPI table.
>      > >>
>      > >> In order to effectively use this information you will ideally
>     want to
>      > >> compare against the total duration of sleep, so export a
>     second sysfs file
>      > >> that will show total time. This file will be exported on all
>     systems and
>      > >> used both for s2idle and s3.
>      > >
>      > > Well, my first question would be how this is related to
>      > >
>      > > /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us
>      > >
>      >
>      > This has a dependency on the platform firmware offering an ACPI LPIT
>      > table.  I don't know how common that is.
> 
>     Required for running Windows with Modern Standby AFAICS.
> 
>      > As this series started from the needs on ChromeOS I would ask is
>     that typically populated by coreboot?
> 
>     It should be, but I'd need to ask for confirmation.
> 
> 
> It looks like Intel platforms have support for the LPIT table: 
> https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/coreboot/src/soc/intel/common/block/acpi/lpit.c?q=f:LPIT%20f:coreboot&ss=chromiumos <https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsource.chromium.org%2Fchromiumos%2Fchromiumos%2Fcodesearch%2F%2B%2Fmain%3Asrc%2Fthird_party%2Fcoreboot%2Fsrc%2Fsoc%2Fintel%2Fcommon%2Fblock%2Facpi%2Flpit.c%3Fq%3Df%3ALPIT%2520f%3Acoreboot%26ss%3Dchromiumos&data=05%7C01%7Cmario.limonciello%40amd.com%7C701602845ad14f37abbb08dac72db514%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638041296400209575%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9ig2jlDevXMjzmTUf42WS5Ey3rLd2lDUXjncz3mbyMI%3D&reserved=0>
> 
> For AMD, we had some patches to add _LPIL 
> https://review.coreboot.org/c/coreboot/+/52381/1 
> <https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Freview.coreboot.org%2Fc%2Fcoreboot%2F%2B%2F52381%2F1&data=05%7C01%7Cmario.limonciello%40amd.com%7C701602845ad14f37abbb08dac72db514%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638041296400209575%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KV6ASbdfNOex%2FZtJYcdItZU1gdjCIXEcP1ExiY0pkf8%3D&reserved=0>
> They never got merged though. We could add an LPIT table to coreboot for 
> AMD platforms if necessary.

_LPI I don't think makes a lot of sense on X86 today, which is why this 
was sent up:
eb087f305919e ("ACPI: processor idle: Check for architectural support 
for LPI")

As for LPIT - I've never seen LPIT on AMD UEFI systems either.  I guess 
it's an Intel specific table?

> 
>      > I would hope it's the same number that is populated in that file on
>      > supported systems though.
> 
>     Well, which is exactly where I'm going.
> 
>     Since there is one sysfs file for exposing this value already and it
>     is used (for example, by sleepgraph), perhaps the way to go would be
>     to extend this interface to systems that don't have LPIT instead of
>     introducing a new one possibly exposing the same value?
> 

Ah; so since Raul confirmed coreboot on Chrome exports that maybe we 
just need to add another way to populate that sysfs file for systems 
without LPIT (IE AMD).  I think that's a very good idea; thanks.

I think we still probably want to have a way to get the total suspend 
time out programmatically though to compare to.  So perhaps the other 
sysfs file I had in the RFC v2 makes sense still.

>      > > and
>      > >
>      > > /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
>      > >
>      >
>      > No relation to this one for what's in the series.
>      >
>      > >> Suggested-by: David E Box <david.e.box@intel.com
>     <mailto:david.e.box@intel.com>>
>      > >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com
>     <mailto:mario.limonciello@amd.com>>
>      > >> ---
>      > >>   Documentation/ABI/testing/sysfs-power | 17 +++++++++++
>      > >>   include/linux/suspend.h               |  4 +++
>      > >>   kernel/power/main.c                   | 42
>     +++++++++++++++++++++++++++
>      > >>   kernel/power/suspend.c                |  2 ++
>      > >>   kernel/time/timekeeping.c             |  2 ++
>      > >>   5 files changed, 67 insertions(+)
>      > >>
>      > >> diff --git a/Documentation/ABI/testing/sysfs-power
>     b/Documentation/ABI/testing/sysfs-power
>      > >> index f99d433ff311..5b47cbb4dc9e 100644
>      > >> --- a/Documentation/ABI/testing/sysfs-power
>      > >> +++ b/Documentation/ABI/testing/sysfs-power
>      > >> @@ -413,6 +413,23 @@ Description:
>      > >>                  The /sys/power/suspend_stats/last_failed_step
>     file contains
>      > >>                  the last failed step in the suspend/resume path.
>      > >>
>      > >> +What:          /sys/power/suspend_stats/last_hw_state_residency
>      > >> +Date:          December 2022
>      > >> +Contact:       Mario Limonciello <mario.limonciello@amd.com
>     <mailto:mario.limonciello@amd.com>>
>      > >> +Description:
>      > >> +               The
>     /sys/power/suspend_stats/last_hw_state_residency file contains
>      > >> +               the amount of time spent in a hardware sleep
>     state.
>      > >> +               This attribute is only available if the system
>     supports
>      > >> +               low power idle.  This is measured in microseconds.
>      > >> +
>      > >> +What:          /sys/power/suspend_stats/last_suspend_total
>      > >> +Date:          December 2022
>      > >> +Contact:       Mario Limonciello <mario.limonciello@amd.com
>     <mailto:mario.limonciello@amd.com>>
>      > >> +Description:
>      > >> +               The
>     /sys/power/suspend_stats/last_suspend_total file contains
>      > >> +               the total duration of the sleep cycle.
>      > >> +               This is measured in microseconds.
>      > >> +
>      > >>   What:          /sys/power/sync_on_suspend
>      > >>   Date:          October 2019
>      > >>   Contact:       Jonas Meurer <jonas@freesources.org
>     <mailto:jonas@freesources.org>>
>      > >> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
>      > >> index cfe19a028918..af343c3f8198 100644
>      > >> --- a/include/linux/suspend.h
>      > >> +++ b/include/linux/suspend.h
>      > >> @@ -68,6 +68,8 @@ struct suspend_stats {
>      > >>          int     last_failed_errno;
>      > >>          int     errno[REC_FAILED_NUM];
>      > >>          int     last_failed_step;
>      > >> +       u64     last_hw_state_residency;
>      > >> +       u64     last_suspend_total;
>      > >>          enum suspend_stat_step  failed_steps[REC_FAILED_NUM];
>      > >>   };
>      > >>
>      > >> @@ -489,6 +491,8 @@ void restore_processor_state(void);
>      > >>   extern int register_pm_notifier(struct notifier_block *nb);
>      > >>   extern int unregister_pm_notifier(struct notifier_block *nb);
>      > >>   extern void ksys_sync_helper(void);
>      > >> +extern void pm_set_hw_state_residency(u64 duration);
>      > >> +extern void pm_account_suspend_type(const struct timespec64 *t);
>      > >>
>      > >>   #define pm_notifier(fn, pri) {                         \
>      > >>          static struct notifier_block fn##_nb =                  \
>      > >> diff --git a/kernel/power/main.c b/kernel/power/main.c
>      > >> index 31ec4a9b9d70..11bd658583b0 100644
>      > >> --- a/kernel/power/main.c
>      > >> +++ b/kernel/power/main.c
>      > >> @@ -6,6 +6,7 @@
>      > >>    * Copyright (c) 2003 Open Source Development Lab
>      > >>    */
>      > >>
>      > >> +#include <linux/acpi.h>
>      > >>   #include <linux/export.h>
>      > >>   #include <linux/kobject.h>
>      > >>   #include <linux/string.h>
>      > >> @@ -54,6 +55,19 @@ void unlock_system_sleep(unsigned int flags)
>      > >>   }
>      > >>   EXPORT_SYMBOL_GPL(unlock_system_sleep);
>      > >>
>      > >> +void pm_set_hw_state_residency(u64 duration)
>      > >> +{
>      > >> +       suspend_stats.last_hw_state_residency = duration;
>      > >> +}
>      > >> +EXPORT_SYMBOL_GPL(pm_set_hw_state_residency);
>      > >> +
>      > >> +void pm_account_suspend_type(const struct timespec64 *t)
>      > >> +{
>      > >> +       suspend_stats.last_suspend_total += (s64)t->tv_sec *
>     USEC_PER_SEC +
>      > >> +                                                t->tv_nsec /
>     NSEC_PER_USEC;
>      > >> +}
>      > >> +EXPORT_SYMBOL_GPL(pm_account_suspend_type);
>      > >> +
>      > >>   void ksys_sync_helper(void)
>      > >>   {
>      > >>          ktime_t start;
>      > >> @@ -377,6 +391,20 @@ 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_hw_state_residency_show(struct kobject *kobj,
>      > >> +               struct kobj_attribute *attr, char *buf)
>      > >> +{
>      > >> +       return sprintf(buf, "%llu\n",
>     suspend_stats.last_hw_state_residency);
>      > >> +}
>      > >> +static struct kobj_attribute last_hw_state_residency =
>     __ATTR_RO(last_hw_state_residency);
>      > >> +
>      > >> +static ssize_t last_suspend_total_show(struct kobject *kobj,
>      > >> +               struct kobj_attribute *attr, char *buf)
>      > >> +{
>      > >> +       return sprintf(buf, "%llu\n",
>     suspend_stats.last_suspend_total);
>      > >> +}
>      > >> +static struct kobj_attribute last_suspend_total =
>     __ATTR_RO(last_suspend_total);
>      > >> +
>      > >>   static struct attribute *suspend_attrs[] = {
>      > >>          &success.attr,
>      > >>          &fail.attr,
>      > >> @@ -391,12 +419,26 @@ static struct attribute *suspend_attrs[] = {
>      > >>          &last_failed_dev.attr,
>      > >>          &last_failed_errno.attr,
>      > >>          &last_failed_step.attr,
>      > >> +       &last_hw_state_residency.attr,
>      > >> +       &last_suspend_total.attr,
>      > >>          NULL,
>      > >>   };
>      > >>
>      > >> +static umode_t suspend_attr_is_visible(struct kobject *kobj,
>     struct attribute *attr, int idx)
>      > >> +{
>      > >> +       if (attr != &last_hw_state_residency.attr)
>      > >> +               return 0444;
>      > >> +#ifdef CONFIG_ACPI
>      > >> +       if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)
>      > >> +               return 0444;
>      > >> +#endif
>      > >> +       return 0;
>      > >> +}
>      > >> +
>      > >>   static const struct attribute_group suspend_attr_group = {
>      > >>          .name = "suspend_stats",
>      > >>          .attrs = suspend_attrs,
>      > >> +       .is_visible = suspend_attr_is_visible,
>      > >>   };
>      > >>
>      > >>   #ifdef CONFIG_DEBUG_FS
>      > >> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
>      > >> index fa3bf161d13f..b6c4a3733212 100644
>      > >> --- a/kernel/power/suspend.c
>      > >> +++ b/kernel/power/suspend.c
>      > >> @@ -423,6 +423,8 @@ static int suspend_enter(suspend_state_t
>     state, bool *wakeup)
>      > >>          if (suspend_test(TEST_PLATFORM))
>      > >>                  goto Platform_wake;
>      > >>
>      > >> +       suspend_stats.last_suspend_total = 0;
>      > >> +
>      > >>          if (state == PM_SUSPEND_TO_IDLE) {
>      > >>                  s2idle_loop();
>      > >>                  goto Platform_wake;
>      > >> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
>      > >> index f72b9f1de178..e1b356787e53 100644
>      > >> --- a/kernel/time/timekeeping.c
>      > >> +++ b/kernel/time/timekeeping.c
>      > >> @@ -24,6 +24,7 @@
>      > >>   #include <linux/compiler.h>
>      > >>   #include <linux/audit.h>
>      > >>   #include <linux/random.h>
>      > >> +#include <linux/suspend.h>
>      > >>
>      > >>   #include "tick-internal.h"
>      > >>   #include "ntp_internal.h"
>      > >> @@ -1698,6 +1699,7 @@ static void
>     __timekeeping_inject_sleeptime(struct timekeeper *tk,
>      > >>          tk_set_wall_to_mono(tk,
>     timespec64_sub(tk->wall_to_monotonic, *delta));
>      > >>          tk_update_sleep_time(tk, timespec64_to_ktime(*delta));
>      > >>          tk_debug_account_sleep_time(delta);
>      > >> +       pm_account_suspend_type(delta);
>      > >>   }
>      > >>
>      > >>   #if defined(CONFIG_PM_SLEEP) &&
>     defined(CONFIG_RTC_HCTOSYS_DEVICE)
>      > >> --
>      > >> 2.34.1
>      > >>
>      >
> 


  parent reply	other threads:[~2022-11-15 17:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10  6:47 [RFC v2 0/3] Introduce infrastructure to report time in hardware sleep state Mario Limonciello
2022-11-10  6:47 ` [RFC v2 1/3] PM: Add a sysfs files to represent sleep duration Mario Limonciello
2022-11-13 23:53   ` Thomas Gleixner
2022-11-14 19:12     ` Limonciello, Mario
2022-11-15 10:32       ` Hans de Goede
2022-11-15 14:13         ` Limonciello, Mario
2022-11-17  2:40           ` Box, David E
2022-11-14  7:12   ` Greg KH
2022-11-15 14:45   ` Rafael J. Wysocki
2022-11-15 15:17     ` Limonciello, Mario
2022-11-15 16:35       ` Rafael J. Wysocki
     [not found]         ` <CAHQZ30BCXtyJ9qqHHX5eztXbgA_A8yH48+AQVMCB64CXjqE+hQ@mail.gmail.com>
2022-11-15 17:26           ` Limonciello, Mario [this message]
2022-11-15 17:52             ` Rafael J. Wysocki
2022-11-15 17:58               ` Limonciello, Mario
2022-11-15 19:08                 ` Rafael J. Wysocki
2022-11-10  6:47 ` [RFC v2 2/3] platform/x86/amd: pmc: Report duration of time in deepest hw state Mario Limonciello
2022-11-10  6:47 ` [RFC v2 3/3] platform/x86/intel/pmc: core: Report duration of time in HW sleep state Mario Limonciello
2022-11-13 23:57   ` Thomas Gleixner
2022-11-14 19:06     ` Limonciello, Mario

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=bb86ba1f-c0cd-ae71-520c-b94d4d71b261@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=david.e.box@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=irenic.rajneesh@gmail.com \
    --cc=jstultz@google.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rajatja@google.com \
    --cc=rrangel@chromium.org \
    --cc=sboyd@kernel.org \
    --cc=svenva@chromium.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).