Files
geminux/POWER-OPTIMIZATION.md

10 KiB

Power optimization

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:

  • 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 (GEMINUX_ENABLE_CPUFREQ="yes" in 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 (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=1 allow_md1=1 timer_sec=600 in modprobe.d/geminux.conf):

  • 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

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 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: 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) 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

Managed via geminux-power-ctl / geminux-control (geminux-power-policy.c):

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 / 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

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 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); 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) + offline dispatch (30-geminux-chrony).
  • Toolkits & Storage: NO_AT_BRIDGE=1 (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.

On-device verification and fallback

Inspect live power, suspend counters, GPU rail state, and wake reasons at any time:

geminux-power-audit
geminux-power-audit --json

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:

echo 0 | doas tee /sys/module/mt6797_spm_sleep/parameters/allow_md1