From 2013a66fddaec53d029e475a703ecfa7b90a1f6b Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 31 Jul 2016 19:01:15 +0200 Subject: [PATCH] Some more Kobo suspend tweaks... Disable wakeup_count handling, that's often causing more harm than anything else... Nickel doesn't even use it, that should have been a hint ;). Make the logging slightly less confusing. Add commented out debug features (dumping relevant dmesg output). Re #2188 --- frontend/device/kobo/device.lua | 1 + platform/kobo/suspend.sh | 46 ++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index a17bd00f7..089a64b7f 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -268,6 +268,7 @@ function Kobo:suspend() end function Kobo:resume() + -- Unflag subsystems for suspend os.execute("echo 0 > /sys/power/state-extended") -- HACK: wait a bit for the kernel to catch up os.execute("sleep 0.1") diff --git a/platform/kobo/suspend.sh b/platform/kobo/suspend.sh index 5f275a4f3..e6b4da9be 100755 --- a/platform/kobo/suspend.sh +++ b/platform/kobo/suspend.sh @@ -1,7 +1,9 @@ #!/bin/sh export PATH="${PATH}:/sbin:/usr/sbin" -echo "[$(date +'%x @ %X')] Kobo Suspend: BEGIN!" +echo "[$(date +'%x @ %X')] Kobo Suspend: Going to sleep . . ." +# NOTE: Sleep as little as possible here, sleeping has a tendency to make everything mysteriously hang... + # Disable wifi if lsmod | grep -q sdio_wifi_pwr ; then wlarm_le -i eth0 down @@ -11,9 +13,23 @@ if lsmod | grep -q sdio_wifi_pwr ; then echo "[$(date +'%x @ %X')] Kobo Suspend: Killed WiFi" fi +# Depending on device/FW version, some kernels do not support wakeup_count, account for that +if [ -e "/sys/power/wakeup_count" ] ; then + #HAS_WAKEUP_COUNT="true" + # NOTE: ... and of course, it appears to be broken, which probably explains why nickel doesn't use this facility... + # (By broken, I mean that the system wakes up right away). + # So, unless that changes, unconditionally disable it. + HAS_WAKEUP_COUNT="false" +fi + +# Clear the kernel ring buffer... (we're missing a proper -C flag...) +#dmesg -c >/dev/null + # Go to sleep -current_wakeup_count="$(cat /sys/power/wakeup_count)" -echo "[$(date +'%x @ %X')] Kobo Suspend: Current WakeUp count: ${current_wakeup_count}" +if [ "${HAS_WAKEUP_COUNT}" == "true" ] ; then + current_wakeup_count="$(cat /sys/power/wakeup_count)" + echo "[$(date +'%x @ %X')] Kobo Suspend: Current WakeUp count: ${current_wakeup_count}" +fi echo 1 > /sys/power/state-extended # NOTE: Sets gSleep_Mode_Suspend to 1. Used as a flag throughout the kernel to suspend/resume various subsystems # cf. kernel/power/main.c @ L#207 @@ -22,10 +38,14 @@ sleep 2 echo "[$(date +'%x @ %X')] Kobo Suspend: Waited for 2s because of reasons..." sync echo "[$(date +'%x @ %X')] Kobo Suspend: Synced FS" -echo ${current_wakeup_count} > /sys/power/wakeup_count -echo "[$(date +'%x @ %X')] Kobo Suspend: Wrote WakeUp count: ${current_wakeup_count} ($?)" +if [ "${HAS_WAKEUP_COUNT}" == "true" ] ; then + echo ${current_wakeup_count} > /sys/power/wakeup_count + echo "[$(date +'%x @ %X')] Kobo Suspend: Wrote WakeUp count: ${current_wakeup_count} ($?)" +fi +echo "[$(date +'%x @ %X')] Kobo Suspend: Asking for a suspend to RAM . . ." echo mem > /sys/power/state -echo "[$(date +'%x @ %X')] Kobo Suspend: Asked to suspend to RAM... ZzZ ZzZ ZzZ? ($?)" +# NOTE: At this point, we *should* be in suspend to RAM, as such, execution should only resume on wakeup... +echo "[$(date +'%x @ %X')] Kobo Suspend: ZzZ ZzZ ZzZ? ($?)" ## NOTE: Ideally, we'd need a way to warn the user that suspending gloriously failed at this point... ## We can safely assume that just from a non-zero return code, without looking at the detailed stderr message ## (most of the failures we'll see are -EBUSY anyway) @@ -33,4 +53,16 @@ echo "[$(date +'%x @ %X')] Kobo Suspend: Asked to suspend to RAM... ZzZ ZzZ ZzZ? ## which is where the non-sensical 1 -> mem -> 0 loop idea comes from... ## cf. nickel_suspend_strace.txt for more details. -echo "[$(date +'%x @ %X')] Kobo Suspend: END! (WakeUp count: $(cat /sys/power/wakeup_count))" +if [ "${HAS_WAKEUP_COUNT}" == "true" ] ; then + echo "[$(date +'%x @ %X')] Kobo Suspend: Woke up! (WakeUp count: $(cat /sys/power/wakeup_count))" +else + echo "[$(date +'%x @ %X')] Kobo Suspend: Woke up!" +fi + +# Print tke kernel log since our attempt to sleep... +#dmesg -c + +# Now that we're up, unflag subsystems for suspend... +# NOTE: We do that in Kobo:resume() to keep things tidy and easier to follow +#echo 0 > /sys/power/state-extended +#echo "[$(date +'%x @ %X')] Kobo Suspend: Unflagged kernel subsystems for suspend"