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

@@ -17,9 +17,8 @@ FORCE_UPDATE=0
if [ "${1:-}" = "udev" ]; then
object="/org/freedesktop/UPower/devices/battery_default"
event="device changed"
if [ "${2:-}" != "recheck" ]; then
(sleep 2; "$0" udev recheck >/dev/null 2>&1) &
fi
# U4: no 2 s recheck fork. Kernel patch 0006 emits a uevent only when
# the reported capacity actually changes, so one event is sufficient.
elif [ "${1:-}" = "force" ]; then
FORCE_UPDATE=1
object="/org/freedesktop/UPower/devices/battery_default"
@@ -7,6 +7,13 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
# U2: cancel a pending deep-standby job after resume.
if [ -r /tmp/bananarchy_autosuspend.pid ]; then
read -r _as_pid < /tmp/bananarchy_autosuspend.pid 2>/dev/null || _as_pid=""
[ -n "$_as_pid" ] && kill "$_as_pid" 2>/dev/null || true
rm -f /tmp/bananarchy_autosuspend.pid
fi
if [ -z "$SXMO_NO_MODEM" ]; then
MMCLI="$(mmcli -m any -J 2>/dev/null)"
if [ -z "$MMCLI" ]; then
@@ -38,4 +38,8 @@ fi
sxmo_jobs.sh stop idle_locker
# U2: enter deep standby after BANANARCHY_SUSPEND_GRACE seconds of screen-off.
( /usr/bin/sxmo_autosuspend.sh >/dev/null 2>&1 & \
printf '%s\n' "$!" > /tmp/bananarchy_autosuspend.pid )
wait
@@ -78,7 +78,7 @@ fi
# Periodically update some status bar components
sxmo_hook_statusbar.sh all
sxmo_jobs.sh start statusbar_periodics sxmo_run_aligned.sh 60 \
sxmo_jobs.sh start statusbar_periodics sxmo_run_aligned.sh 300 \
sxmo_hook_statusbar.sh periodics
# dunst is required for warnings.
@@ -96,12 +96,11 @@ if [ "$(command -v fcitx5)" ]; then
fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary
# Keep system awake so keypad, lid, and power keys always wake the screen immediately
# U1/U2: idle blanking and deep standby are enabled by default; the
# keypad/lid/power keys still wake the screen immediately.
mkdir -p "$XDG_CACHE_HOME/sxmo"
touch "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
if sxmo_wakelock.sh isenabled; then
sxmo_wakelock.sh lock sxmo_not_suspendable infinite
fi
# U2: no infinite wakelock; deep standby is guarded by
# /etc/bananarchy-no-deep-standby and the blocker list.
# Ensure lockscreen is active if session is still locked and locker has not yet mapped
if [ -f /tmp/bananarchy_screen_locked ] && [ ! -f "$XDG_RUNTIME_DIR/xlocker.pid" ]; then
@@ -534,18 +534,14 @@ case "$1" in
sxmo_hook_battery.sh force 2>/dev/null || true
fi
;;
periodics) # 60 s loop
periodics) # 300 s loop (U3): no QMI/D-Bus polls on every tick
if is_screen_dark || [ -f /tmp/bananarchy_screen_locked ]; then
exit 0
fi
set_time
set_inputmethod
if [ -z "$SXMO_NO_MODEM" ]; then
set_modem
fi
set_notch
set_state
set_network wifi wlan0
sxmo_hook_battery.sh 2>/dev/null || true
;;
all)
@@ -570,5 +566,12 @@ case "$1" in
esac
if ! is_screen_dark && [ "${SXMO_WM:-dwm}" = "dwm" ] && command -v xsetroot >/dev/null 2>&1; then
DISPLAY="${DISPLAY:-:0}" xsetroot -name "$(sxmo_status.sh)" 2>/dev/null || true
_bar="$(sxmo_status.sh)"
_bar_cache="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status_bar_cache"
_bar_prev=""
[ -r "$_bar_cache" ] && { read -r _bar_prev < "$_bar_cache" 2>/dev/null || _bar_prev=""; }
if [ "$_bar" != "$_bar_prev" ]; then
printf '%s\n' "$_bar" > "$_bar_cache" 2>/dev/null || true
DISPLAY="${DISPLAY:-:0}" xsetroot -name "$_bar" 2>/dev/null || true
fi
fi
@@ -26,11 +26,21 @@ sxmo_jobs.sh stop periodic_wakelock_check
# Re-enable automatic screen-off on idle to save battery. Locking stays
# explicit (the user locks only on request); we only blank the display.
# U2: cancel a pending deep-standby job on wake.
if [ -r /tmp/bananarchy_autosuspend.pid ]; then
read -r _as_pid < /tmp/bananarchy_autosuspend.pid 2>/dev/null || _as_pid=""
[ -n "$_as_pid" ] && kill "$_as_pid" 2>/dev/null || true
rm -f /tmp/bananarchy_autosuspend.pid
fi
# U1: blank the display after an idle timeout without engaging the locker.
# Create ~/.cache/sxmo/sxmo.noidle to restore the old "never blank" policy.
if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-30}" 'sh -c "sxmo_state.sh set screenoff"'
timeout "${SXMO_UNLOCK_IDLE_TIME:-60}" 'sh -c "/usr/bin/bananarchy-idle-blank.sh off"' \
resume 'sh -c "/usr/bin/bananarchy-idle-blank.sh on"'
fi
wait