Fix battery drain sources across suspend, CPUfreq, radios, and daemons

This commit is contained in:
Luxferre committed 2026-11-23 20:00:17 +02:00
1 parent 4b36aa0726
commit 7f3b3c2c0c
24 files changed
+487 -64

No files matched your search

+72
View File
@@ -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