Measurement-corrected battery optimization pass (DSDS + Wi-Fi)

Re-analyzed the running nokia-argon (a1105, 43 h uptime, DSDS + Wi-Fi on) and
implemented the corrected kernel/userspace optimization list. No sleep state
existed at all (/sys/power/state was 0 bytes) and cpuinfo_transition_latency
was UINT_MAX, while the CPU cores were already ~98% power-collapsed.

Kernel (K1-K14)
- Enable CONFIG_SUSPEND / SUSPEND_FREEZER / PM_WAKELOCKS / PM_AUTOSLEEP and
  build the zImage from the tuned config; ship it as overlay/rootfs/boot/vmlinuz
  plus config and System.map. Add wakeup-source to the WCNSS pronto remoteproc.
- Add clock-latency-ns to cpu-opp-table in all 5 device trees (fixes
  CPUFREQ_ETERNAL at its source instead of a userspace rate_limit_us override).
- New patch 0006: wcn36xx keep-alive 30s->120s, listen_interval=3, VM-BMS
  sample interval 10s->30s, power_supply_changed() only on real capacity
  changes, GPU devfreq polling_ms 50->100.
- Retune the config for idle (HZ=100, PREEMPT_VOLUNTARY, TEO cpuidle governor,
  no ftrace/perf/kprobes/BPF-JIT-always-on/debug options, no serial console,
  DRM_FBDEV_OVERALLOC=0, lz4 zram, ENERGY_MODEL) and drop earlycon /
  console=ttyMSM0 from every kernel cmdline.
- net.ipv6.conf.default.disable_ipv6=1 to stop ND/MLD multicast on new
  interfaces; keep NETFILTER/IPV6/CGROUPS and FRAMEBUFFER_CONSOLE for
  VPN/tethering, elogind and plymouth.

Userspace (U1-U14)
- Idle blanking without the passcode locker (bananarchy-idle-blank.sh +
  idle_locker resume hook, SXMO_UNLOCK_IDLE_TIME=60, sxmo.noidle opts out).
- Guarded deep standby (bananarchy-suspend.sh / -deep-standby.sh /
  sxmo_autosuspend.sh / sxmo_suspend.sh), AllowSuspend=yes, doas rule, no
  infinite wakelock, no sxmo.nosuspend. Shipped disabled via
  /etc/bananarchy-no-deep-standby until the new kernel is boot-tested; freeze
  is preferred, mem is opt-in.
- statusbar_periodics 60s->300s, no mmcli/nmcli/rfkill polls, xsetroot only on
  change; battery udev rule filtered and no 2 s recheck fork.
- On-demand QMI DPM port, longer DSDS/modemmonitor backoffs, chrony long polls,
  NM wifi.scan-interval=600, bluetooth AutoEnable=false, tmpfs on /tmp,
  zero-log superd, GPU devfreq governor on screen-off, longer SIP/Tox timers.
- Fix the cosmetic wpa_supplicant yesno typo; withdraw the disproven duplicate
  wpa_supplicant and soundmonitor 5 s loop items.

Rebuilt images/bananarchy-nokia-argon.img with --mkinitfs: boot.img contains
the new zImage + DTB byte-for-byte and no serial-console cmdline. Deployed the
userspace overlay to the connected phone and verified shell/Python syntax, the
idle-blank round trip, the statusbar hook and the deep-standby guard.
check-rebuild.sh and sync-prebuilt-overlay.sh --check both pass.

