Kernel power headroom analysis: decline full module tree rebuild

Live re-measurement on the connected nokia-argon (screen off, Wi-Fi up,
both SIMs registered) plus kernel-source and pmaports APKBUILD inspection.

Key findings:
- Idle AP is already 98.08% idle, both cores in SPC, all genpd domains off,
  SPI/GPU/SDHCI/remoteprocs runtime-suspended. Remaining activity is ~35.8
  timer IRQs/s, ~29.5 SPC entries/s, 8.4 function-call IPIs/s.
- mem suspend is impossible here: no PSCI node, qcom_scm smc legacy, cpuidle
  qcom_spm, no platform_suspend_ops for MSM8916. CONFIG_SUSPEND would give
  only freeze (s2idle), with no DDR self-refresh.
- Full module tree rebuild is mechanically clean (pmaports 6.12.1-r5 applies
  no patches, 579 modules / 11 MB, same tarball, zstd module layout already
  configured) but would save <1 mA against the ~20-55 mA needed for 24 h in
  DSDS + Wi-Fi, while reintroducing the ABI and untested driver-sleep risks
  of the unbootable ad3461b image. Declined; known-good ABI stays.
- Additional ABI-breaking options documented: ENERGY_MODEL, PERF_EVENTS,
  FUNCTION_GRAPH_TRACER, HZ. RCU_LAZY needs rcu_nocbs=all (bad on 2 cores).
- Where the runtime must come from: modem eDRX/PSM, DSDS policy, Wi-Fi DTIM,
  DDR self-refresh (needs PSCI SYSTEM_SUSPEND in lk2nd).
- Recorded the session's hard-reset incident and the VM-BMS 0xffff FIFO
  transient (19.2 V / Over voltage after hard reset), with a source-only
  clamp recommended as the one kernel-side fix worth doing.

Docs only: no kernel image, module, DTB, config or userspace artifact changed.
This commit is contained in:
Luxferre committed 2026-11-07 18:55:57 +02:00
1 parent da68bb8c60
commit b5a1e0c5f9
5 files changed
+289 -4

No files matched your search

