summaryrefslogtreecommitdiff
path: root/src/sleep
diff options
context:
space:
mode:
authorSonali Srivastava <srivastava.sonali1@gmail.com>2022-08-17 12:54:20 +0530
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-08-26 11:16:35 +0900
commitf13f91f06a06f9d290ac6da85417c766112ddccc (patch)
treef40c45b5a08c2d1688000fdc8f0918cd5123d74b /src/sleep
parent4ccde410a3fc141c9ddf285f24a22dfea99e0287 (diff)
downloadsystemd-f13f91f06a06f9d290ac6da85417c766112ddccc.tar.gz
sleep: freeze and thaw user.slice to save resource while suspend
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index d8e6380d0a..3461d3e45f 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -14,10 +14,13 @@
#include <sys/timerfd.h>
#include <unistd.h>
+#include "sd-bus.h"
#include "sd-messages.h"
#include "btrfs-util.h"
#include "bus-error.h"
+#include "bus-locator.h"
+#include "bus-util.h"
#include "def.h"
#include "exec-util.h"
#include "fd-util.h"
@@ -29,6 +32,7 @@
#include "parse-util.h"
#include "pretty-print.h"
#include "sleep-config.h"
+#include "special.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
@@ -349,11 +353,38 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
return 1;
}
+/* Freeze when invoked and thaw on cleanup */
+static int freeze_thaw_user_slice(const char **method) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ int r;
+
+ if (!method || !*method)
+ return 0;
+
+ r = bus_connect_system_systemd(&bus);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to open connection to systemd: %m");
+
+ r = bus_call_method(bus, bus_systemd_mgr, *method, &error, NULL, "s", SPECIAL_USER_SLICE);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r));
+
+ return 1;
+}
+
static int execute_s2h(const SleepConfig *sleep_config) {
+ _unused_ _cleanup_(freeze_thaw_user_slice) const char *auto_method_thaw = NULL;
int r, k;
assert(sleep_config);
+ r = freeze_thaw_user_slice(&(const char*) { "FreezeUnit" });
+ if (r < 0)
+ log_debug_errno(r, "Failed to freeze unit user.slice, ignoring: %m");
+ else
+ auto_method_thaw = "ThawUnit"; /* from now on we want automatic thawing */;
+
r = check_wakeup_type();
if (r < 0)
log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");