From: Mario Limonciello <superm1@kernel.org>
To: "Rafael J . Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>, Pavel Machek <pavel@ucw.cz>,
linux-acpi@vger.kernel.org (open list:ACPI),
linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software
Suspend, aka swsusp)),
Mario Limonciello <mario.limonciello@amd.com>
Subject: [PATCH 1/4] PM: Add sysfs file for energy consumed over sleep cycle
Date: Sat, 8 Feb 2025 10:22:07 -0600 [thread overview]
Message-ID: <20250208162210.3929473-2-superm1@kernel.org> (raw)
In-Reply-To: <20250208162210.3929473-1-superm1@kernel.org>
From: Mario Limonciello <mario.limonciello@amd.com>
During a sleep cycle the system will consume power to keep the
platform in s2idle or s3. On systems running on a battery this
can be measured by comparing battery before and after the sleep
cycle.
Add a symbol for the battery to report current energy level and
a sysfs file to show this information to a user.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
Documentation/ABI/testing/sysfs-power | 8 ++++++++
include/linux/suspend.h | 2 ++
kernel/power/main.c | 10 ++++++++++
3 files changed, 20 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index a3942b1036e25..e263355f99fc1 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -442,6 +442,14 @@ Description:
'total_hw_sleep' and 'last_hw_sleep' may not be accurate.
This number is measured in microseconds.
+What: /sys/power/suspend_stats/last_sleep_energy
+Date: March 2025
+Contact: Mario Limonciello <mario.limonciello@amd.com>
+Description:
+ The /sys/power/suspend_stats/last_sleep_energy file
+ contains the amount of energy that the battery consumed
+ during the last sleep cycle. This number is measured in mAh.
+
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 da6ebca3ff774..9627e2394c8a9 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -441,6 +441,7 @@ extern int unregister_pm_notifier(struct notifier_block *nb);
extern void ksys_sync_helper(void);
extern void pm_report_hw_sleep_time(u64 t);
extern void pm_report_max_hw_sleep(u64 t);
+extern void pm_report_sleep_energy(u64 t);
#define pm_notifier(fn, pri) { \
static struct notifier_block fn##_nb = \
@@ -484,6 +485,7 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
static inline void pm_report_hw_sleep_time(u64 t) {};
static inline void pm_report_max_hw_sleep(u64 t) {};
+static inline void pm_report_sleep_energy(u64 t) {};
static inline void ksys_sync_helper(void) {}
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 6254814d48171..9305c86e0b91a 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -321,6 +321,7 @@ struct suspend_stats {
u64 last_hw_sleep;
u64 total_hw_sleep;
u64 max_hw_sleep;
+ u64 last_sleep_energy;
enum suspend_stat_step failed_steps[REC_FAILED_NUM];
};
@@ -368,6 +369,12 @@ void pm_report_hw_sleep_time(u64 t)
}
EXPORT_SYMBOL_GPL(pm_report_hw_sleep_time);
+void pm_report_sleep_energy(u64 t)
+{
+ suspend_stats.last_sleep_energy = t;
+}
+EXPORT_SYMBOL_GPL(pm_report_sleep_energy);
+
void pm_report_max_hw_sleep(u64 t)
{
suspend_stats.max_hw_sleep = t;
@@ -399,6 +406,7 @@ suspend_attr(fail, "%u\n");
suspend_attr(last_hw_sleep, "%llu\n");
suspend_attr(total_hw_sleep, "%llu\n");
suspend_attr(max_hw_sleep, "%llu\n");
+suspend_attr(last_sleep_energy, "%llu\n");
#define suspend_step_attr(_name, step) \
static ssize_t _name##_show(struct kobject *kobj, \
@@ -477,6 +485,7 @@ static struct attribute *suspend_attrs[] = {
&last_hw_sleep.attr,
&total_hw_sleep.attr,
&max_hw_sleep.attr,
+ &last_sleep_energy.attr,
NULL,
};
@@ -484,6 +493,7 @@ static umode_t suspend_attr_is_visible(struct kobject *kobj, struct attribute *a
{
if (attr != &last_hw_sleep.attr &&
attr != &total_hw_sleep.attr &&
+ attr != &last_sleep_energy.attr &&
attr != &max_hw_sleep.attr)
return 0444;
--
2.43.0
next prev parent reply other threads:[~2025-02-08 16:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-08 16:22 [PATCH 0/4] Improvements to ACPI battery handling over s2idle Mario Limonciello
2025-02-08 16:22 ` Mario Limonciello [this message]
2025-02-08 16:22 ` [PATCH 2/4] ACPI: battery: Save and report battery capacity over suspend Mario Limonciello
2025-02-10 15:23 ` Sebastian Reichel
2025-02-10 21:24 ` Mario Limonciello
2025-02-08 16:22 ` [PATCH 3/4] ACPI: battery: Refactor wakeup reasons in acpi_battery_update() Mario Limonciello
2025-02-08 16:22 ` [PATCH 4/4] ACPI: battery: Wake system on AC plug or unplug in over s2idle Mario Limonciello
2025-02-08 17:59 ` Rafael J. Wysocki
2025-02-09 13:14 ` Mario Limonciello
2025-02-12 13:49 ` Armin Wolf
2025-02-12 13:57 ` Rafael J. Wysocki
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=20250208162210.3929473-2-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.