Skip to content

Spin waits that take a spin lock (fixes Breath of the Wild's CPU hitches) - #134

Closed
v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:spin-lock-waits
Closed

v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:spin-lock-waits

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

Fixes #129.

What

  • patch_nso.py "Spin waits": the search now also takes polls that look at their state under a spin lock. A region may contain:

    • a lock taken and released on the same address on every path back to the head (an exclusive test-and-set retried until its store succeeds, then an exclusive compare-and-clear or a store-release of zero);
    • a test loop on a word inside the region (load, compare with a constant, branch back to the load); its branch back goes to the original loop, so that loop keeps its own gate;
    • up to four stores whose value and address registers the region never writes, and only in a region that also loads something.

    A store of a value that a pass changes ends its path, and the search runs again without that path (the path that takes an item writes the new cursor). Every loop the search took before is still taken, over the same back-edges or a wider region that covers them.

  • DM_HITCH_DUMP=<ms>[:<s>] (diagnostic): when no frame has been presented for <ms>, it logs every guest thread once per stall. For each thread: what it waits on, its last SVC, its pc / lr and frame-pointer chain, and x0–x2 / x19–x25 when it runs guest code.

  • Guest threads are named on the host (separate commit) as <handle> <guest name>, so sample and Instruments' Time Profiler show which guest thread each sample belongs to.

  • New test dm/tools/tests/test_spin_waits.py. docs/development.md (Spin loops, the Breath of the Wild notes) and docs/agents/05-debugging.md are updated.

Why

In steady play, Breath of the Wild on the Mac had frames with 30–210 ms of CPU work every 1–10 s. These were the visible stutter, since present snapshots already absorb its GPU spikes.

  • Time Profiler: during every hitch, the main thread and both Worker threads sat in one job-queue function (main+0xef62dc), each using most of a core; all other threads were idle.
  • The loop: the first item of some jobs belongs to the thread of core 0, which is the main thread. The other threads wait until that item is taken. On every pass each one takes the queue's lock, checks the cursor, releases the lock and writes a status word.
  • The starvation: the two workers polled at full speed and handed the lock back and forth between their cores. The main thread lost nearly every exclusive store: in 40 s of trace it never held the lock, against about 750 samples for each worker.
  • Why the old rule missed it: the loop stores (the lock and the status word), so the search did not take it and the workers never paused.
  • The fix: through the spin gate, the workers leave the lock free for a moment between passes, and the main thread takes its item at once.

On the Switch the same code waits only until the main thread's core gets to the item. On the host the lock's cache line went to the workers almost every time.

Why pausing these loops is safe: each allowed store writes a fixed value to a fixed address, and nothing live at the head changes. So a loop can change its own state only for a bounded number of passes (a few hundred at most, a few microseconds). After that its passes repeat, and only another thread can end it. The gate polls without sleeping for its first 2 ms, so a loop that ends by itself never sleeps there.

Numbers

Zora's Domain save, M2 Max at 120 Hz, the same host for both, about 42 s of steady play per run, three runs each, load average 2–3.7:

before after
Standing still: frames with more than 30 ms of CPU work, per 30 s 2.8 / 6.3 / 3.5 0 / 0 / 0
Standing still: frame work p99 20–21 ms 8.3–8.4 ms
Standing still: frames late on screen, per 30 s 2.8 / 5.6 / 2.8 2.1 / 0.7 / 2.1 (only 120 Hz refresh slips remain)
Turning the camera: CPU hitches, per 30 s 11.9 / 13.3 / 6.3 0 / 0 / 0
Turning the camera: frame work p99 21–25 ms 9–15 ms
Turning the camera: frames late on screen, per 30 s 12.6 / 13.3 / 7.7 1.4 / 1.4 / 1.4

Process CPU per frame is unchanged, at about 20 ms.

Effect on other games

All 109 modules of the games on this Mac were rewritten with the old and the new search:

Game Module Loops Change
Breath of the Wild main 308 → 310 the job queue poll 0xef6354, and a state setter 0xf82230
Breath of the Wild subsdk0 10 → 10 0x27804 (the movie library's thread loop) widened from 6 to 23 instructions: its old back-edge plus two more
Breath of the Wild sdk 3 byte for byte the same
Mario Kart 8 Deluxe main 25 → 26 a state setter 0x715df8
Mario Kart 8 Deluxe subsdk0 15 → 15 0x24118 widened (the same movie library loop)
Mario Kart 8 Deluxe sdk 20 byte for byte the same
Hades main, sdk 12 / 9 byte for byte the same
Super Smash Bros. Ultimate main, sdk, subsdk0, 98 NROs 9 / 11 / 13, NROs none byte for byte the same

I read the disassembly of each new or wider region:

  • The two state setters (main+0xf82230 in Breath of the Wild, main+0x715df8 in Mario Kart 8 Deluxe): they read a state word, store the new state, and leave on the second pass unless another thread changed the word in between. They never reach the gate's sleep. They are not waits, but gating them is harmless.
  • The movie library loop: it loads its request flags. On the gated paths it clears and sets a flag with constants and calls nothing; the paths that call a callback are outside the region.

Rewrite time: Breath of the Wild's main takes 26 s of CPU instead of 19, because paths through stores are now searched.

Checked

  • The host builds on current main. The host unit tests pass, and so do the 46 tool tests, including the new one.
  • Boot tests on the Mac with DM_METAL_HUD=1, each with a host of the shader chain that game has on disk:
    • Breath of the Wild: host from the gpu-spikes branch, chain b7b9aa970b37. The A/B runs above, and a boot into Zora's Domain with the rewrite from this branch's patch_nso.py. Same red lines as with the old rewrite (the stale c1_full.tsv only), no hang. In the window measured, CPU hitches went from 14.6 to 0 per 30 s, and frame work p99 from 27.3 to 8.5 ms.
    • Mario Kart 8 Deluxe: its own dmhost-coop, chain 3f475989527f. 85 s from boot, with A presses every 4 s from 20 s on. Old and new rewrite: the same two red lines, no hang, frame p50 16.67 ms and p99 about 19.5 ms in both.
    • Hades and Super Smash Bros. Ultimate were not booted: their rewrite is byte for byte the same as before.

Not checked

  • Games whose files are not on this Mac, Paper Mario: The Thousand-Year Door among them. Their rewrite changes only where a loop matches the new forms.
  • The iPhone.
  • A boot of Breath of the Wild with a host built from this branch: current main's shader chain differs from the one on disk. The rule change is in the rewriter only.

… each guest thread names its pthread '<handle> <name>' (0x1008 Worker) once, right before it enters guest code (the SDK names a thread before StartThread), and the main thread is '0x1001 main thread' from its registration. sample <pid> and Instruments' Time Profiler (xctrace record --attach, no root needed) then show which guest thread a sample belongs to; before, every guest thread was an unnamed pthread of the host, told apart only by its thread ID. Breath of the Wild's CPU hitches were found this way: the main thread and the two Workers in one guest loop. Checked: the host unit tests pass, Breath of the Wild on the Mac shows the names in Time Profiler traces
…d): the CPU hitches of 30-210 ms in steady play were the main thread and two workers spinning in one job queue poll (main+0xef62dc). The first item of some of its jobs is for the thread of core 0; the others wait until it is taken, taking and releasing the queue's lock (an exclusive test-and-set, then a compare-and-clear) and writing a status word on every pass, so the spin wait search (a store or an exclusive store ends a path) did not take it. Polled at full speed by the two workers, the lock went back and forth between their cores, and the main thread, whose item it was, lost nearly every exclusive store: in a 40 s Time Profiler trace it never held the lock while each worker held it in about 750 samples (2,140 samples each of the three in the loop), and every frame with more than 30 ms of CPU work was the three spinning there (DM_HITCH_DUMP showed the main thread's item index 0 and the workers' 1 and 2 in x0, the queue's cursor still 0). patch_nso.py "Spin waits": a lock taken and released on the same address on every path back to the head (spin_lock 'acq' / 'rel', counted like the exclusive adds), a test loop on a word inside the region ('tst', whose branch back goes to the original loop and its own gate), and up to four stores whose value and address registers the region never writes ('stc', only in a region that loads something). Such stores write fixed values to fixed addresses, so a loop can change its own state for a few hundred passes at most, well inside the gate's 2 ms of polling, before its passes repeat. A store of a value a pass changes ends its path and the search runs again without it (the path that takes an item stores the new cursor). Every loop the search took before is still taken, over the same back-edges or a wider region that covers them: when the region with stores does not cover the old one's back-edges, the old one is used. Through the gate the workers leave the lock a moment between passes and the main thread takes its item at once. Zora's Domain on an M2 Max at 120 Hz (one host, 42 s of steady play per run, before -> after, three runs each, load average 2-3.7): standing still, frames with more than 30 ms of work 2.8 / 6.3 / 3.5 -> 0 per 30 s, the frame's work p99 20-21 -> 8.3-8.4 ms, frames late on screen 2.8 / 5.6 / 2.8 -> 2.1 / 0.7 / 2.1 per 30 s (120 Hz refresh slips only); turning the camera, CPU hitches 11.9 / 13.3 / 6.3 -> 0, p99 21-25 -> 9-15 ms, late frames 12.6 / 13.3 / 7.7 -> 1.4 each; process CPU per frame unchanged (about 20 ms). Every module of the games on this Mac rewritten with the old and the new search (109 modules): Breath of the Wild's main 308 -> 310 loops (this one and a state setter at main+0xf82230), its subsdk0 one region wider (0x27804, the movie library's thread loop, 6 -> 23 instructions, over its back-edge and two more), Mario Kart 8 Deluxe's main 25 -> 26 (a state setter at main+0x715df8) and its subsdk0 one region wider (0x24118, the same movie library loop); Hades (main, sdk), Super Smash Bros. Ultimate (main, sdk, subsdk0 and its 98 NROs) and both games' sdk rewrite byte for byte as before. Each new or wider region was read in its disassembly: the state setters store their state and leave on the second pass unless another thread changed it, so they never reach the gate's sleep; the movie loop clears and sets its request flag with constants and calls nothing on the gated paths. Breath of the Wild's main takes 26 s of CPU to rewrite instead of 19. Diagnostic that found it: DM_HITCH_DUMP=<ms>[:<s>] logs every guest thread (its wait, last SVC, where it is, x0-x2 and x19-x25 in guest code) when no frame was presented for that long. New test dm/tools/tests/test_spin_waits.py (the lock poll found and its item path left out; a store of a changing value, a lock not released and stores with no load refused; a plain test loop still found). Checked: the host builds, the host unit tests and the 46 tool tests pass; on the Mac with the new rewrite (hosts of the shader chain each game has on disk: Breath of the Wild b7b9aa970b37, Mario Kart 8 Deluxe 3f475989527f), Breath of the Wild into Zora's Domain and Mario Kart 8 Deluxe for 85 s from boot with A presses, the same red lines as with the old rewrite and no hang. Not checked: games whose files are not on this Mac (Paper Mario: The Thousand-Year Door among them), the iPhone. docs/development.md (Spin loops, Breath of the Wild) and docs/agents/05-debugging.md say so

