Repository navigation
drm/asahi: g17: cut the CPU cost of a submission - #597
RyanTheTide wants to merge 4 commits into
Conversation
…evice mutex A direct render publication takes the device mutex twice: once to lend the owner's installed pair, and again to take it back after publishing. At queue depth the event worker holds that mutex for its completion passes, so the submitter spins on it twice per command. On the J616s at render.light kind=tri depth 16 the spin is 4.6% of all CPU samples and the mutex path 8.3%, with DRM_IOCTL_ASAHI_SUBMIT at 17.3 us per call. After a successful publication, try the mutex. If it is free, return the pair as before. If it is busy, put the loan in a per-slot return box in the shared device state, queue an event pass and leave. The next holder of the device mutex that needs the pair settles the box by running the same return_render() the publisher would have run: the owner's next lend, the start of each event pass (both of its locked sections), and both stop paths once the preparation leases are drained. A failed publication still returns its pair at once, since the device-mutex path may retry it right away. Why this is safe: - A boxed pair is still lent. Its entry keeps `preparing` set, so every device-mutex path treats it exactly as a pair whose publisher has not returned yet, which they already handle (the event worker skips it and records a missed event, timeouts defer within their renewal bound, close marks it for release on return). Boxing only makes that window last until the next settle. - The window is bounded. The publisher queues an event pass after filling the box and that pass settles it first thing, before it scans completions, so completions of the boxed pair are not delayed past the pass that would have seen them. - The loan goes into the box before the preparation lease is dropped. Recovery and the stop paths drain the leases before they settle, so they always see every loan, and recovery never runs with a pair still lent by a finished publication. - A slot is lent once at a time, so its box cell is free whenever a publisher fills it. If it ever were not, the publisher returns the loan under the mutex as before. - The box lock nests inside the device mutex and is held only to move one loan. Waiters are woken and growth is queued after the settling holder drops the device mutex, as the publisher does today. The packets dropped while settling are never the last references, since each is published and its lent pair cannot have retired it. The device mutex is then waited for once per contended publication, for the lend. G16 (T6040) and G17 (T8140) share this code; the G13/G14 and G15 backends are not touched. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each submit ioctl allocates the vector of validated commands and the vector of VM pins, and each publication allocates a DeferredBatch whose completion vector holds 64 entries. With init_on_alloc, as in the distribution configs, each of these is also cleared. krealloc() is 3.75% of the CPU samples at render.light kind=tri depth 16 on the J616s. Keep them instead. A queue keeps its two emptied command vectors for its next ioctl, unless they grew past eight commands. A backend keeps the finished publication batch for its next publication. The ioctl and the scheduler publish one owner's commands in turn, so one spare is enough; a publisher that finds it taken allocates its own, as before. Nothing else changes. The vectors are emptied at the points where the old ones were dropped, in the same order: on a validation or pinning failure the pins go first, then the commands, then the parse pin not yet moved into the pin vector, and unenqueued commands are dropped when the ioctl's closure returns. A batch is kept only when it is empty, which DeferredBatch::finish() leaves it, with its full capacity. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
A direct render publication reads the monotonic clock in Port::note_submission() and again in the QoS update, which asks the feed whether the GPU is the bottleneck. On the J616s these reads are 5.4% of the CPU samples at render.light kind=tri depth 16, 2.8% from the QoS update alone. Read it once when the publication starts and pass that time to both. Direct compute publication does the same. The device-mutex hosts and the completion path still read the clock where they did. The QoS update compares the time against a GPU-bound state that lingers for milliseconds, and the idle logic uses the last submission time at millisecond scale, so a time read a few microseconds earlier in the same publication gives the same answers. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each render rewrites its tiling and fragment descriptors in the shared slot ring: it clears all 0x9c0 + 0x2240 bytes and then writes every field. The slot was last used 32 commands earlier, and the firmware read it then, so every store has to take its line back. At render.light kind=tri depth 16 on the J616s, write_descriptors() is 12.7% of the CPU samples and the clear accounts for most of the 5% in memset. Build both descriptors in a cache-aligned host image kept with the pair, then store into the slot only the 64-bit words that differ from what it holds. Between commands with the same render state only a few words change (ordinals, stamps and the per-command addresses), so most lines are only read. The TA descriptor prefetch now asks for reading for the same reason; the queue configuration records are still prefetched for writing. The slot ends up byte-identical to what the old code left there, the same clear plus field writes, whatever the slot held before and whoever wrote it. Nothing else can access the slot meanwhile, since the command holds its exclusive claim and is not published, so the comparison needs no assumption about which words the firmware touches. The fragment slot's MCache spill table is still left alone, and set_mcache() still writes the slot directly. A descriptor that fails to build leaves the slot untouched instead of half written, and its claim is released as before. The image is 11.6 KiB per pair. Both descriptor variants (25G83 and the earlier programs) go through the same writers, so this covers G16 and G17 alike. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
J616s A/C for this PR without commit 4. A = integration 695d974 asahi.ko (build 1c327b87), C = A + commits 1 to 3 (build 01cee971), both on 7.3.0-aurora-fleet9. Each arm was a fresh one-shot boot in the order A C A C A C, with the module loaded from updates/ (fleet9's initramfs rebuilt without asahi so both arms load the same way). The machine was headless (display off), with a 60 s settle before each run and the Borealis overlay ICD from the parity runs. gpubench-vk, median of 3 boots, each value the median of 5 x 250 ms windows: DRM_IOCTL_ASAHI_SUBMIT mean from the ftrace runs (r2 and r3; the r1 traces were lost to an argument bug in my wrapper):
CTS subset (kit cts-subset.txt against the full mustpass, 17285 cases, one run per arm): A 15977 pass / 1308 skip / 0 fail, C 15977 pass / 1308 skip / 0 fail, no flakes, no asahi lines in the kernel log. Peak temperature was 89.5 C during CTS and below 77 C during the benchmarks. On the J616s, commits 1 to 3 show no regression, but there is no gain I can measure either. All C/A ratios for us_per_submit fall between 0.985 and 1.08, inside the boot-to-boot spread (up to 13%), and submit_cpu_us moves both ways by about as much as its own spread. The estimate in the A/B plan was a 2 to 3% cut in submit ioctl time. That is below what 3 boots per arm can resolve on this machine, so measuring it needs a longer run per arm or a perf profile of the ioctl. Raw data: 🤖 Generated with Claude Code |
|
Closing this one. Both machines say the same thing: the submit ioctl is not what limits light work at queue depth, so cutting its CPU cost does not move throughput. The branch What the A/B runs showed (median of 3 boots per arm, interleaved):
Why it does not help. At depth the time per submission stops falling and sits at a floor that is well above the CPU cost of the ioctl:
Going from depth 16 to 64 changes nothing, and the submitting thread is busy for well under half of each period. If the ioctl were the limit, the period would track submit_cpu_us and more depth would hide the GPU side. Neither happens. The floor is about 25 to 27 us per render job and 12 to 14 us per compute job on both SoCs, so it looks like a fixed per-job cost after the kernel hands the job over: the firmware picking up the work command, running it, and signalling completion, one job after another on the queue. That fits the earlier parity profile, where the GPU was idle about 77% of the time at compute depth 64 while the ioctl took about 5 us. So the next thing to look at for the light-work gap against macOS is per-job firmware turnaround and batching (more work per firmware command, fewer completion events per job), not the host submit path. A firmware-side trace of job start and end stamps against the submit timestamps would show how the floor splits between firmware scheduling and GPU execution. Raw data: 🤖 Generated with Claude Code |
Light GPU work at queue depth is CPU bound in the g17 submit path on both the J616s (M4 Pro) and the Neo. On the J616s, render.light kind=tri is 1.35-1.77x slower than macOS at depth 4-64 and compute.light 1.19-1.27x at depth 8-64. ftrace puts DRM_IOCTL_ASAHI_SUBMIT at 17.3 us (render tri d16), 10.0 us (compute d16) and 5.1 us (compute d64), with the GPU idle about 77% of the time at compute d64. perf shows about 82% of the time in the kernel. This series takes the four cheapest hot spots, one commit each, with the correctness argument in each message.
mutex_spin_on_owner). A successful publication now returns the pair at once if the mutex is free, otherwise it puts the loan in a per-slot return box and queues an event pass. The next device-mutex holder that needs the pair settles the box with the samereturn_render(): the owner's next lend, both sections of each event pass, and both stop paths after the leases drain. A boxed pair stays lent (its entry keepspreparing), which every path already handles, and the window is bounded by the queued pass.DeferredBatch(64 entries, cleared by init_on_alloc) were allocated on every submission (krealloc3.75%). Queues and backends now keep them, and drop order on failures is unchanged.note_submission()and the QoS rx update each read the clock (ktime_get5.4%, 2.8% from the QoS update alone). Direct render and compute publications now read it once.write_descriptors()cleared and rewrote about 11 KiB per render into slots that the firmware read last (12.7% inclusive). Both descriptors are now built in a host image kept with the pair, and only the 64-bit words that differ from the slot are stored. The slot ends byte-identical to before whatever it held, so this makes no assumption about what the firmware writes.G16 (T6040) and G17 (T8140) share all of this code. The G13/G14 backend and G15 are not touched. Nothing new is configurable.
Depends on #585 (the integration/aurora 695d974 sync). The branch is based on its merge commit, so until #585 merges the diff here also shows that sync. The g17 code is identical in integration/aurora 695d974.
Testing
release.config: Fedora Asahi base + asahi.config): the asahi module of this branch, and of integration 695d974 with the series applied, built against the fleet9 tree. Each commit builds on its own. WithCLIPPY=1there are no new warnings in g17, only the seven that were already there. checkpatch is clean apart from the Co-Authored-By trailer. A full Image and modules build of the branch is queued on the buildbox.tools/testing/selftests/drivers/gpu/asahi-m4/run-host-tests.pyandtools/asahi/g17-*-tests): the same results before and after. Everything passes exceptg17-compute-deadline-tests, which fails the same way on the base (its harness fails to compilefixed.rs).reports/m4pro-gpu-submit-fastpath-20261030/. The method, raw before and after numbers and the run-to-run spread will go here.Neo A/B
Hardware: Neo (J700, A18 Pro, G17P B1), kernel 7.3.0-aurora-fleet9, Mesa 26.3.0-devel 108c7218bb (the installed Borealis ICD,
VK_DRIVER_FILESset to it on both arms). A is the integration 695d974 asahi module rebuilt the same way (build ID 1c327b87), B is A plus the four commits (build ID eb119626). Both carry fleet9 vermagic and the fleet9 build key (65:E3:85:8E...), the same key as the Neo's own asahi.ko. The module was swapped by anupdates/asahi.kooverride and a reboot per arm, and the loaded build ID was checked after every boot.Method. Six boots in the order A B A B A B. Each arm waits for P-core below 50 C, sleeps 60 s, then runs gpubench-vk
render.light --param kind=triandcompute.lightat depths 1, 4, 16 and 64 (300 ms warm-up, 5 x 250 ms windows, timestamps off), as the session user with the GNOME session idle. Each cell below is the median of the five windows for one boot. trace.sh was not available on the Neo, so there are no ioctl means here.On the Neo the series is flat. Throughput at depth 4 to 64 does not move for either test (render sits at 27.1 to 27.3 us per submit and compute at 13.6 to 13.9 us on both arms, so on this machine these rows look bound by something other than the submit ioctl). The only clean movement in submit CPU time is render d16, which is about 0.9 us (7%) worse with B on all three boots. Depth 1 is latency bound and too noisy to call either way.
CTS. One run per module on its first boot (A r1, B r1), Vulkan CTS 1.4.7.0 with deqp-runner 0.23.3, 2 jobs, the vk-default mustpass filtered by the kit's subset regexes (command buffers, sync2 basic and implicit, timeline semaphores, draw renderpass, occlusion queries, compute basic and indirect dispatch, memory pipeline barriers, fragment operations, rasterization primitives; the renderpass2 suballocation, multi-subpass/multi-cmdbuf and pipeline.monolithic.timestamp regexes match no names in 1.4.7.0). 17127 cases. A has 15780 pass, 1347 skip, 0 fail, 0 crash, 0 flake. B has the same, with an identical per-test status list. No asahi errors, faults or timeouts in dmesg on any of the six boots. The Neo's thermal guard paused the CTS at 95 C and resumed it at 85 C on both arms (P-core peak 105.5 C on A, 105.9 C on B during CTS; 78 to 80 C during the bench-only boots).
The raw gpubench JSON, CTS results and per-boot dmesg are in
reports/m4pro-gpu-submit-fastpath-20261030/neo-ab/. The Neo is back on its own fleet9 asahi.ko. On this data the PR stays a draft. The render d16 submit CPU increase is worth checking against the J616s numbers, since commit 4 (compare-then-store descriptors) is the one expected to trade stores for loads.🤖 Generated with Claude Code