Files
bananarchy/overlay/rootfs/usr/bin/sxmo_state.sh
T
Bantam ad3461babf 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.
2026-11-07 17:03:12 +02:00

185 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
SXMO_STATE="${SXMO_STATE:-$XDG_RUNTIME_DIR/sxmo.state}"
if [ -n "$SXMO_HAS_PEANUTBUTTER" ] && command -v peanutbutter > /dev/null && [ -n "$WAYLAND_DISPLAY" ]; then
SXMO_STATES="${SXMO_STATES:-unlock screenoff}"
elif [ -z "$WAYLAND_DISPLAY" ] && command -v smlock > /dev/null; then
SXMO_STATES="${SXMO_STATES:-unlock screenoff}"
else
SXMO_STATES="${SXMO_STATES:-unlock lock screenoff}"
fi
SXMO_SUSPENDABLE_STATES="${SXMO_SUSPENDABLE_STATES:-screenoff 3}"
transition_can_suspend() {
sxmo_jobs.sh stop idle_suspender 2>/dev/null || true
# U2: no infinite wakelock. Deep standby is guarded by
# /etc/bananarchy-no-deep-standby and the blocker list instead.
:
}
transition() {
state="$1"
if [ "$state" = "unlock" ] && [ -f /tmp/bananarchy_screen_locked ]; then
state="lock"
printf '%s\n' "$state" > "$SXMO_STATE"
sxmo_wm.sh display on >/dev/null 2>&1 &
xlocker wake >/dev/null 2>&1 &
return 0
fi
if [ "$state" = "lock" ]; then
printf '1\n' > /tmp/bananarchy_screen_locked
xlocker >/dev/null 2>&1 &
elif [ "$state" = "screenoff" ]; then
printf '1\n' > /tmp/bananarchy_screen_locked
xlocker screenoff >/dev/null 2>&1 &
fi
sxmo_log "transitioning to stage $state"
printf '%s\n' "$state" > "$SXMO_STATE"
lock_shared
(
# We need a subshell so we can close the lock fd, without
# releasing the lock
exec 3<&-
sxmo_hook_"$state".sh &
sxmo_hook_statusbar.sh state_change &
transition_can_suspend &
wait
)
}
click() {
count="${1:-1}"
# shellcheck disable=SC2086
set -- $SXMO_STATES
i=1
while [ $i -le $# ]; do
tmpstate=
prevstate=
eval "tmpstate=\$$i"
if [ "$tmpstate" = "$state" ]; then
if [ $i = 1 ]; then
eval "prevstate=\$$#"
else
eval "prevstate=\$$((i-1))"
fi
state="$prevstate"
break
fi
i=$((i+1))
done
if [ "$count" -gt 1 ]; then
click $((count-1))
else
transition "$state"
fi
flushstored
}
idle() {
sxmo_jobs.sh stop idle_locker 2>/dev/null || true
sxmo_jobs.sh stop idle_suspender 2>/dev/null || true
sxmo_log "idle: automatic idle locking is disabled"
}
store() {
storeid="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
printf '%s\n' "$state" > "$SXMO_STATE.stored.$storeid"
printf %s "$storeid"
}
flushstored() {
rm -f "$SXMO_STATE.stored."* 2>/dev/null || true
}
restore() {
storeid="$1"
if [ -f "$SXMO_STATE.stored.$storeid" ]; then
state=""
read -r state < "$SXMO_STATE.stored.$storeid" 2>/dev/null || true
transition "$state"
flushstored
fi
}
read_state() {
state=""
if [ -r "$SXMO_STATE" ]; then
read -r state < "$SXMO_STATE" 2>/dev/null || true
fi
}
action="$1"
shift
case "$action" in
get)
read_state
if [ -f /tmp/bananarchy_screen_locked ] && [ "$state" = "unlock" ]; then
state="lock"
fi
printf %s "$state"
exit 0
;;
is_locked)
if [ -f /tmp/bananarchy_screen_locked ]; then
exit 0
fi
if [ -n "$SXMO_HAS_PEANUTBUTTER" ]; then
pidof peanutbutter swaylock waylock i3lock > /dev/null && exit 0
fi
read_state
if [ "$state" = "unlock" ]; then
exit 1
fi
exit 0
;;
esac
exec 3<> "$SXMO_STATE.lock"
lock_exclusive() {
flock -x 3
}
lock_shared() {
flock -s 3
}
case "$action" in
click|idle)
lock_exclusive
read_state
"$action" "$@" ;;
set)
lock_exclusive
read_state
case " $SXMO_STATES " in
*" $1 "*)
transition "$1"
;;
esac
;;
store)
lock_exclusive
read_state
store
;;
restore)
lock_exclusive
restore "$1"
;;
flushstored)
lock_exclusive
flushstored
;;
esac