summaryrefslogtreecommitdiffstats
path: root/src/sleep (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* meson: move declarations of ac-power, detect-virt, sysctl, and sleepYu Watanabe2023-08-011-0/+13
|
* sleep: don't init /sys/power/resume if 'resume=' option is missing and EFI ↵Franck Bui2023-07-271-4/+6
| | | | | | | | | | | is disabled Otherwise in such case a first `systemctl hibernate` would fail but would still initialize /sys/power/resume fooling a second `systemctl hibernate` into believing that 'resume=' is correctly set and can be used by the resume process to find the swap device to resume from. Follow-up for #27330.
* sleep: fix unused variable warningLuca Boccassi2023-07-101-3/+2
| | | | log_level_ignored is used only inside the ifdef, so declare it there too
* sleep: refuse hibernation if there's no possible way to resumeMike Yuan2023-06-261-8/+9
| | | | | Follow-up for 90efe8a6d4c0035c6a01d42805be87d99fb12f9a Closes #19819
* sleep: write hibernate location to efivar HibernateLocationMike Yuan2023-06-231-2/+86
|
* sleep: always write resume_offset if possibleMike Yuan2023-06-231-42/+7
| | | | | | There's no need to conditionalize this. Setting resume_offset=0 doesn't harm, and can even help by overriding potentially existing half-written settings.
* sleep: rename sleep-config.[ch] → sleep-util.[ch]Lennart Poettering2023-06-201-1/+1
| | | | | | 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-5/+5
| | | | | | | | | 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-5/+3
| | | | | | 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-0/+1
| | | | | | | | | | 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: convert a home1.Manager call to BusLocatorDavid Tardon2023-05-241-7/+1
|
* tre-wide: use FORMAT_DEVNUM() a bit moreLennart Poettering2023-04-211-2/+4
|
* sleep: fix default values unmatched with manualMike Yuan2023-03-171-1/+4
|
* 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: use shared constant for freeze timeoutZbigniew Jędrzejewski-Szmek2023-02-201-2/+1
| | | | Let's keep all the timeout definitions in one place.
* sleep: coding style fixletsYu Watanabe2023-01-271-2/+2
|
* sleep: introduce SuspendEstimationSec=Yu Watanabe2023-01-272-15/+36
| | | | | | | | | | | | | | | | | | | 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: drop unnecessary temporal vaiable and initializationYu Watanabe2023-01-261-5/+6
|
* sleep: fetch_batteries_capacity_by_name() does not return -ENOENTYu Watanabe2023-01-261-13/+13
|
* sleep: rename hibernate_delay_sec -> _usecYu Watanabe2023-01-261-1/+1
|
* sleep: fix memleakZbigniew Jędrzejewski-Szmek2023-01-231-1/+1
| | | | | | Those hashmaps are created anew in each iteration of the loop. The leak wasn't really a problem, because the loop is bounded and the hashmaps were not huge, but it's nicer to be correct.
* sleep: reduce double logging and improve messages and comments a bitZbigniew Jędrzejewski-Szmek2023-01-231-1/+2
| | | | | | | | | | | read_battery_capacity_percentage() was already logging, but with a slightly different wording. More could be done, I just touched the most noticable places. Especially in debug messages, it is much more useful to be direct about what couldn't be accessed or parsed, instead of providing "descriptive names" which are not useful to the user at all, who then needs to read the code to figure out what was the actual property name.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* core/sleep: set timeout for freeze/thaw operation to 1.5 secondsmsizanoen12022-12-081-0/+3
| | | | | | | A FreezeUnit operation can hang due to the presence of kernel threads (see last 2 commits). Keeping the default configuration will mean the system will hang for 25 seconds in suspend waiting for the response. 1.5 seconds should be sufficient for most cases.
* sleep: always thaw user.slice even if freezing failedmsizanoen12022-12-081-3/+1
| | | | | | `FreezeUnit` can fail even when some units did got frozen, causing some user units to be frozen. A possible symptom is `user@.service` being frozen while still being able to log in over SSH.
* Rename def.h to constants.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
| | | | | | The name "def.h" originates from before the rule of "no needless abbreviations" was established. Let's rename the file to clarify that it contains a collection of various semi-related constants.
* basic: move version() to build.h+cZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
|
* sleep: freeze and thaw user.slice to save resource while suspendSonali Srivastava2022-08-261-0/+31
|
* sleep: support acpi_btp and suspend system if enabled, skipping custom timerSonali Srivastava2022-08-231-1/+49
|
* sleep: support multiple battery instead of only BAT0Sonali Srivastava2022-08-091-39/+25
|
* tree-wide: fix typoYu Watanabe2022-08-011-1/+1
|
* sleep: store battery discharge rate/hour with hashSonali Srivastava2022-07-201-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-28/+63
| | | | | | | 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.
* Update sleep.conf HibernateDelaySec default to match implementationRichard Huang2022-07-181-1/+1
|
* tree-wide: Remove the repeated ';' from code (#23901)Li kunyu2022-07-051-1/+1
|
* tree-wide: add a space after if, switch, for, and whileYu Watanabe2022-04-011-1/+1
|
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-2/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-1/+1
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* tree-wide: add FORMAT_TIMESPAN()Zbigniew Jędrzejewski-Szmek2021-07-091-3/+2
|
* sleep: clarify that failure setting env var is not fatalLennart Poettering2021-05-221-1/+1
|
* sleep: if hybrid sleep fails, do regular suspendLennart Poettering2021-05-221-4/+26
| | | | Fixes #19550
* sleep: remove duplicate loggingLennart Poettering2021-05-221-2/+2
| | | | | execute() logs about all errors, hence only log about what's new, i.e. what we'll do as consequence, and don't mention the error cause again.
* sleep: use SleepOperation enum everywhere and drop sleep_settings()Lennart Poettering2021-05-221-33/+46
| | | | | | | | | 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.
* fix: point to the correct drop-ins subdirectory for confsJóhann B. Guðmundsson2021-04-221-1/+1
|
* Do not try to return 0 from log_debug()Zbigniew Jędrzejewski-Szmek2021-04-141-4/+4
| | | | | | | | | As @yuwata correctly points out, this became broken when log_debug() started returning -EIO. I wanted to preserve this pattern, but it turns out it is not very widely used, and preserving it would make the whole thing, already quite complicated, even more complex. log_debug() is made like log_info() and friends, and returns void.
* Recommend drop-ins over modifications to the main config fileZbigniew Jędrzejewski-Szmek2021-02-191-8/+9
| | | | As discussed in https://github.com/systemd/systemd/pull/18347.
* tree-wide: enable colorized logging for daemons when run in consoleYu Watanabe2021-01-311-1/+1
| | | | It may be useful when debugging daemons.
* tree-wide: Drop custom formatting for print() help messagesDaan De Meyer2021-01-311-4/+3
| | | | | | | | | | | | I think this formatting was originally used because it simplified adding new options to the help messages. However, these days, most tools their help message end with "\nSee the %s for details.\n" so the final line almost never has to be edited which eliminates the benefit of the custom formatting used for printf() help messages. Let's make things more consistent and use the same formatting for printf() help messages that we use everywhere else. Prompted by https://github.com/systemd/systemd/pull/18355#discussion_r567241580
* systemd-sleep: Set SYSTEMD_SLEEP_ACTION for systemd-sleep hooks.Zach Smith2021-01-091-5/+9
| | | | | | | | | When suspend-then-hibernate is called, hooks have no ability to determine which stage of the request is being handled; they only see 'pre' and 'post' with the verb 'suspend-then-hibernate'. This change introduces an environment variable called SYSTEMD_SLEEP_ACTION that contains the name of the action that is processing: 'suspend', 'hibernate', 'hybrid-sleep', or 'suspend-after-failed-hibernate'.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|