+240
View File
@@ -429,3 +429,243 @@ U1's idle blanking is now a user-facing setting: **Config -> Screen blank**
SMS/notifications wake immediately via `bananarchy-screen-wake.sh`, which also
resets `dwm`'s idle timer. This keeps the panel off for long idle periods
(battery) without delaying call/SMS visibility.
---
## 14. Remaining kernel headroom and the full-module-tree question (live re-measurement)
This section answers two questions with fresh on-device data: what kernel-side
optimizations are still unimplemented after `ad3461b` / `0dbb37f` / `22d629f` /
`da68bb8`, and whether rebuilding the *entire* pmaports kernel module tree is
worth doing to unlock them.
### 14.1 Session, limits, and state
- Host clock 2026-11-07 18:03-18:46 EET; phone `Bananarchy Linux a1107`,
`Linux nokia-argon 6.12.1-msm8916 #1 SMP PREEMPT`, freshly rebooted (uptime
12-22 min during the windows), reachable at `172.16.42.1` over USB RNDIS.
- **Charging throughout**: `pm8916-lbc-chgr/online=1`,
`constant_charge_current=540000`, `pm8916-bms-vm/status=Charging`, capacity
`85 -> 87`, `voltage_now` 4.198 -> 4.309 V. There is no `current_now`, no
coulomb counter, `voltage_ocv` is empty, `hwmon6` exposes only `in0_input`,
`/proc/config.gz` is absent, and the SPMI `regmap` debugfs `registers` files
are read-only and return `XX`. The charger's
`CONSTANT_CHARGE_CURRENT` setter clamps to `PM8916_LBC_CHGR_MIN_CURRENT`
(90 mA) and always writes `CHG_EN`, so charging cannot be disabled from
userspace. **No discharge current was measurable**; every mA figure below is
a structural estimate, exactly as in section 1.
- Wi-Fi associated to `OffOurStreets_`; both SIMs registered on the network
(`SLOT1_REG_STATE=registered / lte / -67 dBm`,
`SLOT2_REG_STATE=registered / gsm / -66 dBm`), so DSDS RF was active during
the measurement. Caveat: `mmcli -L` reported `No modems were found` in this
session even though QMI NAS showed both SIMs registered; the ModemManager
modem object was absent. That is a separate functional issue and does not
remove the modem RF drain.
- Idle windows ran with the panel forced dark (`brightness=0`, `bl_power=4`,
DPMS `Off`) via `bananarchy-idle-blank.sh off`.
- **Session incident**: at ~22 min uptime the phone stopped responding (blank
panel, USB RNDIS gone from the host, no fastboot/EDL/ADB) and needed a hard
power-key reset. `pstore` was empty and the post-reset `dmesg` shows no panic
or oops; after the reset the phone booted normally with the screen on, Wi-Fi
connected and all services started. No kernel image, module, DTB, cmdline or
config was changed in this session — every probe was a read-only
sysfs/debugfs/`/proc` read plus `bananarchy-idle-blank.sh off/on` round-trips.
The cause is unknown; it is another reason not to swap the kernel/module ABI
on a device whose wake path is this fragile.
- **Post-reset fuel-gauge transient (new kernel-side finding)**: for the first
~3.5 min after a hard reset the VM-BMS reports `voltage_now=19199723` uV
(19.2 V), `health=Over voltage`, `status=Full`, `capacity=100`, while
`voltage_ocv` is a sane 4.267 V. The cause is an uninitialised FIFO sample of
`0xffff`: `pm8916_bms_vm_fifo_update_done_irq()` accepts any raw value
`> 8000`, and `0xffff * 292.969 uV = 19.2 V`. It settles to 4.32 V / `Good` /
96% once the first real 30 s FIFO sample arrives. This is a correctness bug
in `pm8916_bms_vm.c`, fixable with a source-only sanity clamp (no config or
ABI change); it is listed in 14.7.
### 14.2 What the idle application processor actually does now
60-second window, screen off, Wi-Fi up, both SIMs registered:
| Signal | Rate |
|---|---|
| `arch_mem_timer` (broadcast timer, GIC 39) | 20.70 /s |
| `arch_timer` (GIC 20) | 15.08 /s |
| Total timer IRQs | **35.78 /s** |
| `IPI3` function call | 8.40 /s |
| `IPI1` timer broadcast | 1.78 /s |
| `IPI2` rescheduling | 0.85 /s |
| `wcn36xx_rx` | 2.43 /s |
| `mmc0` | 2.20 /s |
| `smd-edge` | 0.35 /s |
| `wcn36xx_tx` | 0.08 /s |
| `pm8916_vm_bms` | 0.02 /s |
| `cpu-sleep-0` (SPC) entries, cpu0 / cpu1 | 19.4 /s, 10.1 /s (**29.5 /s**) |
| CPU idle (`/proc/stat`) | 98.08% overall, 99.22% cpu0, 96.93% cpu1 |
Runtime PM / clocks / regulators at the same moment:
- `78b9000.spi`, `1c00000.gpu`, `7824900.sdhci`, `7864900.sdhci` all
`status=suspended`; GPU devfreq `simple_ondemand`, 409.6 MHz, 100 ms poll.
- `pm_genpd_summary`: `mx`, `mx_ao`, `cx`, all GDSCs `off-0`; `cx_ao` `on`
(cpu0); `1c00000.gpu`, `4080000.remoteproc` (modem), `a204000.remoteproc`
(WCNSS) all `suspended`.
- 21 clocks have a nonzero enable count. The always-on ones are structural:
`bimc_ddr_clk_src` 768 MHz (DDR **not** in self-refresh), `a53pll` 1094.4 MHz,
`gcc_mss_q6_bimc_axi_clk` 768 MHz (modem bus), `gcc_usb_hs_system_clk`
80 MHz + `gcc_usb_hs_ahb_clk` 100 MHz (USB RNDIS), `sleep-clk` 32.768 kHz,
and `gcc_blsp1_uart1_apps_clk` 3.686 MHz (the `console=ttyMSM0` serial
console). Regulators with `use > 0` are `s2`, `l5`, `l6`, `l7`, `l8`, `l13`,
`l17` (audio codec, SDHCI, USB PHY, panel supplies) — no orphaned rail.
- All four LEDs are off with `none` / `mmc0` / `mmc1` triggers; no periodic
LED trigger exists.
- With the panel dark, userspace is nearly silent: 19.5 voluntary context
switches/s total, of which `rcu_preempt` 9.8/s, `kcompactd0` 2.1/s, a few
kworkers ~4/s. `Xorg` drops from 43.5/s (screen on) to ~0/s. Nine
`hrtimer_wakeup` entries were armed at any instant, with 0.5-2.5 s periods.
In short: the userspace work from U1-U14 has already removed essentially all
userspace wakeups. What remains is kernel-internal tick/hrtimer/RCU activity
plus a handful of peripheral IRQs, on an AP that is already ~98% idle with
every runtime-PM domain collapsed.
### 14.3 Decisive finding: `mem` suspend is impossible on this platform
Enabling `CONFIG_SUSPEND` would **not** give suspend-to-RAM here:
- `arch/arm/boot/dts/qcom/qcom-msm8916-smp.dtsi` explicitly sets
`psci { status = "disabled"; }` and replaces the PSCI idle state with
`qcom,idle-state-spc`. The live device tree has **no `/proc/device-tree/psci`
node**, no `/sys/firmware/psci`, `dmesg` says
`qcom_scm: convention: smc legacy`, and the cpuidle driver is `qcom_spm`.
- The only `suspend_set_ops()` caller reachable on ARM DT platforms is
`drivers/firmware/psci/psci.c`, and it only registers when PSCI 1.0
`SYSTEM_SUSPEND` is available. `arch/arm/mach-qcom/` has no suspend ops.
`valid_state(PM_SUSPEND_MEM)` in `kernel/power/suspend.c` returns false
without `suspend_ops`, so writing `mem` to `/sys/power/state` degrades to
`mem_sleep_current = s2idle` at best and is rejected otherwise.
- Consequence: `CONFIG_SUSPEND=y` yields **only `freeze` (s2idle)**. s2idle
calls `tick_freeze()` -> `timekeeping_suspend()` and freezes tasks, so the
~36 timer IRQs/s stop, but there is **no RPM-assisted SoC power collapse and
no DDR self-refresh**. `bimc_ddr_clk_src` stays at 768 MHz. That is the one
saving that could plausibly have been worth tens of mA, and it is gated by
firmware (lk2nd would have to implement PSCI `SYSTEM_SUSPEND`), not by the
kernel config.
### 14.4 Full module tree rebuild: feasibility (it is clean)
The rebuild itself turned out to be much less risky than assumed in section 11:
- pmaports `v26.06` `device/testing/linux-postmarketos-qcom-msm8916/APKBUILD`
(`6.12.1-r5`) uses the **same** `msm8916-mainline/linux` `v6.12.1-msm8916`
tarball that `scripts/build-kernel-audio.sh` already caches. Its `prepare()`
is `default_prepare` plus `cp config-...armv7 .config` — **no patches at
all**. There are no pmaports-only driver fixes to lose.
- Our `config-bananarchy-msm8909.armv7` differs from
`config-postmarketos-qcom-msm8916.armv7` in ~248 lines, almost entirely the
GCC/binutils version stamp, `CONFIG_MODULE_COMPRESS_ALL=y`, and
`CONFIG_NFT_REDIR=m` for our `nft_redir.ko`.
- The package tree is **579 `.ko.zst` files / 11 MB**. Our config already has
`CONFIG_MODULE_COMPRESS_ZSTD=y`, `CONFIG_MODULE_COMPRESS_ALL=y` and
`CONFIG_MODULE_DECOMPRESS=y`, so `make modules_install INSTALL_MOD_STRIP=1`
reproduces the exact on-disk layout, and `rebuild-image.sh` already runs
`depmod -b "$ROOTFS" 6.12.1-msm8916`. `scripts/sync-prebuilt-overlay.sh`
would mirror a `prebuilt/kernel-6.12.1-msm8916/lib/modules/...` tree into the
overlay without changes.
So the mechanical part is a bounded build-script change plus ~11 MB of
artifacts. The reason not to do it is the benefit, not the mechanics.
### 14.5 Full module tree rebuild: benefit (it is not real)
Quantify the only thing s2idle adds on top of the current state:
- Eliminating all 29.5 SPC entries/s. Entry+exit latency of
`qcom,idle-state-spc` is 130/150 us; even at a pessimistic 75 mA during each
transition, that is ~0.3-0.5 mA of AP transition overhead. Removing every
timer IRQ, IPI and Wi-Fi/eMMC IRQ wakeup is the same order of magnitude
(<1 mA combined).
- `dpm_suspend()` would run every driver's system-sleep callback. Most of what
those would power down is already runtime-suspended (SPI, GPU, SDHCI,
remoteprocs, panel via DPMS). `wcn36xx_suspend()` would add ARP/NS/GTK
offload and `enable_irq_wake(wcn->rx_irq)` is already set at probe, so Wi-Fi
wake would work, but it only removes 2.43 RX IRQs/s.
- The dominant DSDS + Wi-Fi drain is untouched: two registered SIMs' RF, the
WCNSS/Pronto firmware, the modem bus clock, and DDR in active mode. None of
these are configurable from the kernel. Reaching 24 h on 1500 mAh needs
`<= 62.5 mA` average; a plausible current draw in this mode is ~80-120 mA,
so ~20-55 mA has to come from the modem/Wi-Fi side, not from <1 mA of AP
wakeup overhead.
The remaining config-level items (K6/K7/K13/K14) do not change that verdict:
- `CONFIG_HZ=100` changes the `HZ` macro compiled into module inlines
(`include/linux/jiffies.h`), so it is **not** ABI-safe either.
- `CONFIG_ENERGY_MODEL=y` inserts `em_pd` into `struct device`
(`include/linux/device.h`) and `CONFIG_PERF_EVENTS` /
`CONFIG_FUNCTION_GRAPH_TRACER` change `struct task_struct` — all module-visible.
ARM32 has no EAS, so `ENERGY_MODEL` buys nothing anyway.
- `CONFIG_RCU_LAZY` depends on `RCU_NOCB_CPU` and requires `rcu_nocbs=all`;
on 2 cores that adds always-running `rcuo` kthreads and trades away the idle
saving (already withdrawn as C17/K14).
- `CONFIG_PREEMPT_VOLUNTARY` / `CONFIG_HZ=100` also work against the project's
`< 2 ms` UI wakeup latency target.
- `CONFIG_SCHED_HRTICK` off and `CONFIG_CPU_IDLE_GOV_TEO=y` are genuinely
ABI-safe (the former only touches the private `kernel/sched/sched.h`), but
with no CFS bandwidth quotas and only two cpuidle states they are effectively
no-ops.
### 14.6 Verdict
**Do not rebuild the entire kernel module tree.** It is technically feasible,
but the only feature it unlocks is s2idle, which on this firmware cannot do
`mem`, cannot reach DDR self-refresh, and can save less than ~1 mA of AP
transition overhead against a ~20-55 mA deficit. It would reintroduce exactly
the class of risk that produced the unbootable `ad3461b` image (vermagic +
`struct dev_pm_info`), activate untested system-sleep callbacks for the panel,
DRM, Wi-Fi and modem remoteprocs, and conflict with the low-latency design
goal — for no measurable gain in DSDS + Wi-Fi runtime. pmaports deliberately
ships `# CONFIG_SUSPEND is not set` for this kernel.
Deep standby therefore stays shipped disabled (`/etc/bananarchy-no-deep-standby`)
and inert, and the known-good module ABI stays untouched. If PSCI
`SYSTEM_SUSPEND` ever appears in lk2nd for MSM8909, revisit K1: that is the
change that would make a full rebuild worthwhile.
### 14.7 Remaining kernel-level items, individually
| Item | Expected gain | ABI / design risk | Verdict |
|---|---|---|---|
| K1 `CONFIG_SUSPEND` + wakelocks + autosleep | <1 mA (s2idle only, no `mem`) | vermagic + `struct dev_pm_info`; untested driver sleep callbacks | Declined (see 14.3-14.6) |
| K6 `HZ=100`, `PREEMPT_VOLUNTARY`, no hrtick, TEO | <1 mA, mostly duplicate of K1 | `HZ` macro in module inlines; vermagic; latency regression | Declined |
| K7 disable ftrace/perf/kprobes/BPF-JIT/debug | ~0 when unused | `struct task_struct` layout for perf/ftrace | Declined |
| K8 remove `earlycon console=ttyMSM0` | gates one 3.686 MHz UART clock, ~0.1-1 mA | none (cmdline only), but removes the serial debug lifeline | Optional, deliberately kept |
| K9 unused input/LED classes | 0 (no LED trigger active, all LEDs off) | none | No-op, declined |
| K13 `ZRAM_DEF_COMP_LZ4` | 0 (userspace already sets `lz4`) | changes the `zram` module default | No-op, declined |
| K14 `ENERGY_MODEL` / `RCU_LAZY` | 0 | `struct device` / needs `rcu_nocbs=all` | Declined |
| K2/K3/K4/K5/K10 (DT + patch 0006) | already landed | none | Done in `ad3461b` |
| K12 panel partial updates | deferred (display corruption risk) | none | Still deferred |
| New: `wcn36xx` `listen_interval` 3 -> 5+ | cuts ~1 Wi-Fi RX IRQ/s | none (source patch), but delays inbound Wi-Fi data | Marginal, declined |
| New: `commit=` on the rootfs mount | cuts ~2 eMMC IRQs/s | userspace, not kernel; risks data loss on sudden power cut | Out of scope, noted |
| New: VM-BMS FIFO sanity clamp | 0 power, fixes a 19.2 V / `Over voltage` misreport for ~3.5 min after hard reset | none (source-only patch to `pm8916_bms_vm.c`) | Worth fixing; no rebuild needed |
### 14.8 Where the 24 h actually has to come from
With the display now dark after 5 minutes and userspace quiet, the kernel is
no longer the bottleneck. The remaining budget has to be attacked at the modem
and Wi-Fi layers:
1. **Modem idle power**: LTE eDRX / PSM via `AT+CEDRXS` / `AT+CPSMS` on
`/dev/wwan0at0` (or the QMI NAS equivalents). Two continuously registered
SIMs on LTE + GSM are the largest single drain; PSM/eDRX is the standard
way to cut it by an order of magnitude while staying reachable. This is a
modem-firmware configuration, not a kernel config option.
2. **DSDS policy**: parking the second SIM (or reducing its polling) when idle
trades DSDS availability for a large RF saving.
3. **Wi-Fi DTIM / listen interval**: AP-side DTIM and `wcn36xx`
`listen_interval` tuning can cut the 2.43 RX IRQs/s, at the cost of inbound
data latency.
4. **DDR self-refresh**: requires `mem` suspend, which needs PSCI
`SYSTEM_SUSPEND` in lk2nd. Until then `bimc_ddr_clk_src` stays at 768 MHz
and no kernel-side change can fix it.
None of these four are unlocked by rebuilding the module tree.