79 lines
10 KiB
Markdown
79 lines
10 KiB
Markdown
# Power optimization
|
|
|
|
Battery endurance and reliable deep-sleep recovery are designed across the kernel, system daemons, radios, display, audio, and storage stack in Geminux.
|
|
|
|
## Kernel-level optimizations
|
|
|
|
Configured in [kernel/configs/geminux-mt6797x.config](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/1000 Hz kernels while keeping interactive X11 responsiveness high.
|
|
- **`CONFIG_RCU_LAZY=y`**: Batches idle RCU callbacks to extend CPU C-state residency.
|
|
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Drives scheduler-guided frequency scaling (`schedutil`) across the MT6797X tri-cluster CPU. [geminux-hwinit](overlay/rootfs/etc/init.d/geminux-hwinit) loads `clk-mt6797-mcusys` and `cpufreq-dt` (`GEMINUX_ENABLE_CPUFREQ="yes"` in [conf.d/geminux-hwinit](overlay/rootfs/etc/conf.d/geminux-hwinit)) independently of experimental Cortex-A72 enablement (`GEMINUX_ENABLE_A72="no"`), providing `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) scaling and `soc-thermal` throttling.
|
|
- **`mt6797-gate-unused`**: Loaded at the end of `geminux-hwinit` (`GEMINUX_GATE_UNUSED_CLOCKS="yes"`) to gate ~25 unused bootloader peripheral leaf clocks (`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 [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) so its ALS/proximity IR LED does not continuously poll without a consumer.
|
|
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y`**: Pairs `2 GiB` LZ4 `zram` swap (`etc/conf.d/zram-init`) with `vm.swappiness=100` (`etc/sysctl.d/99-geminux-power.conf`) and `commit=60,noatime` mounts (`etc/fstab`) to minimize power-hungry eMMC flash swap writes.
|
|
- **`CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`**: Accelerates optional LUKS2 `dm-crypt` (`aes-xts-plain64`) with ARMv8 Cryptography Extensions (`--allow-discards` enabled in initramfs) for negligible encryption overhead.
|
|
|
|
## Deep sleep (`mem`) and wakeup reliability
|
|
|
|
`CONFIG_SUSPEND=y` enables Suspend-to-RAM (`mem` / `deep`) via `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=0 timer_sec=600` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf)):
|
|
|
|
- **`pmic_modes=0` & clean SPM timers**: Keeps `MT6351` from dropping `VCORE` to `0.600 V` sleep voltage while CPU0 remains in `WFI`.
|
|
- **Wake IRQ & resume hardening (`0008`)**: Bounds `spm_enter()` PCM timer rollovers cleanly without `.suspend_again`, clears `mtk-eint` hardware debounce when arming edge wakeup pins (`SW_LID` / `EINT5`), and calls `pm_wakeup_event()` from `mtk-pmic-keys`.
|
|
- **Hall lid filtering & debounce (`0011`)**: Tunes Hall EINT debounce to `1 ms` and matrix keypad debounce to `10 ms`, synchronously filtering spurious keystrokes/touches and inhibiting both keypad and touchscreen whenever the lid magnet closes.
|
|
- **Post-suspend lid reconciliation & fuel-gauge accuracy (`0012`)**: Reconciles `gemini-lid` state on `PM_POST_SUSPEND` and raw-GPIO rechecks to avoid stuck `BL_CORE_SUSPENDED`/input lockouts, and pairs `mt6351-fuel-gauge` + `bq25890` zero-current boot OCV calibration (`POWER_SUPPLY_PROP_CALIBRATE` / `MT6351_RGS_CHRDET`) with `win_ua`+`reg_ua` CV-taper validation, `+1%` step caps, and `180 mV` start-up `ADC21` sag tolerance.
|
|
- **PMIC wake IRQ timing & SPM safety backstops (`0013`)**: Moves MT6397/MT6351 PMIC wake IRQ masking (`mt6397_irq_suspend`/`mt6397_irq_resume`) from `PM_SUSPEND_PREPARE` into `LATE_SYSTEM_SLEEP_PM_OPS` so all child drivers' `enable_irq_wake()` settings are already armed before deep sleep, and hardens `mt6797-spm-sleep` `s.sleep` with `WAKE_PCM_WDT`, `pcm_wdt`, `im_wait` (`1000 us`), and a `5000 ms` `cntp` physical timer backstop (`100 ms` on `s.sodi`) so CPU0 cannot wedge indefinitely on an overnight suspend.
|
|
|
|
## Zero-poll userspace daemons
|
|
|
|
All background daemons sleep in event loops with no periodic polling timers:
|
|
|
|
### `geminux-powerd`
|
|
|
|
Uses `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-rearming `timerfd`:
|
|
|
|
- **USB/AC policy (`inhibit_ac_lid`)**: Closing the lid or timing out locks X11 and blanks the backlight without unloading CONSYS or invoking `/sys/power/state`, keeping `bq25890`'s `40 s` charger watchdog fed without `-EBUSY` suspend thrash.
|
|
- **Battery `mem` vs. `low_power_standby`**: Before `mem` sleep, unloads `mt6797_consys` (and reverse dependents `btmt6797`, `radio_mt6797`, `gnss_mt6797`, `mac`) so `CONN`/`VCN*` rails power down and offlines `cpu1..9`. When 4G `MD1` is powered and blocks SPM `mem` sleep, uses zero-thrash `low_power_standby` (`cpu1..9` offline, `cpu0` pinned to `221 MHz` `powersave`, CONSYS unloaded, never `freeze`/`s2idle`).
|
|
- **Wakeup filtering & quiet open-lid re-suspend**: Polls post-resume input/lid events (`90 ms`) even when the lid is open; only a `closed -> open` lid transition, real `EV_KEY`/`EV_REL`/`EV_ABS` activity, or USB/AC attach triggers a desktop wake. Internal timer wakes in open-lid `IDLE_STAGE_LOCKED_BLANK` on battery re-suspend quietly (`quiet_timer_resleep`) without reloading CONSYS or enabling the backlight.
|
|
- **Persisted hardware Airplane Mode**: `Fn+F` / `geminux-power-ctl airplane on` persists `/var/lib/geminux/airplane-mode`, keeps CONSYS Wi-Fi/BT modules unloaded, and puts MD1 into `AT+CFUN=4` while leaving `usb0` active.
|
|
- **Zero-thrash sysfs caching**: Caches applied CPUfreq/profile state to skip redundant sysfs writes, and measures idle timers strictly from the last user input (`CLOCK_MONOTONIC`).
|
|
|
|
### Supporting daemons & X11 efficiency
|
|
|
|
- **`geminux-statusd`**: `epoll` over `signalfd` (`SIGUSR1`), `RTMGRP_LINK`/`RTMGRP_IPV4_IFADDR`, `KOBJECT_UEVENT` (`power_supply`, `net`), `inotify`, and minute-aligned `timerfd`; deduplicates root `WM_NAME` updates (`XStoreName`) with zero child shell forks.
|
|
- **Display & terminal**: [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf) uses `AccelMethod "none"` + `ShadowFB "true"` + `TearFree "true"` to eliminate Glamor fence spin-waits, and `st` disables its cursor-blink timer while unfocused.
|
|
- **`geminux-touchd`**: Event-driven XInput 2.2 gesture engine with zero polling.
|
|
- **Modem & IMS**: `geminux-ccci-daemon`, `geminux-modem-ctl`, and `geminux-imsd` sleep in `epoll_wait()`, arming `geminux-imsd`'s 20 ms RTP `timerfd` only during active voice calls.
|
|
- **`geminux-bt-obex`, `geminux-leds` & `geminux-lock`**: Pure event-driven GLib/GDBus and `epoll` + uevent operation; `geminux-leds` keeps `rgb:indicator-1..5` off (`0 mA`) when idle or at 100%, lighting only `rgb:indicator-6` while actively charging; `geminux-lock` uses a `15 s` refresh once grabbed and redraws only on clock or battery change.
|
|
|
|
## Cluster gating and profiles
|
|
|
|
`geminux-power-ctl` and `geminux-control` switch between three profiles defined in [src/geminux-daemons/geminux-power-policy.c](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 run on `CLOCK_MONOTONIC` from the last active keyboard, touchscreen, pointer, or lid-open event and are never reset by periodic `power_supply` uevents. Closing the clamshell (`SW_LID = 1`) on battery enters RAM sleep (`mem` or zero-thrash `low_power_standby`) unless inhibited by USB/AC (`inhibit_ac_lid`), an active call (`inhibit add call`), an explicit inhibitor, or connected HDMI (`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/BlueZ nodes after `3 s` (`50-geminux-suspend.conf`) so audio DSP clocks gate quickly.
|
|
- **Bluetooth**: BlueZ sets `AutoEnable = false` and `FastConnectable = false` in [etc/bluetooth/main.conf](overlay/rootfs/etc/bluetooth/main.conf), and `geminux-hwinit` soft-blocks Bluetooth at boot until enabled in `geminux-net`.
|
|
- **Wi-Fi & NTP**: NetworkManager keeps `wifi.powersave = 2` (`10-geminux-power.conf`) so associated WLAN never drops GTK rekeys or DNS; `geminux-powerd` powers down CONSYS across suspend. [10-geminux.sources](overlay/rootfs/etc/chrony/sources.d/10-geminux.sources) limits Chrony pools (`maxsources 2`, `minpoll 10 maxpoll 14`) with an offline hook in [30-geminux-chrony](overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony).
|
|
- **GTK / Qt / Tk / XSETTINGS**: [10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh) exports `NO_AT_BRIDGE=1` (disabling unused AT-SPI bridges) and `QT_QPA_PLATFORMTHEME=qt6ct:gtk3`; `xsettingsd` (`SIGHUP` reload), `gtkTtk` (`XA_RESOURCE_MANAGER` `PropertyNotify`), and portal-free `dconf` (`ADW_DISABLE_PORTAL=1`) operate without polling loops.
|
|
- **Storage**: `noatime,commit=60` in `etc/fstab` and `vm.dirty_writeback_centisecs=1500` cut eMMC wakeups; microSD mounts at `/media/sdcard` use `noatime` and pure `eudev` hotplug events (`95-geminux-sdcard.rules`) with zero idle polling.
|
|
|
|
## Auditing on device
|
|
|
|
Inspect live power policy and hardware state on the Gemini PDA at any time:
|
|
|
|
```sh
|
|
geminux-power-audit
|
|
geminux-power-audit --json
|
|
```
|
|
|
|
Outputs active profile, battery capacity/voltage/current, online CPUs (including A72 cluster state), CPUfreq governor, `policy0`/`policy4` max frequencies, Bluetooth `rfkill` state, ZRAM algorithm, and `/sys/power/mem_sleep` modes. Measure actual multi-hour standby battery endurance and idle current draw directly on physical x27 hardware after flashing.
|