ProjectScarlett runs at 7–10 fps with the GPU ~5% busy: every vkQueueSubmit spends ~13 ms in amdgpu userptr (HMM) validation of the imported title memory #669
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from brcly/TuxBox. Originally posted by turboheadcrab on 2026-12-03T06:53:56Z.
Summary
The intro movie, loading screens and account picker all run at 7–10 fps on an RX 9070 XT, while the GPU is about 5% busy. Profiling shows that the frame rate is limited by the kernel cost of each command submission. In every
DRM_IOCTL_AMDGPU_CS, amdgpu re-walks the page tables of every userptr BO in the submission. Those BOs are the title memory that TuxBox imports throughOpenExistingHeapFromAddress*(vkd3d-proton maps that toVK_EXT_external_memory_host). At the intro the game's GTT (drm-total-gtt) is about 1.4 GiB, and each submission costs about 13 ms of CPU time in the kernel, so the queue thread can't submit faster than about 70 times per second. The cost grows linearly with the imported size: a standalone Vulkan program reproduces it at about 8.4 ms per GiB, and after a new game the in-game cost climbs to 56 ms per submission until the title's watchdog fires (tables below).System
106120ca(2026-12-02), packaged build, offlineMeasurements (intro movie and loading screen, 2560x1440)
top -H): onevkd3d_queuethread at about 99% and one title thread at about 93%. The two Bink decode threads are at about 4% each. GPU busy is about 5%./proc/<tid>/stat, utime vs stime):vkd3d_queue: about 0% user, about 98% kernel.perf record -g, 10 s, cpu-clock, both threads (inclusive shares of thevkd3d_queuethread's samples):strace -T -e ioctlon the queue thread, 10 s:DRM_IOCTL_AMDGPU_CScalls (about 68 per second, about 9 per frame).drm-total-gttis about 1.4 GiB (TuxBox's ledger reportstitle pages 7131 MiB, so only part of the title memory is imported).AnonHugePages: 0 kB, and THP is set tomadvise. Every page costs a PTE-level walk.NtYieldExecution→sched_yield, plusgetrusage) in title code. It appears to be waiting on GPU work that is queued behind the slow submissions.Why this happens
Measured: the walk happens inside every CS (profile above), and its cost scales with the imported size (test below). My reading of the kernel and RADV, not verified in their source:
amdgpu_cs_parser_boscallsamdgpu_ttm_tt_get_user_pagesfor every userptr BO in the submission's BO list, on every CS. It does this whether or not the range was invalidated. RADV appears to put every imported (userptr) allocation into every submission's BO list; the standalone test shows the cost even for an empty command buffer, with or withoutbufferDeviceAddress. The cost therefore grows with the total size of imported host memory times the number of submissions, and doesn't depend on what is drawn.The
UserptrRangescomment inruntime/d3d12/src/device/placement/lazy.rsalready notes that amdgpu HMM validation rejects a CS when any page of a bound userptr BO is inaccessible. This report is about the time that validation takes.Standalone reproduction (no TuxBox, no game)
A small native Vulkan program (about 110 lines of C, below) reproduces the problem without the game:
VK_EXT_external_memory_hostin 256 MiB chunks.4 KiB pages (
MADV_NOHUGEPAGE), median per submission:bufferDeviceAddresschanges nothing (1 GiB: 8.5 ms, 4 GiB: 33.7 ms). RADV puts every imported allocation into every submission either way.MADV_HUGEPAGE) cut the cost sharply: 1 GiB goes from 8.6 to 0.53 ms, and 4 GiB to 12.4 ms. At 4 GiB probably only part of the memory got huge pages, because RAM was fragmented with the game running at the same time.The game's ~14 ms per submission therefore matches roughly 1.6 GiB of 4 KiB-page memory being imported through userptr at that point, out of the 7 GiB of title pages. Not all title pages seem to be imported.
userptr_submit.c
In-game check: at the loading screen, the game's DRM client reports
drm-total-gtt1.38 GiB in/proc/<pid>/fdinfo. At 8.4 ms per GiB that predicts about 11.6 ms per submission. The measurement was 12.6–13.6 ms.Related: #666
#666 (duplicate GPU page cluster imports since
106120ca, GTT growing to 18–27 GiB until RADV loses the device) is the same mechanism made worse:This report is about the base cost that remains without duplicates: about 1.4 GiB of imports already costs about 12 ms per submission. That is the 7–10 fps intro and loading screen on
106120ca. #667 stops the runaway, but the imported size still grows during play, and the cost with it (table below).Measured on this card, starting a new game, sampled every minute (
drm-total-gttfrom fdinfo, medianDRM_IOCTL_AMDGPU_CStime over 3 s, presented frames per 10 s):106120ca106120ca106120caNot enough memory for command submission), exit 3 at 750 s2898c907)exe+0x23CF683, exit 5 at 938 sChecked against the latest main (
106120ca) and #667 on 2026-12-03.Ideas (for the maintainers to judge)
always, only about 1 GiB of the 6 GiB resident memory became huge pages. The median CS time went from 13.6 to 12.6 ms (737 submissions in 10 s), and the intro stayed at 74–75 frames per 10 s. The imported title ranges apparently stay at 4 KiB pages, perhaps because of their alignment or per-page protection changes. Huge-page backing that TuxBox arranges itself (2 MiB-aligned reservations, no per-page protection changes) might do better.Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T07:36:52Z.
Same thing here on an RX 6700 XT (RDNA 2, 12 GB), RADV from Mesa 26.3.1, GE-Proton11-15, 32 GB RAM. I spent tonight bisecting it, so here's where the AMD side broke.
To keep shader prep out of the way I ran each older commit's providers with today's translator and DXC helper (
TUXBOX_XSHADER/TUXBOX_PERSISTENT_DXCpointed at the current build). The only translator change between these commits and main is #534, so every run used the same runtime shader cache and only the providers differ.6d4f1cd7(parent of9c3cf86f)PERMISSION_FAULTS 0x3), which I also see on #667 builds, so I think that one is separate.9c3cf86fE_NOTIMPL).a789a4e4(right before106120ca)int3atexe+0x5149AEC(exit 3) at 881 s.106120ca+ #667exe+0x23CF683watchdog (exit 5), 150–300 s after the account picker.So
6d4f1cd7is the last commit before the AMD regression.9c3cf86fbreaks it (green screens), and106120cafixes the refusals by moving RADV to private backing, which turns it into the submission cost described here.What I measured on
106120ca+ #667 lines up with the numbers above:vkd3d_queuethread is 85–90% kernel time for most of the run. perf has nearly all of it inamdgpu_cs_ioctl, mostlyhmm_range_faultandamdgpu_vm_bo_update.drm-total-gttpeaks at 4.3–4.5 GiB, vs ~3.5 GiB on6d4f1cd7.dma_fence_wait_any_timeout,mmu_interval_read_begin). The queues are stuck behind a texture publication fence whose reader signal sits in avkQueueSubmit2that hasn't returned.Things that didn't help: THP
never(page migration down about two-thirds, still exit 5 at 546 s) andTUXBOX_LAZY_PUBLICATION=0(exit 5 at 372 s). One run each.Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T13:51:40Z.
@gtb-sbe I timed the view-creation wait you described in https://github.com/brcly/TuxBox/issues/533#issuecomment-7379297901, and it's large. Posting here since it's the same submission cost.
RX 6700 XT, RADV / Mesa 26.3.1, GE-Proton11-15,
106120ca+ #667 with a temporary trace around the shared init queue indevice/allocation.rs(with_init_transition): per kind, the call count, the time waiting for the queue's mutex, the time inWaitForSingleObjecton the fence, and the slowest call. One run, new game, from the account picker through the load (about 250 s) until it ended in the gfx ring page fault (TCPPERMISSION_FAULTS 0x3) that I also see on other #667 runs.initialize_gpu_tilesreset_gpu_tilesinitialize_gpu_tilescall, so a view-creating thread held the title up.I also tried cutting the number of imports. An experiment that imports the committed run of pages around a page, inside its 2 MiB cluster, instead of the single page, took the live single-page imports from 10–14k down to about 400. But the cluster windows grew to 3.8 GiB, GTT peaked at 4.7 GiB (4.3–4.5 GiB without it), and it still ended in the
exe+0x23CF683watchdog (exit 5) with a 49 s frame. So cutting the import count alone doesn't fix it, at least not without cutting the imported bytes too. One run.So I think your suggestion is the bigger lever: if the creating thread didn't wait on the CPU (the queues that use the buffer wait on the fence on the GPU, or several views' tile initialization goes into one submission), most of those 114 s would come off the title's threads whatever each submission costs.
Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-03T14:00:04Z.
@JeffreyBytes thanks for timing it, 113.5 s of fence waits in ~250 s is more than I expected.
I read through the paths on
106120ca. The title-thread waits areinitialize_gpu_tilesfromregister_buffer(buffer creation in a GPU reservation) andreset_gpu_tilesfromrefresh_cpu_pages, which runs at the start of everyExecuteCommandLists. Both go throughInitTransition::wait_for_queue, so each call is oneSignalplus a CPU wait. With #669 eachSignalis a full CS that re-walks the userptr BOs.What I have in mind:
initialize_gpu_tiles/reset_gpu_tilesonly record theUpdateTileMappingsand mark the init queue dirty, without aSignalor a wait.Signalonce, thenqueue.Wait(init_fence, value)on the GPU. Many view creations between two submissions then cost one CS instead of one each, which I think matters more than where the wait happens.apply(initial state transitions) keeps its CPU wait, since it reuses the allocator.@brcly does this fit with the XMem/D3D12 rework you're doing, or is that path changing anyway? If it fits, I'd write it with a Lanes scenario (buffer created on one thread, written on one queue and read on another with no host wait in between) and measure it on my RX 9060 XT before opening a PR.
Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T14:07:25Z.
@gtb-sbe Batching to one CS per guest submission makes sense to me. I went through the provider's own queues on
106120cafor your open question (read only, nothing built yet), and found a few places outside the device init queue that rely on the CPU wait today:commands/page_mapping/retirement.rs:48) keeps a privateMutex::new(None)slot, runsbind_published→reset_native_gpu_tiles(buffers.rs:395) on it, and then signals the job fence to 2 from the CPU (retirement.rs:70). The guest queue GPU-waits on that 2 (buffers.rs:858). Without the CPU wait, the guest queue would be released before the binds finish, and the guest-submission flush would flush the device init queue, not this one. The worker could signal 2 on the GPU from its own init queue after the binds, or keep its wait.publishandpublish_textureson the fast path (buffers.rs:353and:844) pass&Mutex::new(None), so they create an init queue and drop it on return. A deferred mapping there would never be flushed.refresh_cpu_pages(buffers.rs:779) resets tiles on the init queue, thengpu_updatesandbind_livebind the same buffers on the guest queue. Deferred, the two binds on one resource are unordered, so it needs the flush beforebind_live.present.rs:259callsgpu_mappings.refresh()and then gathers from page-mapped backing on the guest queue inplacement::submit, so it needs the same flush.In
execute_locked,refresh()(submit.rs:226) is itself an init call, so the flush would go after it and beforeplacement::submit(:372): the gathers and scatters inqueue_use.rsand the memory-wait split lists run after that and read GPU-tile buffers.The side queues look clear: the upload/residency transfer queue, the "TuxBox texture readback" copier, the lazy-publication copy queues, the BLAS builder and the detile-table upload only touch their own memory or provider-committed buffers.
I'm happy to test your branch on the RX 6700 XT (RDNA 2) with the same init-queue timing trace, so we'd have before and after numbers from two cards: on
106120ca+ #667 it's 113.5 s of fence waits in about 250 s of loading.Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-03T15:54:09Z.
I wrote the batched version and ran it once on my RX 9060 XT (RDNA 4, RADV / Mesa 26.3.1, GE-Proton11-15), on
106120ca+ #667, against a run of the same build without it (same warm shader cache, default settings).What the change does:
initialize_gpu_tilesandreset_gpu_tilesonly record the update. The next guestExecuteCommandLists(beforeplacement::submit), present, and the page-mapping command signal the init queue once andWaiton it on the GPU. Replaced tiles stay alive until that value is reached.bind_published(the worker and both inline paths) finishes the device init queue on the CPU before its own binds, so they can't land ahead of a deferred init.TUXBOX_TILE_INIT=waitrestores the old behaviour. Lanes passes 33/33, andqueue-page-mappings5 of 5 times.wait_for_queue<initialize_gpu_tilesGame Runningto the intro SRL (crash log timestamps)Prestream, no present for ~2 min, exit 5So the title's threads don't wait in view creation any more, and the load up to the intro is about 2.8 times shorter. It doesn't fix #669 itself: the run still ends in the same stall. The busiest
vkd3d_queuethread spent 202 s of the 413 s run in the kernel (99 % of its CPU time, 60-100 % of every 10 s window during loading), and in the final stall the render thread is waiting indetile::Cache::uploadwith all queues idle, as before. Some of the freed time on the streaming thread went into host imports (PageCache::get_or_open, 0.6 % -> 8 %) and themapped_texturemutex (2.2 % -> 9.9 %).One run each, so treat the timings as rough. @JeffreyBytes the branch is
gtb-sbe:d3d12-batched-tile-init(one commit on106120ca, applies cleanly with #667) if you want to run it with your init-queue trace on the 6700 XT.Imported from brcly/TuxBox. Originally posted by turboheadcrab on 2026-12-03T16:44:52Z.
@JeffreyBytes the gfx ring page fault you see on #667 runs reproduces on RDNA 4. The build was
106120ca+ #667 + #621, on an RX 9070 XT (RADV from Mesa 26.3.1, kernel 7.3.5), and it was a new game from the intro. #621 kept the watchdog off, so the run lasted until the fault.Every minute, GTT (
drm-total-gtt), the medianDRM_IOCTL_AMDGPU_CStime over 3 s, and the frame rate:The page fault came at 1,217 s:
[gfxhub] page fault,Faulty UTCL2 client ID: TCP (0x8),PERMISSION_FAULTS: 0x3,WALKER_ERROR: 0x0,MAPPING_ERROR: 0x0,RW: 0x0(a read), on avkd3d_queuethread, withMORE_FAULTSand 10 fault lines in a row on consecutive 4 KiB pages.ring gfx_0.0.0 timeout, a successful ring reset, and RADVThe CS has been cancelled because the context is lost.GPU worker fence stalled(texture readback and queued texture copy), 8 memory waits held past 5 s, and an 8.3 s placed-texture readback.A second run of the same build, with
TUXBOX_GPU_TIMING=1, ended the same way, only sooner. It faulted at 890 s, about 4 minutes after the new game, at 3.6 GiB GTT: the same[gfxhub]TCPPERMISSION_FAULTS 0x3read fault, 10 in a row, then the ring reset. GPU timing shows the GPU nearly idle all the way up to the fault. The timed pipeline work was 0.85–3 ms per second in every 10 s window, and no single pipeline stood out. CS times in that run: 12.5–13.8 ms at 1.4 GiB, then 21.7 ms at 2.0 GiB and 39.4 ms at 3.6 GiB.So on this card the CS cost tracks GTT the same way as on yours, up to the point where submissions nearly stop. Then the fault ends the run.