mirror of
https://github.com/systemd/systemd.git
synced 2025-02-28 05:57:33 +03:00
sleep: freeze and thaw user.slice to save resource while suspend
This commit is contained in:
parent
4ccde410a3
commit
f13f91f06a
@ -14,10 +14,13 @@
|
|||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "sd-bus.h"
|
||||||
#include "sd-messages.h"
|
#include "sd-messages.h"
|
||||||
|
|
||||||
#include "btrfs-util.h"
|
#include "btrfs-util.h"
|
||||||
#include "bus-error.h"
|
#include "bus-error.h"
|
||||||
|
#include "bus-locator.h"
|
||||||
|
#include "bus-util.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "exec-util.h"
|
#include "exec-util.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
@ -29,6 +32,7 @@
|
|||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "pretty-print.h"
|
#include "pretty-print.h"
|
||||||
#include "sleep-config.h"
|
#include "sleep-config.h"
|
||||||
|
#include "special.h"
|
||||||
#include "stdio-util.h"
|
#include "stdio-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
@ -349,11 +353,38 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
|
|||||||
return 1;
|
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) {
|
static int execute_s2h(const SleepConfig *sleep_config) {
|
||||||
|
_unused_ _cleanup_(freeze_thaw_user_slice) const char *auto_method_thaw = NULL;
|
||||||
int r, k;
|
int r, k;
|
||||||
|
|
||||||
assert(sleep_config);
|
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();
|
r = check_wakeup_type();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
|
log_debug_errno(r, "Failed to check hardware wakeup type, ignoring: %m");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user