Skip to content
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

Shutdown all but one CPU cores on screen off #3

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Helper scripts for PinePhone and PinePhone Pro users
## sleepwalk
"Proof-of-concept" bash script to periodically wake up the phone to check web-based notifications (such as messenger or e-mail notifications). The goal of this is to get a better battery time while still being able to receive web-based notifications. Currently, only calls and SMS will make the phone wake up, when deep sleep is used.

By default, the script will make the phone sleep within 60 seconds, when the screen is turned off (sleep mode will not apply while the screen is on) and will make the phone sleep for 10 minutes (if not interrrupted by pressing the power button to wake the phone). It will then keep the phone awake for 30 seconds and put the phone immediately back to sleep mode for another 10 minutes and so on. You can change the durations directly at the top of the script. While the phone is sleeping, the RGB LED will light up constantly green and when it is awake for the short period of time, it will be a blinking red. The LED will be turned off, when the phone screen is enabled (for example by pressing the power button).
By default, the script will make the phone sleep within 60 seconds, when the screen is turned off (sleep mode will not apply while the screen is on) and will make the phone sleep for 10 minutes (if not interrrupted by pressing the power button to wake the phone). It will then keep the phone awake for 30 seconds and put the phone immediately back to sleep mode for another 10 minutes and so on. You can change the durations directly at the top of the script. While the phone is sleeping, the RGB LED will light up constantly green and when it is awake for the short period of time, it will be a blinking red and all but one CPU cores will be powered off. The LED will be turned off and all CPU core will be powered on, when the phone screen is enabled (for example by pressing the power button).

Howto install and use:
- Save the 'sleepwalk' script to /usr/local/bin and the systemd service file 'sleepwalk.service' to '/etc/systemd/system/'
Expand Down
22 changes: 22 additions & 0 deletions sleepwalk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
SLEEP_SECS=600
WAKE_SECS=30
LOCK_DIR="/tmp/sleepwalk"
CPU_STATE=1 # Assumed state on startup

set_cpu_offline() {
if [ $CPU_STATE -eq 1 ]; then
# Power off all CPU cores except cpu0
for i in $(seq 3); do
echo 0 > /sys/devices/system/cpu/cpu$i/online
done
CPU_STATE=0
fi
}

set_cpu_online() {
if [ $CPU_STATE -eq 0 ]; then
for i in $(seq 3); do
echo 1 > /sys/devices/system/cpu/cpu$i/online
done
CPU_STATE=1
fi
}

start_deep_sleep() {
led_sleep
Expand All @@ -24,8 +44,10 @@ wait_for_notifications() {
fi

if is_screen_on; then
set_cpu_online
break
fi
set_cpu_offline
secs=$(($secs-1))
done
led_disable
Expand Down