Skip to content

host/hitch: log the host threads that carry a frame in the DM_HITCH_DUMP - #3131

Open
adurham wants to merge 1 commit into
seedds:mainfrom
adurham:fix/hitch-dump-host-threads
Open

adurham wants to merge 1 commit into
seedds:mainfrom
adurham:fix/hitch-dump-host-threads

Conversation

@adurham

@adurham adurham commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What and why

DM_HITCH_DUMP logged every guest thread when no frame had been presented for N ms, but a frame can also wait in the host: the guest's main thread parked in nvn_queue_submit under _pthread_mutex_firstfit_lock_wait only says that the replay thread holds g_sub_mu, not what that thread is doing.

The dump now also reads the host threads that declared a real-time policy (the acquire, queue replay and encode thread, from the registry in hle_nvn.c: nvn_rt_threads) first, suspended for a moment like the guest threads and only if the thread ID still matches the one registered, and logs each as a host '<name>' line with its state and up to 54 host frames named by dladdr. The 24-dumps-a-run limit is unchanged. The host unit tests that link hle_thread.c without the graphics layer (t_condvar_stub.c, t_system_event.c) define nvn_rt_threads in their stubs, as they do dm_host_work.

It is what found the cause of the stalls in the next PR of this series (the replay thread inside arch_lookup under MTLCompilerScheduler::buildRequest while the guest's submit waited for it). Reference entry: docs/reference/threads.md, "A stall in the host was not in the hitch dump".

Checked

  • Tests: the host builds; make -C dm/host/tests GAME=0400486024DEC000 -k run fails only memory-profile (a Python 3.9 type annotation in its script), as on unchanged main; dm/tools/tests/test_docs.py passes. dm/tools/env_switches.py --check prints what it prints on main (12 stale names, DM_SPLIT_REGISTERED_MAP without a meaning). clang-tidy was not run (not installed on the machine). No test covers the dump itself: it needs a stalled frame.
  • Games run: Ocarina of Time v131072, DM_HITCH_DUMP=25:100; the log shows the three host lines at each stall.
  • Devices and OS: Mac Studio M4 Max, macOS 27.3, Xcode 27.3. No iPhone.
  • regress.py check --games: not run; only Ocarina of Time is installed on this machine. The change is a diagnostic that runs only with DM_HITCH_DUMP set.

Front ends

Nothing a front end has to act on.

Docs

  • The finding is in its game note and its docs/reference/threads.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • No chain tool changed
  • No game files, keys or data extracted from a game in the change or the attachments

Written with AI: Claude (Hermes Agent) · Responsibility: Adam Durham

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 21, 2026
The dump logged every guest thread when no frame had been presented for the
given time, but a frame can wait in the host too: the guest's main thread
parked in nvn_queue_submit under _pthread_mutex_firstfit_lock_wait only says
that the replay thread holds g_sub_mu, not what that thread is doing.

The dump now also reads the host threads that declared a real-time policy
(the acquire, the queue replay and the encode thread, from the registry in
hle_nvn.c, nvn_rt_threads) before it reads the guest threads: each is
suspended for a moment as the guest threads are, checked against the thread
ID it was registered with (a port of a thread that has ended may name
another), and logged as a `host '<name>'` line with its state and up to 54
host frames named by dladdr. Nothing is logged for a thread that has not
registered. The limit of 24 dumps a run is unchanged. The host unit tests that
link hle_thread.c without the graphics layer (t_condvar_stub.c, t_system_event.c)
define nvn_rt_threads in their stubs, as they do dm_host_work.

It is what found the cause of 50-130 ms stalls in Ocarina of Time's Hall of
Fallen Foes: the replay thread inside arch_lookup under
MTLCompilerScheduler::buildRequest while the guest's submit waited for it.

Checked: the host builds; `make -C dm/host/tests GAME=0400486024DEC000 -k run`
fails only memory-profile (a Python 3.9 type annotation in its script), as it
does on unchanged main; dm/tools/env_switches.py --check prints what it prints
on main (12 stale names, DM_SPLIT_REGISTERED_MAP without a meaning); the docs
tests (test_docs.py) pass, with the entry in docs/reference/threads.md. No test
covers the dump itself: it needs a stalled frame, and a run of the game on an
M4 Max (macOS 27.3) with DM_HITCH_DUMP=25:100 logged the host lines for the
three threads at each stall. clang-tidy was not run (not installed here). Only
Ocarina of Time was run.
@adurham
adurham force-pushed the fix/hitch-dump-host-threads branch from 29243a0 to c94754a Compare November 21, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant