sxmo-utils/scripts/core/sxmo_suspend.sh
ArenM 3ab2b5480f
Read wakeup_count instead of using sxmo_wakeafter
The approach sxmo_wakeafter uses is flawed because the kernel isn't
obligated to pass control to it after suspend. I'm pretty sure it
normally gets called when the kernel updates the system clock.

Since we're waiting for some time after every suspend we're not actually
using opportunistic suspend. It's much simpler to read wakeup_count to
ask the kernel to wait until there's no active locks.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
2023-02-24 09:42:44 +01:00

33 lines
826 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
sxmo_log "going to suspend to crust"
if suspend_time="$(sxmo_hook_mnc.sh)"; then
sxmo_log "calling suspend with suspend_time <$suspend_time>"
start="$(date "+%s")"
rtcwake -m mem -s "$suspend_time" || exit 1
#We woke up again
time_spent="$(( $(date "+%s") - start ))"
if [ "$suspend_time" -gt 0 ] && [ "$((time_spent + 10))" -ge "$suspend_time" ]; then
UNSUSPENDREASON="rtc"
fi
else
sxmo_log "fake suspend (suspend_time ($suspend_time) less than zero)"
UNSUSPENDREASON=rtc # we fake the crust for those seconds
fi
if [ "$UNSUSPENDREASON" = "rtc" ]; then
sxmo_wakelock.sh lock waiting_cronjob infinite
fi
sxmo_hook_postwake.sh