Skip to content

Commit

Permalink
Set desired suspend mode in /sys/power/mem_sleep
Browse files Browse the repository at this point in the history
If S0ix isn't explicitly enabled, default to S3. This means also writing
'deep' to /sys/power/mem_sleep (some systems defaults to s2idle
nowadays). Try to not override user choice done via mem_sleep_default=
kernel option (if 'enable-s0ix' is not set).

At some point, S0ix will be automatically enabled if hardware expects
it, but it isn't this time yet.

QubesOS/qubes-issues#6411
  • Loading branch information
marmarek committed Sep 6, 2024
1 parent 68070df commit 9c2405a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion linux/aux-tools/startup-misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,36 @@ bind_to_pciback() {
echo "$sbdf" > /sys/bus/pci/drivers/pciback/bind
}

if [ -n "$(qvm-features dom0 suspend-s0ix)" ]; then
# try to figure out desired suspend mode:
# 1. explicit 'suspend-s0ix' set to '1' or '' take precence
# 2. otherwise look for `mem_sleep_default` kernel param
# 3. if none of the above is set, default to S3 if supported

suspend_mode=
if suspend_s0ix=$(qvm-features dom0 suspend-s0ix); then
if [ "$suspend_s0ix" = "1" ]; then
suspend_mode=s0ix
else
suspend_mode=s3
fi
fi
if [ -z "$suspend_mode" ] && kopt=$(grep -o 'mem_sleep_default=[^ ]*' /proc/cmdline); then
# take the last one
kopt="$(printf '%s' "$kopt" | tail -n 1)"
if [ "$kopt" = "mem_sleep_default=s2idle" ]; then
suspend_mode=s0ix
elif [ "$kopt" = "mem_sleep_default=deep" ]; then
suspend_mode=s3
fi
fi
if [ -z "$suspend_mode" ] && grep -q deep /sys/power/mem_sleep; then
suspend_mode=s3
fi

# at this point $suspend_mode may still be empty as we don't enable s0ix
# implicitly (yet)

if [ "$suspend_mode" = "s0ix" ]; then
# assign thunderbolt root ports to pciback as workaround for suspend
# issue without PCI hotplut enabled, see
# https://github.com/QubesOS/qubes-linux-kernel/pull/903 for details
Expand All @@ -50,4 +79,7 @@ if [ -n "$(qvm-features dom0 suspend-s0ix)" ]; then
echo "$sbdf" > /sys/bus/pci/drivers/pciback/qubes_exp_pm_suspend
fi
done
echo s2idle > /sys/power/mem_sleep
elif [ "$suspend_mode" = "s3" ]; then
echo deep > /sys/power/mem_sleep
fi

0 comments on commit 9c2405a

Please sign in to comment.