Skip to content

dmaengine: apple-admac: Read the cyclic position only from a consistent snapshot - #979

Merged
RyanTheTide merged 1 commit into
sgv2-kernel-interfacefrom
sgv2/xrun-recovery
Nov 5, 2026
Merged

RyanTheTide merged 1 commit into
sgv2-kernel-interfacefrom
sgv2/xrun-recovery

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Root cause of the J316s speaker dropouts. At a period's end, a residue read between the report post and the descriptor load put the playback position a period ahead. ALSA then stopped the stream with an XRUN. Captured with ftrace on the M1 Pro (pointer 11242 -> 11776 in 0.36 ms).

The fix: retry until the snapshot is consistent. A stalled controller gets a monotonic fallback.

  • KUnit apple-* 38/38 (5 new).
  • W=1 clean.
  • Hardware, sgv2k6x + speakerguardd#52: the full 0.3/0.6/1.0 ladder had 0 dropouts, 0 faults, 0 AVCs and 0 PCM stops.

🤖 Generated with Claude Code

…nt snapshot

At the end of a period the controller runs the residue down to 0, posts
the period's report, and only then loads the next descriptor. A residue
read in between (report counted, residue still 0) put the position a whole
period ahead. The PCM core then saw the hardware pointer past the
application pointer and stopped the stream for an underrun.

On the J316s (M1 Pro) speakers this hit two to three times in each
five-minute full-volume run. PipeWire's timer wakes a few microseconds
before the period interrupt, and the protection supervisor reads the PCM
status every millisecond, so the reads land at period ends. ftrace showed
the playback position jump from 11242 to 11776 frames (a period end plus
512) in 0.36 ms, with the PCM stopped in XRUN by the same read. Both data
loop wakes and the DMA interrupt were on time, and no thread was
preempted.

The old check caught only a descriptor load between the two residue reads.
It also counted a report posted before the first ring read twice.

So read again until the snapshot is consistent: the report ring the same
on both reads, and the residue non-zero, not reloaded and within a period.
A controller that stays at a period's end (stalled, with no descriptor
to load) is reported at the periods done or the last position, whichever
is later. That position is never ahead of the transfer and never behind
an earlier report, since a pointer that goes back reads as a wrap of the
whole buffer. KUnit covers the cases from the trace.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 3c5110a into sgv2-kernel-interface Nov 5, 2026
@RyanTheTide
RyanTheTide deleted the sgv2/xrun-recovery branch November 5, 2026 06:44
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