Repository navigation
Protect the V/I machines: asahi governor, J316/J413/J616 configs, shadow and replay - #6
Closed
RyanTheTide wants to merge 6 commits into
Closed
RyanTheTide wants to merge 6 commits into
RyanTheTide wants to merge 6 commits into
Conversation
speakerguardd now runs every machine's protection from one engine. Estimators, per speaker and per sense period: - feed-forward: the amplifier voltage squared over the speaker's DC resistance (r_ff, defaulting to z_nominal), as the machines' own protection does; on every machine. - measured power: mean V*I, where the amplifier has current sense (S16 V/I sense words, sense_format = s16); Asahi Linux's speakersafetyd method. - low-band resistance, sum(v*i)/sum(i^2) under 120 Hz, only measured and logged for now. Governors: - legacy: unchanged (0.1.2 budgets). What 0.1.1's after-gain budget would have asked for is logged as legacy_011_budget, for comparison only. - asahi: speakersafetyd's published behaviour (measured power, a linear ramp to its min_gain across t_window, peak-hold hysteresis, its cold and warm start rules), reimplemented from its description. Unmeasured time is charged at the worst case and faults hand the speakers to the kernel's safe level instead of panicking (sample rate 0 at start is plain idle). - unified: a model-predictive regulator. It lets through the most power that keeps each model's coil at or under the working limit (less t_ctrl_headroom) over horizon_s, attacks at once and releases with release_s. Where V/I sense exists, the measured-power model runs too and can only tighten. The 1 s and 60 s budgets act on the power before the card's gain. Each governor is fed the power its own gains would have let through, so the ones that do not write the card yield a counterfactual. --shadow logs them all once a second to shadow.jsonl next to the state file. --record keeps raw sense periods, and --replay runs every governor on a recording offline, optionally louder (--gain-db), and reports what each would have done. Cards with a volume control per speaker get per-speaker reductions, linked by group. The V/I machines' sense switches are turned on and their amplifier gain set to its maximum. New configs for the J316 (M1 Pro) and the J413 (M2), with the feed-forward constants from the machines' own tuning and the measured-power constants from speakersafetyd's configs (MIT through 2.0.2; credit to the Asahi Linux contributors). The J700 config gains the unified governor's settings. Its default governor stays legacy. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
- The SN012776 machines' 12-channel S16 sense PCM takes at most 64 KiB per hardware period, less than one 4096-frame sense period, so the open failed with EINVAL. Split the hardware period (2, 4, ... per sense period) until the device takes it; the buffer still holds four sense periods and the reader still waits for a whole one. - Unified governor: over the target, bring the coil back to it by the end of the next period (and let nothing through when even silence would not), instead of an unbounded reduction; nothing-may-pass is a finite 120 dB. - --horizon overrides the unified governor's look-ahead (replay sweeps). Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
On a 338 s recording from the M1 Pro, replayed at 0 to +18 dB against speakersafetyd's own arithmetic, the asahi governor's gains differed by up to 0.25 dB, because the models were stepped once a period on the period's mean power and long gaps were cooled in one lagged step. - The asahi models now integrate the measured V*I sample by sample, as speakersafetyd does, with 0.5% more power than measured (ASAHI_MARGIN, +0.02 dB) so that rounding never leaves them cooler. - Cooling without power is exact for any length (the cascade's closed form), for every model. - The replay counts gaps as speakersafetyd does: over four periods the models cool, shorter gaps hold the temperature. On that recording our gains now never ask for less than speakersafetyd's until after they have first asked for more. Driving speakersafetyd's own model with our gains gives lower peak coil temperatures for every speaker at every level. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The machine's own protection tunes the J616 with the same "spp3" profile as the J316 (family S2, shared by J316, J416, J516, J616 and J716), so the feed-forward constants are the J316's and the measured-power constants are speakersafetyd's j316 values (MIT through 2.0.2; credit to the Asahi Linux contributors). speakersafetyd has no J616 profile. Only the sense channel map differs: the six SN012776 amps' slots on the AOP's serializer give LW1 RW1 LW2 RW2 LT RT. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
unified_caps (or --unified-caps) caps the unified governor's thermal reduction at t_reduction_max and its power-budget reduction at p_reduction_max, as macOS's loudspeaker manager does (12 dB and 3 dB on the J700); past them the coil may run to its hard limit, where the daemon hands the speakers to the kernel. Off by default. --ctrl-headroom overrides t_ctrl_headroom for replay sweeps. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…w-only - j316, j413 and j616 select governor = asahi and max_reduction = 7 (as speakersafetyd's unit does); [Globals] max_reduction is the default for -m. - The unified governor may write the card only with --experimental-unified; elsewhere it runs in shadow. - The udev rule starts the daemon on those three machines too, and the unit conflicts with speakersafetyd: one daemon owns the sense PCM. - README: the V/I machines, the asahi governor and its evidence, switching from speakersafetyd and back, shadow/record/replay. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
RyanTheTide
added a commit
that referenced
this pull request
Oct 24, 2026
Porting PR #6 onto 0.1.6 turned up a defect in 0.1.6's hand-off. Uncovered time was charged at the gain the controls held when the charge was made, not while the time passed. The hand-off introduced for R3 writes the safe level first. After a failed sample-rate read, the disarm runs before the pass's charge, so the time since the last period was charged at 20 dB although it played at 0 dB: 100 times less power. The same holds for any write between the end of the model's account and the charge. The guard now keeps a short record of what the controls held and whether the lock was renewed since the account's end. A worst-case charge takes the least reduction held over its span, with the lease split as before. Measured frames take the most reduction held, for the budgets' power before the gain. The record is trimmed to the entry in effect at the account's end. Two tests fail without this. A hand-off after 150 ms of unaccounted playback at 0 dB is charged at 0 dB (71.4 C, against 50.2 C before), and time after it at the safe level. Through the loop, a rate read that fails right after a period charges the pending time at 0 dB (57.3 C, against 50.1 C before). 80 of 80 pass. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Contributor
Author
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.
speakerguardd now protects the Apple laptops with speaker current and voltage sense: the MacBook Pro 16" M1 Pro (J316), the MacBook Air M2 (J413) and the MacBook Pro 16" M4 Pro (J616). Until now it only covered the MacBook Neo. The Neo's behaviour is unchanged (the 0.1.2 legacy governor).
What's in it
group. The SN012776 machines' 12-channel sense PCM takes at most 64 KiB per hardware period, so the hardware period is split until the device accepts it.asahigovernor, which writes the card on these machines. It is the behaviour Asahi Linux's speakersafetyd ships, reimplemented from its description: measured V*I per sample into the two-node model with speakersafetyd's constants, the ramp to itsmin_gain, and peak-hold hysteresis. Credit: the Asahi Linux contributors (speakersafetyd, MIT through 2.0.2). No code was copied. The differences only go toward protection:--shadowlogs every governor and estimator once a second.--recordkeeps raw sense periods, and--replayruns every governor on them offline, optionally louder.unifiedgovernor stays shadow-only. It is a look-ahead regulator on the feed-forward model, after macOS's design, and it writes the card only with--experimental-unified. In replay it was not louder than the current protection on the M1 Pro or the Neo (0.2 to 0.6 dB more mean reduction), so it doesn't govern anywhere.Evidence
cargo test --lockedpasses 64 of 64.Known cost: a sense outage longer than 100 ms is charged at the worst case, a full-scale square at 18.5 dBV into the tweeter model. That mutes the speakers (the kernel holds SN012776 at -100 dB) until the model cools, about 20 s. It is safe, and it's kept.
Using it next to speakersafetyd: the unit conflicts with speakersafetyd. To switch, mask speakersafetyd (
systemctl mask --now speakersafetyd). To go back, unmask it and reboot.Assisted-by: LLM
🤖 Generated with Claude Code