Repository navigation
Add focus boost for the 16-inch M4 Max - #97
AxxzyWasTaken wants to merge 3 commits into
Conversation
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryAdds a focus boost service for the 16-inch M4 Max (
The earlier threads were checked against the current code. Owner checks, bounded socket reads, exit cleanup, immediate scans after app switches, live-socket fallback, and the corrected shutdown instructions are present. No new actionable issues were found. Tests were not run during this review.
|
65e39a4 to
9dd244e
Compare
|
Rebased onto |
9dd244e to
627c76b
Compare
|
Pushed
Added test cases for symlinked/wrong-UID session paths, wrong socket owner, and late-spawned worker reset on hold expiry; |
627c76b to
c117ecc
Compare
|
Pushed
|
A short burst of page work on the M4 Max stays slow because schedutil takes time to raise the clock, and a blanket uclamp.min costs power all the time, video included. The new service sets uclamp.min to 822 on the focused Hyprland app for 3 seconds after input or a window change, then back to 0. A fullscreen app using at least 0.75 of a core keeps the boost without input. It runs only on the J616C and reads input only to time it. Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
- Change only processes whose real and effective uid in /proc/<pid>/status are the session owner's, for the focused PID Hyprland reports and for every process uclampset touches, so a replaced socket can't steer the root service at other users. - Derive the session owner from lstat(/run/user/<uid>) (non-root, directory name matching st_uid), verify every hypr path component and socket with lstat (no symlinks, matching owner), verify SO_PEERCRED peer uid on both Hyprland sockets, and skip dead leftover sockets so a crashed newer session does not block an older live one. - Rescan the focused app's cgroups on hold expiry, app switch, and exit so worker children spawned after the last scan do not keep an inherited boost. - Give up on an activewindow reply over 64 KiB or 1 s, and drop an event line over 64 KiB instead of buffering it. - Reset every boosted process on SIGTERM, SIGINT and any other exit; KillMode=mixed keeps systemd's SIGTERM off an in-flight uclampset. - A switch to another app clears the scan state, so the new app is boosted at once instead of at the next rescan, and a pending focus change no longer waits out the select timeout. - README and manual: mask, not disable, turns it off, since the vendor wants link under /usr/lib can't be disabled. The test now drives the event loop against fake Hyprland sockets: switching between two boosted apps, resetting a late-spawned worker on hold expiry, rejecting symlinked/mismatched-uid session paths and wrong socket owners, skipping dead sockets in favor of an older live session, a window owned by another uid, and SIGTERM resetting the boost. Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
… and low-power guard Drop the fullscreen-only gate on sustained workload detection so both windowed and fullscreen games/heavy focused apps stay on P-cores automatically without affecting desktop or hardware-decoded video battery life: - Monitor CPU usage of any focused app cgroup with hysteresis (enter at >= 0.75 cores, or >= 0.25 cores while G17 GPU reports effort_full=true; exit at 0.50 / 0.15) while keeping 10 s idle sleep when inactive. - During active 3D workloads (heavy_focus && gpu_full), raise a short GPU idle_off_delay_ms (< 16 ms) to 16 ms to avoid ~137/s GPU core power-cycling stutter on battery Balanced, and restore the saved value on window switch, workload exit, low-power switch, service stop, or startup crash recovery via /run/omarchy-mac-focus-boost-gpu-idle (preserving external sysfs overrides). - Respect the system low-power platform profile (cached at 1 s to avoid sysfs overhead on input events), disabling both CPU boost and GPU idle hold in Low Power mode. - Update focus-boost-test.sh with unit + live event-loop tests covering crash recovery, external sysfs override preservation, windowed CPU-only vs 3D workloads, low-power drop, and SIGTERM cleanup, plus README and manual docs.
c117ecc to
8205063
Compare
What changes
Adds
omarchy-mac-focus-boost, a service for the 16-inch M4 Max (J616C) only. For 3 seconds after keyboard, trackpad or mouse input or a window change, it setsuclamp.minto 822 on every process of the focused Hyprland app, then back to 0.Any focused windowed or fullscreen app doing sustained heavy work (
>= 0.75CPU cores, or>= 0.25CPU cores while the G17 GPU reportseffort_full=true, with0.50/0.15exit hysteresis) keeps the boost automatically without input, while desktop, browsing, and hardware-decoded video (< 0.15CPU cores,effort_full=false) stay untouched atuclamp.min = 0with10 sidle wakeups.During active 3D workloads (
heavy_focus && effort_full=true), ifidle_off_delay_msis below16 ms(for example2 mson battery Balanced, which otherwise triggers ~137 GPU power-cycles/sec during 120 fps games), it temporarily liftsidle_off_delay_msto16 msand restores the original value on window switch, workload end, Low Power switch, service stop, or startup crash recovery via/run/omarchy-mac-focus-boost-gpu-idle(leaving external sysfs overrides untouched). In thelow-powerplatform profile (cached at 1 s), both CPU boost and GPU idle hold stay off.A blanket
uclamp.mincosts power all the time, and with none, short bursts run about three times slower:uclamp.min0uclamp.min822Boosting only on input and sustained focused workloads keeps video cheap: YouTube in Brave, untouched, was 15.6 W with a focus boost that didn't wait for input, and 11.9 W with this one.
It runs as root, because reading input, raising
uclamp.min, and updatingidle_off_delay_msneed it. Input events are only timed, never stored. It changes only processes whose real and effective uid match the verified Hyprland session owner's.Verification
omacom/main(8205063).omarchy-mac/test/focus-boost-test.shandomarchy-mac/test/platform-test.sh: all checks pass (3/3 consecutive runs), including fake-socket event-loop tests for:SIGTERMreset;idle_off_delay_msat2 ms);effort_full=true: keeps CPU boost and raisesidle_off_delay_ms2 -> 16 ms);low-powerprofile immediately dropping both CPU boost and GPU idle hold;50 msleft intact) and startuprecover_stale()after an unclean exit.J616C, battery Balanced): windowed and fullscreen 120 fpsCordial(0.34.0) automatically promoted to P-cores (uclamp_min=822) and16 msGPU hold, restoring cleanly touclamp_min=0and2 ms(cores_powered=false,7.7 Wbattery desktop) within 2 s of unfocusing.Screenshots
No visible change: it's a background service.