Eliminate dual-target idle wakeups and stage upcoming a1114 (carbonara) build
- Replace continuous polling in bananarchy-lid and bananarchy-volume-keys with /dev/input inotify watching and IRQ-driven poll(..., -1) steady state, and sync CPU/schedutil/GPU power knobs on flip transitions - Grant video-group write permissions to Adreno 304 devfreq governor, sync GPU powersave/simple_ondemand across bananarchy-display-power-sync and locker.so, and restore schedutil rate_limit_us on forced transitions - Trim per-minute statusbar clock forks, skip unchanged ext4 brightness rewrites and no-op sxmo_autosuspend spawns on blanking, and make bananarchy-bt-obex fully event-driven via inotify and blocking select - Register upcoming build a1114 (carbonara) in version.sh, check-rebuild.sh, CHANGELOG.md, AGENTS.md, and BATTERY-OPTIMIZATION-ANALYSIS.md while keeping a1111 (lennon) as the current public release
This commit is contained in:
1 parent
ed04da3e23
commit
e42024e90d
22 files changed
+416
-75
No files matched your search
@@ -47,6 +47,9 @@
|
||||
#define BA_EVIOCGSW(len) BA_IOC(2U, 'E', 0x1bU, (unsigned int)(len))
|
||||
#define COVER_MARKER "/run/bananarchy/cover-backlight"
|
||||
#define MAIN_DPMS_PATH "/sys/class/drm/card0-SPI-1/dpms"
|
||||
#define CPU_GOV "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor"
|
||||
#define SCHEDUTIL_RATE "/sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us"
|
||||
#define GPU_GOV "/sys/class/devfreq/1c00000.gpu/governor"
|
||||
|
||||
static char *const session_env[] = {
|
||||
(char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
|
||||
@@ -271,6 +274,8 @@ static void on_transition(int closed)
|
||||
* which is also the gate the cover daemon uses to take the SPI bus. */
|
||||
write_text_file(BRIGHTNESS, "0");
|
||||
write_text_file(BL_POWER, "4");
|
||||
write_text_file(CPU_GOV, "powersave");
|
||||
write_text_file(GPU_GOV, "powersave");
|
||||
run_dpms("off");
|
||||
cover_send("CLOSED");
|
||||
locker_send("SCREENOFF\n");
|
||||
@@ -278,6 +283,9 @@ static void on_transition(int closed)
|
||||
} else {
|
||||
int bl = read_int_file(BRIGHTNESS_SAVE, 10);
|
||||
int kbd = read_int_file(KBD_SAVE, 1);
|
||||
write_text_file(CPU_GOV, "schedutil");
|
||||
write_text_file(SCHEDUTIL_RATE, "40000");
|
||||
write_text_file(GPU_GOV, "simple_ondemand");
|
||||
/* Release the cover's shared SPI bus before relighting the main panel.
|
||||
* The cover daemon restores the mux on this datagram; give it a moment so
|
||||
* the DPMS re-init below hits the internal panel, not the cover. */
|
||||
@@ -429,12 +437,15 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds,
|
||||
int main(void)
|
||||
{
|
||||
int lock_fd;
|
||||
int inotify_fd;
|
||||
int gpio_override;
|
||||
int need_scan = 1;
|
||||
struct watch_list list;
|
||||
long long now;
|
||||
long long last_scan = 0;
|
||||
long long last_hall_poll = 0;
|
||||
long long last_transition = 0;
|
||||
long long last_broadcast = 0;
|
||||
long long reconcile_at = 0;
|
||||
long long candidate_since;
|
||||
long long fast_until = 0;
|
||||
int evdev_found = 0;
|
||||
@@ -452,6 +463,8 @@ int main(void)
|
||||
return 1;
|
||||
install_reaper();
|
||||
memset(&list, 0, sizeof(list));
|
||||
gpio_override = getenv("BANANARCHY_LID_GPIO_FILE") != NULL;
|
||||
inotify_fd = open_input_inotify();
|
||||
switch_mask = current_switch_mask(&evdev_found);
|
||||
hall = hall_state();
|
||||
hall_observed = hall;
|
||||
@@ -464,6 +477,7 @@ int main(void)
|
||||
candidate = stable_closed;
|
||||
now = now_ms();
|
||||
candidate_since = now;
|
||||
last_hall_poll = now;
|
||||
write_lid_state(stable_closed);
|
||||
if(stable_closed)
|
||||
on_transition(1);
|
||||
@@ -471,14 +485,19 @@ int main(void)
|
||||
sync_sw_lid(0);
|
||||
cover_send("OPEN");
|
||||
}
|
||||
last_broadcast = now;
|
||||
reconcile_at = now + LID_BROADCAST_MS;
|
||||
while(1) {
|
||||
struct pollfd fds[WATCH_MAX];
|
||||
struct pollfd fds[WATCH_MAX + 1];
|
||||
int nfds = 0;
|
||||
int poll_nfds;
|
||||
int timeout_ms;
|
||||
int prev_count;
|
||||
int i;
|
||||
if(now - last_scan > 2000) {
|
||||
if(need_scan ||
|
||||
((inotify_fd < 0 || list.count == 0) && now - last_scan >= 2000)) {
|
||||
scan_devices(&list, WATCH_SWITCHES);
|
||||
last_scan = now;
|
||||
need_scan = 0;
|
||||
if(list.count > 0 && !evdev_found) {
|
||||
switch_mask = current_switch_mask(&evdev_found);
|
||||
}
|
||||
@@ -489,17 +508,46 @@ int main(void)
|
||||
fds[nfds].revents = 0;
|
||||
nfds++;
|
||||
}
|
||||
if(poll(fds, (nfds_t)nfds, LID_LOOP_MS) < 0 && errno != EINTR) {
|
||||
for(i = 0; i < list.count; i++)
|
||||
poll_nfds = nfds;
|
||||
if(inotify_fd >= 0) {
|
||||
fds[poll_nfds].fd = inotify_fd;
|
||||
fds[poll_nfds].events = POLLIN;
|
||||
fds[poll_nfds].revents = 0;
|
||||
poll_nfds++;
|
||||
}
|
||||
if(gpio_override || candidate != stable_closed || now < fast_until) {
|
||||
timeout_ms = LID_LOOP_MS;
|
||||
} else if(list.count == 0) {
|
||||
timeout_ms = 500;
|
||||
} else {
|
||||
timeout_ms = -1;
|
||||
if(reconcile_at > 0) {
|
||||
long long rem = reconcile_at - now;
|
||||
timeout_ms = rem > 0 ? (int)rem : 0;
|
||||
}
|
||||
if(inotify_fd < 0 && (timeout_ms < 0 || timeout_ms > 2000))
|
||||
timeout_ms = 2000;
|
||||
}
|
||||
if(poll(fds, (nfds_t)poll_nfds, timeout_ms) < 0 && errno != EINTR) {
|
||||
for(i = list.count - 1; i >= 0; i--)
|
||||
drop_device(&list, list.devs[i].fd);
|
||||
need_scan = 1;
|
||||
}
|
||||
now = now_ms();
|
||||
edge = 0;
|
||||
prev_count = list.count;
|
||||
if(nfds > 0)
|
||||
read_ready(&list, fds, nfds, &switch_mask, &edge);
|
||||
if(list.count < prev_count)
|
||||
need_scan = 1;
|
||||
if(inotify_fd >= 0 && (fds[nfds].revents & POLLIN) &&
|
||||
drain_inotify(inotify_fd)) {
|
||||
need_scan = 1;
|
||||
}
|
||||
/* An EV_SW edge is the hardware interrupt: read the raw hall lines at
|
||||
* once instead of waiting for the next reconciliation tick. The result
|
||||
* is sticky, so a stale EV_SW mask cannot flip the candidate back. */
|
||||
* once instead of waiting for a poll tick. The result is sticky, so a
|
||||
* stale EV_SW mask cannot flip the candidate back, and steady state can
|
||||
* sleep indefinitely on hardware interrupts without debugfs polling. */
|
||||
if(edge) {
|
||||
hall = hall_state();
|
||||
hall_observed = hall >= 0 ? hall :
|
||||
@@ -508,8 +556,9 @@ int main(void)
|
||||
fast_until = now + 120;
|
||||
if(hall == 1 && !(switch_mask & (int)switch_bit(SW_LID)))
|
||||
sync_sw_lid(1);
|
||||
} else if(now - last_hall_poll >=
|
||||
(now < fast_until ? HALL_EDGE_MS : HALL_POLL_MS)) {
|
||||
} else if((now < fast_until && now - last_hall_poll >= HALL_EDGE_MS) ||
|
||||
(gpio_override && now - last_hall_poll >= HALL_POLL_MS) ||
|
||||
(reconcile_at > 0 && now >= reconcile_at)) {
|
||||
hall = hall_state();
|
||||
if(hall >= 0)
|
||||
hall_observed = hall;
|
||||
@@ -527,14 +576,16 @@ int main(void)
|
||||
stable_closed = candidate;
|
||||
last_transition = now;
|
||||
on_transition(stable_closed);
|
||||
reconcile_at = now + LID_BROADCAST_MS;
|
||||
}
|
||||
if(now - last_broadcast >= LID_BROADCAST_MS) {
|
||||
if(reconcile_at > 0 && now >= reconcile_at &&
|
||||
candidate == stable_closed) {
|
||||
reconcile_at = 0;
|
||||
write_lid_state(stable_closed);
|
||||
sync_sw_lid(stable_closed);
|
||||
if(stable_closed)
|
||||
enforce_closed_dark();
|
||||
cover_send(stable_closed ? "CLOSED" : "OPEN");
|
||||
last_broadcast = now;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -155,7 +155,11 @@ static void read_ready(struct watch_list *list, struct pollfd *fds, int nfds)
|
||||
int main(void)
|
||||
{
|
||||
const char *lock_override = getenv("BANANARCHY_VOLUME_LOCK");
|
||||
const char *glob_override = getenv("BANANARCHY_INPUT_GLOB");
|
||||
int has_glob_override = glob_override && *glob_override;
|
||||
int lock_fd;
|
||||
int inotify_fd;
|
||||
int need_scan = 1;
|
||||
struct watch_list list;
|
||||
long long last_scan = 0;
|
||||
if(is_non_flip_profile())
|
||||
@@ -166,16 +170,22 @@ int main(void)
|
||||
return 1;
|
||||
install_reaper();
|
||||
memset(&list, 0, sizeof(list));
|
||||
inotify_fd = open_input_inotify();
|
||||
while(1) {
|
||||
long long now = now_ms();
|
||||
struct pollfd fds[WATCH_MAX];
|
||||
struct pollfd fds[WATCH_MAX + 1];
|
||||
int nfds = 0;
|
||||
int poll_nfds;
|
||||
int timeout_ms;
|
||||
int prev_count;
|
||||
int i;
|
||||
if(now - last_scan > 2000) {
|
||||
if(need_scan ||
|
||||
((inotify_fd < 0 || list.count == 0) && now - last_scan >= 2000)) {
|
||||
scan_devices(&list, WATCH_VOLUME_KEYS);
|
||||
last_scan = now;
|
||||
need_scan = 0;
|
||||
}
|
||||
if(list.count == 0) {
|
||||
if(list.count == 0 && inotify_fd < 0) {
|
||||
poll(NULL, 0, 500);
|
||||
continue;
|
||||
}
|
||||
@@ -185,11 +195,33 @@ int main(void)
|
||||
fds[nfds].revents = 0;
|
||||
nfds++;
|
||||
}
|
||||
if(poll(fds, (nfds_t)nfds, 1000) < 0 && errno != EINTR) {
|
||||
for(i = 0; i < list.count; i++)
|
||||
poll_nfds = nfds;
|
||||
if(inotify_fd >= 0) {
|
||||
fds[poll_nfds].fd = inotify_fd;
|
||||
fds[poll_nfds].events = POLLIN;
|
||||
fds[poll_nfds].revents = 0;
|
||||
poll_nfds++;
|
||||
}
|
||||
if(list.count == 0)
|
||||
timeout_ms = 500;
|
||||
else if(has_glob_override || inotify_fd < 0)
|
||||
timeout_ms = 1000;
|
||||
else
|
||||
timeout_ms = -1;
|
||||
if(poll(fds, (nfds_t)poll_nfds, timeout_ms) < 0 && errno != EINTR) {
|
||||
for(i = list.count - 1; i >= 0; i--)
|
||||
drop_device(&list, list.devs[i].fd);
|
||||
need_scan = 1;
|
||||
}
|
||||
prev_count = list.count;
|
||||
if(nfds > 0)
|
||||
read_ready(&list, fds, nfds);
|
||||
if(list.count < prev_count)
|
||||
need_scan = 1;
|
||||
if(inotify_fd >= 0 && (fds[nfds].revents & POLLIN) &&
|
||||
drain_inotify(inotify_fd)) {
|
||||
need_scan = 1;
|
||||
}
|
||||
read_ready(&list, fds, nfds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -252,6 +253,34 @@ static BA_UNUSED void scan_devices(struct watch_list *list, enum watch_filter fi
|
||||
globfree(&gl);
|
||||
}
|
||||
|
||||
static BA_UNUSED int open_input_inotify(void)
|
||||
{
|
||||
const char *override = getenv("BANANARCHY_INPUT_GLOB");
|
||||
int fd;
|
||||
if(override && *override)
|
||||
return -1;
|
||||
fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
if(fd < 0)
|
||||
return -1;
|
||||
if(inotify_add_watch(fd, "/dev/input",
|
||||
IN_CREATE | IN_DELETE | IN_ATTRIB | IN_MOVED_TO) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
static BA_UNUSED int drain_inotify(int fd)
|
||||
{
|
||||
char buf[512];
|
||||
int got = 0;
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
while(read(fd, buf, sizeof(buf)) > 0)
|
||||
got = 1;
|
||||
return got;
|
||||
}
|
||||
|
||||
static BA_UNUSED int is_non_flip_profile(void)
|
||||
{
|
||||
const char *override = getenv("BANANARCHY_LID_PROFILE");
|
||||
|
||||
@@ -102,6 +102,7 @@ void blankScreenBacklight() {
|
||||
readSmallFileTrimmed("/run/bananarchy/cover-backlight") == "1") {
|
||||
writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", "0");
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "powersave");
|
||||
writeSysfsStr("/sys/class/devfreq/1c00000.gpu/governor", "powersave");
|
||||
return;
|
||||
}
|
||||
std::string cur = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness");
|
||||
@@ -113,6 +114,7 @@ void blankScreenBacklight() {
|
||||
writeSysfsStr("/sys/class/backlight/backlight/brightness", "0");
|
||||
writeSysfsStr("/sys/class/backlight/backlight/bl_power", "4");
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "powersave");
|
||||
writeSysfsStr("/sys/class/devfreq/1c00000.gpu/governor", "powersave");
|
||||
}
|
||||
|
||||
void wakeScreenBacklight() {
|
||||
@@ -121,6 +123,7 @@ void wakeScreenBacklight() {
|
||||
return;
|
||||
}
|
||||
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor", "schedutil");
|
||||
writeSysfsStr("/sys/class/devfreq/1c00000.gpu/governor", "simple_ondemand");
|
||||
std::string cur = readSmallFileTrimmed("/tmp/sxmo_saved_brightness");
|
||||
int val = std::atoi(cur.c_str());
|
||||
if (val < 1) {
|
||||
|
||||
Reference in new issue
Block a user