Files
geminux/POWER-OPTIMIZATION.md
T

61 lines
11 KiB
Markdown

# Power optimization
Battery endurance and deep idle efficiency are first-class design requirements across the kernel, daemons, radios, display, audio, and storage stack in Geminux.
## Kernel-level optimizations
Configured in [kernel/configs/geminux-mt6797x.config](file:///home/lux/proj/geminux/kernel/configs/geminux-mt6797x.config) and built into `7.3.5-geminux`:
- **`CONFIG_HZ_100=y`**: 100 Hz tick rate cuts periodic timer interrupt overhead compared to 250 Hz / 1000 Hz kernels while remaining responsive for interactive X11 workloads.
- **`CONFIG_RCU_LAZY=y`**: Batches RCU callbacks during idle periods to extend CPU C-state residency.
- **`CONFIG_SUSPEND=y`**: Enables deep Suspend-to-RAM (`mem` / `deep`) via `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=0 timer_sec=600` in [etc/modprobe.d/geminux.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/modprobe.d/geminux.conf)) triggered on Gemini PDA lid close (`SW_LID`), battery idle timeout, or power button press. Keeping `pmic_modes=0` avoids asserting `MT6351` `VCORE` sleep voltage (`0.600 V`) while CPU0 remains powered in `WFI`, `spm_enter()` bounds silent PCM timer rollovers cleanly without `.suspend_again`, `mtk-eint` clears hardware debounce when switching wakeup pins such as `SW_LID` (`EINT5`) to edge-sensitive mode, `mtk-pmic-keys` reports `pm_wakeup_event()` on wakeup keypresses, `0011-gemini-lid-sync-filter-and-debounce.patch` tunes Hall EINT debounce to `1 ms` (keypad `10 ms`) while synchronously filtering spurious keystrokes/touches and inhibiting both matrix keypad and touchscreen whenever the lid magnet closes, and `0012-gemini-lid-wake-and-fg-taper-fix.patch` reconciles `gemini-lid` state on `PM_POST_SUSPEND` and raw-GPIO rechecks to prevent stuck `BL_CORE_SUSPENDED` / input lockouts alongside `mt6351-fuel-gauge` + `bq25890` boot zero-current OCV calibration (`POWER_SUPPLY_PROP_CALIBRATE` / `MT6351_RGS_CHRDET`), CV-taper (`win_ua`+`reg_ua`, `+1%` cap), and start-up `ADC21` sag tolerance hardening.
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Uses scheduler utilization feedback (`schedutil`) across the MT6797X tri-cluster topology instead of static `performance` governors. [etc/init.d/geminux-hwinit](file:///home/lux/proj/geminux/overlay/rootfs/etc/init.d/geminux-hwinit) loads `clk-mt6797-mcusys` and `cpufreq-dt` by default (`GEMINUX_ENABLE_CPUFREQ="yes"` in [etc/conf.d/geminux-hwinit](file:///home/lux/proj/geminux/overlay/rootfs/etc/conf.d/geminux-hwinit)) independently of experimental Cortex-A72 bring-up (`GEMINUX_ENABLE_A72="no"`), enabling `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) frequency scaling and `soc-thermal` cooling throttling.
- **`mt6797-gate-unused`**: Loaded at the end of `geminux-hwinit` (`GEMINUX_GATE_UNUSED_CLOCKS="yes"`) to gate ~25 unused bootloader peripheral leaf clocks (unused `SPI`, `UART`, `PWM`, `IRTX`, `ICUSB`, `ANC_MD32`, etc.) left enabled due to `clk_ignore_unused` while leaving active display/I2C clocks untouched.
- **Sensor IR LED gating**: `stk3310` is blacklisted in [etc/modprobe.d/geminux.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) because its probe unconditionally enables continuous ALS and proximity IR LED polling with no userspace consumer.
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y`** with `2 GiB` LZ4 `zram` swap (`etc/conf.d/zram-init`) and `vm.swappiness=100` (`etc/sysctl.d/99-geminux-power.conf`): avoids slow, power-hungry flash swap I/O on eMMC and pairs with `commit=60,noatime` mount options (`etc/fstab`).
- **`CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`** paired with `--allow-discards` in initramfs: runs optional LUKS2 `dm-crypt` (`aes-xts-plain64`) encryption using ARMv8 hardware AES Cryptography Extensions with negligible battery overhead.
## Zero-poll userspace daemons
All background system services avoid wake-up timers and polling loops:
- **`geminux-powerd`**: Sleeps indefinitely in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC` blank-screen wakeup, keyboard/touch/pointer activity), `KOBJECT_UEVENT` netlink (filtered strictly to `input` with lid-state reconciliation, `power_supply`, and `drm`), `/run/geminux/powerd.sock`, and a lazy-rearming `timerfd`; caches applied CPUfreq/profile state to avoid redundant sysfs and `/run/geminux/power-profile` rewrites; implements two-stage screensaver dimming and auto-lock/blank or suspend strictly timed from the last active user input (`dim_timeout_s` / `suspend_timeout_s`). On USB/AC (`inhibit_ac_lid`), closing the lid or timing out locks X11 and blanks the backlight cleanly without unloading CONSYS or invoking `/sys/power/state`, letting `bq25890`'s `40 s` charger watchdog stay fed without `-EBUSY` suspend thrashing. On battery, before entering `mem` `/sys/power/state`, it unloads `mt6797_consys` (and reverse dependents `btmt6797`, `radio_mt6797`, `gnss_mt6797`, `mac`) so `CONN`/`VCN*` rails power down and parks `cpu1..9` offline; when 4G `MD1` is powered and blocks SPM `mem` sleep, it drops `freeze` (`s2idle`) entirely in favor of zero-thrash `low_power_standby` (`cpu1..9` offline, `cpu0` pinned to `221 MHz` `powersave`, CONSYS unloaded, zero periodic wake timers) until lid open, input wake, or AC/HDMI attach. In hardware Airplane Mode (`Fn+F` / `geminux-power-ctl airplane on`, persisted under `/var/lib/geminux/airplane-mode`), `geminux-powerd` keeps the CONSYS Wi-Fi/BT kernel modules unloaded and places MD1 in `AT+CFUN=4` flight mode while leaving `usb0` active.
- **`geminux-statusd`**: Uses `signalfd` (`SIGUSR1`), `RTMGRP_LINK` netlink, filtered `KOBJECT_UEVENT` (`power_supply` and `net` only), `inotify`, and a minute-aligned `timerfd`; deduplicates root `WM_NAME` updates (`XStoreName`) so `dwm` never repaints when the bar text is unchanged, with zero child shell forks.
- **Display & terminal idle efficiency**: [10-geminux-gpu.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf) uses `AccelMethod "none"` + `ShadowFB "true"` + `TearFree "true"` for rotated `SSD2092` scanout, avoiding Glamor fence spin-waits, and `st` disables its cursor-blink timeout when unfocused so idle XLibre CPU usage remains near `0%`.
- **`geminux-touchd`**: Event-driven XInput 2.2 multi-touch gesture recognizer with zero polling loops.
- **`geminux-ccci-daemon`, `geminux-modem-ctl` & `geminux-imsd`**: Event-driven `epoll_wait()` over `/dev/ccci_*`, filtered `ccci` uevents, AT port, `/run/geminux/imsd.sock`, SIP/ESP sockets, and netlink; enter completely idle sleep when no modem activity is pending, and `geminux-imsd` arms its 20 ms RTP `timerfd` strictly during active calls.
- **`geminux-bt-obex`, `geminux-leds` & `geminux-lock`**: Event-driven GLib/GDBus and `epoll_wait()` + `KOBJECT_UEVENT` control without periodic polling. `geminux-leds` keeps the back AW9120 cover strip (`rgb:indicator-1..5`) off (`0 mA`) when idle or at 100% charge, lighting only `rgb:indicator-6` during active battery charging unless manually overridden. `geminux-lock` uses a `15 s` refresh interval once input is grabbed and redraws only when clock minute/date or battery status changes.
## Cluster gating and profiles
`geminux-power-ctl` (and `geminux-control`) switches between three profiles managed in [src/geminux-daemons/geminux-power-policy.c](file:///home/lux/proj/geminux/src/geminux-daemons/geminux-power-policy.c):
| Profile | Governor | A72 big cores (`cpu8..9`) | A53 LL (`policy0`) / L (`policy4`) max freq | Battery idle (dim -> lock+suspend) | AC idle (lock+blank screensaver) |
| --- | --- | --- | --- | --- | --- |
| `eco` | `schedutil` | Offline (`0`) | `715 MHz` / `962 MHz` | `60 s` -> `180 s` | `180 s` |
| `balanced` | `schedutil` | Online (`1`, `2002 MHz`) | `897 MHz` / `1209 MHz` (bat), `1547 MHz` / `1846 MHz` (AC) | `120 s` -> `300 s` | `300 s` |
| `performance` | `performance` | Online (`1`, `2600 MHz`) | `1547 MHz` / `1846 MHz` (clamped to DT `cpuinfo_max_freq`) | `180 s` (lock+blank, no suspend) | `600 s` |
All idle thresholds above are measured from the last active keyboard, touchscreen, pointer, or lid-open event (`CLOCK_MONOTONIC`) and are not reset by periodic battery `power_supply` uevents.
Closing the Gemini PDA clamshell (`SW_LID = 1`) on battery enters RAM suspend (`mem` when `MD1` is gated, or zero-thrash `low_power_standby` when `MD1` is active), unless inhibited by USB/AC power (`inhibit_ac_lid`, which locks + blanks without suspend), an active voice call (`inhibit add call`), an explicit inhibitor, or a connected external HDMI monitor (`SiI9024`).
## Audio, radios, and storage defaults
- **Audio**: PipeWire uses `default.clock.min-quantum = 1024` and `quantum = 2048` (`10-geminux-power.conf`); WirePlumber suspends idle ALSA and BlueZ nodes after `3` seconds (`50-geminux-suspend.conf`) so audio DSP clocks gate quickly.
- **Bluetooth**: BlueZ disables automatic adapter enable and fast page scan (`AutoEnable = false`, `FastConnectable = false` in [etc/bluetooth/main.conf](file:///home/lux/proj/geminux/overlay/rootfs/etc/bluetooth/main.conf)), and `geminux-hwinit` runs `rfkill block bluetooth` after loading `btmt6797`; users toggle Bluetooth on demand via `geminux-net`.
- **Wi-Fi & NTP**: NetworkManager configures `wifi.powersave = 2` (`10-geminux-power.conf`) to keep CONSYS Wi-Fi awake while associated so GTK rekeys, ARP, and DNS never stall; `geminux-powerd` powers down CONSYS cleanly across system suspend. [etc/chrony/sources.d/10-geminux.sources](file:///home/lux/proj/geminux/overlay/rootfs/etc/chrony/sources.d/10-geminux.sources) caps NTP pool peers (`maxsources 2`) and lengthens polling (`minpoll 10 maxpoll 14`), paired with an offline hook on `down|vpn-down` in [30-geminux-chrony](file:///home/lux/proj/geminux/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony).
- **GTK / Qt / Tk / XSETTINGS / D-Bus**: [etc/profile.d/10-geminux-env.sh](file:///home/lux/proj/geminux/overlay/rootfs/etc/profile.d/10-geminux-env.sh) exports `NO_AT_BRIDGE=1` so GTK/Qt/`webarchy` never auto-activate AT-SPI accessibility bridge daemons and sets `QT_QPA_PLATFORMTHEME=qt6ct:gtk3` for zero-daemon-overhead Qt5/Qt6 theme routing; `geminux-session` runs `xsettingsd` as an event-driven X11 `XSETTINGS` daemon (`SIGHUP` on theme switch) with zero polling timers, `gtkTtk` reacts purely to X11 `RESOURCE_MANAGER` `PropertyNotify` events without polling, and `dconf-service` activates over session D-Bus only when `gsettings` writes `color-scheme`.
- **Storage**: `noatime,commit=60` in `etc/fstab` alongside `vm.dirty_writeback_centisecs=1500` reduces eMMC write amplification and wakes; microSD mounts at `/media/sdcard` likewise mount with `noatime` and rely purely on `eudev` hotplug events (`95-geminux-sdcard.rules`) with zero background polling when idle or empty.
## Auditing on device
Run the bundled C11 audit utility at any time:
```sh
geminux-power-audit
geminux-power-audit --json
```
It prints the live power profile, battery capacity/voltage/current, online CPU count (including A72 cluster gating status), CPUfreq governor, `policy0`/`policy4` max frequency caps, Bluetooth `rfkill` soft-block status, ZRAM compression algorithm, and supported `/sys/power/mem_sleep` modes. Live idle current draw and multi-hour standby battery endurance benchmarks must be measured on physical Gemini PDA (x27) hardware after flashing.