Skip to content

touchbar: sleep until there is something to do - #73

Open
dnlbtz wants to merge 2 commits into
standardagents:mainfrom
dnlbtz:touchbar-poll
Open

dnlbtz wants to merge 2 commits into
standardagents:mainfrom
dnlbtz:touchbar-poll

Conversation

@dnlbtz

@dnlbtz dnlbtz commented Nov 29, 2026

Copy link
Copy Markdown

With nothing to draw, the two Touch Bar daemons wake the CPU about 290
times a second. The renderer's main loop sleeps 5 ms between nonblocking
receives, and t1-touchbar-hw waits for input with a 10 ms timeout. On my
MacBookPro14,3 that was 1210 of the 1440 idle exits per second of the whole
machine.

The renderer now blocks in poll() on the hardware socket and on a wake
socket that the desktop provider and overlay threads write to after they
publish. It sets a timeout only while something is timed: a fade or
progress animation (at the old 5 ms pacing) or the next hold repeat. For
this t1-platform gets SeqPacketClient::wait_readable, backed by
t1_seqpacket_wait_readable in C.

t1-touchbar-hw now waits up to 50 ms while a renderer is connected, the
session check interval. Digitizer, Fn and renderer readiness still end the
wait at once. Without a renderer it keeps the 10 ms probe of the listener.
With #70 applied, the Fn state under a keyboard grab is then read every
50 ms instead of every 10 ms.

Measured on a MacBookPro14,3 with CachyOS (kernel 7.3.6), idle, panel on:
both daemons running against both stopped with SIGSTOP, interleaved 30 s
windows, package power from RAPL and system power from the SMC (PSTR).

context switches/s, renderer + service package system
before 194 + 97 0.28 to 0.32 W 0.37 W
after 10 + 20 0.06 W 0.07 W

The 10 a second left in the renderer are the overlay watcher's 100 ms file
poll, which I did not touch.

Tested: cargo fmt --check, clippy and the tests of t1-platform,
t1-touchbar and t1-touchbar-hw, the t1-daemons C tests with and without
the sanitizers. With Rust 1.100 clippy also reports a deprecated
fetch_update and assert_is_empty in code this does not touch. On the
machine: display and keyboard brightness, the hold repeat, Fn under keyd,
and the Touch ID overlay fading in and out.

The renderer main loop tried a nonblocking receive and slept 5 ms when
nothing had arrived, so an idle Touch Bar woke the CPU about 200 times a
second. It now blocks in poll() on the hardware socket and on a wake
socket that the desktop-provider and overlay threads write to after
publishing, with a timeout only while something is timed: a fade or a
progress animation (the old 5 ms pacing) or the next hold repeat.

t1-platform gets SeqPacketClient::wait_readable for this, backed by
t1_seqpacket_wait_readable in C.
With a renderer connected the service woke every 10 ms to look for
input, about 100 times a second. Digitizer, Fn and renderer readiness
already end the wait, so it now waits up to the session check interval
(50 ms), which is still often enough for the session check. Without a
renderer it keeps the 10 ms probe of the listener.

This branch has not been deployed

No deployments
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