Fix battery drain sources across suspend, CPUfreq, radios, and daemons
This commit is contained in:
1 parent
4b36aa0726
commit
7f3b3c2c0c
24 files changed
+475
-52
No files matched your search
+2
-2
@@ -26,8 +26,8 @@ Geminux combines a custom-patched Linux `7.3.5` kernel, pure-Linux MTK flasher,
|
||||
- **`libgemui.so`** ([src/libgemui/](file:///home/lux/proj/geminux/src/libgemui)): Double-buffered Cairo + Pango/HarfBuzz Xlib toolkit polling X11 events, `SIGUSR1` self-pipe for instant `.Xresources` reloads, dynamic timers, `MSG_NOSIGNAL`/drained Unix socket IPC (`gemui_unix_cmd`), and non-blocking extra FDs (such as V4L2 or `inotify`).
|
||||
- **11 landscape HiDPI applications** ([src/geminux-apps/](file:///home/lux/proj/geminux/src/geminux-apps)): `geminux-control`, `geminux-audio`, `geminux-datetime`, `geminux-net` (5 tabs including active WLAN persistence and `DNS` configuration), `geminux-dialer`, `geminux-callscreen`, `geminux-sms`, `geminux-contacts`, `geminux-camera` (MT6797 Media Controller pipeline + 10-bit Bayer demosaic/AWB software ISP), `geminux-themes`, and `geminux-lock`.
|
||||
- **Zero-poll C11 daemons** ([src/geminux-daemons/](file:///home/lux/proj/geminux/src/geminux-daemons)):
|
||||
- `geminux-powerd` — `epoll` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, keyboard/touch/pointer activity), `KOBJECT_UEVENT`, `/run/geminux/powerd.sock`, and `timerfd`; drives two-stage screensaver idle dim/lock/suspend timed from the last active user input and resolves the active desktop user dynamically from UID `10000`.
|
||||
- `geminux-statusd` — `epoll` over `signalfd` (`SIGUSR1`), `RTMGRP_LINK`/`RTMGRP_IPV4_IFADDR`, `KOBJECT_UEVENT`, `inotify`, and minute-aligned `timerfd`; updates root `WM_NAME` with zero child shell forks.
|
||||
- `geminux-powerd` — `epoll` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, keyboard/touch/pointer activity), filtered `KOBJECT_UEVENT` (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and `timerfd`; caches CPUfreq/profile writes, tears down/reloads `mt6797_consys` across suspend (`-EBUSY` workaround), drives two-stage screensaver idle dim/lock/suspend timed from the last active user input, and resolves the active desktop user dynamically from UID `10000`.
|
||||
- `geminux-statusd` — `epoll` over `signalfd` (`SIGUSR1`), `RTMGRP_LINK`/`RTMGRP_IPV4_IFADDR`, filtered `KOBJECT_UEVENT` (`power_supply`, `net`), `inotify`, and minute-aligned `timerfd`; deduplicates root `WM_NAME` updates with zero child shell forks.
|
||||
- `geminux-touchd` — XInput 2.2 multi-touch gesture daemon (2-finger tap/hold right-click, 3-finger middle-click, 2-finger scroll).
|
||||
- `geminux-leds` — AW9120 back cover RGB controller driving `rgb:indicator-1..5` (default off when idle/full; `rgb:indicator-6` amber while charging; persistent manual override; `SIGPIPE`-safe socket server at `/run/geminux/leds.sock`).
|
||||
- `geminux-ccci-daemon` — `epoll` over `/dev/ccci_*`, uevents, and `/run/geminux/ccci.sock`; idles cleanly if MD firmware is absent.
|
||||
|
||||
+15
-12
@@ -9,7 +9,9 @@ Configured in [kernel/configs/geminux-mt6797x.config](file:///home/lux/proj/gemi
|
||||
- **`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`) triggered on Gemini PDA lid close (`SW_LID`) or power button press.
|
||||
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Uses scheduler utilization feedback (`schedutil`) across the MT6797X tri-cluster (Cortex-A53 + Cortex-A72) topology instead of static `performance` governors.
|
||||
- **`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.
|
||||
|
||||
@@ -17,21 +19,21 @@ Configured in [kernel/configs/geminux-mt6797x.config](file:///home/lux/proj/gemi
|
||||
|
||||
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`, keyboard/touch/pointer activity), `KOBJECT_UEVENT` netlink (AC charger/HDMI hotplug), `/run/geminux/powerd.sock`, and a lazy-rearming `timerfd`; 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`).
|
||||
- **`geminux-statusd`**: Uses `signalfd` (`SIGUSR1`), `RTMGRP_LINK` netlink, `inotify`, and a minute-aligned `timerfd` so the DWM status bar wakes only on actual network/power/modem changes or minute boundaries with zero child shell forks.
|
||||
- **`geminux-powerd`**: Sleeps indefinitely in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, keyboard/touch/pointer activity), `KOBJECT_UEVENT` netlink (filtered strictly to `input`, `power_supply`, and `drm` subsystems), `/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`). Before entering `/sys/power/state`, it unloads `mt6797_consys` (and reverse dependents `btmt6797`, `radio_mt6797`, `gnss_mt6797`, `mac`) so `mt6797_consys_prepare()` no longer refuses suspend with `-EBUSY` and the `CONN`/`VCN*` rails power down cleanly; on resume, it asynchronously reloads them while preserving Bluetooth `rfkill` soft-block state and verifies `SW_LID` before re-enabling the backlight.
|
||||
- **`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.
|
||||
- **`geminux-touchd`**: Event-driven XInput 2.2 multi-touch gesture recognizer with zero polling loops.
|
||||
- **`geminux-ccci-daemon` & `geminux-modem-ctl`**: Event-driven `epoll_wait()` over `/dev/ccci_*`, AT port, and netlink; enter completely idle sleep when no modem activity is pending.
|
||||
- **`geminux-bt-obex` & `geminux-leds`**: 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-ccci-daemon` & `geminux-modem-ctl`**: Event-driven `epoll_wait()` over `/dev/ccci_*`, filtered `ccci` uevents, AT port, and netlink; enter completely idle sleep when no modem activity is pending.
|
||||
- **`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 max freq | Battery idle (dim -> lock+suspend) | AC idle (lock+blank screensaver) |
|
||||
| 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`) | `1391 MHz` | `60 s` -> `180 s` | `180 s` |
|
||||
| `balanced` | `schedutil` | Online (`1`) | `1547 MHz` | `120 s` -> `300 s` | `300 s` |
|
||||
| `performance` | `schedutil` | Online (`1`) | `1846 MHz` | `180 s` (lock+blank, no suspend) | `600 s` |
|
||||
| `eco` | `schedutil` | Offline (`0`) | `624 MHz` / `832 MHz` | `60 s` -> `180 s` | `180 s` |
|
||||
| `balanced` | `schedutil` | Online (`1`) | `806 MHz` / `1092 MHz` (bat), `897 MHz` / `1209 MHz` (AC) | `120 s` -> `300 s` | `300 s` |
|
||||
| `performance` | `schedutil` | Online (`1`) | `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.
|
||||
|
||||
@@ -40,8 +42,9 @@ Closing the Gemini PDA clamshell (`SW_LID = 1`) suspends immediately to RAM (`me
|
||||
## 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**: `bluetooth` OpenRC service is disabled from default boot (`AutoEnable=false` in `etc/bluetooth/main.conf`); users toggle Bluetooth on demand via `geminux-net`.
|
||||
- **Wi-Fi**: 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; the radio still powers down cleanly on Wi-Fi toggle-off or system S3 suspend.
|
||||
- **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 / 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 GTK3/`webarchy` never auto-activate AT-SPI accessibility bridge daemons.
|
||||
- **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
|
||||
@@ -53,4 +56,4 @@ 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, 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.
|
||||
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.
|
||||
@@ -19,5 +19,12 @@ case "$ACTION" in
|
||||
pkill -USR1 geminux-statusd 2>/dev/null || true
|
||||
) >/dev/null 2>&1 &
|
||||
;;
|
||||
down|vpn-down)
|
||||
(
|
||||
if ! ip route show default 2>/dev/null | grep -q '^default '; then
|
||||
chronyc offline >/dev/null 2>&1 || true
|
||||
fi
|
||||
) >/dev/null 2>&1 &
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -1,11 +1,11 @@
|
||||
[General]
|
||||
Name = Geminux-GeminiPDA
|
||||
ControllerMode = dual
|
||||
FastConnectable = true
|
||||
FastConnectable = false
|
||||
Experimental = true
|
||||
KernelExperimental = true
|
||||
JustWorksRepairing = always
|
||||
|
||||
[Policy]
|
||||
AutoEnable = true
|
||||
AutoEnable = false
|
||||
ReconnectAttempts = 7
|
||||
@@ -1,2 +1,2 @@
|
||||
pool pool.ntp.org iburst maxpoll 10
|
||||
pool time.cloudflare.com iburst maxpoll 10
|
||||
pool pool.ntp.org iburst maxsources 2 minpoll 10 maxpoll 14
|
||||
pool time.cloudflare.com iburst maxsources 2 minpoll 10 maxpoll 14
|
||||
@@ -5,4 +5,7 @@ GEMINUX_ENABLE_CONSYS="yes"
|
||||
GEMINUX_ENABLE_CAMERA="yes"
|
||||
GEMINUX_ENABLE_CCCI="yes"
|
||||
GEMINUX_ENABLE_MEDIATEK_DRM="yes"
|
||||
GEMINUX_ENABLE_CPUFREQ="yes"
|
||||
GEMINUX_ENABLE_SENSORS="no"
|
||||
GEMINUX_GATE_UNUSED_CLOCKS="yes"
|
||||
GEMINUX_ENABLE_A72="no"
|
||||
@@ -46,7 +46,11 @@ start() {
|
||||
load_group mediatek_drm clk-mt6797-mm mtk-mmsys mtk-mutex phy-mtk-mipi-dsi-drv panel-novatek-nt36672e mediatek-drm
|
||||
fi
|
||||
|
||||
load_group input_leds leds-aw9120 gemini-lid regulator-haptic stk3310 novatek-nt36xxx
|
||||
load_group input_leds leds-aw9120 gemini-lid regulator-haptic novatek-nt36xxx
|
||||
|
||||
if [ "${GEMINUX_ENABLE_SENSORS:-no}" = "yes" ]; then
|
||||
load_group sensors stk3310
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_ENABLE_AUDIO:-yes}" = "yes" ]; then
|
||||
load_group audio snd-soc-mt6797-afe snd-soc-mt6351 snd-soc-aw8738 mt6797-mt6351 mtk-btcvsd mt6797-btcvsd
|
||||
@@ -79,6 +83,9 @@ start() {
|
||||
log_msg " consys wlan0: not present after wait"
|
||||
fi
|
||||
load_group consys_bt algif_rng algif_aead uhid uinput rfcomm bnep hidp btmt6797
|
||||
if command -v rfkill >/dev/null 2>&1; then
|
||||
rfkill block bluetooth >> "$LOG_FILE" 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_ENABLE_CCCI:-yes}" = "yes" ]; then
|
||||
@@ -90,7 +97,19 @@ start() {
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_ENABLE_A72:-no}" = "yes" ]; then
|
||||
load_group a72 mt6797-a72 clk-mt6797-mcusys cpufreq-dt mtk-cci-devfreq
|
||||
load_group a72 mt6797-a72
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_ENABLE_CPUFREQ:-yes}" = "yes" ]; then
|
||||
load_group cpufreq clk-mt6797-mcusys cpufreq-dt
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_ENABLE_A72:-no}" = "yes" ]; then
|
||||
load_group cci_devfreq mtk-cci-devfreq
|
||||
fi
|
||||
|
||||
if [ "${GEMINUX_GATE_UNUSED_CLOCKS:-yes}" = "yes" ]; then
|
||||
load_group gate_unused mt6797-gate-unused
|
||||
fi
|
||||
|
||||
eend 0
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Enforce MT6797X safe hardware initialization order
|
||||
softdep clk_mt6797_mcusys pre: mt6797_a72
|
||||
softdep cpufreq_dt pre: mt6797_a72 clk_mt6797_mcusys
|
||||
softdep cpufreq_dt pre: clk_mt6797_mcusys
|
||||
softdep mtk_cci_devfreq pre: clk_mt6797_mcusys
|
||||
softdep mediatek_drm pre: clk_mt6797_mm mtk_mmsys mtk_mutex phy_mtk_mipi_dsi_drv panel_novatek_nt36672e
|
||||
softdep panfrost pre: clk_mt6797_mfg rt5735_regulator
|
||||
@@ -47,3 +46,4 @@ blacklist clk_mt6797_vdec
|
||||
blacklist mt6797_vdec_probe
|
||||
blacklist mt6797_vdec_replay
|
||||
blacklist bmi160_i2c
|
||||
blacklist stk3310
|
||||
@@ -1,7 +1,7 @@
|
||||
# Larger PipeWire quantum buffers reduce audio DSP/CPU wakeups for battery life.
|
||||
context.properties = {
|
||||
default.clock.rate = 48000
|
||||
default.clock.min-quantum = 128
|
||||
default.clock.min-quantum = 1024
|
||||
default.clock.quantum = 2048
|
||||
default.clock.max-quantum = 4096
|
||||
}
|
||||
@@ -32,3 +32,4 @@ export GDK_DPI_SCALE=0.94
|
||||
export QT_AUTO_SCREEN_SCALE_FACTOR=0
|
||||
export QT_SCALE_FACTOR=1.85
|
||||
export QT_FONT_DPI=96
|
||||
export NO_AT_BRIDGE=1
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -163,15 +163,26 @@ int main(void) {
|
||||
geminux_profile_params_t eco = geminux_policy_params(POWER_PROFILE_ECO, false);
|
||||
assert(strcmp(eco.governor, "schedutil") == 0);
|
||||
assert(!eco.a72_online);
|
||||
assert(eco.a53_ll_max_khz == 624000UL);
|
||||
assert(eco.a53_max_khz == 832000UL);
|
||||
assert(eco.suspend_timeout_s > 0);
|
||||
|
||||
geminux_profile_params_t bal = geminux_policy_params(POWER_PROFILE_BALANCED, false);
|
||||
assert(strcmp(bal.governor, "schedutil") == 0);
|
||||
assert(bal.a72_online);
|
||||
assert(bal.a53_ll_max_khz == 806000UL);
|
||||
assert(bal.a53_max_khz == 1092000UL);
|
||||
|
||||
geminux_profile_params_t bal_ac = geminux_policy_params(POWER_PROFILE_BALANCED, true);
|
||||
assert(strcmp(bal_ac.governor, "schedutil") == 0);
|
||||
assert(bal_ac.a53_ll_max_khz == 897000UL);
|
||||
assert(bal_ac.a53_max_khz == 1209000UL);
|
||||
|
||||
geminux_profile_params_t perf = geminux_policy_params(POWER_PROFILE_PERFORMANCE, true);
|
||||
assert(strcmp(perf.governor, "schedutil") == 0);
|
||||
assert(perf.a72_online);
|
||||
assert(perf.a53_ll_max_khz == 1547000UL);
|
||||
assert(perf.a53_max_khz == 1846000UL);
|
||||
assert(perf.suspend_timeout_s == 0);
|
||||
|
||||
/* Idle screensaver timing from last active input (battery balanced: dim=120s, suspend=300s) */
|
||||
@@ -426,9 +437,21 @@ int main(void) {
|
||||
const char uev_ps[] = "change@/devices/platform/charger\0SUBSYSTEM=power_supply\0ACTION=change\0";
|
||||
const char uev_in[] = "change@/devices/platform/input\0SUBSYSTEM=input\0ACTION=change\0";
|
||||
const char uev_pfx[] = "change@/devices/platform/charger\0SUBSYSTEM=power_supply2\0";
|
||||
const char uev_drm[] = "change@/devices/platform/drm\0SUBSYSTEM=drm\0ACTION=change\0";
|
||||
const char uev_net[] = "add@/devices/platform/wlan0\0SUBSYSTEM=net\0ACTION=add\0";
|
||||
assert(geminux_uevent_is_power_supply(uev_ps, sizeof(uev_ps)));
|
||||
assert(!geminux_uevent_is_power_supply(uev_in, sizeof(uev_in)));
|
||||
assert(!geminux_uevent_is_power_supply(uev_pfx, sizeof(uev_pfx)));
|
||||
assert(geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), "power_supply"));
|
||||
assert(geminux_uevent_has_subsystem(uev_in, sizeof(uev_in), "input"));
|
||||
assert(geminux_uevent_has_subsystem(uev_drm, sizeof(uev_drm), "drm"));
|
||||
assert(geminux_uevent_has_subsystem(uev_net, sizeof(uev_net), "net"));
|
||||
assert(!geminux_uevent_has_subsystem(uev_in, sizeof(uev_in), "inputs"));
|
||||
assert(!geminux_uevent_has_subsystem(uev_pfx, sizeof(uev_pfx), "power_supply"));
|
||||
assert(!geminux_uevent_has_subsystem("", 0, "input"));
|
||||
assert(!geminux_uevent_has_subsystem(NULL, 10, "input"));
|
||||
assert(!geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), NULL));
|
||||
assert(!geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), ""));
|
||||
|
||||
/* Wi-Fi active connection preservation (iw link + merge into empty/partial scan) */
|
||||
char iw_bssid[24], iw_ssid[96];
|
||||
@@ -541,6 +564,55 @@ def main():
|
||||
check=True,
|
||||
)
|
||||
|
||||
overlay_dir = os.path.join(BASE_DIR, "overlay", "rootfs")
|
||||
required_overlay_needles = {
|
||||
os.path.join(overlay_dir, "etc", "bluetooth", "main.conf"): (
|
||||
"AutoEnable = false",
|
||||
"FastConnectable = false",
|
||||
),
|
||||
os.path.join(overlay_dir, "etc", "pipewire", "pipewire.conf.d", "10-geminux-power.conf"): (
|
||||
"default.clock.min-quantum = 1024",
|
||||
),
|
||||
os.path.join(overlay_dir, "etc", "conf.d", "geminux-hwinit"): (
|
||||
'GEMINUX_ENABLE_CPUFREQ="yes"',
|
||||
'GEMINUX_ENABLE_SENSORS="no"',
|
||||
'GEMINUX_GATE_UNUSED_CLOCKS="yes"',
|
||||
),
|
||||
os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"): (
|
||||
"blacklist stk3310",
|
||||
"softdep cpufreq_dt pre: clk_mt6797_mcusys",
|
||||
),
|
||||
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
|
||||
"export NO_AT_BRIDGE=1",
|
||||
),
|
||||
}
|
||||
for path, needles in required_overlay_needles.items():
|
||||
with open(path, "r", encoding="utf-8") as handle:
|
||||
txt = handle.read()
|
||||
for needle in needles:
|
||||
if needle not in txt:
|
||||
raise AssertionError(f"Expected {needle!r} in {path}")
|
||||
|
||||
with open(os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"), "r", encoding="utf-8") as handle:
|
||||
modprobe_txt = handle.read()
|
||||
for line in modprobe_txt.splitlines():
|
||||
if line.startswith("softdep clk_mt6797_mcusys") or line.startswith("softdep cpufreq_dt"):
|
||||
if "mt6797_a72" in line:
|
||||
raise AssertionError(f"CPUfreq softdep must not depend on mt6797_a72: {line}")
|
||||
|
||||
with open(os.path.join(DAEMON_DIR, "geminux-powerd.c"), "r", encoding="utf-8") as handle:
|
||||
powerd_src = handle.read()
|
||||
trig_idx = powerd_src.find("static void trigger_suspend(powerd_ctx_t *ctx) {")
|
||||
assert trig_idx >= 0, "trigger_suspend missing in geminux-powerd.c"
|
||||
trig_src = powerd_src[trig_idx:]
|
||||
prep_idx = trig_src.find("prepare_consys_for_suspend(")
|
||||
susp_idx = trig_src.find('"/sys/power/state"')
|
||||
rest_idx = trig_src.find("restore_consys_after_resume(")
|
||||
if prep_idx < 0 or susp_idx < 0 or rest_idx < 0 or not (prep_idx < susp_idx < rest_idx):
|
||||
raise AssertionError("trigger_suspend must unload CONSYS before /sys/power/state and restore it after")
|
||||
if '"mt6797_consys"' not in powerd_src or '"mt6797-consys"' not in powerd_src:
|
||||
raise AssertionError("geminux-powerd.c must unload mt6797_consys and reload mt6797-consys")
|
||||
|
||||
print("[PASS] Zero-poll daemon loops, power/lid policy, and touch gestures verified")
|
||||
return 0
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ typedef struct {
|
||||
char password[128];
|
||||
char bat_text[96];
|
||||
char err_msg[96];
|
||||
int last_min;
|
||||
int last_yday;
|
||||
int timer_ms;
|
||||
bool grabbed;
|
||||
bool checking;
|
||||
} lock_state_t;
|
||||
@@ -99,10 +102,23 @@ static void on_timer(gemui_app_t *app, void *ud) {
|
||||
lock_state_t *st = ud;
|
||||
if (!st->grabbed) {
|
||||
st->grabbed = gemui_grab_input(app);
|
||||
if (st->grabbed && st->timer_ms != 15000) {
|
||||
st->timer_ms = 15000;
|
||||
gemui_set_timer_ms(app, 15000, on_timer, st);
|
||||
}
|
||||
}
|
||||
char prev_bat[96];
|
||||
snprintf(prev_bat, sizeof(prev_bat), "%s", st->bat_text);
|
||||
refresh_battery(st);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
if (tm.tm_min != st->last_min || tm.tm_yday != st->last_yday ||
|
||||
strcmp(prev_bat, st->bat_text) != 0) {
|
||||
gemui_request_redraw(app);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
lock_state_t *st = ud;
|
||||
@@ -113,6 +129,8 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
st->last_min = tm.tm_min;
|
||||
st->last_yday = tm.tm_yday;
|
||||
char clock_str[32], date_str[64];
|
||||
strftime(clock_str, sizeof(clock_str), "%H:%M", &tm);
|
||||
strftime(date_str, sizeof(date_str), "%A, %d %B %Y", &tm);
|
||||
@@ -190,6 +208,8 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
int main(void) {
|
||||
lock_state_t st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.last_min = -1;
|
||||
st.last_yday = -1;
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
snprintf(st.user, sizeof(st.user), "%s", (pw && pw->pw_name) ? pw->pw_name : "user");
|
||||
refresh_battery(&st);
|
||||
@@ -211,7 +231,8 @@ int main(void) {
|
||||
|
||||
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
|
||||
gemui_set_handlers(st.app, &h, &st);
|
||||
gemui_set_timer_ms(st.app, 1000, on_timer, &st);
|
||||
st.timer_ms = st.grabbed ? 15000 : 250;
|
||||
gemui_set_timer_ms(st.app, st.timer_ms, on_timer, &st);
|
||||
int rc = gemui_run(st.app);
|
||||
gemui_ungrab_input(st.app);
|
||||
gemui_destroy(st.app);
|
||||
|
||||
@@ -35,8 +35,8 @@ geminux-powerd: geminux-powerd.c geminux-power-policy.c geminux-power-policy.h
|
||||
geminux-power-ctl: geminux-power-ctl.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
geminux-statusd: geminux-statusd.c
|
||||
$(CC) $(CFLAGS) $(X11_CFLAGS) -o $@ $< $(X11_LIBS)
|
||||
geminux-statusd: geminux-statusd.c geminux-power-policy.h geminux-tz-valid.h
|
||||
$(CC) $(CFLAGS) $(X11_CFLAGS) -o $@ geminux-statusd.c $(X11_LIBS)
|
||||
|
||||
geminux-touchd: geminux-touchd.c geminux-touch-gesture.c geminux-touch-gesture.h
|
||||
$(CC) $(CFLAGS) $(XTOUCH_CFLAGS) -o $@ geminux-touchd.c geminux-touch-gesture.c $(XTOUCH_LIBS)
|
||||
|
||||
@@ -237,8 +237,16 @@ int main(void) {
|
||||
}
|
||||
} else if (fd == ctx.uev_fd) {
|
||||
char ubuf[1024];
|
||||
while (recv(ctx.uev_fd, ubuf, sizeof(ubuf), 0) > 0) {}
|
||||
ssize_t ur;
|
||||
bool need_ccci = false;
|
||||
while ((ur = recv(ctx.uev_fd, ubuf, sizeof(ubuf), 0)) > 0) {
|
||||
if (memmem(ubuf, (size_t)ur, "ccci", 4) != NULL) {
|
||||
need_ccci = true;
|
||||
}
|
||||
}
|
||||
if (need_ccci && (ctx.ctl_fd < 0 || ctx.fs_fd < 0 || ctx.rpc_fd < 0)) {
|
||||
open_ccci_devs(&ctx);
|
||||
}
|
||||
} else if (fd == ctx.ctl_fd) {
|
||||
handle_ctl_read(&ctx);
|
||||
} else if (fd == ctx.fs_fd || fd == ctx.rpc_fd) {
|
||||
|
||||
@@ -62,14 +62,38 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
char gov0[64] = "unknown";
|
||||
char max0[32] = "unknown", max4[32] = "unknown";
|
||||
read_str("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", gov0, sizeof(gov0));
|
||||
read_str("/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq", max0, sizeof(max0));
|
||||
read_str("/sys/devices/system/cpu/cpufreq/policy4/scaling_max_freq", max4, sizeof(max4));
|
||||
|
||||
const char *bt_state = "absent";
|
||||
d = opendir("/sys/class/rfkill");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, soft[16] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/type", de->d_name);
|
||||
if (read_str(p, typ, sizeof(typ)) == 0 && strcmp(typ, "bluetooth") == 0) {
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/soft", de->d_name);
|
||||
if (read_str(p, soft, sizeof(soft)) == 0) {
|
||||
bt_state = (atoi(soft) != 0) ? "blocked" : "unblocked";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
if (json) {
|
||||
printf("{\"profile\":\"%s\",\"battery_pct\":\"%s\",\"battery_status\":\"%s\","
|
||||
"\"voltage_uv\":\"%s\",\"current_ua\":\"%s\",\"online_cpus\":%d,"
|
||||
"\"a72_online\":%d,\"governor\":\"%s\",\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\"}\n",
|
||||
"\"a72_online\":%d,\"governor\":\"%s\",\"policy0_max_khz\":\"%s\","
|
||||
"\"policy4_max_khz\":\"%s\",\"bt_rfkill_soft\":\"%s\","
|
||||
"\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\"}\n",
|
||||
profile, bat_cap, bat_status, bat_uv, bat_ua, online_cpus, a72_online,
|
||||
gov0, zram_algo, mem_sleep);
|
||||
gov0, max0, max4, bt_state, zram_algo, mem_sleep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -79,6 +103,8 @@ int main(int argc, char **argv) {
|
||||
printf("Battery Status : %s%% (%s, V=%s uV, I=%s uA)\n", bat_cap, bat_status, bat_uv, bat_ua);
|
||||
printf("CPUs Online : %d total (%d A72 big cores online)\n", online_cpus, a72_online);
|
||||
printf("CPUfreq Governor : %s\n", gov0);
|
||||
printf("CPUfreq Caps : policy0=%s kHz, policy4=%s kHz\n", max0, max4);
|
||||
printf("Bluetooth RFKill : %s\n", bt_state);
|
||||
printf("ZRAM Compression : %s\n", zram_algo);
|
||||
printf("Suspend Modes : %s\n", mem_sleep);
|
||||
return 0;
|
||||
|
||||
@@ -41,19 +41,22 @@ geminux_profile_params_t geminux_policy_params(geminux_profile_t prof, bool on_a
|
||||
out.governor = "schedutil";
|
||||
if (prof == POWER_PROFILE_ECO) {
|
||||
out.a72_online = false;
|
||||
out.a53_max_khz = 1391000UL;
|
||||
out.a53_ll_max_khz = 624000UL;
|
||||
out.a53_max_khz = 832000UL;
|
||||
out.a72_max_khz = 0UL;
|
||||
out.dim_timeout_s = on_ac ? 180 : 60;
|
||||
out.suspend_timeout_s = on_ac ? 0 : 180;
|
||||
} else if (prof == POWER_PROFILE_PERFORMANCE) {
|
||||
out.a72_online = true;
|
||||
out.a53_ll_max_khz = 1547000UL;
|
||||
out.a53_max_khz = 1846000UL;
|
||||
out.a72_max_khz = 2600000UL;
|
||||
out.dim_timeout_s = on_ac ? 600 : 180;
|
||||
out.suspend_timeout_s = 0;
|
||||
} else {
|
||||
out.a72_online = true;
|
||||
out.a53_max_khz = 1547000UL;
|
||||
out.a53_ll_max_khz = on_ac ? 897000UL : 806000UL;
|
||||
out.a53_max_khz = on_ac ? 1209000UL : 1092000UL;
|
||||
out.a72_max_khz = 2002000UL;
|
||||
out.dim_timeout_s = on_ac ? 300 : 120;
|
||||
out.suspend_timeout_s = on_ac ? 0 : 300;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
#define GEMINUX_POWER_POLICY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define GEMINUX_MAX_INHIBITORS 16
|
||||
|
||||
@@ -39,6 +41,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
const char *governor;
|
||||
bool a72_online;
|
||||
unsigned long a53_ll_max_khz;
|
||||
unsigned long a53_max_khz;
|
||||
unsigned long a72_max_khz;
|
||||
int dim_timeout_s;
|
||||
@@ -58,4 +61,25 @@ bool geminux_policy_add_inhibit(geminux_power_policy_t *p, const char *tag);
|
||||
bool geminux_policy_del_inhibit(geminux_power_policy_t *p, const char *tag);
|
||||
bool geminux_should_suspend_on_lid(const geminux_power_policy_t *p);
|
||||
|
||||
static inline bool geminux_uevent_has_subsystem(const char *buf, size_t len, const char *subsys) {
|
||||
if (!buf || len == 0 || !subsys || !subsys[0]) return false;
|
||||
const size_t slen = strlen(subsys);
|
||||
static const char pfx[] = "SUBSYSTEM=";
|
||||
const size_t plen = sizeof(pfx) - 1;
|
||||
size_t i = 0;
|
||||
while (i < len) {
|
||||
while (i < len && (buf[i] == '\0' || buf[i] == '\n' || buf[i] == '\r')) i++;
|
||||
if (i >= len) break;
|
||||
size_t start = i;
|
||||
while (i < len && buf[i] != '\0' && buf[i] != '\n' && buf[i] != '\r') i++;
|
||||
size_t tok_len = i - start;
|
||||
if (tok_len == plen + slen &&
|
||||
memcmp(buf + start, pfx, plen) == 0 &&
|
||||
memcmp(buf + start + plen, subsys, slen) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* GEMINUX_POWER_POLICY_H */
|
||||
@@ -41,6 +41,18 @@ typedef struct {
|
||||
uint64_t last_input_ms;
|
||||
geminux_idle_stage_t idle_stage;
|
||||
geminux_power_policy_t policy;
|
||||
bool charge_thresh_set;
|
||||
bool policy_applied;
|
||||
geminux_profile_t applied_profile;
|
||||
bool applied_ac;
|
||||
bool applied_a72_ready;
|
||||
bool applied_cpufreq_present;
|
||||
pid_t consys_restore_pid;
|
||||
bool consys_suspended;
|
||||
bool bt_was_loaded;
|
||||
bool bt_was_blocked;
|
||||
bool gnss_was_loaded;
|
||||
bool radio_was_loaded;
|
||||
} powerd_ctx_t;
|
||||
|
||||
static uint64_t monotonic_ms(void) {
|
||||
@@ -78,7 +90,11 @@ static void ensure_run_dir(void) {
|
||||
}
|
||||
|
||||
static void refresh_ac_and_hdmi(powerd_ctx_t *ctx) {
|
||||
write_sysfs_str("/sys/class/power_supply/battery/charge_control_end_threshold", "100");
|
||||
if (!ctx->charge_thresh_set) {
|
||||
if (write_sysfs_str("/sys/class/power_supply/battery/charge_control_end_threshold", "100") == 0) {
|
||||
ctx->charge_thresh_set = true;
|
||||
}
|
||||
}
|
||||
ctx->policy.on_ac_power = false;
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (d) {
|
||||
@@ -117,6 +133,8 @@ static void refresh_ac_and_hdmi(powerd_ctx_t *ctx) {
|
||||
|
||||
static void lock_x11_session(void);
|
||||
static void trigger_suspend(powerd_ctx_t *ctx);
|
||||
static void apply_cpu_sysfs(powerd_ctx_t *ctx, bool force);
|
||||
static void apply_cpu_policy(powerd_ctx_t *ctx, bool force);
|
||||
|
||||
static void save_active_brightness(powerd_ctx_t *ctx, const char *bri_path) {
|
||||
if (ctx->idle_stage != IDLE_STAGE_ACTIVE) return;
|
||||
@@ -222,10 +240,19 @@ static void note_user_activity(powerd_ctx_t *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_cpu_policy(powerd_ctx_t *ctx) {
|
||||
static void apply_cpu_sysfs(powerd_ctx_t *ctx, bool force) {
|
||||
bool a72_ready = (access("/sys/module/mt6797_a72", F_OK) == 0);
|
||||
bool cpufreq_present = (access("/sys/devices/system/cpu/cpufreq/policy0", F_OK) == 0);
|
||||
if (!force && ctx->policy_applied &&
|
||||
ctx->applied_profile == ctx->policy.profile &&
|
||||
ctx->applied_ac == ctx->policy.on_ac_power &&
|
||||
ctx->applied_a72_ready == a72_ready &&
|
||||
ctx->applied_cpufreq_present == cpufreq_present) {
|
||||
return;
|
||||
}
|
||||
|
||||
geminux_profile_params_t par = geminux_policy_params(ctx->policy.profile, ctx->policy.on_ac_power);
|
||||
|
||||
bool a72_ready = (access("/sys/module/mt6797_a72", F_OK) == 0);
|
||||
if (!par.a72_online || a72_ready) {
|
||||
for (int cpu = 8; cpu <= 9; cpu++) {
|
||||
char p[128];
|
||||
@@ -244,7 +271,8 @@ static void apply_cpu_policy(powerd_ctx_t *ctx) {
|
||||
write_sysfs_str(p, par.governor);
|
||||
|
||||
int first_cpu = atoi(de->d_name + 6);
|
||||
unsigned long cap = (first_cpu >= 8) ? par.a72_max_khz : par.a53_max_khz;
|
||||
unsigned long cap = (first_cpu >= 8) ? par.a72_max_khz :
|
||||
(first_cpu >= 4) ? par.a53_max_khz : par.a53_ll_max_khz;
|
||||
if (cap > 0) {
|
||||
snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpufreq/%s/scaling_max_freq", de->d_name);
|
||||
snprintf(freq_buf, sizeof(freq_buf), "%lu", cap);
|
||||
@@ -254,8 +282,20 @@ static void apply_cpu_policy(powerd_ctx_t *ctx) {
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
if (force || !ctx->policy_applied || ctx->applied_profile != ctx->policy.profile) {
|
||||
ensure_run_dir();
|
||||
write_sysfs_str(PROFILE_FILE, geminux_policy_profile_name(ctx->policy.profile));
|
||||
}
|
||||
|
||||
ctx->policy_applied = true;
|
||||
ctx->applied_profile = ctx->policy.profile;
|
||||
ctx->applied_ac = ctx->policy.on_ac_power;
|
||||
ctx->applied_a72_ready = a72_ready;
|
||||
ctx->applied_cpufreq_present = cpufreq_present;
|
||||
}
|
||||
|
||||
static void apply_cpu_policy(powerd_ctx_t *ctx, bool force) {
|
||||
apply_cpu_sysfs(ctx, force);
|
||||
evaluate_idle(ctx);
|
||||
}
|
||||
|
||||
@@ -334,23 +374,194 @@ static void lock_x11_session(void) {
|
||||
close(pfd[0]);
|
||||
}
|
||||
|
||||
static int run_cmd_sync(const char *const argv[]) {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) return -1;
|
||||
if (pid == 0) {
|
||||
int devnull = open("/dev/null", O_RDWR);
|
||||
if (devnull >= 0) {
|
||||
if (devnull != STDIN_FILENO) dup2(devnull, STDIN_FILENO);
|
||||
if (devnull != STDOUT_FILENO) dup2(devnull, STDOUT_FILENO);
|
||||
if (devnull != STDERR_FILENO) dup2(devnull, STDERR_FILENO);
|
||||
if (devnull > 2) close(devnull);
|
||||
}
|
||||
execv(argv[0], (char *const *)argv);
|
||||
_exit(127);
|
||||
}
|
||||
int st = 0;
|
||||
while (waitpid(pid, &st, 0) < 0) {
|
||||
if (errno != EINTR) return -1;
|
||||
}
|
||||
return (WIFEXITED(st) && WEXITSTATUS(st) == 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void reap_consys_restore(powerd_ctx_t *ctx, bool wait_block) {
|
||||
if (ctx->consys_restore_pid <= 0) return;
|
||||
int opts = wait_block ? 0 : WNOHANG;
|
||||
pid_t r;
|
||||
do {
|
||||
r = waitpid(ctx->consys_restore_pid, NULL, opts);
|
||||
} while (r < 0 && errno == EINTR);
|
||||
if (r == ctx->consys_restore_pid || (r < 0 && errno == ECHILD)) {
|
||||
ctx->consys_restore_pid = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_bt_rfkill_soft_blocked(void) {
|
||||
DIR *d = opendir("/sys/class/rfkill");
|
||||
if (!d) return true;
|
||||
bool found = false;
|
||||
bool blocked = true;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, soft[16] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/type", de->d_name);
|
||||
if (read_sysfs_line(p, typ, sizeof(typ)) == 0 && strcmp(typ, "bluetooth") == 0) {
|
||||
found = true;
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/soft", de->d_name);
|
||||
if (read_sysfs_line(p, soft, sizeof(soft)) == 0 && atoi(soft) == 0) {
|
||||
blocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
return found ? blocked : true;
|
||||
}
|
||||
|
||||
static void set_bt_rfkill_soft_blocked(bool blocked) {
|
||||
DIR *d = opendir("/sys/class/rfkill");
|
||||
if (d) {
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/type", de->d_name);
|
||||
if (read_sysfs_line(p, typ, sizeof(typ)) == 0 && strcmp(typ, "bluetooth") == 0) {
|
||||
snprintf(p, sizeof(p), "/sys/class/rfkill/%s/soft", de->d_name);
|
||||
write_sysfs_str(p, blocked ? "1" : "0");
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
if (blocked) {
|
||||
const char *argv[] = {"/usr/sbin/rfkill", "block", "bluetooth", NULL};
|
||||
run_cmd_sync(argv);
|
||||
}
|
||||
}
|
||||
|
||||
/* mt6797_consys_prepare() refuses suspend with -EBUSY while CONN is powered;
|
||||
* unloading reverse dependents lets mt6797_consys_remove() power off CONN/VCN rails. */
|
||||
static void prepare_consys_for_suspend(powerd_ctx_t *ctx) {
|
||||
reap_consys_restore(ctx, true);
|
||||
if (access("/sys/module/mt6797_consys", F_OK) != 0) {
|
||||
ctx->consys_suspended = false;
|
||||
return;
|
||||
}
|
||||
ctx->consys_suspended = true;
|
||||
ctx->bt_was_loaded = (access("/sys/module/btmt6797", F_OK) == 0);
|
||||
ctx->bt_was_blocked = ctx->bt_was_loaded ? is_bt_rfkill_soft_blocked() : true;
|
||||
ctx->gnss_was_loaded = (access("/sys/module/gnss_mt6797", F_OK) == 0);
|
||||
ctx->radio_was_loaded = (access("/sys/module/radio_mt6797", F_OK) == 0);
|
||||
|
||||
static const char *const mods[] = {
|
||||
"btmt6797",
|
||||
"radio_mt6797",
|
||||
"gnss_mt6797",
|
||||
"mac",
|
||||
"mt6797_consys",
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(mods) / sizeof(mods[0]); i++) {
|
||||
char mpath[128];
|
||||
snprintf(mpath, sizeof(mpath), "/sys/module/%s", mods[i]);
|
||||
if (access(mpath, F_OK) == 0) {
|
||||
const char *argv[] = {"/sbin/rmmod", mods[i], NULL};
|
||||
run_cmd_sync(argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void restore_consys_after_resume(powerd_ctx_t *ctx) {
|
||||
if (!ctx->consys_suspended) return;
|
||||
ctx->consys_suspended = false;
|
||||
reap_consys_restore(ctx, true);
|
||||
|
||||
bool bt_loaded = ctx->bt_was_loaded;
|
||||
bool bt_blocked = ctx->bt_was_blocked;
|
||||
bool gnss_loaded = ctx->gnss_was_loaded;
|
||||
bool radio_loaded = ctx->radio_was_loaded;
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) return;
|
||||
if (pid == 0) {
|
||||
int devnull = open("/dev/null", O_RDWR);
|
||||
if (devnull >= 0) {
|
||||
if (devnull != STDIN_FILENO) dup2(devnull, STDIN_FILENO);
|
||||
if (devnull != STDOUT_FILENO) dup2(devnull, STDOUT_FILENO);
|
||||
if (devnull != STDERR_FILENO) dup2(devnull, STDERR_FILENO);
|
||||
if (devnull > 2) close(devnull);
|
||||
}
|
||||
const char *wlan_core[] = {"/sbin/modprobe", "mt6797-wlan-core", NULL};
|
||||
const char *consys[] = {"/sbin/modprobe", "mt6797-consys", NULL};
|
||||
const char *mac[] = {"/sbin/modprobe", "mac", NULL};
|
||||
run_cmd_sync(wlan_core);
|
||||
run_cmd_sync(consys);
|
||||
run_cmd_sync(mac);
|
||||
if (bt_loaded) {
|
||||
const char *bt[] = {"/sbin/modprobe", "btmt6797", NULL};
|
||||
run_cmd_sync(bt);
|
||||
if (bt_blocked) {
|
||||
set_bt_rfkill_soft_blocked(true);
|
||||
}
|
||||
}
|
||||
if (gnss_loaded) {
|
||||
const char *gnss[] = {"/sbin/modprobe", "gnss-mt6797", NULL};
|
||||
run_cmd_sync(gnss);
|
||||
}
|
||||
if (radio_loaded) {
|
||||
const char *radio[] = {"/sbin/modprobe", "radio-mt6797", NULL};
|
||||
run_cmd_sync(radio);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
ctx->consys_restore_pid = pid;
|
||||
}
|
||||
|
||||
static void refresh_lid_state(powerd_ctx_t *ctx) {
|
||||
for (int i = 0; i < ctx->num_ev; i++) {
|
||||
unsigned long evbits = 0;
|
||||
if (ioctl(ctx->ev_fds[i], EVIOCGBIT(0, sizeof(evbits)), &evbits) >= 0 &&
|
||||
(evbits & (1UL << EV_SW))) {
|
||||
unsigned long swbits = 0, swstate = 0;
|
||||
if (ioctl(ctx->ev_fds[i], EVIOCGBIT(EV_SW, sizeof(swbits)), &swbits) >= 0 &&
|
||||
(swbits & (1UL << SW_LID)) &&
|
||||
ioctl(ctx->ev_fds[i], EVIOCGSW(sizeof(swstate)), &swstate) >= 0) {
|
||||
ctx->policy.lid_closed = !!(swstate & (1UL << SW_LID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
lock_x11_session();
|
||||
toggle_backlight(ctx, false);
|
||||
prepare_consys_for_suspend(ctx);
|
||||
write_sysfs_str("/sys/power/mem_sleep", "deep");
|
||||
if (write_sysfs_str("/sys/power/state", "mem") == 0 ||
|
||||
write_sysfs_str("/sys/power/state", "freeze") == 0) {
|
||||
/* Woken back up from suspend */
|
||||
ctx->idle_stage = IDLE_STAGE_ACTIVE;
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
toggle_backlight(ctx, true);
|
||||
bool suspended = (write_sysfs_str("/sys/power/state", "mem") == 0 ||
|
||||
write_sysfs_str("/sys/power/state", "freeze") == 0);
|
||||
restore_consys_after_resume(ctx);
|
||||
refresh_lid_state(ctx);
|
||||
refresh_ac_and_hdmi(ctx);
|
||||
apply_cpu_policy(ctx);
|
||||
} else if (!ctx->policy.lid_closed) {
|
||||
if (suspended && !ctx->policy.lid_closed) {
|
||||
ctx->idle_stage = IDLE_STAGE_ACTIVE;
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
toggle_backlight(ctx, true);
|
||||
evaluate_idle(ctx);
|
||||
apply_cpu_policy(ctx, true);
|
||||
} else {
|
||||
toggle_backlight(ctx, false);
|
||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||
arm_timer_ms(ctx->tmr_fd, 0);
|
||||
apply_cpu_sysfs(ctx, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +607,7 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
|
||||
if (strncmp(buf, "profile ", 8) == 0) {
|
||||
if (geminux_policy_set_profile_name(&ctx->policy, buf + 8)) {
|
||||
apply_cpu_policy(ctx);
|
||||
apply_cpu_policy(ctx, false);
|
||||
dprintf(cfd, "OK profile=%s\n", geminux_policy_profile_name(ctx->policy.profile));
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown profile\n");
|
||||
@@ -406,11 +617,11 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
trigger_suspend(ctx);
|
||||
} else if (strncmp(buf, "inhibit add ", 12) == 0) {
|
||||
geminux_policy_add_inhibit(&ctx->policy, buf + 12);
|
||||
apply_cpu_policy(ctx);
|
||||
apply_cpu_policy(ctx, false);
|
||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||
} else if (strncmp(buf, "inhibit del ", 12) == 0) {
|
||||
geminux_policy_del_inhibit(&ctx->policy, buf + 12);
|
||||
apply_cpu_policy(ctx);
|
||||
apply_cpu_policy(ctx, false);
|
||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||
} else if (strcmp(buf, "lid-suspend on") == 0) {
|
||||
ctx->policy.lid_suspend_enabled = true;
|
||||
@@ -469,6 +680,7 @@ int main(void) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
powerd_ctx_t ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.consys_restore_pid = -1;
|
||||
ctx.saved_brightness = 128;
|
||||
geminux_policy_init(&ctx.policy);
|
||||
|
||||
@@ -497,12 +709,13 @@ int main(void) {
|
||||
ctx.idle_stage = IDLE_STAGE_ACTIVE;
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
scan_input_devices(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
apply_cpu_policy(&ctx, true);
|
||||
|
||||
struct epoll_event events[16];
|
||||
bool running = true;
|
||||
while (running) {
|
||||
int n = epoll_wait(ctx.epfd, events, 16, -1);
|
||||
reap_consys_restore(&ctx, false);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
break;
|
||||
@@ -514,7 +727,7 @@ int main(void) {
|
||||
while (read(ctx.sig_fd, &si, sizeof(si)) > 0) {
|
||||
if (si.ssi_signo == SIGHUP) {
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
apply_cpu_policy(&ctx, true);
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
@@ -534,19 +747,28 @@ int main(void) {
|
||||
char ubuf[2048];
|
||||
ssize_t ur;
|
||||
bool need_ev_rescan = false;
|
||||
bool need_ps_or_drm = false;
|
||||
while ((ur = recv(ctx.uev_fd, ubuf, sizeof(ubuf), 0)) > 0) {
|
||||
if (memmem(ubuf, (size_t)ur, "SUBSYSTEM=input", 15)) {
|
||||
if (geminux_uevent_has_subsystem(ubuf, (size_t)ur, "input")) {
|
||||
need_ev_rescan = true;
|
||||
}
|
||||
if (geminux_uevent_has_subsystem(ubuf, (size_t)ur, "power_supply") ||
|
||||
geminux_uevent_has_subsystem(ubuf, (size_t)ur, "drm")) {
|
||||
need_ps_or_drm = true;
|
||||
}
|
||||
}
|
||||
if (need_ev_rescan) scan_input_devices(&ctx);
|
||||
if (need_ps_or_drm) {
|
||||
bool prev_ac = ctx.policy.on_ac_power;
|
||||
bool prev_hdmi = ctx.policy.hdmi_connected;
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
if (prev_ac != ctx.policy.on_ac_power || prev_hdmi != ctx.policy.hdmi_connected) {
|
||||
if (!ctx.policy.lid_closed) {
|
||||
note_user_activity(&ctx);
|
||||
}
|
||||
apply_cpu_policy(&ctx);
|
||||
apply_cpu_policy(&ctx, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct input_event iev;
|
||||
bool saw_activity = false;
|
||||
@@ -567,7 +789,7 @@ int main(void) {
|
||||
ctx.last_input_ms = monotonic_ms();
|
||||
toggle_backlight(&ctx, true);
|
||||
refresh_ac_and_hdmi(&ctx);
|
||||
apply_cpu_policy(&ctx);
|
||||
apply_cpu_policy(&ctx, true);
|
||||
}
|
||||
} else if (iev.type == EV_KEY && iev.code == KEY_POWER && iev.value == 1) {
|
||||
if (ctx.idle_stage == IDLE_STAGE_LOCKED_BLANK) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "geminux-power-policy.h"
|
||||
#include "geminux-tz-valid.h"
|
||||
|
||||
static int read_line(const char *path, char *buf, size_t sz) {
|
||||
@@ -104,11 +105,15 @@ static void update_status(Display *dpy) {
|
||||
char clk[32];
|
||||
strftime(clk, sizeof(clk), "%a %d %H:%M", &tm);
|
||||
|
||||
static char last_bar[256] = {0};
|
||||
char bar[256];
|
||||
snprintf(bar, sizeof(bar), " %s | %s | %s | %s ", net, mdm, bat, clk);
|
||||
if (strcmp(bar, last_bar) != 0) {
|
||||
snprintf(last_bar, sizeof(last_bar), "%s", bar);
|
||||
XStoreName(dpy, DefaultRootWindow(dpy), bar);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
|
||||
static void arm_minute_timer(int tfd) {
|
||||
struct timespec now;
|
||||
@@ -189,6 +194,15 @@ int main(void) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
} else if (fd == uev_fd) {
|
||||
char drain[2048];
|
||||
ssize_t nr;
|
||||
while ((nr = recv(uev_fd, drain, sizeof(drain), 0)) > 0) {
|
||||
if (geminux_uevent_has_subsystem(drain, (size_t)nr, "power_supply") ||
|
||||
geminux_uevent_has_subsystem(drain, (size_t)nr, "net")) {
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char drain[1024];
|
||||
while (read(fd, drain, sizeof(drain)) > 0) {}
|
||||
|
||||
Reference in new issue
Block a user