sleep: introduce SuspendEstimationSec=

Before v252, HibernateDelaySec= specifies the maximum timespan that the
system in suspend state, and the system hibernate after the timespan.

However, after 96d662fa4c, the setting is
repurposed as the default interval to measure battery charge level and
estimate the battery discharging late. And if the system has enough
battery capacity, then the system will stay in suspend state and not
hibernate even if the time passed. See issue #25269.

To keep the backward compatibility, let's introduce another setting
SuspendEstimationSec= for controlling the interval to measure
battery charge level, and make HibernateDelaySec= work as of v251.

This also drops implementation details from the man page.

Fixes #25269.
This commit is contained in:
Yu Watanabe
2023-01-27 20:52:12 +00:00
committed by Luca Boccassi
parent 2ed56afeb3
commit 4f58b656d9
5 changed files with 77 additions and 46 deletions
+8 -3
View File
@@ -65,10 +65,14 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
int allow_suspend = -1, allow_hibernate = -1,
allow_s2h = -1, allow_hybrid_sleep = -1;
sc = new0(SleepConfig, 1);
sc = new(SleepConfig, 1);
if (!sc)
return log_oom();
*sc = (SleepConfig) {
.hibernate_delay_usec = USEC_INFINITY,
};
const ConfigTableItem items[] = {
{ "Sleep", "AllowSuspend", config_parse_tristate, 0, &allow_suspend },
{ "Sleep", "AllowHibernation", config_parse_tristate, 0, &allow_hibernate },
@@ -83,6 +87,7 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
{ "Sleep", "HybridSleepState", config_parse_strv, 0, sc->states + SLEEP_HYBRID_SLEEP },
{ "Sleep", "HibernateDelaySec", config_parse_sec, 0, &sc->hibernate_delay_usec },
{ "Sleep", "SuspendEstimationSec", config_parse_sec, 0, &sc->suspend_estimation_usec },
{}
};
@@ -113,8 +118,8 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
sc->modes[SLEEP_HYBRID_SLEEP] = strv_new("suspend", "platform", "shutdown");
if (!sc->states[SLEEP_HYBRID_SLEEP])
sc->states[SLEEP_HYBRID_SLEEP] = strv_new("disk");
if (sc->hibernate_delay_usec == 0)
sc->hibernate_delay_usec = 2 * USEC_PER_HOUR;
if (sc->suspend_estimation_usec == 0)
sc->suspend_estimation_usec = DEFAULT_SUSPEND_ESTIMATION_USEC;
/* Ensure values set for all required fields */
if (!sc->states[SLEEP_SUSPEND] || !sc->modes[SLEEP_HIBERNATE]
+3
View File
@@ -6,6 +6,8 @@
#include "hashmap.h"
#include "time-util.h"
#define DEFAULT_SUSPEND_ESTIMATION_USEC (1 * USEC_PER_HOUR)
typedef enum SleepOperation {
SLEEP_SUSPEND,
SLEEP_HIBERNATE,
@@ -20,6 +22,7 @@ typedef struct SleepConfig {
char **modes[_SLEEP_OPERATION_MAX];
char **states[_SLEEP_OPERATION_MAX];
usec_t hibernate_delay_usec;
usec_t suspend_estimation_usec;
} SleepConfig;
SleepConfig* free_sleep_config(SleepConfig *sc);