summaryrefslogtreecommitdiffstats
path: root/src/shared/sleep-config.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* sleep: add HibernateOnACPower= option (#33846)Marc Reisner2024-08-051-0/+1
| | | * Add HibernateOnACPower= systemd-sleep configuration option
* hibernate-util,logind: also differentiate the case of misconfigured resumeMike Yuan2024-05-081-0/+1
|
* hibernate-util,logind: emit a clear error if the specified resume dev is missingMike Yuan2024-05-081-0/+1
| | | | | | | | | Currently, SLEEP_NOT_ENOUGH_SWAP_SPACE (ENOSPC) is returned on all sorts of error conditions. But one important case that's worth differentiating from that is when the resume device is manually specified yet missing. Closes #32644
* sleep: add SleepMemMode= setting for configuring /sys/power/mem_sleepMike Yuan2024-03-281-1/+15
| | | | | | | | The setting is used when /sys/power/state is set to 'mem' (common for suspend) or /sys/power/disk is set to 'suspend' (hybrid-sleep). We default to kernel choice here, i.e. respect what's set through 'mem_sleep_default=' kernel cmdline option.
* sleep-config: make sleep_mode_supported take a pathMike Yuan2024-03-281-2/+2
| | | | Preparation for later commits.
* sleep-config: make sleep_operation_is_hibernation uppercaseMike Yuan2024-03-281-1/+1
|
* sleep: introduce sleep_operation_is_hibernationMike Yuan2023-10-271-0/+4
|
* hibernate-util: introduce hibernation_is_safeMike Yuan2023-10-201-0/+1
| | | | | | | After 7470b80763ac0f598ca1ef73d44763967119c18d, we refuse to hibernate if we fail to write HibernateLocation EFI variable and resume= is not set. Let's teach sleep_supported to follow the practice too.
* sleep-config: introduce sleep_supported_full that returns a reasonMike Yuan2023-10-201-1/+13
| | | | | | | | Preparation for later commits. Also some other cleanups: * Add assertions * Use FOREACH_ARRAY
* sleep-config: minor cleanup for can_sleep_{state,disk}Mike Yuan2023-10-201-4/+4
| | | | | * Rename to sleep_{state,mode}_supported * Treat unreadable/unwriable sysfs files as error
* sleep-config: add explanatory comment on "modes"Mike Yuan2023-09-271-1/+2
|
* sleep-config: several cleanupsMike Yuan2023-09-271-7/+13
| | | | | | | | * Rename free_sleep_config to sleep_config_free * Rearrange functions * Make SleepConfig.modes and .states only contain operations that needs configuration * Add missing assert
* sleep-util: split into sleep-config and hibernate-utilMike Yuan2023-09-271-0/+35
|
* sleep: rename sleep-config.[ch] → sleep-util.[ch]Lennart Poettering2023-06-201-82/+0
| | | | | | The file long ceased to be exclusively about configuration of the sleep operation. It contains many many calls for other purposes, hence give it a more generic name.
* sleep-config: rename .device field to .pathLennart Poettering2023-06-201-1/+1
| | | | | | | | | This has been badly named given the path doesn't refer to a device quite likely, but to a path to a regular file. Hence let's be more precise with naming. (.device kinda suggests this was an sd_device object of sorts, but it really isn't.)
* sleep-config: replace SwapEntry's .type field with a proper enumLennart Poettering2023-06-201-1/+8
| | | | | | Following our usual rule: let's parse this early into internal representation, and stick to that. don't pass unparsed strings around needlessly.
* battery-util: move battery_is_discharging_and_low() to battery-util.[ch]Lennart Poettering2023-06-051-1/+0
| | | | | | | | | | This moves a first batch of functions from sleep-config.[ch] over to battery-util.[ch]. In the long run we should probably move even more stuff over, i.e. anything that deals with the battery sysfs driver interface. No code change.
* sleep: check if we're on AC power before checking battery capacityMike Yuan2023-02-211-1/+1
| | | | | | | | | | Before this commit, battery_is_low() returns true if there's no battery on the system. It's now modified to check if the system is on AC power first, and returns false early if that's the case. Fixes #26492
* sleep: introduce SuspendEstimationSec=Yu Watanabe2023-01-271-0/+3
| | | | | | | | | | | | | | | | | | | Before v252, HibernateDelaySec= specifies the maximum timespan that the system in suspend state, and the system hibernate after the timespan. However, after 96d662fa4c8cab24da57523c5e49e6ef3967fc13, 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.
* sleep: rename hibernate_delay_sec -> _usecYu Watanabe2023-01-261-1/+1
|
* test-sleep: add a very simple test that prints battery suspend estimatesZbigniew Jędrzejewski-Szmek2023-01-231-0/+1
|
* sleep: support acpi_btp and suspend system if enabled, skipping custom timerSonali Srivastava2022-08-231-0/+2
|
* sleep: support multiple battery instead of only BAT0Sonali Srivastava2022-08-091-3/+9
|
* sleep: store battery discharge rate/hour with hashSonali Srivastava2022-07-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Estimated battery discharge rate per hour is stored in : /var/lib/systemd/sleep/battery_discharge_percentage_rate_per_hour This value is used to determine the initial suspend interval. In case this file is not available or value is invalid, HibernateDelaySec interval is used. After wakeup from initial suspend, this value is again estimated and written to file if value is in range of 1-199. Logs for reference : HibernateDelaySec=15min - Updated in /etc/systemd/sleep.conf Jul 14 19:17:58 localhost systemd-sleep[567]: Current battery charge percentage: 100% Jul 14 19:17:58 localhost systemd-sleep[567]: Failed to read discharge rate from /var/lib/systemd/sleep/batt ery_discharge_percentage_rate_per_hour: No such file or directory Jul 14 19:17:58 localhost systemd-sleep[567]: Set timerfd wake alarm for 15min Jul 14 19:33:00 localhost systemd-sleep[567]: Current battery charge percentage after wakeup: 90% Jul 14 19:33:00 localhost systemd-sleep[567]: Attempting to estimate battery discharge rate after wakeup from 15min sleep Jul 14 19:33:00 localhost systemd-sleep[567]: product_id does not exist: No such file or directory Jul 14 19:33:00 localhost systemd-sleep[567]: Estimated discharge rate 39 successfully updated to /var/lib/systemd/sleep/battery_discharge_percentage_rate_per_hour Jul 14 19:33:00 localhost systemd-sleep[567]: Current battery charge percentage: 90% Jul 14 19:33:00 localhost systemd-sleep[567]: product_id does not exist: No such file or directory Jul 14 19:33:00 localhost systemd-sleep[567]: Set timerfd wake alarm for 1h 48min 27s Jul 14 21:21:30 localhost systemd-sleep[567]: Current battery charge percentage after wakeup: 90% Jul 14 21:21:30 localhost systemd-sleep[567]: Battery was not discharged during suspension
* sleep: use current charge level to decide suspensionSonali Srivastava2022-07-201-0/+2
| | | | | | | If battery current charge percentage is below 5% hibernate directly. Else initial suspend interval is set for HibernateDelaySec. On wakeup estimate battery discharge rate per hour and if battery charge percentage is not below 5% system is suspended else hibernated.
* sleep: use SleepOperation enum everywhere and drop sleep_settings()Lennart Poettering2021-05-221-16/+5
| | | | | | | | | Instead of comparing strings everywhere, let's use the new enum. This allows us to drop sleep_settings(), since the operation enum can be directly used as index into the config settings. Some minor other refactoring is done, but mostly just shifting thing around a bit, no actual change in behaviour.
* sleep: introduce high-level SleepOperation enumLennart Poettering2021-05-221-0/+12
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* sleep-config: modernize destructorsLennart Poettering2020-06-111-1/+1
| | | | | All other destructors in the same .c file return NULL, let's make sure the one where this so far wasn't done does it too.
* systemd-sleep: always attempt hibernation if configuredZach Smith2020-01-061-2/+2
| | | | | | | | When calculation of swap file offset is unsupported, rely on the /sys/power/resume & /sys/power/resume_offset values if configured rather than requiring a matching swap entry to be identified. Refactor to use dev_t for comparison of resume= device instead of string.
* systemd-sleep: always prefer resume device or fileZach Smith2019-10-241-1/+26
| | | | | | | This change checks each swap partition or file reported in /proc/swaps to see if it matches the values configured with resume= and resume_offset= kernel parameters. If a match is found, the matching swap entry is used as the hibernation location regardless of swap priority.
* systemd-sleep: use swaps in priority orderZach Smith2019-07-291-1/+1
| | | | | | | | In situations where hibernation is requested but resume= and resume_offset= kernel parameters are not configured, systemd will attempt to locate a suitable swap location by inspecting /proc/swaps. This change will use the first suitable swap with the highest configured priority.
* systemd-sleep: refactor sleep config parsingZach Smith2019-05-301-1/+22
| | | | | | | | remove verb from parse refactor required fields checks refactor allow settings
* shared/sleep-config: add switches to kill specific sleep modesZbigniew Jędrzejewski-Szmek2018-10-081-1/+1
| | | | | | | | | | | | /etc/systemd/sleep.conf gains four new switches: AllowSuspend=, AllowHibernation=, AllowSuspendThenHibernate=, AllowHybridSleep=. Disabling specific modes was already possible by masking suspend.target, hibernate.target, suspend-then-hibernate.target, or hybrid-sleep.target. But this is not convenient for distributions, which want to set some defaults based on what they want to support. Having those available as configuration makes it easy to put a config file in /usr/lib/systemd/sleep.conf.d/ that overrides the defaults and gives instructions how to undo that override.
* Drop my copyright headersZbigniew Jędrzejewski-Szmek2018-06-141-4/+0
| | | | | | | perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-1/+1
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* Merge pull request #8676 from keszybz/drop-license-boilerplateLennart Poettering2018-04-101-13/+0
|\ | | | | Drop license boilerplate
| * tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | | | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* | sleep: Add support for setting a disk offset when hibernatingMario Limonciello2018-04-091-0/+3
|/ | | | | | | | | | | The Linux kernel is adding support for configuring the offset into a disk. This allows swapfiles to be more usable as users will no longer need to set the offset on their kernel command line. Use this API in systemd when hibernating as well. Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
* Introduce suspend-to-hibernate (#8274)Mario Limonciello2018-03-081-1/+3
| | | | | | | | | | | | | | Suspend to Hibernate is a new sleep method that invokes suspend for a predefined period of time before automatically waking up and hibernating the system. It's similar to HybridSleep however there isn't a performance impact on every suspend cycle. It's intended to use with systems that may have a higher power drain in their supported suspend states to prevent battery and data loss over an extended suspend cycle. Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* tree-wide: place #pragma once at the same place everywhereLennart Poettering2016-02-201-2/+2
| | | | | | Usually, we place the #pragma once before the copyright blurb in header files, but in a few cases we didn't. Move those around, so that we do the same thing everywhere.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* #pragma once here and thereZbigniew Jędrzejewski-Szmek2015-01-231-0/+2
|
* systemd-sleep: add support for freeze and standbyZbigniew Jędrzejewski-Szmek2013-05-061-0/+26
A new config file /etc/systemd/sleep.conf is added. It is parsed by systemd-sleep and logind. The strings written to /sys/power/disk and /sys/power/state can be configured. This allows people to use different modes of suspend on systems with broken or special hardware. Configuration is shared between systemd-sleep and logind to enable logind to answer the question "can the system be put to sleep" as correctly as possible without actually invoking the action. If the user configured systemd-sleep to only use 'freeze', but current kernel does not support it, logind will properly report that the system cannot be put to sleep. https://bugs.freedesktop.org/show_bug.cgi?id=57793 https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=7e73c5ae6e7991a6c01f6d096ff8afaef4458c36 http://lists.freedesktop.org/archives/systemd-devel/2013-February/009238.html SYSTEM_CONFIG_FILE and USER_CONFIG_FILE defines were removed since they were used in only a few places and with the addition of /etc/systemd/sleep.conf it becomes easier to just append the name of each file to the dir name.