hle_nvn.c defines dm_present_ns weakly (hle_thread.c holds it), so the graphics tests, which link hle_nvn.c without hle_thread.c, still link.
seedds added a commit that referenced this pull request Oct 24, 2026
…ath of the Wild; fixes #129). In steady play on the Mac, Breath of the Wild had frames with 30-210 ms of CPU work every 1-10 s: the main thread and the two workers spinning in one job queue poll (main+0xef62dc). The first item of some of its jobs is for the thread of core 0; the others wait until it is taken, taking and releasing the queue's lock (an exclusive test-and-set, then a compare-and-clear) and writing a status word on every pass, so the spin wait search (a store or an exclusive store ends a path) did not take it. Polled at full speed by the two workers, the lock went back and forth between their cores, and the main thread, whose item it was, lost nearly every exclusive store: in a 40 s Time Profiler trace it never held the lock while each worker held it in about 750 samples. patch_nso.py "Spin waits": a lock taken and released on the same address on every path back to the head (spin_lock 'acq' / 'rel', counted like the exclusive adds), a test loop on a word inside the region ('tst', whose branch back goes to the original loop and its own gate), and up to four stores whose value and address registers the region never writes ('stc', only in a region that loads something). Such stores write fixed values to fixed addresses, so a loop can change its own state for a few hundred passes at most, well inside the gate's 2 ms of polling, before its passes repeat. A store of a value a pass changes ends its path and the search runs again without it (the path that takes an item stores the new cursor); when the region with stores does not cover the old one's back-edges, the old one is used. Through the gate the workers leave the lock a moment between passes and the main thread takes its item at once. Zora's Domain on an M2 Max at 120 Hz (one host, 42 s of steady play per run, three runs each, before -> after): standing still, frames with more than 30 ms of work 2.8 / 6.3 / 3.5 -> 0 per 30 s, the frame's work p99 20-21 -> 8.3-8.4 ms; turning the camera, CPU hitches 11.9 / 13.3 / 6.3 -> 0, p99 21-25 -> 9-15 ms; process CPU per frame unchanged. Every module on the game drives rewritten with the old and the new search (206: 108 NSOs and Super Smash Bros. Ultimate's 98 NROs): 175 byte for byte as before (Hades, Super Smash Bros. Ultimate, Super Mario Odyssey among them), 7 fail alike under both (every rtld, New Super Mario Bros. U Deluxe), and 24 take new or wider loops, all but Breath of the Wild's queue through the store rule alone: Monster Hunter Rise's main 90 -> 166 (72 of them one inlined countdown whose reset makes the next pass leave), BALL x PIT 87 -> 94, Animal Crossing: New Horizons 162 -> 166, Balatro 9 -> 12, Octopath Traveler 0 75 -> 78, Pikmin 4 80 -> 83, Bayonetta 3 35 -> 37, Breath of the Wild 308 -> 310, one more each in Big Brain Academy, Mario Kart 8 Deluxe, Metroid Dread, Pokemon Legends: Z-A, Stardew Valley, Super Mario Bros. Wonder (both builds) and Tears of the Kingdom; the movie library's thread loop is wider in the subsdk0 of Breath of the Wild, Mario Kart 8 Deluxe, Animal Crossing, BALL x PIT, Monster Train 2 and Octopath Traveler 0, and one loop is wider in the main of AI: THE SOMNIUM FILES and Advance Wars 1+2. No loop of the old search is lost or loses a back-edge. Each distinct shape was read in its disassembly: one-pass resets and state setters (the gate is reached only when another thread changes the word), parser states that leave on the next pass, and real flag waits. Rewriting all 206 takes about 4,100 s of CPU instead of 3,250. Diagnostics: DM_HITCH_DUMP=<ms>[:<s>] logs every guest thread (its wait, last SVC, where it is, x0-x2 and x19-x25 in guest code) when no NVN frame was presented for that long, and each guest thread names its pthread '<handle> <name>' (0x1008 Worker) before it enters guest code, the main thread '0x1001 main thread', so sample and Instruments' Time Profiler show which guest thread a sample belongs to. The graphics tests that link hle_nvn.c without the host define dm_present_ns (t_host_stubs.c weak, t_nvn.c). New test dm/tools/tests/test_spin_waits.py. Checked: the host builds, the host unit tests, the 46 tool tests and the gfx run list pass; Breath of the Wild into Zora's Domain and Mario Kart 8 Deluxe for 85 s from boot with the new rewrite (the PR's author), and Monster Hunter Rise from a fresh save for 180 s headless with each rewrite on one host (e72a065's, the chain of its Mac libraries): 60 fps, frame p95 about 17.5 ms, the same red lines, no hang. Not checked: Paper Mario: The Thousand-Year Door, DARK SOULS: REMASTERED, FINAL FANTASY TACTICS and FINAL FANTASY RESONANCE (no files on the drives), the iPhone. docs/development.md (Spin loops, Breath of the Wild) and docs/agents/05-debugging.md say so
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Taken as 6d34984 on main, squashed with two additions:

  • Graphics tests: hle_nvn.c now writes dm_present_ns, which only hle_thread.c defined, so every test that links hle_nvn.c without the host (t_nvn, t_present_crop, t_readback and the others) failed to link. t_host_stubs.c (weak) and t_nvn.c now define it, and the whole gfx run list passes.

  • The other games: I rewrote all 206 modules on my drives (108 NSOs and Smash's 98 NROs) with the old and the new search. 175 are byte for byte as before and 7 fail under both (every rtld, New Super Mario Bros. U Deluxe). The other 24, in 18 games, take new or wider loops, so "every other module rewrites byte for byte" didn't hold here. Apart from Breath of the Wild's queue, all of them come from the store rule alone:

    • New loops: Monster Hunter Rise 90 → 166, BALL x PIT +7, Animal Crossing +4, Balatro, Octopath Traveler 0 and Pikmin 4 +3 each, Bayonetta 3 +2, and +1 each in Big Brain Academy, Metroid Dread, Z-A, Stardew Valley, Wonder and Tears of the Kingdom.
    • Wider loops: the movie library loop in 4 more games' subsdk0, and one loop each in AI: THE SOMNIUM FILES's and Advance Wars's main.

    No old loop is lost or loses a back-edge. I read each distinct shape: 72 of Monster Hunter Rise's new loops are one inlined countdown whose reset makes the next pass leave. The rest are state setters, parser states that leave on the next pass (Octopath Traveler 0 main+0x4ebfa54, Balatro main+0x1f4600), or real flag waits, so none of them sleep at the gate unless another thread changes the word. docs/development.md and the commit message list them now.

Checked here: the host unit tests, the tool tests and the gfx run list pass. Monster Hunter Rise, the game with the most new loops, ran alike with both rewrites on one host, 180 s headless from a fresh save each: 60 fps, frame p95 about 17.5 ms, the same red lines, no hang.

Not checked: TTYD, DARK SOULS, FFT and FINAL FANTASY RESONANCE (not on my drives), and the iPhone.

Two small things about DM_HITCH_DUMP, for a follow-up if you like:

  • It only sees NVN presents, so it never fires for the Vulkan and GL games. Writing the time in present_enqueue (nvn_mtl.m) would cover all three.
  • hitch_main uses the thr_t pointers after releasing G, and it calls dladdr while the thread is suspended. A thread that exits during a dump, or one suspended while it holds the dyld lock, would be trouble in a live run.

Thanks for the profiler work, the hitch dump and the thread names! They made the cause easy to follow.

@seedds seedds closed this Oct 24, 2026
@v0lumehi
v0lumehi deleted the spin-lock-waits branch October 24, 2026 17:17
seedds added a commit that referenced this pull request Oct 25, 2026
…s and the dyld lock (follow-up to #134's review). The present time dm_present_ns was written only in the NVN present (hle_nvn.c), so the dump never fired for the Vulkan and GL games; it is now written in present_enqueue (nvn_mtl.m), which mtl_present (NVN), mtl_present_ext (Vulkan: hle_vk.m; GL: hle_gl.m) all reach, and the NVN-only write is gone. hitch_main took thr_t pointers under G, released G, and read the threads afterwards, so a thread that exits and is freed during a dump was a use-after-free; and it called dladdr while the target thread was suspended, which deadlocks if that thread holds the dyld lock. Now hitch_grab copies what a line needs (handle, name, wait state, svc, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G (thread exit and thr_free need G, so no listed thread is freed or leaves), and between suspend and resume only mach calls and memory reads run; hitch_log then looks the symbols up (module table, dladdr) and logs after every thread runs again. The tests' weak dm_present_ns definitions (t_host_stubs.c, t_nvn.c) stay as they are. Checked: the host unit tests and the gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). From PR #137 (v0lumehi). Also checked on current main: the host unit tests and the gfx run list pass; on the Mac with DM_HITCH_DUMP=20:2, Mario vs. Donkey Kong (NVN) logged two dumps in its opening movie and Balatro (GL, which never dumped before: no present time was written outside NVN) one, every guest thread with its guest frames and host symbols, and both games ran on to the end of the run. Not checked: a Vulkan game (none on the drives; Vulkan presents reach present_enqueue through mtl_present_ext as GL's do)
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…on Breath of the Wild; fixes seedds#129). In steady play on the Mac, Breath of the Wild had frames with 30-210 ms of CPU work every 1-10 s: the main thread and the two workers spinning in one job queue poll (main+0xef62dc). The first item of some of its jobs is for the thread of core 0; the others wait until it is taken, taking and releasing the queue's lock (an exclusive test-and-set, then a compare-and-clear) and writing a status word on every pass, so the spin wait search (a store or an exclusive store ends a path) did not take it. Polled at full speed by the two workers, the lock went back and forth between their cores, and the main thread, whose item it was, lost nearly every exclusive store: in a 40 s Time Profiler trace it never held the lock while each worker held it in about 750 samples. patch_nso.py "Spin waits": a lock taken and released on the same address on every path back to the head (spin_lock 'acq' / 'rel', counted like the exclusive adds), a test loop on a word inside the region ('tst', whose branch back goes to the original loop and its own gate), and up to four stores whose value and address registers the region never writes ('stc', only in a region that loads something). Such stores write fixed values to fixed addresses, so a loop can change its own state for a few hundred passes at most, well inside the gate's 2 ms of polling, before its passes repeat. A store of a value a pass changes ends its path and the search runs again without it (the path that takes an item stores the new cursor); when the region with stores does not cover the old one's back-edges, the old one is used. Through the gate the workers leave the lock a moment between passes and the main thread takes its item at once. Zora's Domain on an M2 Max at 120 Hz (one host, 42 s of steady play per run, three runs each, before -> after): standing still, frames with more than 30 ms of work 2.8 / 6.3 / 3.5 -> 0 per 30 s, the frame's work p99 20-21 -> 8.3-8.4 ms; turning the camera, CPU hitches 11.9 / 13.3 / 6.3 -> 0, p99 21-25 -> 9-15 ms; process CPU per frame unchanged. Every module on the game drives rewritten with the old and the new search (206: 108 NSOs and Super Smash Bros. Ultimate's 98 NROs): 175 byte for byte as before (Hades, Super Smash Bros. Ultimate, Super Mario Odyssey among them), 7 fail alike under both (every rtld, New Super Mario Bros. U Deluxe), and 24 take new or wider loops, all but Breath of the Wild's queue through the store rule alone: Monster Hunter Rise's main 90 -> 166 (72 of them one inlined countdown whose reset makes the next pass leave), BALL x PIT 87 -> 94, Animal Crossing: New Horizons 162 -> 166, Balatro 9 -> 12, Octopath Traveler 0 75 -> 78, Pikmin 4 80 -> 83, Bayonetta 3 35 -> 37, Breath of the Wild 308 -> 310, one more each in Big Brain Academy, Mario Kart 8 Deluxe, Metroid Dread, Pokemon Legends: Z-A, Stardew Valley, Super Mario Bros. Wonder (both builds) and Tears of the Kingdom; the movie library's thread loop is wider in the subsdk0 of Breath of the Wild, Mario Kart 8 Deluxe, Animal Crossing, BALL x PIT, Monster Train 2 and Octopath Traveler 0, and one loop is wider in the main of AI: THE SOMNIUM FILES and Advance Wars 1+2. No loop of the old search is lost or loses a back-edge. Each distinct shape was read in its disassembly: one-pass resets and state setters (the gate is reached only when another thread changes the word), parser states that leave on the next pass, and real flag waits. Rewriting all 206 takes about 4,100 s of CPU instead of 3,250. Diagnostics: DM_HITCH_DUMP=<ms>[:<s>] logs every guest thread (its wait, last SVC, where it is, x0-x2 and x19-x25 in guest code) when no NVN frame was presented for that long, and each guest thread names its pthread '<handle> <name>' (0x1008 Worker) before it enters guest code, the main thread '0x1001 main thread', so sample and Instruments' Time Profiler show which guest thread a sample belongs to. The graphics tests that link hle_nvn.c without the host define dm_present_ns (t_host_stubs.c weak, t_nvn.c). New test dm/tools/tests/test_spin_waits.py. Checked: the host builds, the host unit tests, the 46 tool tests and the gfx run list pass; Breath of the Wild into Zora's Domain and Mario Kart 8 Deluxe for 85 s from boot with the new rewrite (the PR's author), and Monster Hunter Rise from a fresh save for 180 s headless with each rewrite on one host (903b236's, the chain of its Mac libraries): 60 fps, frame p95 about 17.5 ms, the same red lines, no hang. Not checked: Paper Mario: The Thousand-Year Door, DARK SOULS: REMASTERED, FINAL FANTASY TACTICS and FINAL FANTASY RESONANCE (no files on the drives), the iPhone. docs/development.md (Spin loops, Breath of the Wild) and docs/agents/05-debugging.md say so
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…s and the dyld lock (follow-up to seedds#134's review). The present time dm_present_ns was written only in the NVN present (hle_nvn.c), so the dump never fired for the Vulkan and GL games; it is now written in present_enqueue (nvn_mtl.m), which mtl_present (NVN), mtl_present_ext (Vulkan: hle_vk.m; GL: hle_gl.m) all reach, and the NVN-only write is gone. hitch_main took thr_t pointers under G, released G, and read the threads afterwards, so a thread that exits and is freed during a dump was a use-after-free; and it called dladdr while the target thread was suspended, which deadlocks if that thread holds the dyld lock. Now hitch_grab copies what a line needs (handle, name, wait state, svc, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G (thread exit and thr_free need G, so no listed thread is freed or leaves), and between suspend and resume only mach calls and memory reads run; hitch_log then looks the symbols up (module table, dladdr) and logs after every thread runs again. The tests' weak dm_present_ns definitions (t_host_stubs.c, t_nvn.c) stay as they are. Checked: the host unit tests and the gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). From PR seedds#137 (v0lumehi). Also checked on current main: the host unit tests and the gfx run list pass; on the Mac with DM_HITCH_DUMP=20:2, Mario vs. Donkey Kong (NVN) logged two dumps in its opening movie and Balatro (GL, which never dumped before: no present time was written outside NVN) one, every guest thread with its guest frames and host symbols, and both games ran on to the end of the run. Not checked: a Vulkan game (none on the drives; Vulkan presents reach present_enqueue through mtl_present_ext as GL's do)
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.

Breath of the Wild on the Mac: short hitches from 30–210 ms CPU frames (follow-up to #71)

2 participants