From ad0b7e03db613f86f244c9af797db6d12e7b9f62 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 6 Jan 2024 22:45:43 +0800 Subject: [PATCH 1/3] battery-util: raise log level for battery_is_discharging_and_low --- src/shared/battery-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/battery-util.c b/src/shared/battery-util.c index 85cb067c841..37b3f6a6ea3 100644 --- a/src/shared/battery-util.c +++ b/src/shared/battery-util.c @@ -241,13 +241,13 @@ int battery_is_discharging_and_low(void) { r = on_ac_power(); if (r < 0) - log_debug_errno(r, "Failed to check if the system is running on AC, assuming it is not: %m"); + log_warning_errno(r, "Failed to check if the system is running on AC, assuming it is not: %m"); if (r > 0) return false; r = battery_enumerator_new(&e); if (r < 0) - return log_debug_errno(r, "Failed to initialize battery enumerator: %m"); + return log_error_errno(r, "Failed to initialize battery enumerator: %m"); FOREACH_DEVICE(e, dev) { int level; From 22b21b2ea2db3485923cce3d0c2305c6538ff83a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 15 Jan 2024 02:58:52 +0800 Subject: [PATCH 2/3] units: update Description= for systemd-sleep units --- units/systemd-hibernate.service.in | 2 +- units/systemd-hybrid-sleep.service.in | 2 +- units/systemd-suspend-then-hibernate.service.in | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/units/systemd-hibernate.service.in b/units/systemd-hibernate.service.in index 25cd7a0ff95..c43195bc076 100644 --- a/units/systemd-hibernate.service.in +++ b/units/systemd-hibernate.service.in @@ -8,7 +8,7 @@ # (at your option) any later version. [Unit] -Description=Hibernate +Description=System Hibernate Documentation=man:systemd-hibernate.service(8) DefaultDependencies=no Requires=sleep.target diff --git a/units/systemd-hybrid-sleep.service.in b/units/systemd-hybrid-sleep.service.in index fe57f57fae6..c85215bdacf 100644 --- a/units/systemd-hybrid-sleep.service.in +++ b/units/systemd-hybrid-sleep.service.in @@ -8,7 +8,7 @@ # (at your option) any later version. [Unit] -Description=Hybrid Suspend+Hibernate +Description=System Hybrid Suspend+Hibernate Documentation=man:systemd-hybrid-sleep.service(8) DefaultDependencies=no Requires=sleep.target diff --git a/units/systemd-suspend-then-hibernate.service.in b/units/systemd-suspend-then-hibernate.service.in index 150d8d2c239..d7ab2c195e5 100644 --- a/units/systemd-suspend-then-hibernate.service.in +++ b/units/systemd-suspend-then-hibernate.service.in @@ -8,7 +8,7 @@ # (at your option) any later version. [Unit] -Description=Suspend; Hibernate if not used for a period of time +Description=System Suspend then Hibernate Documentation=man:systemd-suspend-then-hibernate.service(8) DefaultDependencies=no Requires=sleep.target From f2723ca745022ced5023cb3e1ed0cce0192e3ac9 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 6 Jan 2024 23:36:24 +0800 Subject: [PATCH 3/3] man/systemd-sleep.conf: document the operation of s2h more thoroughly --- man/systemd-sleep.conf.xml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/man/systemd-sleep.conf.xml b/man/systemd-sleep.conf.xml index f7e753990a0..f984bcb33fe 100644 --- a/man/systemd-sleep.conf.xml +++ b/man/systemd-sleep.conf.xml @@ -86,14 +86,20 @@ suspend-then-hibernate - A low power state where the system is initially suspended (the state is stored in - RAM). If the system supports low-battery alarms (ACPI _BTP), then the system will be woken up by - the ACPI low-battery signal and hibernated (the state is then stored on disk). Also, if not - interrupted within the timespan specified by HibernateDelaySec= or the estimated - timespan until the system battery charge level goes down to 5%, then the system will be woken up by the - RTC alarm and hibernated. The estimated timespan is calculated from the change of the battery - capacity level after the time specified by SuspendEstimationSec= or when - the system is woken up from the suspend. + A low power state where the system is initially suspended (the state is stored in RAM). + When the battery level is too low (less than 5%) or a certain timespan has passed, whichever + happens first, the system is automatically woken up and then hibernated. This establishes a balance + between speed and safety. + + If the system has no battery, it would be hibernated after HibernateDelaySec= + has passed. If not set, then defaults to 2h. + + If the system has battery and HibernateDelaySec= is not set, low-battery + alarms (ACPI _BTP) are tried first for detecting battery percentage and wake up the system for hibernation. + If not available, or HibernateDelaySec= is set, the system would regularly wake + up to check the time and detect the battery percentage/discharging rate. The rate is used to + schedule the next detection. If that is also not available, SuspendEstimationSec= + is used as last resort. @@ -194,8 +200,8 @@ The amount of time the system spends in suspend mode before the system is automatically put into hibernate mode. Only used by systemd-suspend-then-hibernate.service8. - If the system has a battery, then defaults to the estimated timespan until the system battery charge level goes down to 5%. - If the system has no battery, then defaults to 2h. + Refer to suspend-then-hibernate for details on how this option interacts with + other options/system battery state. @@ -206,10 +212,10 @@ The RTC alarm will wake the system after the specified timespan to measure the system battery - capacity level and estimate battery discharging rate, which is used for estimating timespan until the system battery charge - level goes down to 5%. Only used by + capacity level and estimate battery discharging rate. Only used by systemd-suspend-then-hibernate.service8. - Defaults to 1h. + Refer to suspend-then-hibernate for details on how this option interacts with + other options/system battery state.