Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleep: several fixlets #25374

Merged
merged 9 commits into from Jan 30, 2023
Merged

sleep: several fixlets #25374

merged 9 commits into from Jan 30, 2023

Conversation

yuwata
Copy link
Member

@yuwata yuwata commented Nov 13, 2022

Fixes #25269.

src/shared/sleep-config.c Outdated Show resolved Hide resolved
@bluca bluca added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Nov 13, 2022
@yuwata yuwata removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Nov 14, 2022
@yuwata
Copy link
Member Author

yuwata commented Nov 14, 2022

@bluca Thank you for your review. Updated the commit messages to response the above comments. PTAL.

@bluca bluca added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Nov 14, 2022
src/sleep/sleep.c Show resolved Hide resolved
src/sleep/sleep.c Show resolved Hide resolved
@bluca bluca added good-to-merge/with-minor-suggestions and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Nov 15, 2022
src/sleep/sleep.c Outdated Show resolved Hide resolved
@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed good-to-merge/with-minor-suggestions labels Nov 16, 2022
@keszybz
Copy link
Member

keszybz commented Dec 2, 2022

@yuwata please see Lennart's comments above.

@n-peugnet
Copy link

@yuwata I applied this pull request (as well as #25662) on top of Debian's systemd v252.2-1 but did not get the expected result: the system did not go to hibernation after HibernateDelaySec elapsed.

Here is an excerpt of journalctl logs with a call to suspend-then-hibernate and a wakeup form sleep:

déc. 12 02:03:48 X260-NICOLAS systemd[1]: Reached target Sleep.
déc. 12 02:03:48 X260-NICOLAS wpa_supplicant[721]: p2p-dev-wlp4s0: CTRL-EVENT-DSCP-POLICY clear_all
déc. 12 02:03:48 X260-NICOLAS wpa_supplicant[721]: p2p-dev-wlp4s0: CTRL-EVENT-DSCP-POLICY clear_all
déc. 12 02:03:48 X260-NICOLAS wpa_supplicant[721]: nl80211: deinit ifname=p2p-dev-wlp4s0 disabled_11b_rates=0
déc. 12 02:03:48 X260-NICOLAS systemd[1]: Starting autorandr execution hook...
déc. 12 02:03:48 X260-NICOLAS systemd[1]: Starting System Suspend...
déc. 12 02:03:49 X260-NICOLAS wpa_supplicant[721]: wlp4s0: CTRL-EVENT-DSCP-POLICY clear_all
déc. 12 02:03:49 X260-NICOLAS systemd-sleep[31938]: Entering sleep state 'suspend'...
déc. 12 02:03:49 X260-NICOLAS kernel: PM: suspend entry (deep)
déc. 12 02:03:49 X260-NICOLAS wpa_supplicant[721]: wlp4s0: CTRL-EVENT-DSCP-POLICY clear_all
déc. 12 02:03:49 X260-NICOLAS wpa_supplicant[721]: nl80211: deinit ifname=wlp4s0 disabled_11b_rates=0
déc. 12 02:03:49 X260-NICOLAS kernel: Filesystems sync: 0.184 seconds
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware i915/skl_dmc_ver1_27.bin
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware regulatory.db
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware intel/ibt-11-5.ddc
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware regulatory.db.p7s
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware intel/ibt-11-5.sfi
déc. 12 02:03:49 X260-NICOLAS kernel: (NULL device *): firmware: direct-loading firmware iwlwifi-8000C-36.ucode
déc. 12 07:39:20 X260-NICOLAS kernel: Freezing user space processes ... (elapsed 0.081 seconds) done.
déc. 12 07:39:20 X260-NICOLAS kernel: OOM killer disabled.
déc. 12 07:39:20 X260-NICOLAS kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
déc. 12 07:39:20 X260-NICOLAS kernel: printk: Suspending console(s) (use no_console_suspend to debug)
déc. 12 07:39:20 X260-NICOLAS kernel: sd 1:0:0:0: [sda] Synchronizing SCSI cache
déc. 12 07:39:20 X260-NICOLAS kernel: sd 1:0:0:0: [sda] Stopping disk
déc. 12 07:39:20 X260-NICOLAS kernel: e1000e: EEE TX LPI TIMER: 00000011
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: interrupt blocked
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: PM: Preparing to enter system sleep state S3
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: event blocked
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: EC stopped
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: PM: Saving platform NVS memory
déc. 12 07:39:20 X260-NICOLAS kernel: Disabling non-boot CPUs ...
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: CPU 1 is now offline
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: CPU 2 is now offline
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: CPU 3 is now offline
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: PM: Low-level resume complete
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: EC started
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: PM: Restoring platform NVS memory
déc. 12 07:39:20 X260-NICOLAS kernel: Enabling non-boot CPUs ...
déc. 12 07:39:20 X260-NICOLAS kernel: x86: Booting SMP configuration:
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: Booting Node 0 Processor 1 APIC 0x2
déc. 12 07:39:20 X260-NICOLAS kernel: CPU1 is up
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: Booting Node 0 Processor 2 APIC 0x1
déc. 12 07:39:20 X260-NICOLAS kernel: CPU2 is up
déc. 12 07:39:20 X260-NICOLAS kernel: smpboot: Booting Node 0 Processor 3 APIC 0x3
déc. 12 07:39:20 X260-NICOLAS kernel: CPU3 is up
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: PM: Waking up from system sleep state S3
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: interrupt unblocked
déc. 12 07:39:20 X260-NICOLAS kernel: sd 1:0:0:0: [sda] Starting disk
déc. 12 07:39:20 X260-NICOLAS kernel: ACPI: EC: event unblocked
déc. 12 07:39:20 X260-NICOLAS kernel: i915 0000:00:02.0: [drm] [ENCODER:94:DDI A/PHY A] is disabled/in DSI mode with an ungated DDI clock, gate it
déc. 12 07:39:20 X260-NICOLAS kernel: i915 0000:00:02.0: [drm] [ENCODER:102:DDI B/PHY B] is disabled/in DSI mode with an ungated DDI clock, gate it
déc. 12 07:39:20 X260-NICOLAS kernel: i915 0000:00:02.0: [drm] [ENCODER:117:DDI C/PHY C] is disabled/in DSI mode with an ungated DDI clock, gate it
déc. 12 07:39:20 X260-NICOLAS kernel: usb 1-8: reset high-speed USB device number 3 using xhci_hcd
déc. 12 07:39:20 X260-NICOLAS kernel: ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: supports DRM functions and may not be fully accessible
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: ACPI cmd f5/00:00:00:00:00:a0(SECURITY FREEZE LOCK) filtered out
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: ACPI cmd ef/10:03:00:00:00:a0(SET FEATURES) filtered out
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: supports DRM functions and may not be fully accessible
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: configured for UDMA/133
déc. 12 07:39:20 X260-NICOLAS kernel: ata2.00: Enabling discard_zeroes_data
déc. 12 07:39:20 X260-NICOLAS kernel: usb 1-7: reset full-speed USB device number 4 using xhci_hcd
déc. 12 07:39:20 X260-NICOLAS kernel: OOM killer enabled.
déc. 12 07:39:20 X260-NICOLAS kernel: Restarting tasks ... done.
déc. 12 07:39:20 X260-NICOLAS kernel: random: crng reseeded on system resumption
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Bootloader revision 0.0 build 2 week 52 2014
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Device revision is 5
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Secure boot is enabled
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: OTP lock is enabled
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: API lock is enabled
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Debug lock is disabled
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Minimum firmware build 1 week 10 2014
déc. 12 07:39:20 X260-NICOLAS kernel: Bluetooth: hci0: Found device firmware: intel/ibt-11-5.sfi
déc. 12 07:39:20 X260-NICOLAS systemd-logind[706]: Lid opened.
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/ldac
déc. 12 07:39:20 X260-NICOLAS systemd-resolved[619]: Clock change detected. Flushing caches.
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/aptx_hd
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx_hd
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/aptx
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/sbc
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/sbc
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/sbc_xq
déc. 12 07:39:20 X260-NICOLAS kernel: psmouse serio1: synaptics: queried max coordinates: x [..5712], y [..4780]
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/sbc_xq
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx_ll_1
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx_ll_0
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_1
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_0
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/faststream
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/faststream_duplex
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/opus_05
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/opus_05
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink/opus_05_duplex
déc. 12 07:39:20 X260-NICOLAS bluetoothd[1441]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource/opus_05_duplex
déc. 12 07:39:20 X260-NICOLAS kernel: psmouse serio1: synaptics: queried min coordinates: x [1232..], y [1074..]
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Daily apt upgrade and clean activities was skipped because of an unmet condition check (ConditionACPower=true).
déc. 12 07:39:20 X260-NICOLAS systemd-sleep[31938]: System returned from sleep state.
déc. 12 07:39:20 X260-NICOLAS kernel: PM: suspend exit
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Starting Clean php session files...
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Started Timeline of Snapper Snapshots.
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Starting Load/Save RF Kill Switch Status...
déc. 12 07:39:20 X260-NICOLAS systemd[1]: systemd-suspend.service: Deactivated successfully.
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Finished System Suspend.
déc. 12 07:39:20 X260-NICOLAS dbus-daemon[698]: [system] Rejected send message, 0 matched rules; type="error", sender=":1.48" (uid=1000 pid=1160 comm="/usr/bin/wireplumber") interface="(unset)">
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Stopped target Sleep.
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Reached target Suspend.
déc. 12 07:39:20 X260-NICOLAS systemd[1]: Stopped target Suspend.

I saw kernel: ACPI: EC: interrupt blocked and ACPI: EC: event blocked messages that may be related to this issue.

@yuwata
Copy link
Member Author

yuwata commented Dec 12, 2022

@n-peugnet Thank you for testing this PR, and sorry for late to update this PR. I will take a look.

@hissssst
Copy link

I don't know if it is possible for a regular user to ask for this, but it would be nice to have this PR prioritized, since it heavily affects regular workflows of users with laptops without S3 sleep state, who rely on suspend-then-hibernate

@je-s
Copy link

je-s commented Jan 14, 2023

Is there anything else needed to do or to discuss in order to get this PR merged? I'm happy to assist in case assistance is needed, since v252 has pretty significant impacts on the UX due to broken configurations (which have been made on purpose and worked for years).

I want to add some perspectives to the discussion at #25269:
The hibernate-at-low-battery feature introduced in v252 standing by itself is a very good thing to do and makes total sense, but so there are quite a few good use cases for suspend-then-hibernate after a declared amount of time;

  • Battery saving:
    The option offers a good balance between the near-instant resumption during shorter breaks in device use, and battery saving for longer ones.
  • Convenience and ease of use:
    Giving -or better said; leaving- the user a convenience option, so he doesn't need to think too much about which sleep state is the right one to choose from in the current situation. The automation known until v251 was able to offer a good balance for that, too.
  • Security:
    In case you have an encrypted device and your session is automatically suspended to disk after a given amount of time, it requires the user to decrypt their device again to restore their session. This makes it more difficult to tamper with a running session, since you reduce the chances of even finding one.

I think that having both options available in conjunction is the only logical thing to do.

@wired
Copy link

wired commented Jan 19, 2023

any updates on this? would love to see it get merged.

@devsnek
Copy link

devsnek commented Jan 21, 2023

I also found that this patch did not fix the HibernateDelaySec option. happy to test any updates. i'm also poking around a bit, hoping i can get something working 😔

@github-actions github-actions bot added util-lib please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Jan 26, 2023
@bluca bluca force-pushed the sleep-fixlets branch 2 times, most recently from 412a8f9 to f7f6af9 Compare January 26, 2023 11:37
@bluca
Copy link
Member

bluca commented Jan 26, 2023

The new timespan param specifies the interval used to estimate battery dischage rate. The name should indicate this… "BatteryEstimationSec=" ?

done, ptal

@keszybz
Copy link
Member

keszybz commented Jan 26, 2023

I didn't do a full review, but the changed parts look OK. Let's do this.

@keszybz keszybz added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Jan 26, 2023
@devsnek
Copy link

devsnek commented Jan 26, 2023

this doesn't appear to contain the fix I posted

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

However, after 96d662f, 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 systemd#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 systemd#25269.
- use device_get_sysattr_int(),
- drop redundant log message.
Also, rename get_battery_identifier() to siphash24_compress_device_sysattr().

This also makes any errors in sd_id128_get_machine() or id128_get_product()
ignored. For the machine ID, the failure should not be significant unless
the file stored in the discharge level is reused by another system, which
is quite unusual. For the product ID, if the firmware provides useless
ID (all zero or all 0xFF), then loading/storing the discharge rate
becomes completely broken, that should be avoided.

Note, now sysattrs are used instead of properties in uevent files, but
both provide the same information, hence no functionality should be
changed.
The enumerator is now mostly consistent with on_ac_power() in
udev-util.c.
@bluca bluca merged commit 0a5bd40 into systemd:main Jan 30, 2023
45 of 46 checks passed
@vixalien
Copy link

vixalien commented Feb 2, 2023

thanks for everyone involved

@keszybz keszybz removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Feb 3, 2023
@keszybz
Copy link
Member

keszybz commented Feb 3, 2023

this doesn't appear to contain the fix I posted

@devsnek if something is missing, please open a new pull request.

@wired
Copy link

wired commented Feb 26, 2023

things work beautifully again, thank you!

@hydrandt
Copy link

@wired meaning that HibernateDelaySec now again sets time after which the machine wakes up from S3 (or similar) and hibernates?

This seems to have been backported to 252. I am on Ubuntu 23.04. Doesn't seem this made it into 23.04's systemd (currently 252.5-2ubuntu3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

suspend-then-hibernate: add option to force early hibernate