Skip to content

dmaengine: apple-admac: count a display ADMAC's pending report at a period's end - #3692

Merged
RyanTheTide merged 2 commits into
aurora-silicon:mainfrom
m0d16l14n1:fix/admac-display-report-lag
Dec 1, 2026
Merged

RyanTheTide merged 2 commits into
aurora-silicon:mainfrom
m0d16l14n1:fix/admac-display-report-lag

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: on a display ADMAC (the DisplayPort/HDMI audio DMA of the display engines), the playback position stepped back by a whole period at every period's end. The PCM core took the step back for a wrap of the whole buffer and stopped the stream for an underrun, so DP/HDMI audio restarted every period: with PipeWire's default timer scheduling nothing was heard, and with period interrupts it was heard with gaps. A display ADMAC posts a period's report once the display engine has played the period, about a FIFO's worth after the channel loaded the next descriptor; until then the residue is the next period's while the reports still count the fetched one as in progress. A read behind the last reported position is now taken as that: the pending period is done, if the period after it was submitted (counted in descriptors). The position never passes what was submitted and never goes back. Only display ADMACs (ad->display) are affected.
Tested: J815 (MacBook Air 15" M5), at the first commit 39e02fa50b96 (head 84269b0c21ad adds the descriptor-count bound from review; its J815 row is pending), HDMI TV behind a USB-C hub on each of the two Type-C ports in turn, YouTube in Firefox through PipeWire. This patch as 70d72f7dd11d on a J815 tree (main 37a19f9 + open PRs, with #3264 for the link rate); apple-admac.c and its test header are identical there and at 39e02fa. PipeWire defaults (timer scheduling), 20 s on each port: 1 stream start, 0 position steps back, 0 XRUN, 48001 / 48003 frames/s, PipeWire ERR 0 -> 0. Without this patch, same setup: about 28 stream restarts/s, ERR 110 -> 463 in 18 s, no sound. 0 failed units, 0 new kernel errors, no SELinux on this install. KUnit apple-admac-* 10/10 at 84269b0c21ad on arm64 QEMU (new cases admac_pos_display_report_lag and admac_pos_display_short_buffer; the latter fails with the first commit's submitted_pos check); checkpatch --strict clean.
Risk: two-way door. Display ADMACs only: T8142 (J813, J815) and the T6050 display ADMACs this path was written for. The MCA/AOP ADMACs (speakers, headphone jack, microphones) are unchanged.
Not yet: a J815 row at 84269b0c21ad; J813; T6050 (M5 Pro); a DisplayPort monitor (only an HDMI TV behind a hub so far); a stream kept across a deep sleep.

Details

admac_cyclic_pos() computes the position as reclaimed + period * (reports + 1) - residue. That order of events (report posted, then the next descriptor loaded) holds on the MCA ADMAC it was written for (see its comment, J316s). On a display ADMAC the report comes later than the load:

  • at start the channel fetches about 4 KiB at once (532 stereo 24-in-32 frames), then the position advances at the stream rate in 256-frame steps;
  • at the first period boundary the residue reloads to the next period while the period's report is still outstanding, so the position reads exactly a period behind (the buffer start for the first period);
  • snd_pcm_update_hw_ptr0() sees the position go back and adds a buffer: hw_ptr passes appl_ptr, XRUN.

admac_display_pos() adds the pending period to such a read, bounded by submitted_pos, and otherwise keeps the last reported position. Reads that are not behind are returned unchanged, so a position that the existing code already got right (after the report) is untouched.

This is independent of the sink: it follows from the order of the controller's report and its descriptor load.

#3264 is not a prerequisite in code. It fixes a separate fault on the same path (a stray link rate, 4x too fast on this board); neither change touches the other's code. On the J815 both are needed for correct DP audio: with only #3264 the stream still restarted at every period's end, and with only this PR it would play at the wrong rate. The row above ran with both.

Second commit (review). The first commit took the pending period as done only if the position a period on was not past submitted_pos. submitted_pos is kept modulo two buffers and admac_cyclic_pos_after() orders positions less than a buffer apart; with a two-period buffer, four or five descriptors in flight on a display channel span more than that, and the position stood still until the report came. It now counts: the next period is submitted when the reports in the ring plus two do not exceed nperiods_outstanding. The comment no longer mentions a DisplayPort monitor, which has not been tested.

Evidence
before (J815, #3264 applied, IRQ-driven sink, period 2048, buffer 6144; /proc/asound/cardN/pcm0p/sub0/status)
  ms     state    hw_ptr  appl_ptr  trigger_time
  6.4    RUNNING     532      4096  385.459810210
  33.2   RUNNING    1812      4096  385.459810210
  39.8   RUNNING    6144      4096  385.459810210   <- step back read as a wrap
  42.0   RUNNING     532      4096  385.495552815   <- restarted
  ...    a new trigger_time every ~36 ms

after (this patch, PipeWire timer scheduling, period 1024, buffer 16384)
  port 1, 20 s: stream starts 1, position steps back 0, XRUN 0, 48001 frames/s, PipeWire ERR 0 -> 0
  port 2, 20 s: stream starts 1, position steps back 0, XRUN 0, 48003 frames/s, PipeWire ERR 0 -> 0
  with period interrupts: 10 s, starts 1, steps back 0, XRUN 0, 48004 frames/s, ERR 0

display ADMAC reports (24 MHz stamps): 256000 ticks per 512-frame period = 48000 frames/s

KUnit (arm64 QEMU, LLVM) at 84269b0c21ad: apple-admac-position 7/7, apple-admac-realign 3/3
  with the first commit's submitted_pos check put back: admac_pos_display_short_buffer fails, the rest pass

…eriod's end

A display ADMAC posts a period's report once the display engine has
played the period, a FIFO's worth after the channel fetched the period's
last bytes and loaded the next descriptor. Until the report comes, the
residue is the next period's while the reports still count the fetched
one as in progress, so the position reads a whole period behind. At
every period's end the position stepped back to the period's start, the
PCM core took that for a wrap of the whole buffer, and the stream
stopped for an underrun.

On the J815 (T8142) with an HDMI TV behind a USB-C hub, DisplayPort
audio restarted about 28 times a second: with period interrupts it was
heard with gaps, and with PipeWire's timer scheduling, its default, not
at all.

Take a display ADMAC position behind the last one reported as such a
read: the period whose report is pending is done. The position never
passes what was submitted and never goes back.

Signed-off-by: Nick <nekreshen@yandex.ru>
@m0d16l14n1
m0d16l14n1 requested review from a team as code owners November 30, 2026 08:49
@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at 84269b0c: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 84269b0c
Conflicts ok not computed yet
PR text ok Risk: two-way · . Display ADMACs only: T8142 (J813, J815) and the T6050 display ADMACs this path was written for. The MCA/AOP ADMACs (speakers, headphone jack, microphones) are unchanged.

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 39e02fa5

Blockers:

  • Hosted pull_request CI checks (pr-text, Host tests, and kernel build/KUnit workflows) are currently completed/action_required awaiting maintainer workflow approval for this fork PR; only pr-readiness has executed at 39e02fa5.
  • The J815 playback row in Tested: ran on commit 70d72f7dd11d (main 37a19f92f82b + open PRs including #3264) rather than directly on 39e02fa5; please clarify whether #3264 is a required prerequisite or add an exact-head 39e02fa5 boot/smoke row.

Checked:

  • drivers/dma/apple-admac.c (admac_display_pos(), admac_cyclic_read_residue()), drivers/dma/apple-admac-test.h (admac_pos_display_report_lag), and surrounding ring/position/reclaim logic on origin/main.
  • Verified the change is strictly gated on ad->display (MCA/AOP ADMAC channels are untouched), never steps reported_pos backward, and leaves the ADMAC_RESIDUE_READS fallback (admac_cyclic_pos_at_period_end()) monotonic.
Evidence
  • Non-blocking edge case (submitted_pos wraparound on small period counts): admac_cyclic_pos_after() only distinguishes positions separated by < buf_len, whereas admac_display_start_current_tx() + admac_cyclic_write_desc() can keep 4–5 descriptors (or more on an 8-slot display ring) in flight while drivers/gpu/drm/apple/audio.c allows periods_min = 2. Whenever nperiods_outstanding >= periods_per_buf + 2 (for example buf_len = 2 * period_len with 4–5 outstanding descriptors, buf_len = 3 * period_len with 5–6 outstanding, or buf_len = 4 * period_len with 6 outstanding), submitted_pos wraps past the half-space boundary of admac_cyclic_pos_after(), causing !admac_cyclic_pos_after(adtx, adtx->submitted_pos, ahead) to evaluate false and hold reported_pos flat until the report arrives instead of returning ahead. It still will not step backward, so it avoids the XRUN wrap, but checking the unwrapped descriptor count (admac_read_reports(&r) + 2 <= adtx->nperiods_outstanding) instead of wrapped submitted_pos would handle all buffer period counts and ring depths cleanly.
  • Minor comment mismatch: drivers/dma/apple-admac.c lines 67–68 say (every period's end, on the J815 with an HDMI TV and with a DisplayPort monitor alike), while Not yet: in the PR body notes a DisplayPort monitor has not been tested yet (only an HDMI TV behind a hub).
  • Workflow runs at 39e02fa50b9687d5ab644fc695df8d93a103c5ce: pr-readiness (pull_request_target) succeeded; pr-text and Host tests (pull_request) are completed/action_required; Host tests (pull_request_target) skipped.

…criptor count

admac_display_pos() took the pending period as done only when the
position a period on was not past submitted_pos. submitted_pos is kept
modulo two buffers, and admac_cyclic_pos_after() orders positions less
than a buffer apart. With a buffer of a few periods the descriptors in
flight can span more than that (four or five on a display channel
against a two-period buffer), so the check failed and the position
stood still until the report arrived.

Count instead: the period after the one in progress is submitted when
the reports in the ring plus two do not exceed the descriptors
outstanding. The comment no longer claims a DisplayPort monitor was
tested; only an HDMI TV was.

Signed-off-by: Nick <nekreshen@yandex.ru>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 30, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 84269b0c

Blockers:

  • Hosted pull_request CI checks (pr-text, Host tests, and kernel build/KUnit workflows) are completed/action_required awaiting maintainer workflow approval for this fork PR; only pr-readiness has executed at 84269b0c.
  • Needs a current-head J815 hardware row referencing 84269b0c (the PR body still cites 39e02fa50b96 / 70d72f7dd11d, and pr-readiness has flagged needs-hw-row at 84269b0c).

Checked:

  • Commit 84269b0c (drivers/dma/apple-admac.c, drivers/dma/apple-admac-test.h).
  • Verified admac_display_pos() now bounds the pending period cleanly by admac_read_reports(r) + 2 > adtx->nperiods_outstanding (eliminating submitted_pos wraparound aliasing on short-buffer period counts), admac_pos_display_short_buffer covers the two-period / four-descriptor case, and the DisplayPort monitor comment wording matches the HDMI TV test scope.
Evidence
  • Workflow runs at 84269b0c21ad60687ab1639c4c4793631d4369e9: pr-readiness (pull_request_target) succeeded; pr-text and Host tests (pull_request) are completed/action_required; Host tests (pull_request_target) skipped.
  • Code is clean; ready to approve once fork CI runs green and a J815 hardware row is recorded at 84269b0c.

@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

Addressed at 84269b0c21ad (a second commit on top, no force push):

  • submitted_pos wrap: the pending period now counts as done only when reports + 2 <= nperiods_outstanding, as you suggested, instead of comparing with the wrapped submitted_pos. New KUnit case admac_pos_display_short_buffer (two-period buffer, four descriptors in flight) fails with the first commit's check and passes now; apple-admac-* 10/10 on arm64 QEMU, checkpatch --strict clean.
  • Comment: no longer mentions a DisplayPort monitor; only an HDMI TV has been tested.
  • drm/apple: audio: start the format sieve with no rates #3264: not a prerequisite in code. It is a separate fault on the same path and neither change touches the other's code; on the J815 both are needed for correct DP audio, and the row ran with both. Spelled out in the body.
  • Exact-head row: the earlier row ran on a copy of the first commit. A J815 row at 84269b0c21ad, merged unchanged into a J815 candidate, comes next.

Hosted CI on this PR is still waiting for workflow approval.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 84269b0c21ad

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Commit 84269b0c (drivers/dma/apple-admac.c, drivers/dma/apple-admac-test.h).

  • Verified admac_display_pos() now bounds the pending period cleanly by admac_read_reports(r) + 2 > adtx->nperiods_outstanding (eliminating submitted_pos wraparound aliasing on short-buffer period counts), admac_pos_display_short_buffer covers the two-period / four-descriptor case, and the DisplayPort monitor comment wording matches the HDMI TV test scope.

Follow-ups (not blocking): fork CI approval; J815 row at head

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 84269b0c21ad (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot]. Row: the hardware row at 84269b0 that the readiness check found (PR body or comment). CI: linux train L4 = main (after L3) + 34 approved PRs (#3419 dropped: conflicts): Apple driver compile pass, Apple DTBs W=1 pass, planned KUnit ane-boot/clpc/ane-pm/dcp-fabric/dcp-topology/dcp-display/macaudio/asahi/sep all pass, host tests apple-dcp + apple-scaler-recovery pass (the red host-tests on some heads were base failures since fixed on main). The rest of the hosted run is queued behind the backlog. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 9335971 into aurora-silicon:main Dec 1, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m5 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants