Package release ZIPs, streamline docs, and backport X11 DPMS/lock fixes

- Streamline README, INSTALL, MANUAL, ARCHITECTURE, and POWER-OPTIMIZATION docs
- Add release ZIP packager (package-image.sh, scripts/package-release-zip.py, rebuild-image.sh --package) with sanitized rootfs, SHA256SUMS, and FLASH-INSTRUCTIONS.txt
- Add automatic offline MT6797 firmware ext4 injection in flash-mtk.py and scripts/extract-vendor-fw.py
- Backport X11 DPMS wake + XResetScreenSaver in geminux-powerd and _GEMINUX_LOCK_READY + grab-first sync in geminux-lock, rebuild aarch64 prebuilts, and expand tests
This commit is contained in:
Luxferre committed 2026-11-28 09:18:51 +02:00
1 parent 5472d4273a
commit 180d0a91e6
18 files changed
+1242 -480

No files matched your search

+32 -41
View File
@@ -1,78 +1,69 @@
# Power optimization
Battery endurance and reliable deep-sleep recovery are designed across the kernel, system daemons, radios, display, audio, and storage stack in Geminux.
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.
## Kernel-level optimizations
Configured in [kernel/configs/geminux-mt6797x.config](kernel/configs/geminux-mt6797x.config) and built into `7.3.5-geminux`:
Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/configs/geminux-mt6797x.config):
- **`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.
- **`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`).
## 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)):
`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)):
- **`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.
- **`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.
## 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`:
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`:
- **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`).
- **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.
### 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.
- **`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).
## 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):
Managed via `geminux-power-ctl` / `geminux-control` ([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) |
| Profile | Governor | A72 (`cpu8..9`) | A53 LL (`policy0`) / L (`policy4`) max freq | Battery idle (dim -> suspend) | AC idle (lock+blank) |
| --- | --- | --- | --- | --- | --- |
| `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` |
| `balanced` | `schedutil` | Online (`1`, `2002 MHz`) | `897` / `1209 MHz` (bat), `1547` / `1846 MHz` (AC) | `120 s` -> `300 s` | `300 s` |
| `performance` | `performance` | Online (`1`, `2600 MHz`) | `1547 MHz` / `1846 MHz` (clamped to DT max) | `180 s` (lock+blank only) | `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`).
Idle timers count strictly from the last user input (`CLOCK_MONOTONIC`), ignoring periodic battery uevents. Lid close (`SW_LID = 1`) on battery suspends unless inhibited by AC (`inhibit_ac_lid`), an active call, a manual inhibitor, or 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.
- **Audio**: PipeWire `min-quantum = 1024`, `quantum = 2048` (`10-geminux-power.conf`); WirePlumber suspends idle nodes after `3 s`.
- **Bluetooth**: `AutoEnable = false`, `FastConnectable = false` ([etc/bluetooth/main.conf](overlay/rootfs/etc/bluetooth/main.conf)); soft-blocked at boot.
- **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
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.
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.