Skip to content

Eliminate idle polling wakeups in shell status and power daemons - #297

Open
grierj wants to merge 1 commit into
OrchardLinux:mainfrom
grierj:idle-wakeups
Open

grierj wants to merge 1 commit into
OrchardLinux:mainfrom
grierj:idle-wakeups

Conversation

@grierj

@grierj grierj commented Dec 5, 2026

Copy link
Copy Markdown

Problem

Tracing an idle J207 (iPad Pro 10.5-inch) session with ftrace (sched_process_exec) showed 8 process forks per second (24 execs / 3 s) and 326 arch_timer IRQs/s at complete desktop idle:

  • panels/power/Status.qml ran a 1-second omarchy-battery-status --shell timer (which also forked awk) across four live instances simultaneously (bar StatusCluster, lock screen StatusCluster, ControlCenter, and panels/power/Panel).
  • plugins/status/RotationLock.qml ran four separate 2-second polling timers and four startup busctl probes.
  • arch-ipad-auto-brightness woke every second and atomically rewrote its status JSON even when disabled.
  • omarchy-powerd woke every second in both its main loop (timeout()) and playback_worker() (dark.wait(1)) while lit.

Changes

  • desktop/shell/bin/omarchy-battery-status: compute size (Wh) and rate (W) in pure bash 64-bit integer arithmetic with zero awk forks (guarding octal leading zeros, empty optional sysfs files under set -e, and digit-length overflow).
  • qs.Commons.BatteryStatus (Commons/BatteryStatus.qml + thin panels/power/Status.qml): share one UPower-signal-driven reader (onBatteryChanged, displayDevice percentage/state/present signals) with a 30 s fallback timer, coalesced concurrent refreshes (refreshPending), and on-demand refresh when Control Center or the Power panel opens.
  • qs.Commons.RotationLockState (Commons/RotationLockState.qml + thin plugins/status/RotationLock.qml): share one busctl probe and directory-watched FileView (watching both ~/.config/omarchy and its parent so directory replacement re-arms the watch) with no polling timer, plus a shared toggle() helper used by both ControlCenter and DisplayPage.
  • desktop/configuration/auto-brightness: give the live daemon sole ownership of status.json and a private Unix datagram wake socket (0o600, never touched by --probe/--dry-run, per-instance staging + inode-checked cleanup), interrupt both enabled and disabled waits on CLI toggles, stop and reset sensor state when off, cache status only after atomic replace succeeds, report live brightness in cmd_status, update IioSource.interval on SIGHUP, and close PTY fds on Popen failure.
  • system/overlay/usr/libexec/omarchy-powerd: watch the inhibitor child via os.pidfd_open() (1 s fallback if unavailable) so steady ON sleeps until its 5 s key scan while honoring retry deadlines and never spinning while waiting on logind, and block playback_worker() on dark.wait() while lit.
  • tests/test_idle_wakeups.py: unit tests covering pure-bash omarchy-battery-status with PATH="", singleton proxies, auto-brightness wake socket / --probe safety / handoff cleanup, and omarchy-powerd idle timeouts.

Live verification (J207 / iPad Pro 10.5-inch)

  • 5-second idle ftrace (sched_process_exec): 40 execs / 5 s → 0 background execs / 5 s
  • arch_timer IRQs/s: 326/s → 80/s (4× reduction); CPU 172 MHz residency: 96% (4800 / 5000 ms)
  • omarchy-powerd voluntary context switches across all threads over 4 s lit idle: 1 (with pidfd attached)
  • omarchy-auto-brightness: --probe leaves live status.json intact; on/off toggles wake via Unix socket in <0.3 s; status.json untouched while off.

At desktop idle the shell was spawning 8 processes per second because
panels/power/Status.qml ran a 1-second omarchy-battery-status timer
(which also forked awk) across four live instances (bar, lock screen,
control center, and power panel). RotationLock.qml likewise ran four
separate 2-second polling timers and four startup busctl probes, while
arch-ipad-auto-brightness rewrote its status JSON every second even when
turned off and omarchy-powerd woke every second in both its main loop
and playback_worker while lit.

- Compute omarchy-battery-status size and rate in pure bash without awk
  (guarding optional sysfs reads, octal leading zeros, and integer width).
- Share one UPower-signal-driven BatteryStatus singleton (30 s fallback,
  coalesced concurrent refreshes, on-demand refresh when Control Center
  or Power panel opens).
- Share one RotationLockState singleton watching the config directory
  (and its parent for directory replacement) with one busctl probe and a
  shared setLocked() helper used by both Control Center and Display
  settings.
- Give arch-ipad-auto-brightness a daemon-owned Unix wake socket (never
  touched by --probe/--dry-run), interrupt both enabled and disabled
  waits on CLI toggles, stop and reset sensor state while off, cache
  status only after atomic replace succeeds, report live brightness in
  cmd_status, update IioSource.interval on SIGHUP, and close PTY fds on
  Popen failure.
- Watch omarchy-powerd inhibitor child exit via pidfd_open so the main
  loop can sleep until its 5 s key scan while honoring retry deadlines,
  and block playback_worker on the dark event while lit.

Assisted-by: LLM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant