Skip to content

AVD: describe the video decoder's IO-coherent DMA (T8112, T604x) - #1169

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
avx2/avd-dma-coherent
Nov 7, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
avx2/avd-dma-coherent

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The video decoder's DMA is coherent with the CPU caches, but no Apple DT says so, so Linux maps every decoded frame uncached. Any consumer that reads pixels from a decoded frame reads at about 2.4 GB/s on an M2: VA-API image download (vaapi-copy, hwdownload), GStreamer copies when the sink has no VideoMeta, and software fallbacks. Zero-copy GPU import is unaffected. On the M2, reading each frame takes 2.9 ms at 1080p and 11.7 ms at 4K, so decode plus read tops out at 320 / 81 fps.

This PR adds dma-coherent to the binding and to the AVD nodes of T8112 (M2) and T604x (M4 Pro/Max). Buffers become cacheable and need no cache maintenance, and no userspace change is needed. Each SoC gets the line only after the probe below passes on it; T8140 (Neo) and T600x (M1 Pro) follow when those machines are back online.

Proof that the AVD is IO-coherent (T8112 and T6040)

The test was run on an M2 (J413) and a J616s on fleet27 using avd-bench plus an LD_PRELOAD ioctl shim. The shim allocates with V4L2_MEMORY_FLAG_NON_COHERENT and queues with V4L2_BUF_FLAG_NO_CACHE_CLEAN | NO_CACHE_INVALIDATE, so every cache operation is skipped. Each case was run at 16 pictures in flight and at 1 (with 1 in flight, nothing evicts the lines between the CPU access and the device access). Every displayed frame was checked against software decode:

  • CAPTURE buffers fully written by the CPU right before QBUF decoded bit-exact. Decoder writes replace dirty CPU lines.
  • CAPTURE buffers pulled into the CPU cache before QBUF and read after DQBUF with no invalidate came back bit-exact.
  • Bitstream OUTPUT buffers written through a cacheable mapping and queued without a clean decoded bit-exact. Decoder reads see dirty CPU lines.

Benchmark

Same boot, no reboot, 3 passes per row. The phases ran in this order: stock module, then a test-only module that marks the device coherent at probe (the same effect as this DT line), then stock again.

stock dma-coherent stock
H.264 1080p decode fps 1680-1720 1688-1722 1699-1727
HEVC 1080p decode fps 1921-1941 1921-1939 1890-1935
H.264 2160p decode fps 438-447 438-443 438-447
HEVC 2160p decode fps 485-490 485-490 486-490
read each 1080p frame 2.94 ms 0.24 ms 2.92 ms
read each 2160p frame 11.73 ms 1.05 ms 11.70 ms
H.264 1080p decode + read fps 318 1718 321
H.264 2160p decode + read fps 81 442 81

Decode alone is unchanged within noise, and every row is bit-exact. There were no DART faults and no AVC denials, and SELinux stayed enforcing.

For comparison, keeping the coherent default and having userspace set V4L2_MEMORY_FLAG_NON_COHERENT also gives 25-29 GB/s readback. But it costs a cache clean of every CAPTURE buffer at QBUF: 200-245 us per 1080p buffer and 800-910 us per 2160p buffer of CPU time. Every consumer would also need changing. Describing the hardware as it is avoids both costs.

J616s (T6040)

The probe passes the same way. On M4 Pro the CPU already reads the uncached mapping fast (50.6 GB/s for 1080p, 43.6 GB/s for 4K), so this changes no measured speed there. Same boot, stock / dma-coherent / stock, 3 passes, all rows bit-exact:

fps stock dma-coherent stock
H.264 1080p 1865-1893 1866-1891 1865-1894
HEVC 1080p 2584-2610 2563-2594 2582-2603
H.264 2160p 479-482 478-480 478-479
HEVC 2160p 689-699 689-698 689-698
VP9 1080p 874-879 874-879 874-878
AV1 1080p 2278-2308 2285-2320 2294-2315

There were no DART faults and no AVC denials, and SELinux stayed enforcing. T6041 shares the same decoder node (t604x.dtsi); it has no hardware here.

Checks

  • checkpatch --strict clean.
  • dt_binding_check for apple,avd.yaml passes; the t8112-j413 DTB compiles with dma-coherent on avd@269080000 and gives no avd schema warnings.
  • dt-checks and host-tests CI pass; the t6040-j616s and t6041-j616c DTBs carry the property.

🤖 Generated with Claude Code

The decoder's DMA is coherent with the CPU caches on the SoCs measured
so far. Allow the dma-coherent property so a SoC description can say so.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
The T8112 AVD is IO-coherent in both directions. Measured on an M2
(J413) with every cache operation skipped (V4L2_MEMORY_FLAG_NON_COHERENT
plus V4L2_BUF_FLAG_NO_CACHE_CLEAN/INVALIDATE), one picture in flight:
- CPU-dirtied CAPTURE buffers (the whole buffer written right before
  QBUF) decode bit-exact, so decoder writes replace CPU cache lines;
- CPU-cached CAPTURE buffers read back bit-exact after DQBUF without an
  invalidate;
- bitstream OUTPUT buffers written through a cacheable mapping and
  queued without a clean decode bit-exact, so decoder reads see dirty
  CPU lines.

Without dma-coherent every decoded frame is mapped uncached: a consumer
that reads pixels (VA-API image download, GStreamer copies, software
fallbacks) reads it at about 2.4 GB/s. With the property the buffers
are cacheable and need no cache maintenance.

M2, same boot, avd-bench, 16 pictures in flight, 3 passes, every frame
checked against software decode (stock -> dma-coherent -> stock):
  decode fps          h264 1080p   1680-1720 / 1688-1722 / 1699-1727
                      hevc 1080p   1921-1941 / 1921-1939 / 1890-1935
                      h264 2160p    438-447  /  438-443  /  438-447
                      hevc 2160p    485-490  /  485-490  /  486-490
  read every frame    1080p        2.94 ms   /  0.24 ms  /  2.92 ms
                      2160p       11.73 ms   /  1.05 ms  / 11.70 ms
  decode + read fps   h264 1080p    318      /  1718     /   321
                      h264 2160p     81      /   442     /    81

Decoding alone is unchanged; every result is bit-exact.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
The T6040 AVD is IO-coherent in both directions, measured the same way
as on T8112 on a J616s: with every cache operation skipped and one
picture in flight, CPU-dirtied and CPU-cached CAPTURE buffers and
CPU-written bitstream buffers queued without a clean all decode
bit-exact. T6041 uses the same decoder block and node.

On M4 Pro the CPU already reads the uncached mapping fast (about 50 GB/s
for 1080p frames), so this changes no measured speed. It describes the
hardware correctly, leaves the DART mappings cacheable and needs no
cache maintenance.

J616s, same boot, avd-bench, 16 pictures in flight, 3 passes, every
frame checked against software decode (stock -> dma-coherent -> stock):
  h264 1080p   1865-1893 / 1866-1891 / 1865-1894 fps
  hevc 1080p   2584-2610 / 2563-2594 / 2582-2603 fps
  h264 2160p    479-482  /  478-480  /  478-479  fps
  hevc 2160p    689-699  /  689-698  /  689-698  fps
  vp9  1080p    874-879  /  874-879  /  874-878  fps
  av1  1080p   2278-2308 / 2285-2320 / 2294-2315 fps

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
@RyanTheTide RyanTheTide changed the title AVD: describe the video decoder's IO-coherent DMA (cacheable decoded frames) AVD: describe the video decoder's IO-coherent DMA (T8112, T604x) Nov 7, 2026
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 7, 2026 19:08
@RyanTheTide RyanTheTide closed this Nov 7, 2026
@RyanTheTide
RyanTheTide deleted the avx2/avd-dma-coherent branch November 7, 2026 19:29
@RyanTheTide
RyanTheTide restored the avx2/avd-dma-coherent branch November 7, 2026 19:29
@RyanTheTide RyanTheTide reopened this Nov 7, 2026
Conflict in apple,avd.yaml: integration moved the AVD properties into
per-compatible if/then branches. Take integration's file and add
dma-coherent to the branch that covers the T8112 and T604x decoders.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
@RyanTheTide
RyanTheTide merged commit ad21b1b into integration/aurora Nov 7, 2026
2 checks passed
@RyanTheTide
RyanTheTide deleted the avx2/avd-dma-coherent branch November 7, 2026 19:46
RyanTheTide added a commit that referenced this pull request Nov 7, 2026
Brings aurora-wip up to the 11-08 morning integration tip: DT
descriptions for every Mac family (#1094, #1097, #1111, #1131, #1132,
#1148, #1149, #1155, #1156, #1157, #1172), the J616s scaler (#1168), the
panel primaries from boot data (#1105), AVD macOS command parity
(#1116), AVD dma-coherent (#1169), the M2 PMU RTC alarm (#1151), G17
admission without spinning (#1146) and the AOP map wait (#1147).

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
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