Repository navigation
supervisor, session: idle the speaker path while nothing plays - #176
Merged
Merged
Conversation
With nothing playing there is no grant to protect: the kernel holds the
amps at its floor and refuses every start. Yet the PCM reader and the
helper checker woke every millisecond (about 2 x 990 wakeups/s on every
Mac), the 10 ms loop ran at the RT uclamp default (util_min 1024), which
put the P-clusters at their top step on every tick, and the thermal
thread polled at 10 Hz.
After half a second with no grant and no demand the supervisor goes
idle. Both pollers read every 100 ms. The loop ticks every 250 ms, or at
once when the helper renames a new report into its directory (inotify),
and drops its utilization floor to 0. The thermal thread polls once a
second while the engine publishes nothing. Every check still runs at
that pace, and hard amp faults still latch.
A demand wakes everything first. The tick that sees it while idle does
not act on it: it kicks both pollers (eventfds), restores the loop's
default floor and ticks again 2 ms later, after their fresh readings. A
grant always comes from a tick read at full rate, and the lease still
needs two clean ticks in a row. While a stream plays nothing changes:
1 ms polls, 10 ms ticks, the default floor. If the report directory
cannot be watched, the loop keeps its 10 ms tick while idle.
The protect stage no longer beats while idle (next commit), so the
supervisor logs once per idle spell that every other check holds
("protection ready: ... idles until a stream starts").
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The protect stage ran with node.always-process, so PipeWire's dummy driver ran it, and the voicing in front of it, on silence all the time (M1 Pro: 47 cycles/s, about 1.2 ms of voicing per cycle, about 6% of a core, plus the data loop's RT boost). macOS stops its speaker engine shortly after the last client. The generated graph drops always-process from both halves of the protect stage and makes its output non-passive. A client stream runs the stage and the voicing on the dummy driver from its first frame, and a link from the stage's output to the amps keeps it running without a client, as before. That leaves a gap before the grant, which a new sink closes: sgv2.hold.<m>, with no device, no clock of its own, and outside the amps' group. The helper links the stage's output to it while the speakers are wanted (play=1, plus one more report, so the supervisor reads play=0 while the stage still beats). A stream that ends before the grant then keeps its held frames moving to the amps, and a withdrawal during the hold can be granted again. With nothing playing the hold is unlinked and the stage stops. While nothing plays and nothing is linked, the helper writes its report every 250 ms instead of 50 ms. A change is still reported at once, and the supervisor accepts a report for 500 ms. The helper also unlinks the hold when it stops. Checked on PipeWire 1.6.7 with the graph's shape (null sinks, builtin copy nodes). Idle, every node is suspended or idle. With a 50 ms client that leaves before the amps are linked, the hold keeps the stage running on the dummy driver; the amps take over as driver once linked; unlinking the hold stops everything. With the output passive and no always-process, the stage stopped under a linked amps sink. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without always-process the protect stage and the voicing first negotiate their ports when the first stream after a PipeWire start links in, and that stream lost its first 4096 frames at the stage's output on the J413 (1024 before, from the amps' own first link). When the stage's output and the hold first both exist, the helper links the hold for one second. The stage and the voicing negotiate and run once on the dummy driver with no client and no amps, then stop. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RyanTheTide
marked this pull request as ready for review
November 18, 2026 00:18
erikwb
pushed a commit
to erikwb/speakerguardd
that referenced
this pull request
Nov 22, 2026
aurora-silicon#187 generated the J815 graph before aurora-silicon#176 added the hold sink and its links to the generator, so the checked-in file is stale: gen.py --check fails and the J815 graph lacks the hold sink that keeps the protect stage running between a stream's end and the grant's end. Regenerated with packaging/session/gen.py; no hand edits. Signed-off-by: Ryan <ryan@aurorasilicon.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With nothing playing, speakerguardd v2 kept working as if a stream might start any millisecond:
node.always-process, so the dummy driver ran it and the voicing on silence (M1 Pro: 47 cycles/s, about 6% of a core);No grant is held while idle (the kernel floors the amps and refuses every start), so none of that protects anything.
Supervisor (
pace): after 0.5 s with no grant and no demand, the pollers read every 100 ms, the loop ticks every 250 ms or at once on a new helper report (inotify), the loop's util_min drops to 0, and the thermal thread polls once a second. The tick that sees a demand while idle does not act on it: it wakes the pollers and ticks again 2 ms later, so a grant always comes from readings taken at full rate, and the lease still needs two clean ticks. While a stream plays nothing changes.Graph and helper: the protect stage drops
always-processand its output is no longer passive. A client runs the stage from its first frame; a link to the amps keeps it running as before. A new device-less sink,sgv2.hold.<m>(not a driver, outside the amps' group), is linked by the helper while the speakers are wanted, so a stream that ends before the grant still reaches the amps and a withdrawal during the hold can be granted again. With nothing playing the hold is unlinked and the stage and the voicing stop. The helper's report period is 250 ms while idle (changes are still reported at once). When the graph first appears, the helper links the hold for one second, so the stage negotiates once before the first stream.Untouched: the observer's checks and bounds, the lease rule, the plugin, the voicing law and the parity attestations.
Idle rows: nothing playing, panel off, SMC total system power, same boot, package / this branch / package again.
At idle every sgv2 node is suspended; pw-top ERR stays 0 on the voicing nodes.
Wakes: a -200 dBFS marker (digital zero on the amps' 24-bit PCM) into the protect stage, recorded at the stage's output, frames checked for order and loss.
In the journal every wake reads play=1, then the grant 40-60 ms later, then the held frames released (11-53 ms held with the package, 32-96 ms with this branch). On the fourth J413 cold wake the helper reported links=0 for the test stream's whole life (the test linked it node-to-node into the 12-port protect input with
pw-link), so no grant came until that stream ended and its 500 ms pre-roll overflowed. Later rows link channel for channel, and none repeated it. Asyncpw-playstreams still lose 512 frames on a cold wake with either build (a PipeWire issue with async buffers across a driver change).speakerguardd-selfcheck verifypasses on the J413, J316s, J616s and J700 with both builds. Enforcing, no AVCs.The J616s row ran these three commits on the 0.47 package (same helper and gen.py, supervisor built on that package's commit). The J700 row ran this branch merged with v2 4ac2b90, over the 0.49 package with the LV2 plugin from the same tree, so both arms carry #171 and #179 and differ only by this change. On both Macs every voicing node reads ERR 0 at idle, and the speaker node reads at most one ERR after verify with either build.
Tests:
cargo test --workspace, clippy-D warnings, fmt, and the session tests (new: hold links, priming, generated graph shape) pass.🤖 Generated with Claude Code