Skip to content

supervisor, session: idle the speaker path while nothing plays - #176

Merged
RyanTheTide merged 4 commits into
v2from
sgidle2/idle-quiet
Nov 18, 2026
Merged

RyanTheTide merged 4 commits into
v2from
sgidle2/idle-quiet

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

With nothing playing, speakerguardd v2 kept working as if a stream might start any millisecond:

  • the PCM reader and the helper checker polled every 1 ms (about 2 x 990 wakeups/s);
  • the protect stage ran with node.always-process, so the dummy driver ran it and the voicing on silence (M1 Pro: 47 cycles/s, about 6% of a core);
  • the 10 ms loop inherited the RT uclamp default (util_min 1024), which kept the P-clusters at their top step.

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-process and 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.

Mac package this branch speakerguardd wakeups/s system ctxsw/s
J413 (battery) 1.782 / 1.800 W 1.029 / 1.022 W 2099 -> 30 3024 -> 688
J316s (AC) 3.279 / 3.430 W 2.439 / 2.425 W 2087 -> 30 3047 -> 760
J616s (AC) 3.480 / 3.682 W 2.843 / 2.828 W 2082 -> 30 3075 -> 769
J700 (AC) 1.839 / 1.836 W 1.651 / 1.655 W 2077 -> 30 3677 -> 1335

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.

Mac build cold after 12 s idle (sync client) warm first wake after a PipeWire start
J413 package 3/3 lossless 2/2 1024 lost
J413 this branch 3/4 lossless (see below) 2/2 4096 lost (before the priming commit)
J316s package 3/4 lossless (1024 lost) 2/2
J316s this branch 4/4 lossless 2/2 1024 lost
J616s package 3/4 lossless (1024 lost) 1/2 (one capture caught 512 frames of the marker)
J616s this branch 4/4 lossless 2/2 1024 lost
J700 package 3/4 lossless (1024 lost) 1/2 (one capture caught 512 frames of the marker)
J700 this branch 4/4 lossless 2/2 1024 lost

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. Async pw-play streams still lose 512 frames on a cold wake with either build (a PipeWire issue with async buffers across a driver change).

speakerguardd-selfcheck verify passes 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

RyanTheTide and others added 3 commits November 13, 2026 22:32
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
RyanTheTide marked this pull request as ready for review November 18, 2026 00:18
@RyanTheTide
RyanTheTide merged commit 593e123 into v2 Nov 18, 2026
6 checks passed
@RyanTheTide
RyanTheTide deleted the sgidle2/idle-quiet branch 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>
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