Repository navigation
drm/asahi: g17: let the firmware write render fragment end timestamps - #1229
RyanTheTide merged 4 commits into
Conversation
The upper window for dynamic kernel objects ran from KERNEL_OFFSET to the end of the kernel range, past the firmware MMIO aperture at 0xfffffc2180000000. The firmware gives the addresses from the aperture on a fixed meaning: the register windows, and the gart ranges HwData names. An object allocated there would take an address the firmware treats as something else. Put the bounds in one helper, dynamic::upper(), and use it in every place that allocated from that window. Signed-off-by: Jonathan Goyvaerts <[email protected]> Assisted-by: LLM
Render end timestamps are written by the host at retirement: the kernel converts the pass's internal stamps to nanoseconds and stores them into the user's timestamp buffer. The firmware can do that itself. macOS aliases timestamp buffers into the gart range HwData.unk_28 names ([0xfffffc2181400000, +64 MiB)) and puts window addresses into each render's second stamp pair, TA +0x90e (vertex start/end) and 3D +0x21a8 (fragment start/end). The firmware then writes those stamps in nanoseconds, equal to the host's conversion of its own internal stamps. Bind timestamp buffers into that window, firmware-only like the other alias, and hand the firmware the window address of each render's fragment end destination. The other three stay host-written: - Start stamps: the firmware latches a start stamp before the command's barriers resolve, so a reset of the same query ordered before the command can still land on top of it. - The vertex end: handed to the firmware, it does not hold the host's value by the end of the wait below. Astro Bot under KytyPS5 with hk's frame profiler, which also stamps every render's vertex end, sent 312,088 stamps through the window; exactly half (156,044) fell back to the host, each after the full wait. Without the profiler none did. At retirement the kernel reads the fragment end destination, without writing, until it holds the expected value (at most 200 us), and does not write it. A host write, or a firmware write landing after the fence, could undo a reset userspace may make once the fence has signalled. A value that does not land in time is written by the host, still before the fence. On an M4 Pro every fragment end stamp had landed by the first read. Compute commands, end-stamp copies and buffers that do not fit in the window keep host-written stamps too. asahi-g17/capacity counts kept and host-written window stamps. No uAPI change. Signed-off-by: Jonathan Goyvaerts <[email protected]> Assisted-by: LLM
RyanTheTide
left a comment
There was a problem hiding this comment.
host-tests fails on this head in g17-t6041-initdata-tests and t6040-calibration-tests. Both pass on integration/aurora without this branch. Those harnesses compile fw/initdata.rs on its own, and HwData::init now names crate::hw::t8140::dynamic::TIMESTAMP_WINDOW, which isn't available there:
error[E0433]: cannot find `hw` in `crate`
1054 | self.unk_28 = crate::hw::t8140::dynamic::TIMESTAMP_WINDOW.start;
Either add a hw::t8140::dynamic stub with TIMESTAMP_WINDOW to those two harnesses, or keep the literal in fw/initdata.rs and v25g83.rs with a const_assert!/comment tying it to dynamic::TIMESTAMP_WINDOW.start.
One thing to check in the code: Destination::write_window() busy-waits with udelay for up to 40 x 5 us for each windowed fragment end. That is fine while the stamp has always landed by the first read, as reported. But if the firmware ever stops writing through the window (window mapping refused, firmware variant), every render with a fragment end stamp pays the full 200 us in retirement. A counter-based fallback might be worth it: stop handing out window addresses after N consecutive host fallbacks.
The host tests g17-t6041-initdata-tests and t6040-calibration-tests compile fw/initdata.rs and v25g83.rs on their own, without crate::hw, so naming hw::t8140::dynamic::TIMESTAMP_WINDOW in HwData::init broke both. Write the base as a literal again, and assert in hw/t8140.rs that TIMESTAMP_WINDOW still starts there, so the two cannot drift apart. Signed-off-by: Jonathan Goyvaerts <[email protected]> Assisted-by: LLM
…write Destination::write_window() waits up to 40 x 5 us for the firmware's fragment end stamp before the host writes it. The stamp has always landed by the first read, but if the firmware ever stops writing through the window (the mapping refused, another firmware), every render with a fragment end stamp would pay the full 200 us in retirement. After 8 host fallbacks in a row, hand no render a window address again; its stamps then go the host path with no wait. A stamp the firmware writes resets the count. Signed-off-by: Jonathan Goyvaerts <[email protected]> Assisted-by: LLM
23eee3b
into
aurora-silicon:integration/aurora
The G17 firmware can write a render's fragment end timestamp itself, the way macOS has it do. Today the kernel converts the pass's internal stamp and writes it into the user's buffer at retirement. No uAPI change.
1.
drm/asahi: g17: keep dynamic kernel objects below the MMIO apertureKERNEL_OFFSETto the end of the kernel range, past the firmware MMIO aperture at0xfffffc2180000000. The firmware gives addresses from the aperture up a fixed meaning (register windows and the gart rangesHwDatanames), so an object allocated there could land on one of them.dynamic::upper(), used by every allocation from that window. Commit 2 needs this, because its window lies inside the aperture.2.
drm/asahi: g17: let the firmware write render end timestampsHwData.unk_28names ([0xfffffc2181400000, +64 MiB)).+0x90e(vertex start/end) and 3D+0x21a8(fragment start/end).asahi-g17/capacitygains atimestamp_window firmware=<kept> host_fallbacks=<host-written>line.Testing (J616s, M4 Pro, firmware 25G83)
dEQP-VK.pipeline.monolithic.timestamp.*in one process: 252 pass, 26 not supported, 0 fail.window_slot()incompletion.rs) came from the fallback count above. On this branch it is checked by compile and KUnit, not yet booted: on hardware so far, fragment end stamps never needed the fallback.27c200da5d28.rust/anddrivers/gpu/drm/asahi/build with no new warnings. The asahi KUnit suites (arm64 qemu): 231 tests, 229 pass, 2 skipped, including the newasahi_g17_timestamp_window.A related but independent Mesa change, in its own aurora-silicon/mesa PR: hk serves every G17P timestamp from a command's end, because start stamps can't be ordered behind a reset on G17P whoever writes them.
🤖 Generated with Claude Code