Fix deep-sleep battery drainers, enable MD1 mem suspend, and update docs

This commit is contained in:
Luxferre committed 2026-11-28 10:38:56 +02:00
1 parent 180d0a91e6
commit 29314ca9e6
20 files changed
+996 -75

No files matched your search

+44 -23
View File
@@ -1,44 +1,59 @@
# Power optimization
Battery endurance and reliable deep-sleep recovery span kernel configuration, suspend/wake IRQ handling, zero-poll daemons, CPU cluster gating, audio, radios, and storage in Geminux.
Geminux tunes the kernel, hardware power rails, radios, and daemons for cool idle operation and multi-day closed-lid standby on the Gemini PDA's `4268 mAh` battery.
## Standby modes and targets
| Mode (lid closed on battery) | Endurance target (max avg draw) | Active hardware & wake path |
| --- | --- | --- |
| **Airplane Mode ON** | **>= 72 h** (`<= 59 mA` avg) | `MD1` powered off (`stage=0`), CONSYS Wi-Fi/BT unloaded, Panfrost `VGPU`/LDOs/`MFGPLL` off, TCXO gated in SPM `mem` sleep; wakes on Hall lid switch (`SW_LID`), power key, USB attach, or internal `600 s` PCM timer rollover |
| **Airplane Mode OFF** | **>= 48 h** (`<= 89 mA` avg) | CONSYS unloaded, GPU rails off, 4G `MD1` stays in LTE DRX idle while AP enters SPM `mem` sleep (`allow_md1=1`); RF LDOs (`VTCXO28`, `VRF18`, `VRF12`) use `SRCLKEN0` low-IQ mode; incoming calls/SMS/SIP INVITEs wake AP via `CCIF0`/`CLDMA`/`MD1_WDT` |
*Actual standby life depends on physical cell health, signal strength / carrier LTE DRX interval, and SIM configuration.*
## Kernel-level optimizations
Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/configs/geminux-mt6797x.config):
- **`CONFIG_HZ_100=y` & `CONFIG_RCU_LAZY=y`**: Cuts timer interrupt overhead vs. 250/1000 Hz kernels and batches idle RCU callbacks for deeper CPU C-state residency.
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Enables `schedutil` DVFS via `clk-mt6797-mcusys` + `cpufreq-dt` loaded by [geminux-hwinit](overlay/rootfs/etc/init.d/geminux-hwinit) (`GEMINUX_ENABLE_CPUFREQ="yes"` in [conf.d/geminux-hwinit](overlay/rootfs/etc/conf.d/geminux-hwinit)), scaling `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) independently of Cortex-A72 bring-up (`GEMINUX_ENABLE_A72="no"`).
- **`mt6797-gate-unused`**: Gates ~25 unused bootloader leaf clocks (`SPI`, `UART`, `PWM`, `IRTX`, `ICUSB`, `ANC_MD32`, etc.) left on by `clk_ignore_unused`.
- **Sensor IR LED gating**: Blacklists `stk3310` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) to stop unconsumed ALS/proximity IR polling.
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y` & `CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`**: `2 GiB` LZ4 `zram` (`vm.swappiness=100`) avoids eMMC flash swap writes; ARMv8 AES-CE accelerates optional LUKS2 (`--allow-discards`).
- **`CONFIG_HZ_100=y` & `CONFIG_RCU_LAZY=y`**: Cuts periodic timer interrupts compared to 250/1000 Hz kernels and batches idle RCU callbacks for deeper CPU C-state residency.
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Drives `schedutil` DVFS via `clk-mt6797-mcusys` + `cpufreq-dt` loaded by [geminux-hwinit](overlay/rootfs/etc/init.d/geminux-hwinit) (`GEMINUX_ENABLE_CPUFREQ="yes"` in [conf.d/geminux-hwinit](overlay/rootfs/etc/conf.d/geminux-hwinit)), scaling `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) without waking the Cortex-A72 cluster (`GEMINUX_ENABLE_A72="no"`).
- **`mt6797-gate-unused`**: Gates ~25 unused bootloader leaf clocks (`SPI`, `UART`, `PWM`, `IRTX`, `ICUSB`, `ANC_MD32`, etc.) left running under `clk_ignore_unused`.
- **Sensor IR LED gating**: Blacklists `stk3310` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) to prevent unconsumed ALS/proximity IR polling.
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y` & `CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`**: Uses `2 GiB` LZ4 `zram` (`vm.swappiness=100`) instead of eMMC flash swap, with ARMv8 AES-CE acceleration for optional LUKS2 (`--allow-discards`).
## Deep sleep (`mem`) and wakeup reliability
`CONFIG_SUSPEND=y` drives Suspend-to-RAM (`mem`) through `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=0 timer_sec=600` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf)):
`CONFIG_SUSPEND=y` drives Suspend-to-RAM (`mem`) through `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=1 allow_md1=1 timer_sec=600` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf)):
- **`pmic_modes=0`**: Prevents `MT6351` from dropping `VCORE` to `0.600 V` while CPU0 remains in `WFI`.
- **SPM & wake IRQ hardening (`0008`)**: Bounds `spm_enter()` PCM timer rollovers without `.suspend_again`, clears `mtk-eint` debounce on edge wakeups (`SW_LID`/`EINT5`), and fires `pm_wakeup_event()` from `mtk-pmic-keys`.
- **Hall lid filtering & debounce (`0011`)**: Applies `1 ms` Hall EINT / `10 ms` keypad debounce, synchronously filtering spurious inputs and inhibiting keypad + touch when closed.
- **Lid resume & fuel gauge (`0012`)**: Reconciles `gemini-lid` state via `PM_POST_SUSPEND` + raw-GPIO rechecks (preventing stuck `BL_CORE_SUSPENDED`/input lockouts), and improves `mt6351-fuel-gauge` + `bq25890` zero-current boot OCV, CV-taper validation, `+1%` step caps, and `180 mV` `ADC21` sag tolerance.
- **PMIC wake IRQ order & SPM backstops (`0013`)**: Moves `mt6397_irq_suspend`/`mt6397_irq_resume` from `PM_SUSPEND_PREPARE` into `LATE_SYSTEM_SLEEP_PM_OPS` so child `enable_irq_wake()` settings arm cleanly before deep sleep, and adds `WAKE_PCM_WDT`, `pcm_wdt`, `im_wait` (`1000 us`), and a `5000 ms` `cntp` physical timer backstop (`100 ms` on `s.sodi`) on `mt6797-spm-sleep` `s.sleep` to prevent unrecoverable overnight hangs.
- **PMIC sleep modes & TCXO hardware gating (`0014`)**: Re-enables `pmic_modes=1` so `TOP_CON` BIT(6) gates the 26 MHz TCXO whenever `SRCLKEN0` drops low, bucks (`VCORE`/`VGPU`/`VS1`/`VS2`) step down via `VSLEEP_EN`, and six LDOs enter SRCLKEN0 low-IQ mode—while clamping `VCORE` slot `s.slots[7]` (`MT6351_VCORE_CON6`) to `0x10` (`0.700 V`) so CPU0 never browns out in `WFI`.
- **MD1 cellular `mem` suspend (`0014`)**: Enables `allow_md1=1` so closed-lid standby enters true SPM `mem` sleep even while 4G `MD1` is booted (SODI still refuses active MD1):
- Arms `WAKE_CCIF0` (`BIT(8)`), `WAKE_MD1_WDT` (`BIT(25)`), and `WAKE_CLDMA` (`BIT(26)`) dynamically when `MD1` is active, and exposes the latest wakeup bitmask via `last_wake_r12`.
- Enables `MT6351_LDO_MODE_CTRL_BIT` (`SRCLKEN0` low-IQ mode) on `VTCXO28`/`VRF18`/`VRF12` without cutting RF transceiver power.
- Guards pending `rx_work` and unread RX GPDs in `mt6797_ccci_suspend()`, restores/restarts RX `SO` rings in `mt6797_ccci_resume()`, and raises `pm_wakeup_event()` to `3000 ms` on CLDMA/CCIF interrupts.
- **Panfrost VGPU / LDO / MFGPLL suspend rail-off (`0014`)**: Once all four GPU core domains are runtime-suspended, `panfrost_device_suspend()` releases OPP/regulator references alongside `mt->vgpu` (shutting off external `rt5735_vgpu`), clears `MT6797_GPULDO_EN` (`0x1ff -> 0`), and parks `mfg-sel` on `clk26m` to power off `MFGPLL`, restoring in vendor LDO → `vgpu` → `clk_set_rate` → OPP order on resume.
- **CCCI MD1 cold-boot & flight-mode gating (`0014`)**: `mt6797_ccci_power_off()` and cold-boot `stage=0` re-gate `INFRA_CG0_MD_MASK`/`INFRA_CG1_MD_MASK`, set `C2K_LTE_LS_ISO_BIT` and `MD1_EXT_BUCK_ISO_BIT`, clear `MDPLL1` 26 MHz clock bits, and ensure `SPM_MD1_PWR_CON` is powered down so Airplane Mode leaks zero modem power.
- **SPM, Hall lid, PMIC IRQ & fuel-gauge hardening (`0008`, `0011`, `0012`, `0013`)**: Bounds `spm_enter()` PCM rollovers, clears `mtk-eint` debounce across wakeups, debounces Hall `SW_LID` (`1 ms`) / keypad (`10 ms`), reconciles `gemini-lid` on `PM_POST_SUSPEND`, moves `mt6397_irq_suspend`/`resume` to `LATE_SYSTEM_SLEEP_PM_OPS`, adds `WAKE_PCM_WDT` + a `5000 ms` `cntp` safety backstop, and stabilizes `mt6351-fuel-gauge` + `bq25890` zero-current OCV/taper calibration.
## Zero-poll userspace daemons
### `geminux-powerd`
Sleeps in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC`), filtered `KOBJECT_UEVENT` netlink (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and a lazy `timerfd`:
Starts `after modules geminux-hwinit geminux-ccci` and waits in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC`), filtered `KOBJECT_UEVENT` netlink (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and a lazy `timerfd`:
- **USB/AC policy (`inhibit_ac_lid`)**: Locks/blanks without unloading CONSYS or invoking `/sys/power/state`, keeping `bq25890`'s `40 s` watchdog fed without `-EBUSY` suspend thrash.
- **Battery `mem` vs. `low_power_standby`**: Unloads `mt6797_consys` (+ dependents) and offlines `cpu1..9` before `mem` sleep; if 4G `MD1` blocks `mem`, holds zero-thrash `low_power_standby` (`cpu0 @ 221 MHz` `powersave`, never `freeze`/`s2idle`).
- **Wakeup filtering & quiet open-lid re-suspend**: Polls post-resume events (`90 ms`) even with the lid open so only `closed -> open` lid events, genuine `EV_KEY`/`EV_REL`/`EV_ABS` activity, or USB/AC attach wake the session; internal timer wakes during open-lid `IDLE_STAGE_LOCKED_BLANK` re-suspend quietly (`quiet_timer_resleep`) without reloading CONSYS or waking the backlight.
- **X11 DPMS wake & lock sync**: Unblanking runs `DPMSForceLevel(..., DPMSModeOn)` + `XResetScreenSaver()` in a privilege-dropped child so X11/HDMI outputs never stay blanked across S3 or lid events; pre-suspend locking waits up to `1800 ms` for `geminux-lock` to draw, grab input, and publish `_GEMINUX_LOCK_READY`.
- **Persisted state & caching**: Persists Airplane Mode (`/var/lib/geminux/airplane-mode`) and caches CPUfreq/profile writes.
- **USB/AC policy (`inhibit_ac_lid`)**: Locks and blanks (`bl_power=4` + `DPMSModeOff`) without unloading CONSYS or invoking `/sys/power/state`, keeping `bq25890`'s `40 s` watchdog fed without `-EBUSY` thrash.
- **Battery `mem` & standby backoff**: Enters `mem` suspend whenever `md1/stage == 0` or `allow_md1=Y` (falling back to `low_power_standby` for active MD1 only if `allow_md1=N`). Before suspending, it reaps any in-flight `radio_worker_pid`, unloads CONSYS, and ensures `md1/stage == 0` when Airplane Mode is enabled; transient `-EBUSY` results trigger exponential retries (`3s -> 10s -> 30s -> 60s`) and immediate `SIGCHLD` re-arming when `radio_worker_pid` completes.
- **Wakeup filtering & modem-wake grace**: Polls post-resume input events (`90 ms`) BEFORE onlining secondary CPUs and checks `/sys/module/mt6797_spm_sleep/parameters/last_wake_r12`:
- Internal `600 s` PCM timer rollovers (`quiet_timer_resleep`) keep `cpu1..7` offline and re-enter `mem` sleep after `300 ms` without waking Xorg or reloading CONSYS.
- Modem wakes (`CCIF0`/`MD1_WDT`/`CLDMA`) grant a `3500 ms` closed-lid grace window so `ModemManager`/`geminux-modem-ctl`/`geminux-imsd` can assert `inhibit add call`; once the call ends (`inhibit del`), suspend re-arms after `1000 ms`.
- Only `closed -> open` lid transitions, genuine user input, or AC attach wake the session.
- **X11 DPMS blank/wake & lock sync**: Blanking sets `brightness=0`, `bl_power=4`, and `DPMSModeOff`; unblanking calls `DPMSForceLevel(..., DPMSModeOn)` + `XResetScreenSaver()` in a `500 ms` timeout-capped privilege-dropped child; pre-suspend locking waits up to `1800 ms` for `geminux-lock` to publish `_GEMINUX_LOCK_READY`.
### Supporting daemons & X11 efficiency
- **`geminux-statusd`**: `epoll` (`signalfd`, netlink, filtered uevents, `inotify`, minute-aligned `timerfd`); deduplicates `WM_NAME` updates with zero shell forks.
- **Display & `st`**: `ShadowFB` + `TearFree` (`AccelMethod "none"` in [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf)) eliminates Glamor spin-waits; `st` stops cursor blink timers when unfocused.
- **Input, Audio, Modem, LEDs & Lock**: `geminux-touchd`, `geminux-ccci-daemon`, `geminux-modem-ctl`, `geminux-imsd` (20 ms RTP `timerfd` armed only mid-call), `geminux-bt-obex`, `geminux-leds` (AW9120 strip `0 mA` idle/100%, `rgb:indicator-6` while charging), and `geminux-lock` (`15 s` refresh, diff-checked).
- **`geminux-statusd`**: Event-driven `epoll` (`signalfd`, netlink, filtered uevents, `inotify`, minute-aligned `timerfd`); deduplicates `WM_NAME` updates with zero shell forks.
- **`geminux-modem-ctl`**: Sleeps in `epoll_wait(..., -1)` via `inotify` on `/run/geminux` (`airplane-mode`, `ims-state`) with no `dbus-monitor` or retry timer while Airplane Mode is active.
- **Display & `st`**: `ShadowFB` + `TearFree` (`AccelMethod "none"` in [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf)) avoids Glamor spin-waits; `st` pauses cursor blink timers when unfocused.
- **Input, Audio, Modem, LEDs & Lock**: `geminux-touchd`, `geminux-ccci-daemon`, `geminux-imsd` (`20 ms` RTP `timerfd` armed only mid-call), `geminux-bt-obex`, `geminux-leds` (AW9120 strip `0 mA` idle/100%, amber `rgb:indicator-6` while charging), and `geminux-lock` (`15 s` clock refresh, diff-checked).
## Cluster gating and profiles
@@ -59,11 +74,17 @@ Idle timers count strictly from the last user input (`CLOCK_MONOTONIC`), ignorin
- **Wi-Fi & NTP**: `wifi.powersave = 2` prevents associated CONSYS key/DNS stalls; Chrony uses `maxsources 2`, `minpoll 10 maxpoll 14` ([10-geminux.sources](overlay/rootfs/etc/chrony/sources.d/10-geminux.sources)) + offline dispatch ([30-geminux-chrony](overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony)).
- **Toolkits & Storage**: `NO_AT_BRIDGE=1` ([10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh)) avoids idle AT-SPI daemons; `noatime,commit=60` and `dirty_writeback_centisecs=1500` cut eMMC wakes; `/media/sdcard` mounts `noatime` purely via `eudev` hotplug.
## Auditing on device
## On-device verification and fallback
Inspect live power, suspend counters, GPU rail state, and wake reasons at any time:
```sh
geminux-power-audit
geminux-power-audit --json
```
Reports live profile, battery stats, online CPUs, governors, frequency caps, Bluetooth `rfkill` state, ZRAM algorithm, and `/sys/power/mem_sleep`. Actual idle current draw and overnight endurance must be measured on physical hardware.
Look for `"spm_pmic_modes":"Y"`, `"spm_allow_md1":"Y"`, incrementing `"suspend_success"` and `"gpu_rail_suspends"`, `"vgpu_state":"disabled"`, `"last_failed_dev":"none"`, and standby current draw (`current_ua`) after a closed-lid battery sleep window. If you ever need to test cellular fallback without MD1 `mem` suspend, disable `allow_md1` at runtime:
```sh
echo 0 | doas tee /sys/module/mt6797_spm_sleep/parameters/allow_md1
```