Docs: BATTERY-OPTIMIZATION-ANALYSIS.md (measurement-corrected, with
implementation status), CHANGELOG.md, MANUAL.md, README.md, AGENTS.md.
This commit is contained in:
Bantam committed 2026-11-07 17:03:12 +02:00
1 parent 2ea2db443d
commit ad3461babf
169 files changed
+151574 -333

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
#!/bin/sh
# Enter deep standby when the screen is off (U2). Disable by creating
# /etc/bananarchy-no-deep-standby. Enable suspend-to-RAM by creating
# /etc/bananarchy-allow-mem-suspend (only after verifying wake sources).
[ -f /etc/bananarchy-no-deep-standby ] && exit 0
[ -x /usr/bin/bananarchy-suspend.sh ] || exit 0
[ -r /sys/power/state ] || exit 0
# Blockers: an active call, an SSH session, or an active VPN/tether must
# keep the system awake.
incall=0
[ -r /tmp/sxmo_in_call ] && { read -r incall < /tmp/sxmo_in_call 2>/dev/null || incall=0; }
[ "$incall" = "1" ] && exit 0
pgrep -f 'sxmo_modemcall.sh' >/dev/null 2>&1 && exit 0
pgrep -f 'sshd-session' >/dev/null 2>&1 && exit 0
if command -v nmcli >/dev/null 2>&1; then
nmcli -t con show --active 2>/dev/null | grep -qE ':tun|:wireguard|^Hotspot' && exit 0
fi
# The screen must still be dark.
br=1
[ -r /sys/class/backlight/backlight/brightness ] && \
{ read -r br < /sys/class/backlight/backlight/brightness 2>/dev/null || br=1; }
case "$br" in ''|*[!0-9]*) br=1 ;; esac
[ "$br" -eq 0 ] || exit 0
exec doas -n /usr/bin/bananarchy-suspend.sh
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
# Open/close the QMI BAM-DMUX data port on demand (U9/K11).
# With Wi-Fi as the default route and no cellular data profile there is no
# reason to keep the modem data plane open at boot.
QMICLI="qmicli --silent -pd qrtr://0"
case "${1:-}" in
open)
$QMICLI --dpm-open-port=hw-data-ep-type=bam-dmux,hw-data-ep-iface-number=1,hw-data-rx-id=1,hw-data-tx-id=1 >/dev/null 2>&1 || true
;;
close)
$QMICLI --dpm-close-port=hw-data-ep-type=bam-dmux,hw-data-ep-iface-number=1,hw-data-rx-id=1,hw-data-tx-id=1 >/dev/null 2>&1 || true
;;
*)
printf 'Usage: %s [open|close]\n' "${0##*/}" >&2
exit 1
;;
esac
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
# Blank/restore the display without engaging the passcode locker (U1).
# sxmo_wm.sh display off/on already handles brightness, bl_power, DPMS,
# the CPU governor and the keyboard backlight.
case "${1:-}" in
off) exec /usr/bin/sxmo_wm.sh display off ;;
on) exec /usr/bin/sxmo_wm.sh display on ;;
*)
printf 'Usage: %s [off|on]\n' "${0##*/}" >&2
exit 1
;;
esac
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# Root helper: enter the deepest *safe* system sleep state.
# Called via doas from bananarchy-deep-standby.sh.
STATE_FILE=/sys/power/state
[ -r "$STATE_FILE" ] || exit 0
states=""
read -r states < "$STATE_FILE" 2>/dev/null || states=""
target=""
# freeze (s2idle) keeps every IRQ wake-capable, so keypad, lid, modem and
# Wi-Fi always resume the phone. mem needs platform wakeup sources and is
# therefore opt-in.
case " $states " in *" freeze "*) target=freeze ;; esac
if [ -f /etc/bananarchy-allow-mem-suspend ]; then
case " $states " in *" mem "*) target=mem ;; esac
fi
[ -n "$target" ] || exit 0
# This write blocks until the system resumes.
printf '%s\n' "$target" > "$STATE_FILE"
@@ -64,7 +64,10 @@ else
/tmp/tinydm.log /tmp/tinydm.log.old /tmp/Xorg.0.log /tmp/Xorg.0.log.old 2>/dev/null || true
fi
rm -f "$XDG_RUNTIME_DIR/sxmo.led.lock" "$XDG_RUNTIME_DIR"/sxmo_bat_state_* 2>/dev/null || true
touch "$XDG_CACHE_HOME/sxmo/sxmo.noidle" "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
# U1/U2: do not force sxmo.noidle / sxmo.nosuspend. Idle blanking and
# deep standby are the defaults; create ~/.cache/sxmo/sxmo.noidle to opt out
# of idle blanking, or /etc/bananarchy-no-deep-standby to opt out of suspend.
rm -f "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ] && printf "%s\n" "$DBUS_SESSION_BUS_ADDRESS" > "$XDG_RUNTIME_DIR/dbus.bus"
printf "1\n" > /tmp/bananarchy_screen_locked
printf "lock\n" > "$XDG_RUNTIME_DIR/sxmo.state"
@@ -143,8 +146,17 @@ while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
if pidof -s dwm >/dev/null 2>&1; then
exit 0
fi
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
/usr/bin/bananarchy-sync-dunst-theme --no-restart >/dev/null 2>&1 || true
# U14: skip X resource/wallpaper work when the panel is powered down.
_dark=0
if [ -r /sys/class/backlight/backlight/brightness ]; then
_bl=1
read -r _bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _bl=1
[ "${_bl:-1}" = "0" ] && _dark=1
fi
if [ "$_dark" = "0" ]; then
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
/usr/bin/bananarchy-sync-dunst-theme --no-restart >/dev/null 2>&1 || true
fi
WP_FILE="/usr/share/wallpapers/bananarchy.png"
if [ -f "$XDG_CONFIG_HOME/sxmo/wallpaper" ]; then
custom_wp="$(head -n 1 "$XDG_CONFIG_HOME/sxmo/wallpaper" 2>/dev/null)"
@@ -161,7 +173,7 @@ while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
*) WP_FLAG="--bg-fill" ;;
esac
fi
( feh --no-fehbg "$WP_FLAG" "$WP_FILE" >/dev/null 2>&1 </dev/null & )
if [ "$_dark" = "0" ]; then ( feh --no-fehbg "$WP_FLAG" "$WP_FILE" >/dev/null 2>&1 </dev/null & ); fi
if [ "$first_iter" = "0" ]; then
pidof -s fcitx5 >/dev/null 2>&1 || superctl start fcitx5 >/dev/null 2>&1 || ( /usr/bin/bananarchy-fcitx5.sh </dev/null & )
fi
+11 -2
View File
@@ -1,3 +1,12 @@
#!/bin/sh
# Autosuspend is disabled on Bananarchy so keypad, lid, and power keys always wake the screen immediately.
exit 0
# Wait for a grace period after screen-off, then enter deep standby once (U2).
# The write to /sys/power/state blocks until resume, so this job exits after
# one suspend cycle; sxmo_hook_unlock.sh/postwake.sh cancel it on wake.
[ -f /etc/bananarchy-no-deep-standby ] && exit 0
sleep "${BANANARCHY_SUSPEND_GRACE:-60}"
br=1
[ -r /sys/class/backlight/backlight/brightness ] && \
{ read -r br < /sys/class/backlight/backlight/brightness 2>/dev/null || br=1; }
case "$br" in ''|*[!0-9]*) br=1 ;; esac
[ "$br" -eq 0 ] || exit 0
exec /usr/bin/bananarchy-deep-standby.sh
+2 -2
View File
@@ -75,9 +75,9 @@ mainloop() {
else
/usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
fi
sleep 10
sleep 30
else
sleep 120
sleep 600
fi
done
) &
+2 -1
View File
@@ -180,5 +180,6 @@ monitor_jack_events &
while : ; do
handle_change || true
sleep 2
# U10: pactl subscribe is event-driven; only back off after a failure.
sleep 10
done
+3 -1
View File
@@ -16,7 +16,9 @@ SXMO_SUSPENDABLE_STATES="${SXMO_SUSPENDABLE_STATES:-screenoff 3}"
transition_can_suspend() {
sxmo_jobs.sh stop idle_suspender 2>/dev/null || true
sxmo_wakelock.sh lock sxmo_not_suspendable infinite 2>/dev/null || true
# U2: no infinite wakelock. Deep standby is guarded by
# /etc/bananarchy-no-deep-standby and the blocker list instead.
:
}
transition() {
+2 -2
View File
@@ -1,3 +1,3 @@
#!/bin/sh
# System suspend is disabled on Bananarchy so keypad, lid, and power keys always wake the screen immediately.
exit 0
# Bananarchy deep standby (U2). Guarded by /etc/bananarchy-no-deep-standby.
exec /usr/bin/bananarchy-deep-standby.sh
+7
View File
@@ -52,6 +52,10 @@ xorgdisplay() {
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'powersave\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi
# K5: pin the Adreno 304 devfreq to its minimum OPP while dark.
if [ -w /sys/class/devfreq/1c00000.gpu/governor ]; then
printf 'powersave\n' > /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true
fi
xset s off s noblank >/dev/null 2>&1 || true
xset dpms force off >/dev/null 2>&1 || true
;;
@@ -59,6 +63,9 @@ xorgdisplay() {
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'schedutil\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi
if [ -w /sys/class/devfreq/1c00000.gpu/governor ]; then
printf 'simple_ondemand\n' > /sys/class/devfreq/1c00000.gpu/governor 2>/dev/null || true
fi
xset s off s noblank >/dev/null 2>&1 || true
xset dpms force on >/dev/null 2>&1 || true
if [ -w /sys/class/backlight/backlight/bl_power ]; then