forked from shauninman/MinUI
-
Notifications
You must be signed in to change notification settings - Fork 71
fix: throw out all the defensive sleep logic #736
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
Open
frysee
wants to merge
19
commits into
main
Choose a base branch
from
lean-suspend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7348c4c
fix: throw out all the defensive sleep logic
frysee 4a18584
fix: RA - avoid calling PLAT_wifiConnected(), use the deferred result
frysee bc96f4a
chore: minor cleanup
frysee 1b7af6c
fix: Disable wifi again to keep suspend from failing constantly
frysee 5ccc02a
fix: wake slightly faster
frysee f91ac76
fix: dac detection on boot
frysee 777751e
fix: remaining reconnect issues
frysee 14e5649
fix: more robust pairing from #730
frysee 67733ee
fix: cache A2DP MAC to reliably detect BT headset disconnect (from #730)
frysee a070d7c
fix: connect A2DP after pairing and enable JustWorksRepairing for hea…
carroarmato0 f419406
fix: correct tg5050 JustWorksRepairing comment (AIC8800, not XRadio)
carroarmato0 492f320
fix: remove doubled up section after cherry picking
frysee 247421f
fix: earlier picked commit
frysee 426af37
fix: connect A2DP after pairing and enable JustWorksRepairing for hea…
frysee 7a28b22
chore: improve bluealsa restart logic on device disconnection
frysee aef9983
Apply suggestion from @frysee
frysee bc23a89
Apply suggestion from @frysee
frysee 42c1a42
fix: change resetAudio to use SDL atomic operations for thread safety
frysee 9eb3014
fix: add conditional compilation for snd_config_update_free_global on…
frysee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,37 +3,64 @@ set -uo pipefail | |
| set +e | ||
| exec 0<&- | ||
|
|
||
| #logfile="/mnt/SDCARD/.userdata/tg5040/logs/suspend_$(date +%Y%m%d_%H%M%S).log" | ||
| #exec >> "$logfile" 2>&1 | ||
| logfile="/mnt/SDCARD/.userdata/tg5040/logs/suspend_$(date +%Y%m%d_%H%M%S).log" | ||
| exec >> "$logfile" 2>&1 | ||
|
|
||
| wifid_running= | ||
| bluetoothd_running= | ||
|
|
||
| sleep_retval= | ||
| sleep_retval=1 | ||
|
|
||
| asound_state_dir=/tmp/asound-suspend | ||
|
|
||
| log_wakeup_sources() { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be removed before we merge. |
||
| local label="$1" | ||
| >&2 echo " [$label] wakeup_count: $(cat /sys/power/wakeup_count 2>/dev/null)" | ||
| if [ -f /sys/power/pm_wakeup_irq ]; then | ||
| >&2 echo " [$label] last wakeup IRQ: $(cat /sys/power/pm_wakeup_irq 2>/dev/null)" | ||
| fi | ||
| if [ -f /sys/power/wake_lock ]; then | ||
| local locks | ||
| locks=$(cat /sys/power/wake_lock 2>/dev/null) | ||
| [ -n "$locks" ] && >&2 echo " [$label] active wakelocks: $locks" | ||
| fi | ||
| if [ -r /sys/kernel/debug/wakeup_sources ]; then | ||
| >&2 echo " [$label] wakeup sources (wakeup_count>0 | active | prevent_suspend>0):" | ||
| awk 'NR==1 || $4 != "0" || $6 != "0" || $10 != "0"' \ | ||
| /sys/kernel/debug/wakeup_sources 2>/dev/null | head -20 >&2 | ||
| fi | ||
| >&2 echo " [$label] dmesg (last 10 lines):" | ||
| dmesg 2>/dev/null | tail -10 >&2 | ||
| } | ||
|
|
||
| before() { | ||
| >&2 echo "Preparing for suspend..." | ||
|
|
||
| # Run pre-sleep hooks synchronously before services are stopped. | ||
| # Subshell ensures a crashing hook cannot block suspend. | ||
| ( "$SYSTEM_PATH/bin/run_hooks.sh" pre-sleep.d --sync-only ) >/dev/null 2>&1 || true | ||
|
|
||
| >&2 echo "Saving mixer state..." | ||
| mkdir -p "$asound_state_dir" | ||
| alsactl --file "$asound_state_dir/asound.state.pre" store || true | ||
| log_wakeup_sources "before" | ||
|
|
||
| if pgrep bluetoothd; then | ||
| bluetoothd_running=1 | ||
| >&2 echo "Stopping bluetoothd..." | ||
| /etc/bluetooth/bt_init.sh stop || true | ||
| fi | ||
| # Enable kernel PM debug messages so driver-level suspend rejections | ||
| # appear in dmesg. | ||
| echo 1 >/sys/power/pm_debug_messages 2>/dev/null || true | ||
|
|
||
| #>&2 echo "Saving mixer state..." | ||
| #mkdir -p "$asound_state_dir" | ||
| #alsactl --file "$asound_state_dir/asound.state.pre" store || true | ||
|
|
||
| #if pgrep bluetoothd; then | ||
| # bluetoothd_running=1 | ||
| # >&2 echo "Stopping bluetoothd..." | ||
| # /etc/bluetooth/bt_init.sh stop || true | ||
| #fi | ||
|
|
||
| if pgrep wpa_supplicant; then | ||
| wifid_running=1 | ||
| >&2 echo "Stopping wpa_supplicant..." | ||
| /etc/wifi/wifi_init.sh stop || true | ||
| rmmod xradio_wlan > /dev/null 2>&1 || true | ||
| fi | ||
| } | ||
|
|
||
|
|
@@ -45,14 +72,21 @@ after() { | |
|
|
||
| if [ -n "$wifid_running" ]; then | ||
| >&2 echo "Starting wpa_supplicant..." | ||
| modprobe xradio_wlan > /dev/null 2>&1 || true | ||
| # wait for wlan0 to appear before starting wpa_supplicant | ||
| for i in $(seq 1 10); do | ||
| if ip link show wlan0 > /dev/null 2>&1; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| /etc/wifi/wifi_init.sh start || true | ||
| fi | ||
|
|
||
| if [ -n "$bluetoothd_running" ]; then | ||
| >&2 echo "Starting bluetoothd..." | ||
| /etc/bluetooth/bt_init.sh start || true | ||
| fi | ||
|
|
||
| #if [ -n "$bluetoothd_running" ]; then | ||
| # >&2 echo "Starting bluetoothd..." | ||
| # /etc/bluetooth/bt_init.sh start || true | ||
| #fi | ||
| # >&2 echo "Restoring mixer state..." | ||
| # alsactl --file "$asound_state_dir/asound.state.post" store || true | ||
| # alsactl --file "$asound_state_dir/asound.state.pre" restore || true | ||
|
|
@@ -61,10 +95,21 @@ after() { | |
| before | ||
|
|
||
| >&2 echo "Suspending..." | ||
| sleep_max_tries=5 | ||
| sleep_max_tries=15 | ||
| for i in $(seq 1 $sleep_max_tries); do | ||
| >&2 echo "Deep sleep attempt $i of $sleep_max_tries" | ||
|
|
||
| # Synchronize with wakeup events: read wakeup_count and write it back. | ||
| # If a wakeup event occurred since reading, the write fails and we retry. | ||
| wakeup_count=$(cat /sys/power/wakeup_count 2>/dev/null) | ||
| if [ -n "$wakeup_count" ]; then | ||
| if ! echo "$wakeup_count" >/sys/power/wakeup_count 2>/dev/null; then | ||
| >&2 echo "Deep sleep: wakeup event detected before sleep (wakeup_count=$wakeup_count), retrying in 1 second" | ||
| sleep 1 | ||
| continue | ||
| fi | ||
| fi | ||
|
|
||
| sleep_time=$(date +%s) | ||
| echo mem >/sys/power/state | ||
| sleep_retval=$? | ||
|
|
@@ -89,10 +134,10 @@ for i in $(seq 1 $sleep_max_tries); do | |
| sleep_retval=0 | ||
| break | ||
| fi | ||
|
|
||
|
|
||
| >&2 echo "Deep sleep failed: retrying in 3 seconds" | ||
| sleep 3 | ||
| >&2 echo "Deep sleep failed: retrying in 1 second" | ||
| log_wakeup_sources "attempt $i" | ||
| sleep 1 | ||
| done | ||
|
|
||
| # Resume services in background to reduce UI latency | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.