Repository navigation
asahi: look up and build background/end-of-tile shaders under the cache lock - #470
Conversation
…he lock Honeykrisp keeps one agx_bg_eot_cache per device (dev->bg_eot), and command buffers record on any thread, but agx_get_bg_eot_shader() searched and inserted into its hash table, allocated from it and uploaded to its pool without a lock. Two threads recording render passes with different attachments corrupt the table or the pool: double frees and heap corruption, no submission needed. agx_get_precompiled() already takes cache->lock for uploads to the same pool. Take the lock around the whole lookup, build and insert. That also covers the G17P and M5 native builders, which allocate and upload from their own early-return paths. Nothing under the build path takes the lock again. A cache miss now compiles with the lock held, which only serializes the first use of each key. Gallium's caches are per context and only pay an uncontended lock. New shim test hk-g17p-bg-eot-threads (16 threads, 255 attachment subsets, 20 fresh devices): fails 3 of 3 runs before (double free or corruption, malloc(): unsorted double linked list corrupted, SIGSEGV), passes 10 of 10 after. On the M4 Pro itself the same recording loop crashed 5 of 10 runs. Same race as upstream Mesa issue 16812 (MR 46059, which locks only inside agx_compile_bg_eot_shader() and would miss the native builders here). Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com> Assisted-by: LLM
Keep both sets of shim tests in src/asahi/meson.build and src/asahi/vulkan/meson.build next to the ones aurora-silicon#444 added. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
After #444 landed this branch conflicted with aurora-wip in |
Keep this branch's shim test blocks next to the ones aurora-silicon#436 added in src/asahi/meson.build and src/asahi/vulkan/meson.build. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Merged. Rows: M4 Pro (J616s, G17P) in the same overlay as #436, and M1 Pro (G13S) A/B on aurora-wip 9e85c78 with and without this head. dEQP-VK 374,140 cases identical. GLES2/3/31 + KHR 106,812 cases identical apart from one flush_finish timing case, which passes 30/30 standalone in both arms. 0 firmware crashes. |
What
Honeykrisp keeps one
agx_bg_eot_cacheper device (dev->bg_eot), and command buffers record on any thread.agx_get_bg_eot_shader()searched and inserted into the cache's hash table, allocated from it (rzalloc(cache->ht)) and uploaded to its pool without a lock. Two threads recording render passes with different attachment sets corrupt the table or the pool: double frees, heap corruption or a segfault, with nothing submitted.agx_get_precompiled()already takescache->lockfor uploads to the same pool.This is the race of upstream Mesa issue 16812 (MR 46059). That MR locks only inside
agx_compile_bg_eot_shader(). Here the G17P and M5 native builders also allocate and upload from their own early-return paths, so this change takes the lock around the whole lookup, build and insert instead.How
agx_get_bg_eot_shader()now takescache->lockand calls the old body. Nothing under the build path takes the lock again. Neitheragx_get_precompiled()noragx_helper_program()is reached from the builders, and hk's ownbg_eot.lockuser (hk_cmd_draw.c, M5 tile templates) does not callagx_get_bg_eot_shader()while holding it. A cache miss now compiles with the lock held, so only the first use of each key is serialized. Gallium's caches are per context and only pay an uncontended lock.New shim test
hk-g17p-bg-eot-threads: 16 threads record dynamic-rendering passes over 255 subsets of eight colour attachments with mixed load/store ops, on 20 fresh devices, and nothing is submitted.Testing
MacBook Pro 16" M4 Pro (J616s, T6040, G17P), GPU firmware 25G83, Linux 7.3.0-m4.171, on AC. Release builds from one build directory with the same meson options:
aurora-wip57df4db;Guarded runs, 0 GPU recoveries.
hk-g17p-bg-eot-threads(16 threads x 20 devices, no-op DRM shim), 10 runs--suite asahi --suite vulkanThe single-thread row shows that the uncontended lock costs nothing measurable when recording.
Commands
Raw output
🤖 Generated with Claude Code