mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-28 13:22:57 +00:00
PM: Add sysfs files to represent time spent in hardware sleep state
Userspace can't easily discover how much of a sleep cycle was spent in a hardware sleep state without using kernel tracing and vendor specific sysfs or debugfs files. To make this information more discoverable, introduce 3 new sysfs files: 1) The time spent in a hw sleep state for last cycle. 2) The time spent in a hw sleep state since the kernel booted 3) The maximum time that the hardware can report for a sleep cycle. All of these files will be present only if the system supports s2idle. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
6a8f57ae2e
commit
b52124a78a
3 changed files with 84 additions and 12 deletions
|
@ -413,6 +413,35 @@ Description:
|
||||||
The /sys/power/suspend_stats/last_failed_step file contains
|
The /sys/power/suspend_stats/last_failed_step file contains
|
||||||
the last failed step in the suspend/resume path.
|
the last failed step in the suspend/resume path.
|
||||||
|
|
||||||
|
What: /sys/power/suspend_stats/last_hw_sleep
|
||||||
|
Date: June 2023
|
||||||
|
Contact: Mario Limonciello <mario.limonciello@amd.com>
|
||||||
|
Description:
|
||||||
|
The /sys/power/suspend_stats/last_hw_sleep file
|
||||||
|
contains the duration of time spent in a hardware sleep
|
||||||
|
state in the most recent system suspend-resume cycle.
|
||||||
|
This number is measured in microseconds.
|
||||||
|
|
||||||
|
What: /sys/power/suspend_stats/total_hw_sleep
|
||||||
|
Date: June 2023
|
||||||
|
Contact: Mario Limonciello <mario.limonciello@amd.com>
|
||||||
|
Description:
|
||||||
|
The /sys/power/suspend_stats/total_hw_sleep file
|
||||||
|
contains the aggregate of time spent in a hardware sleep
|
||||||
|
state since the kernel was booted. This number
|
||||||
|
is measured in microseconds.
|
||||||
|
|
||||||
|
What: /sys/power/suspend_stats/max_hw_sleep
|
||||||
|
Date: June 2023
|
||||||
|
Contact: Mario Limonciello <mario.limonciello@amd.com>
|
||||||
|
Description:
|
||||||
|
The /sys/power/suspend_stats/max_hw_sleep file
|
||||||
|
contains the maximum amount of time that the hardware can
|
||||||
|
report for time spent in a hardware sleep state. When sleep
|
||||||
|
cycles are longer than this time, the values for
|
||||||
|
'total_hw_sleep' and 'last_hw_sleep' may not be accurate.
|
||||||
|
This number is measured in microseconds.
|
||||||
|
|
||||||
What: /sys/power/sync_on_suspend
|
What: /sys/power/sync_on_suspend
|
||||||
Date: October 2019
|
Date: October 2019
|
||||||
Contact: Jonas Meurer <jonas@freesources.org>
|
Contact: Jonas Meurer <jonas@freesources.org>
|
||||||
|
|
|
@ -68,6 +68,9 @@ struct suspend_stats {
|
||||||
int last_failed_errno;
|
int last_failed_errno;
|
||||||
int errno[REC_FAILED_NUM];
|
int errno[REC_FAILED_NUM];
|
||||||
int last_failed_step;
|
int last_failed_step;
|
||||||
|
u64 last_hw_sleep;
|
||||||
|
u64 total_hw_sleep;
|
||||||
|
u64 max_hw_sleep;
|
||||||
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
|
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -489,6 +492,8 @@ void restore_processor_state(void);
|
||||||
extern int register_pm_notifier(struct notifier_block *nb);
|
extern int register_pm_notifier(struct notifier_block *nb);
|
||||||
extern int unregister_pm_notifier(struct notifier_block *nb);
|
extern int unregister_pm_notifier(struct notifier_block *nb);
|
||||||
extern void ksys_sync_helper(void);
|
extern void ksys_sync_helper(void);
|
||||||
|
extern void pm_report_hw_sleep_time(u64 t);
|
||||||
|
extern void pm_report_max_hw_sleep(u64 t);
|
||||||
|
|
||||||
#define pm_notifier(fn, pri) { \
|
#define pm_notifier(fn, pri) { \
|
||||||
static struct notifier_block fn##_nb = \
|
static struct notifier_block fn##_nb = \
|
||||||
|
@ -526,6 +531,9 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void pm_report_hw_sleep_time(u64 t) {};
|
||||||
|
static inline void pm_report_max_hw_sleep(u64 t) {};
|
||||||
|
|
||||||
static inline void ksys_sync_helper(void) {}
|
static inline void ksys_sync_helper(void) {}
|
||||||
|
|
||||||
#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
|
#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* Copyright (c) 2003 Open Source Development Lab
|
* Copyright (c) 2003 Open Source Development Lab
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/acpi.h>
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
#include <linux/kobject.h>
|
#include <linux/kobject.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
|
@ -83,6 +84,19 @@ int unregister_pm_notifier(struct notifier_block *nb)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
|
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
|
||||||
|
|
||||||
|
void pm_report_hw_sleep_time(u64 t)
|
||||||
|
{
|
||||||
|
suspend_stats.last_hw_sleep = t;
|
||||||
|
suspend_stats.total_hw_sleep += t;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
|
||||||
|
|
||||||
|
void pm_report_max_hw_sleep(u64 t)
|
||||||
|
{
|
||||||
|
suspend_stats.max_hw_sleep = t;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(pm_report_max_hw_sleep);
|
||||||
|
|
||||||
int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
|
int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -314,24 +328,27 @@ static char *suspend_step_name(enum suspend_stat_step step)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define suspend_attr(_name) \
|
#define suspend_attr(_name, format_str) \
|
||||||
static ssize_t _name##_show(struct kobject *kobj, \
|
static ssize_t _name##_show(struct kobject *kobj, \
|
||||||
struct kobj_attribute *attr, char *buf) \
|
struct kobj_attribute *attr, char *buf) \
|
||||||
{ \
|
{ \
|
||||||
return sprintf(buf, "%d\n", suspend_stats._name); \
|
return sprintf(buf, format_str, suspend_stats._name); \
|
||||||
} \
|
} \
|
||||||
static struct kobj_attribute _name = __ATTR_RO(_name)
|
static struct kobj_attribute _name = __ATTR_RO(_name)
|
||||||
|
|
||||||
suspend_attr(success);
|
suspend_attr(success, "%d\n");
|
||||||
suspend_attr(fail);
|
suspend_attr(fail, "%d\n");
|
||||||
suspend_attr(failed_freeze);
|
suspend_attr(failed_freeze, "%d\n");
|
||||||
suspend_attr(failed_prepare);
|
suspend_attr(failed_prepare, "%d\n");
|
||||||
suspend_attr(failed_suspend);
|
suspend_attr(failed_suspend, "%d\n");
|
||||||
suspend_attr(failed_suspend_late);
|
suspend_attr(failed_suspend_late, "%d\n");
|
||||||
suspend_attr(failed_suspend_noirq);
|
suspend_attr(failed_suspend_noirq, "%d\n");
|
||||||
suspend_attr(failed_resume);
|
suspend_attr(failed_resume, "%d\n");
|
||||||
suspend_attr(failed_resume_early);
|
suspend_attr(failed_resume_early, "%d\n");
|
||||||
suspend_attr(failed_resume_noirq);
|
suspend_attr(failed_resume_noirq, "%d\n");
|
||||||
|
suspend_attr(last_hw_sleep, "%llu\n");
|
||||||
|
suspend_attr(total_hw_sleep, "%llu\n");
|
||||||
|
suspend_attr(max_hw_sleep, "%llu\n");
|
||||||
|
|
||||||
static ssize_t last_failed_dev_show(struct kobject *kobj,
|
static ssize_t last_failed_dev_show(struct kobject *kobj,
|
||||||
struct kobj_attribute *attr, char *buf)
|
struct kobj_attribute *attr, char *buf)
|
||||||
|
@ -391,12 +408,30 @@ static struct attribute *suspend_attrs[] = {
|
||||||
&last_failed_dev.attr,
|
&last_failed_dev.attr,
|
||||||
&last_failed_errno.attr,
|
&last_failed_errno.attr,
|
||||||
&last_failed_step.attr,
|
&last_failed_step.attr,
|
||||||
|
&last_hw_sleep.attr,
|
||||||
|
&total_hw_sleep.attr,
|
||||||
|
&max_hw_sleep.attr,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static umode_t suspend_attr_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
|
||||||
|
{
|
||||||
|
if (attr != &last_hw_sleep.attr &&
|
||||||
|
attr != &total_hw_sleep.attr &&
|
||||||
|
attr != &max_hw_sleep.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 = {
|
static const struct attribute_group suspend_attr_group = {
|
||||||
.name = "suspend_stats",
|
.name = "suspend_stats",
|
||||||
.attrs = suspend_attrs,
|
.attrs = suspend_attrs,
|
||||||
|
.is_visible = suspend_attr_is_visible,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
|
|
Loading…
Reference in a new issue