summaryrefslogtreecommitdiff
path: root/src/sleep
diff options
context:
space:
mode:
authorSonali Srivastava <srivastava.sonali1@gmail.com>2022-07-23 17:30:42 +0530
committerLuca Boccassi <luca.boccassi@gmail.com>2022-08-23 19:36:51 +0100
commit1afe3d712eaaca73d33da9f27b2a965589c6c842 (patch)
tree74640b512ac9764cae75f7a7f092534138f25c27 /src/sleep
parentcae8edd93ca2ef90c41cb9b6322b6908d12947b5 (diff)
downloadsystemd-1afe3d712eaaca73d33da9f27b2a965589c6c842.tar.gz
sleep: support acpi_btp and suspend system if enabled, skipping custom timer
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 14191cfc61..d8e6380d0a 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -262,7 +262,7 @@ static int execute(
return r;
}
-static int execute_s2h(const SleepConfig *sleep_config) {
+static int custom_timer_suspend(const SleepConfig *sleep_config) {
_cleanup_hashmap_free_ Hashmap *last_capacity = NULL, *current_capacity = NULL;
int r;
@@ -335,7 +335,55 @@ static int execute_s2h(const SleepConfig *sleep_config) {
if (!woken_by_timer)
/* Return as manual wakeup done. This also will return in case battery was charged during suspension */
return 0;
+
+ r = check_wakeup_type();
+ if (r < 0)
+ log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
+ if (r > 0) {
+ log_debug("wakeup type is APM timer");
+ /* system should hibernate */
+ break;
+ }
+ }
+
+ return 1;
+}
+
+static int execute_s2h(const SleepConfig *sleep_config) {
+ int r, k;
+
+ assert(sleep_config);
+
+ r = check_wakeup_type();
+ if (r < 0)
+ log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
+
+ k = battery_trip_point_alarm_exists();
+ if (k < 0)
+ log_debug_errno(k, "Failed to check whether acpi_btp support is enabled or not, ignoring: %m");
+
+ if (r >= 0 && k > 0) {
+ log_debug("Attempting to suspend...");
+ r = execute(sleep_config, SLEEP_SUSPEND, NULL);
+ if (r < 0)
+ return r;
+
+ r = check_wakeup_type();
+ if (r < 0)
+ return log_debug_errno(r, "Failed to check hardware wakeup type: %m");
+
+ if (r == 0)
+ /* For APM Timer wakeup, system should hibernate else wakeup */
+ return 0;
+ } else {
+ r = custom_timer_suspend(sleep_config);
+ if(r < 0)
+ return log_debug_errno(r, "Suspend cycle with manual battery discharge rate estimation failed: %m");
+ if(r == 0)
+ /* manual wakeup */
+ return 0;
}
+ /* For above custom timer, if 1 is returned, system will directly hibernate */
log_debug("Attempting to hibernate");
r = execute(sleep_config, SLEEP_HIBERNATE, NULL);