Refactor presuspend checks to run infrequently
autosuspend calls the presuspend check when the kernel locks are clear, and it hasn't been called recently. If we always call it, there's a risk that running all checks could take too long and we'll fail to suspend often. Successfully exiting means that there is nothing going on, so the system is free to suspend within a reasonable timeframe (something like < 10 seconds). All the checks currently use the (default) delay wait mechanism, but I would like to try to write others. For example `playerctl -F` could be used when playerctl is blocking suspend. Unfortunately managing spawned jobs and race conditions is harder than it seems at first glance. Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
This commit is contained in:
@@ -8,14 +8,26 @@
|
||||
|
||||
set -e
|
||||
|
||||
while true; do
|
||||
# Make sure it's fresh before checking locks, reading wakeup_count will
|
||||
# block so we can't poll it here
|
||||
sxmo_hook_wakelocks.sh
|
||||
last_check=0
|
||||
wait_can_suspend() {
|
||||
# If we already checked recently, then there's nothing to do. This helps
|
||||
# mitigate the chance that running all checks could take too long and
|
||||
# cause suspend to fail.
|
||||
if [ "$((last_check + 10))" -gt "$(date +%s)" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
sxmo_hook_block_suspend.sh
|
||||
|
||||
last_check="$(date +%s)"
|
||||
}
|
||||
|
||||
while true; do
|
||||
# Reading from wakeup_count blocks until there are no wakelocks
|
||||
wakeup_count=$(cat /sys/power/wakeup_count)
|
||||
|
||||
wait_can_suspend
|
||||
|
||||
# If the wakeup count has changed since we read it, this will fail so we
|
||||
# know to try again. If something takes a wake_lock after we do this, it
|
||||
# will cause the kernel to abort suspend.
|
||||
|
@@ -2,11 +2,6 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
|
||||
if [ "$1" = "-" ]; then
|
||||
waitfirst=1
|
||||
shift
|
||||
fi
|
||||
|
||||
timeout="$1"
|
||||
shift
|
||||
|
||||
@@ -18,13 +13,6 @@ finish() {
|
||||
|
||||
trap 'finish' TERM INT
|
||||
|
||||
if [ -n "$waitfirst" ]; then
|
||||
sleep "$timeout" &
|
||||
SLEEPPID="$!"
|
||||
wait "$SLEEPPID"
|
||||
unset SLEEPPID
|
||||
fi
|
||||
|
||||
while : ; do
|
||||
"$@" &
|
||||
CMDPID="$!"
|
||||
|
Reference in New Issue
Block a user