WIP: perf(os): LockMutex and UnlockMutex take the calling thread and the core checkpoint's test from their context #1957

Draft
siantm wants to merge 10 commits from siantm/Longshot:perf/mutex-ctx-thread into main
Contributor

Summary

This PR depends on #1956 (perf/os-inline, the HosThread head) and #1953
(perf/mutex-lock-wait-cold, mutex_lock_wait's signature); their commits show in this diff until they merge.

LockMutex and UnlockMutex are the game's busiest nn::os calls. Each found the calling thread through the host
thread-local (hos_self(), a call into hos_thread.c) and ran the virtual-core checkpoint as a call
(hos_vcore_checkpoint(), which reads the same thread-local) before its lookup. Their context already names the thread:
Ctx.thread is the HosThread running it (setup_guest; a fiber's context takes its thread's at each switch).

This PR takes both from there:

  • mutex_lock and mutex_unlock take the thread as an argument; the HLE functions pass hos_ctx_thread(c), and
    mutex_lock_owed (the end of a condition variable's wait) still passes hos_self().
  • obj_at (host/nn_os_sync.c) is obj for an HLE function's own context: it tests the thread's vc_kick through
    the context (hos_vcore_checkpoint_at in host/hos.h, a relaxed atomic load, as hos_vcore_checkpoint() reads it:
    a waiting thread sets it while this one runs) and calls hos_vcore_checkpoint() only when a better waiter asked for
    the core, which reads the kick again as it always has.
  • vc_kick moves to the HosThread head, after #1956's HosThreadHead fields (offset 268, _Static_assert'ed);
    nothing else moves.

Not switched: the same thread and the same checkpoint, without the thread-local reads and the call.

Stacked: on #1956's head 2a1ad8f2 (main @ f1f2dc5b with aca07f9c, 7df10ab4, 2a1ad8f2) and #1953's four commits at its
head 8443bba1, cherry-picked here as f02113e5, 72ede7ee, 6f64422b and ca2e8c2f (the same lines; #1953 is on main @
6e1521a7, the parent of f1f2dc5b). This PR's own commits are the last three: cd2d0384 (the change), 1af56b97 (its test)
and a912c5b8 (the kick read atomically). From 4d98f819 (its nn_os_sync.c half) on exp/x86-asm-sync.

Read first: obj_at, mutex_lock, mutex_unlock and the two HLE functions in host/nn_os_sync.c;
hos_ctx_thread and hos_vcore_checkpoint_at in host/hos.h.

Testing

Tested: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks only. This change
has not run in the game on this PC yet (Still to test). Each check ran in a hidden console of its own, through the PC's
job queue (jobs fb-1957-1 and fb-1957-2), at the head a912c5b8 (on main @ f1f2dc5b, as above), unless it says otherwise:

  • python -I -B tests/test_cv_handoff_threads.py (no --cc: LONGSHOT_MINGW's clang; again with CC set to that
    clang): exit 0 both times. It now runs LockMutex and UnlockMutex through the real obj_at, hos_ctx_thread and
    hos_vcore_checkpoint_at with a context whose thread is not hos_self()'s record, and its eight new broken variants
    (either entry through obj() or obj_nockpt() or taking hos_self(), the kick read from hos_self()'s record, the
    lookup before the checkpoint) each fail at their own check. At the test commit 1af56b97 (before the atomic load) it
    passes as well. With the two entries put back to obj() and hos_self() it fails (FAIL:1204 ckpts() == calls),
    while this PR's earlier fixture (at cd2d0384) passes that code.
  • python -I -B tests/run_all.py --strict --changed origin/main: exit 1, "105 passed, 22 failed, 5 skipped" (skipped,
    Linux or the game's modules: nx2/test_leaf.py, test_driver_env_choose, test_mesh_fallback_layout,
    test_posix_thread_priority, test_tracy_funcs). Passing among them: test_cv_handoff_threads,
    test_multiwait_wake, test_obj_cache_size, test_guest_os, test_spawn_emit, test_invalidate_vcore and the
    test_vcore_* checks that compile. All 22 failures fail on main @ f1f2dc5b too (run there by name in the same
    job): test_crash_dialog, test_crash_record, test_dev_ab, test_dev_packs, test_frame_overlap,
    test_host_guest_writes, test_libc_hooks, test_lift_cache, test_linux_preflight, test_linux_pressure,
    test_make_game_ngx, test_mods_list, test_oot_shadow_fit, test_perf_report, test_present_queue_default,
    test_profiling_mode, test_sdiv_overflow, test_slow_frames, test_target_reuse_memory, test_vcore_escape,
    test_vcore_mask0, test_vk_occlusion_queries.
  • host/nn_os_sync.c and host/hos_thread.c compiled (syntax only) with the host build's flags, with and without
    Tracy, against the a64.h this head's nx2/rtgen.py writes (HosThreadHead; the vc_kick offset assert): no
    error.

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): Castle Town's market and a heavy scene, 60 s each, warmed
    and interleaved: main with #1956 and #1953 (this PR's parent) against this PR, and main against this PR; once
    with HOS_VCORES at its default (on) and once with HOS_VCORES=0. Average fps, 1 % lows, median and p99 frame
    times, no stall and the same vcores: lines and escapes as the parent (by hand)
  • A route where worker threads contend for mutexes (loading a save into the Market): wait tails and stalls, this PR
    against its parent, HOS_VCORES at its default and off (by hand)
  • Linux: build the host and run python3 -I -B tests/test_cv_handoff_threads.py, expecting it to pass (by hand)
  • Linux and Windows with other CPUs (an AMD CPU, fewer cores), and the Steam Deck: Castle Town's market for two
    minutes, this PR against main, expecting the same frame times as main or better and no stall (the test farm: a
    request posted on this PR)

Measurements

Verdict: micro-benchmark only, not measured in play yet: an uncontended LockMutex + UnlockMutex took 20.48 ns
on this PR's parent and 19.17 ns with this change, inside the rounds' spread (17.85 to 31.23 against 17.03 to 21.63): no
gain shown in this micro-benchmark. No play measurement exists yet. The figures are of earlier revisions (below) and were
not run again at this head: since then the kick is read with an atomic load (a912c5b8) and the parents carry their
review fixes.

Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5, -O2 -march=native -ffp-contract=off -fno-strict-aliasing as the
host is built. An uncontended LockMutex + UnlockMutex through the HLE functions themselves, each checkout's
nn_os_sync.c cut as its tests/test_cv_handoff_threads.py then cut it, with that fixture's stubs made as the game has
them (hos_self() and hos_vcore_checkpoint() out-of-line calls reading a thread-local, the lookup the checkpoint and
then the object); 21 interleaved rounds of 5,000,000 pairs in one timing-cpu job of the PC's job queue, the median and
the rounds' range. Measured on main @ 51f5f9da, with the parents as they were then.

Baseline: this PR's parent 92647c07 (main @ 51f5f9da with perf/os-inline and perf/mutex-lock-wait-cold), so
the table shows this PR's own commit alone.

Before: this PR's parent @ 92647c07 After: this PR @ a2828eec
uncontended LockMutex + UnlockMutex, ns (median of 21 rounds, range) 20.48 (17.85 to 31.23) 19.17 (17.03 to 21.63)
LockMutex + UnlockMutex (uncontended)    base           median    20.48 ns  (rounds 17.85 to 31.23)
LockMutex + UnlockMutex (uncontended)    PR             median    19.17 ns  (rounds 17.03 to 21.63)

Risks

If Ctx.thread were not the running thread's record, a lock would be owned by another thread's record and the kick test
would read another thread's request. Every guest context gets it in setup_guest and a fiber's at each switch, as cur
does. tests/test_cv_handoff_threads.py runs the two HLE functions through the real obj_at, hos_ctx_thread and
hos_vcore_checkpoint_at with a context whose thread is not hos_self()'s record, and fails if either entry takes
hos_self() or skips a pending kick. The offset of vc_kick is asserted. No switch: a revert is enough. Players notice
nothing.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary This PR depends on #1956 (`perf/os-inline`, the `HosThread` head) and #1953 (`perf/mutex-lock-wait-cold`, `mutex_lock_wait`'s signature); their commits show in this diff until they merge. `LockMutex` and `UnlockMutex` are the game's busiest `nn::os` calls. Each found the calling thread through the host thread-local (`hos_self()`, a call into `hos_thread.c`) and ran the virtual-core checkpoint as a call (`hos_vcore_checkpoint()`, which reads the same thread-local) before its lookup. Their context already names the thread: `Ctx.thread` is the `HosThread` running it (`setup_guest`; a fiber's context takes its thread's at each switch). This PR takes both from there: - `mutex_lock` and `mutex_unlock` take the thread as an argument; the HLE functions pass `hos_ctx_thread(c)`, and `mutex_lock_owed` (the end of a condition variable's wait) still passes `hos_self()`. - `obj_at` (`host/nn_os_sync.c`) is `obj` for an HLE function's own context: it tests the thread's `vc_kick` through the context (`hos_vcore_checkpoint_at` in `host/hos.h`, a relaxed atomic load, as `hos_vcore_checkpoint()` reads it: a waiting thread sets it while this one runs) and calls `hos_vcore_checkpoint()` only when a better waiter asked for the core, which reads the kick again as it always has. - `vc_kick` moves to the `HosThread` head, after #1956's `HosThreadHead` fields (offset 268, `_Static_assert`'ed); nothing else moves. Not switched: the same thread and the same checkpoint, without the thread-local reads and the call. Stacked: on #1956's head 2a1ad8f2 (`main` @ f1f2dc5b with aca07f9c, 7df10ab4, 2a1ad8f2) and #1953's four commits at its head 8443bba1, cherry-picked here as f02113e5, 72ede7ee, 6f64422b and ca2e8c2f (the same lines; #1953 is on `main` @ 6e1521a7, the parent of f1f2dc5b). This PR's own commits are the last three: cd2d0384 (the change), 1af56b97 (its test) and a912c5b8 (the kick read atomically). From 4d98f819 (its `nn_os_sync.c` half) on `exp/x86-asm-sync`. Read first: `obj_at`, `mutex_lock`, `mutex_unlock` and the two HLE functions in `host/nn_os_sync.c`; `hos_ctx_thread` and `hos_vcore_checkpoint_at` in `host/hos.h`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks only. This change has not run in the game on this PC yet (Still to test). Each check ran in a hidden console of its own, through the PC's job queue (jobs fb-1957-1 and fb-1957-2), at the head a912c5b8 (on `main` @ f1f2dc5b, as above), unless it says otherwise: - `python -I -B tests/test_cv_handoff_threads.py` (no `--cc`: `LONGSHOT_MINGW`'s clang; again with `CC` set to that clang): exit 0 both times. It now runs `LockMutex` and `UnlockMutex` through the real `obj_at`, `hos_ctx_thread` and `hos_vcore_checkpoint_at` with a context whose thread is not `hos_self()`'s record, and its eight new broken variants (either entry through `obj()` or `obj_nockpt()` or taking `hos_self()`, the kick read from `hos_self()`'s record, the lookup before the checkpoint) each fail at their own check. At the test commit 1af56b97 (before the atomic load) it passes as well. With the two entries put back to `obj()` and `hos_self()` it fails (`FAIL:1204 ckpts() == calls`), while this PR's earlier fixture (at cd2d0384) passes that code. - `python -I -B tests/run_all.py --strict --changed origin/main`: exit 1, "105 passed, 22 failed, 5 skipped" (skipped, Linux or the game's modules: `nx2/test_leaf.py`, `test_driver_env_choose`, `test_mesh_fallback_layout`, `test_posix_thread_priority`, `test_tracy_funcs`). Passing among them: `test_cv_handoff_threads`, `test_multiwait_wake`, `test_obj_cache_size`, `test_guest_os`, `test_spawn_emit`, `test_invalidate_vcore` and the `test_vcore_*` checks that compile. All 22 failures fail on `main` @ f1f2dc5b too (run there by name in the same job): `test_crash_dialog`, `test_crash_record`, `test_dev_ab`, `test_dev_packs`, `test_frame_overlap`, `test_host_guest_writes`, `test_libc_hooks`, `test_lift_cache`, `test_linux_preflight`, `test_linux_pressure`, `test_make_game_ngx`, `test_mods_list`, `test_oot_shadow_fit`, `test_perf_report`, `test_present_queue_default`, `test_profiling_mode`, `test_sdiv_overflow`, `test_slow_frames`, `test_target_reuse_memory`, `test_vcore_escape`, `test_vcore_mask0`, `test_vk_occlusion_queries`. - `host/nn_os_sync.c` and `host/hos_thread.c` compiled (syntax only) with the host build's flags, with and without Tracy, against the `a64.h` this head's `nx2/rtgen.py` writes (`HosThreadHead`; the `vc_kick` offset assert): no error. **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): Castle Town's market and a heavy scene, 60 s each, warmed and interleaved: `main` with #1956 and #1953 (this PR's parent) against this PR, and `main` against this PR; once with `HOS_VCORES` at its default (on) and once with `HOS_VCORES=0`. Average fps, 1 % lows, median and p99 frame times, no stall and the same `vcores:` lines and escapes as the parent (by hand) - A route where worker threads contend for mutexes (loading a save into the Market): wait tails and stalls, this PR against its parent, `HOS_VCORES` at its default and off (by hand) - Linux: build the host and run `python3 -I -B tests/test_cv_handoff_threads.py`, expecting it to pass (by hand) - Linux and Windows with other CPUs (an AMD CPU, fewer cores), and the Steam Deck: Castle Town's market for two minutes, this PR against `main`, expecting the same frame times as `main` or better and no stall (the test farm: a request posted on this PR) ## Measurements **Verdict:** micro-benchmark only, not measured in play yet: an uncontended `LockMutex` + `UnlockMutex` took 20.48 ns on this PR's parent and 19.17 ns with this change, inside the rounds' spread (17.85 to 31.23 against 17.03 to 21.63): no gain shown in this micro-benchmark. No play measurement exists yet. The figures are of earlier revisions (below) and were not run again at this head: since then the kick is read with an atomic load (a912c5b8) and the parents carry their review fixes. Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5, `-O2 -march=native -ffp-contract=off -fno-strict-aliasing` as the host is built. An uncontended `LockMutex` + `UnlockMutex` through the HLE functions themselves, each checkout's `nn_os_sync.c` cut as its `tests/test_cv_handoff_threads.py` then cut it, with that fixture's stubs made as the game has them (`hos_self()` and `hos_vcore_checkpoint()` out-of-line calls reading a thread-local, the lookup the checkpoint and then the object); 21 interleaved rounds of 5,000,000 pairs in one `timing-cpu` job of the PC's job queue, the median and the rounds' range. Measured on `main` @ 51f5f9da, with the parents as they were then. Baseline: this PR's parent 92647c07 (`main` @ 51f5f9da with `perf/os-inline` and `perf/mutex-lock-wait-cold`), so the table shows this PR's own commit alone. | | Before: this PR's parent @ 92647c07 | After: this PR @ a2828eec | |---|---|---| | uncontended LockMutex + UnlockMutex, ns (median of 21 rounds, range) | 20.48 (17.85 to 31.23) | 19.17 (17.03 to 21.63) | ``` LockMutex + UnlockMutex (uncontended) base median 20.48 ns (rounds 17.85 to 31.23) LockMutex + UnlockMutex (uncontended) PR median 19.17 ns (rounds 17.03 to 21.63) ``` ## Risks If `Ctx.thread` were not the running thread's record, a lock would be owned by another thread's record and the kick test would read another thread's request. Every guest context gets it in `setup_guest` and a fiber's at each switch, as `cur` does. `tests/test_cv_handoff_threads.py` runs the two HLE functions through the real `obj_at`, `hos_ctx_thread` and `hos_vcore_checkpoint_at` with a context whose thread is not `hos_self()`'s record, and fails if either entry takes `hos_self()` or skips a pending kick. The offset of `vc_kick` is asserted. No switch: a revert is enough. Players notice nothing. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(hle): GetCurrentThread, GetTlsValue, SetTlsValue and a thread's own GetThreadPriority answered at their call sites in lifted code (A64_OS_INLINE)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
b922eadf4a
Each of the four is an HLE function that reads or writes one field of the calling thread's record. Called from lifted
code it pays the way out: the caller's registers synced to the context and back, the hooked definition's tail call,
HOS_HLE_STATS's test and the host thread-local. nx2/guest_os.py rewrites each direct call, devirtualised call and tail
call of their hooked definitions into the field access itself through Ctx.thread (the HosThread running the context);
GetThreadPriority only about the calling thread's own ThreadType, the hooked definition as before about another. Calls
through a pointer still reach the HLE functions. HosThread now starts with guest_tt, tls_slots and priority, at offsets
_Static_assert'ed in host/hos_thread.c. Lift time, on by default (bit-exact against the HLE functions by test);
A64_OS_INLINE=0 lifts as before. HOS_HLE_STATS=1 no longer counts the inlined calls.

tests/test_guest_os.py: the rewrite (calls, the devirtualised arm, tail calls, other calls kept, =0 and a lift without
the hooks unchanged), the wiring in nx2/lift.py and nx2/chunks.py, and the four HLE functions cut from hos_thread.c
against the inlined C over two threads' records, 16,000 calls; --bench times GetTlsValue and GetThreadPriority called
and inlined.

From 4d98f819 (its lifter and HosThread half) and bb27910b on exp/x86-asm-sync. vc_kick stays where main has it (the
mutex change that reads it from the context is a branch of its own).

Assisted-by: Claude Code
mutex_lock's spin and sleep, taken only when another thread holds the mutex, are moved word for word into
mutex_lock_wait (noinline, cold), so the uncontended lock (owner check, one compare-exchange) is a small leaf that does
not save registers or set up a frame for the wait. tests/test_cv_handoff_threads.py cuts the new function too.

From cafb4100 on exp/x86-asm-sync (its other half, the virtual cores' owner slots on their own cache lines, needs the
lock-free slots main does not have).

Assisted-by: Claude Code
perf(os): LockMutex and UnlockMutex take the calling thread and the core checkpoint's test from their context
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 15s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
0747cefa46
The two hottest nn::os calls found the calling thread through the host thread-local (hos_self) and ran the virtual-core
checkpoint as a call on every lock and unlock. Their context already names the thread (Ctx.thread, the HosThread running
it; a fiber's context takes the thread's at each switch), so they take it from there: mutex_lock and mutex_unlock take
the thread as an argument, and obj_at tests the thread's vc_kick through the context (hos.h hos_vcore_checkpoint_at) and
calls hos_vcore_checkpoint only when a better waiter asked for the core, which reads the kick again as before. vc_kick
moves to the HosThread head beside priority (offset 268, _Static_assert'ed); nothing else moves. Not switched: the same
thread and the same checkpoint, without the thread-local reads and the call.

tests/test_cv_handoff_threads.py: the fixture's contexts carry their thread, and the LockMutex/UnlockMutex HLEs are checked
to take the context's thread, which is the calling thread.

From 4d98f819 (its nn_os_sync.c half) on exp/x86-asm-sync. On top of perf/os-inline (the HosThread head) and
perf/mutex-lock-wait-cold's 1e6a4721 (cherry-picked: mutex_lock_wait's signature).

Assisted-by: Claude Code
BeanBot left a comment

Recommendation: Request changes. The mutex fast path reads the virtual-core kick flag non-atomically, and the stacked lifter change adds unsynchronized reads and writes of thread state. The reported benchmark shows no clear gain, and there are no in-game frame-time results.

LockMutex and UnlockMutex use the calling context for mutex ownership and skip the checkpoint call when no kick is pending. The stack also moves contended waits out of line and inlines four nn::os calls in lifted code. This can save host calls, at the cost of coupling lifted code to the host thread layout, scanning generated C during the build, and losing coverage in runtime HLE counts.

Does it help: Unproven. The author's Windows i7-9700 fixture compared the mutex commit alone against its stacked parent over 21 interleaved rounds. The median fell from 20.48 ns to 19.17 ns per uncontended pair, but the ranges overlapped at 17.85–31.23 ns and 17.03–21.63 ns. The fixture used scheduler stubs. There are no gameplay, contended-wait, clean-build time, or executable-size results for this stack.
Other systems: The scheduler, mutex and CV handoff, and guest worker and fiber paths share the changed thread state. The reported Windows fixtures cover mutex/CV behavior and multiwait wakes, but stub out the new checkpoint. Linux and Steam Deck scheduling, Tier 1 frame pacing, and the movie decoder's contended load path still need coverage. The standalone lifter changes both forked and spawned emission and affects build time, the lift cache, and HLE profiling. No direct changes to the renderer API, GPU passes, saves, audio, or input were found.
Switches: The mutex commit adds no switch. The stack adds A64_OS_INLINE, on by default, with 0 restoring HLE calls. The build switch table documents it and the existing A64_ lift-key rule covers it. Gameplay and clean-build A/B results are missing for the default. HOS_HLE_STATS remains off by default, but enabling it on a default build omits inlined calls. HOS_VCORES remains on by default.

Reviewed: 0747cefa46 against 2e1f6c32d3: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, all three commit messages, and all nine changed-file diffs. Read nx2/guest_os.py, nx2/lift.py, tests/test_guest_os.py, and docs/dev/reference/build.md in full. Read the changed sections and traced their dependencies in host/hos.h, host/hos_thread.c, host/nn_os_sync.c, nx2/chunks.py, and tests/test_cv_handoff_threads.py. Unrelated sections of those larger files, downstream build passes, and existing test records received targeted reads. No local docs/review-checklist.md, sibling Tooling checkout, or changed generated or translation files were present. Run evidence came from the PR description.; nothing run (a code review).
Checked and fine:

  • Main and worker setup populate Ctx.thread before guest execution, and fiber_switch refreshes it before entering the destination fiber.
  • The mutex split preserves reservation checks, owner CAS, waiter accounting, and the wake protocol. CV reacquisition still uses hos_self(), and the new object lookup keeps the cache flush after the lookup.
  • The vendored emitter's direct, devirtualized, and tail-call forms have the context syncs around the replaced calls. The other-thread priority fallback retains its original callee.
  • The lift key discovers the imported module and hashes A64_OS_INLINE. The standalone configuration and spawn table are wired in the expected places.
  • All three commits have Assisted-by trailers. The added fixture addresses are synthetic. The diff contains no game artifacts, generated shader edits, third-party changes, or renderer API version changes. git diff --check passed.

Blocking (to change before merge)

  1. host/hos.h:220: The inline checkpoint reads vc_kick through volatile while another thread stores it atomically. A waiting worker can request a holder's core while that holder enters LockMutex or UnlockMutex, making this a data race on the new path. Use __atomic_load_n with __ATOMIC_RELAXED, as hos_vcore_checkpoint already does.
  2. nx2/guest_os.py:41: The inlined priority load races with ChangeThreadPriority and svcSetThreadPriority targeting the running thread. This race exists in the HLE too, but inlining exposes the plain load to hoisting or reuse across repeated guest calls. Use consistent atomic priority access in the generated code, the HLE and SVC paths, and the scheduler. Use an atomic exchange where the setter returns the old value.
  3. nx2/guest_os.py:36: The generated TLS read and write can race with vc_sync_tls. A same-core affinity change writes the target's core TLS slot while that target is running, and the inline copy lets the compiler reuse a plain load across guest calls. Use consistent relaxed atomics in the emitted accesses, the HLE implementations, and the scheduler's TLS reads and writes.
  4. nx2/guest_os.py:38: Casting the record to uint64_t* points at the scalar guest_tt member. Indexing that pointer into tls_slots crosses a C subobject boundary even for slot 0. Share a typed thread prefix between generated and host C, or obtain the pointer from the asserted byte offset of the actual array before indexing.
  5. host/nn_os_sync.c:645: The extracted cold path carries over an unsynchronized trace_ms initialization. Two threads entering their first contended waits can both access the sentinel while one writes it. Initialize the setting before workers start or use synchronized publication.
  6. host/nn_os_sync.c:664: The moved 10-second diagnostic reads m->count while the owner can change it without m->lk. Its owner pointer can also become stale before name lookup, as can holder in the final trace log at line 678. For example, the owner can unlock and be joined and destroyed while the waiter is descheduled. Log stable identifiers or take a lifetime-safe snapshot, and omit the count unless its reads and writes are synchronized.
  7. tests/test_cv_handoff_threads.py:231: The fixture replaces obj_at and hos_ctx_thread and gives its context the same value as hos_self(). Reverting either mutex entry to obj() or to hos_self() still passes. Exercise the production helpers and lookup wrapper, assert that both entries process a pending kick before lookup, and use distinguishable fixture thread records to verify the owner they actually pass.
  8. tests/test_guest_os.py:86: The wiring check matches source strings, and the compiled fixture inserts READS directly. If emit_function stops returning the rewritten C, the suite can still pass. Emit and execute a synthetic hooked function through the real lifter with the switch on and off, and extend the spawn test to compare its output with single-process emission.
  9. tests/test_guest_os.py:32: The new check hardcodes gcc in both the suite declaration and its CLI default. On a Clang-only setup with CC=clang, strict mode can reject it before it runs. Honor CC and use the available GNU-style compiler in the runner and standalone check. Apply the same selection to the modified CV fixture.
  10. nx2/guest_os.py:90: Once a standalone image has any matching hook, the default runs a regex over every emitted function and dispatches a Python callback for every direct call, including calls to unrelated targets. Match at call emission or limit the post-pass to the configured target names so unrelated code avoids the extra work.
  11. docs/dev/reference/build.md:73: A default build with HOS_HLE_STATS=1 undercounts the four operations, and the ratio of direct to indirect calls can now change the ranking that profiling tools report. Preserve useful runtime counting when enabled. If maintainers accept a separate profiling build, document the A64_OS_INLINE=0 rebuild requirement in the profiling reference and the HOS_HLE_STATS switch entry.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • The uncontended microbenchmark leaves the performance claim open. Report interleaved exact-head gameplay runs against current main and the parent containing both dependencies. Include the Market and a heavy or contended scene, average FPS, 1% lows, median and p99 frame time, and mutex or game-thread CPU cost. The repository's required own-PC gameplay run is still missing.
  • The cold split and kick path change the path used by contended workers, while all reported timings use a free mutex. Check wait tails, stalls and scheduler escapes during load and play with virtual cores on and off on Windows, Linux and Steam Deck, including Tier 1 NVIDIA and AMD systems. The already-default HOS_VCORES setting needs an explicit off comparison.
  • The stacked lifter change ships enabled without a measured default. Once the emit overhead is reduced, report clean lift/build time and executable size on Windows and Linux, and gameplay frame-time results with A64_OS_INLINE on and off. The mutex fixture isolates the last commit and cannot justify the lifter default.

Suggestions (the author may take or leave)

  • Share the lookup and cache-flush body between obj and obj_at so a future cache change reaches both paths.
  • If the optional guest OS microbenchmark supplies reported numbers, use a monotonic clock and interleaved rounds. Its current wall clock and best-of-five reporting are sensitive to clock corrections and run order.
  • host/nn_os_sync.c:645: Two first-time waiters can race on trace_ms. Set it before guest threads start or publish it atomically.
  • host/nn_os_sync.c:664: The owner can change count while this log reads it, and it can be destroyed before name lookup here or in the final trace. Omit the racy count and use a lifetime-safe identifier or snapshot.

Testing: Read-only review. The author reports Windows mutex/CV and multiwait fixture passes at af867cb6. The earlier changed-check batch reported 81 passed, 14 failed, and 3 skipped, with the same 14 failures on its then-base. Exact-head CI, lint and supported Windows/Linux build results are missing.
Overlaps and merge order: #1956 supplies the HosThread layout and lifter changes. #1953 supplies the cold mutex helper. Land the dependencies before #1957, then rebase the mutex commit onto current main with both present and verify the final diff and results. The checkout lists #1956 followed by the cherry-picked #1953.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The mutex fast path reads the virtual-core kick flag non-atomically, and the stacked lifter change adds unsynchronized reads and writes of thread state. The reported benchmark shows no clear gain, and there are no in-game frame-time results. LockMutex and UnlockMutex use the calling context for mutex ownership and skip the checkpoint call when no kick is pending. The stack also moves contended waits out of line and inlines four nn::os calls in lifted code. This can save host calls, at the cost of coupling lifted code to the host thread layout, scanning generated C during the build, and losing coverage in runtime HLE counts. **Does it help:** Unproven. The author's Windows i7-9700 fixture compared the mutex commit alone against its stacked parent over 21 interleaved rounds. The median fell from 20.48 ns to 19.17 ns per uncontended pair, but the ranges overlapped at 17.85–31.23 ns and 17.03–21.63 ns. The fixture used scheduler stubs. There are no gameplay, contended-wait, clean-build time, or executable-size results for this stack. **Other systems:** The scheduler, mutex and CV handoff, and guest worker and fiber paths share the changed thread state. The reported Windows fixtures cover mutex/CV behavior and multiwait wakes, but stub out the new checkpoint. Linux and Steam Deck scheduling, Tier 1 frame pacing, and the movie decoder's contended load path still need coverage. The standalone lifter changes both forked and spawned emission and affects build time, the lift cache, and HLE profiling. No direct changes to the renderer API, GPU passes, saves, audio, or input were found. **Switches:** The mutex commit adds no switch. The stack adds A64_OS_INLINE, on by default, with 0 restoring HLE calls. The build switch table documents it and the existing A64_ lift-key rule covers it. Gameplay and clean-build A/B results are missing for the default. HOS_HLE_STATS remains off by default, but enabling it on a default build omits inlined calls. HOS_VCORES remains on by default. **Reviewed:** 0747cefa46b3 against 2e1f6c32d30e: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, all three commit messages, and all nine changed-file diffs. Read nx2/guest_os.py, nx2/lift.py, tests/test_guest_os.py, and docs/dev/reference/build.md in full. Read the changed sections and traced their dependencies in host/hos.h, host/hos_thread.c, host/nn_os_sync.c, nx2/chunks.py, and tests/test_cv_handoff_threads.py. Unrelated sections of those larger files, downstream build passes, and existing test records received targeted reads. No local docs/review-checklist.md, sibling Tooling checkout, or changed generated or translation files were present. Run evidence came from the PR description.; nothing run (a code review). **Checked and fine:** - Main and worker setup populate Ctx.thread before guest execution, and fiber_switch refreshes it before entering the destination fiber. - The mutex split preserves reservation checks, owner CAS, waiter accounting, and the wake protocol. CV reacquisition still uses hos_self(), and the new object lookup keeps the cache flush after the lookup. - The vendored emitter's direct, devirtualized, and tail-call forms have the context syncs around the replaced calls. The other-thread priority fallback retains its original callee. - The lift key discovers the imported module and hashes A64_OS_INLINE. The standalone configuration and spawn table are wired in the expected places. - All three commits have Assisted-by trailers. The added fixture addresses are synthetic. The diff contains no game artifacts, generated shader edits, third-party changes, or renderer API version changes. git diff --check passed. **Blocking** (to change before merge) 1. host/hos.h:220: The inline checkpoint reads vc_kick through volatile while another thread stores it atomically. A waiting worker can request a holder's core while that holder enters LockMutex or UnlockMutex, making this a data race on the new path. Use __atomic_load_n with __ATOMIC_RELAXED, as hos_vcore_checkpoint already does. 2. nx2/guest_os.py:41: The inlined priority load races with ChangeThreadPriority and svcSetThreadPriority targeting the running thread. This race exists in the HLE too, but inlining exposes the plain load to hoisting or reuse across repeated guest calls. Use consistent atomic priority access in the generated code, the HLE and SVC paths, and the scheduler. Use an atomic exchange where the setter returns the old value. 3. nx2/guest_os.py:36: The generated TLS read and write can race with vc_sync_tls. A same-core affinity change writes the target's core TLS slot while that target is running, and the inline copy lets the compiler reuse a plain load across guest calls. Use consistent relaxed atomics in the emitted accesses, the HLE implementations, and the scheduler's TLS reads and writes. 4. nx2/guest_os.py:38: Casting the record to uint64_t* points at the scalar guest_tt member. Indexing that pointer into tls_slots crosses a C subobject boundary even for slot 0. Share a typed thread prefix between generated and host C, or obtain the pointer from the asserted byte offset of the actual array before indexing. 5. host/nn_os_sync.c:645: The extracted cold path carries over an unsynchronized trace_ms initialization. Two threads entering their first contended waits can both access the sentinel while one writes it. Initialize the setting before workers start or use synchronized publication. 6. host/nn_os_sync.c:664: The moved 10-second diagnostic reads m->count while the owner can change it without m->lk. Its owner pointer can also become stale before name lookup, as can holder in the final trace log at line 678. For example, the owner can unlock and be joined and destroyed while the waiter is descheduled. Log stable identifiers or take a lifetime-safe snapshot, and omit the count unless its reads and writes are synchronized. 7. tests/test_cv_handoff_threads.py:231: The fixture replaces obj_at and hos_ctx_thread and gives its context the same value as hos_self(). Reverting either mutex entry to obj() or to hos_self() still passes. Exercise the production helpers and lookup wrapper, assert that both entries process a pending kick before lookup, and use distinguishable fixture thread records to verify the owner they actually pass. 8. tests/test_guest_os.py:86: The wiring check matches source strings, and the compiled fixture inserts READS directly. If emit_function stops returning the rewritten C, the suite can still pass. Emit and execute a synthetic hooked function through the real lifter with the switch on and off, and extend the spawn test to compare its output with single-process emission. 9. tests/test_guest_os.py:32: The new check hardcodes gcc in both the suite declaration and its CLI default. On a Clang-only setup with CC=clang, strict mode can reject it before it runs. Honor CC and use the available GNU-style compiler in the runner and standalone check. Apply the same selection to the modified CV fixture. 10. nx2/guest_os.py:90: Once a standalone image has any matching hook, the default runs a regex over every emitted function and dispatches a Python callback for every direct call, including calls to unrelated targets. Match at call emission or limit the post-pass to the configured target names so unrelated code avoids the extra work. 11. docs/dev/reference/build.md:73: A default build with HOS_HLE_STATS=1 undercounts the four operations, and the ratio of direct to indirect calls can now change the ranking that profiling tools report. Preserve useful runtime counting when enabled. If maintainers accept a separate profiling build, document the A64_OS_INLINE=0 rebuild requirement in the profiling reference and the HOS_HLE_STATS switch entry. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - The uncontended microbenchmark leaves the performance claim open. Report interleaved exact-head gameplay runs against current main and the parent containing both dependencies. Include the Market and a heavy or contended scene, average FPS, 1% lows, median and p99 frame time, and mutex or game-thread CPU cost. The repository's required own-PC gameplay run is still missing. - The cold split and kick path change the path used by contended workers, while all reported timings use a free mutex. Check wait tails, stalls and scheduler escapes during load and play with virtual cores on and off on Windows, Linux and Steam Deck, including Tier 1 NVIDIA and AMD systems. The already-default HOS_VCORES setting needs an explicit off comparison. - The stacked lifter change ships enabled without a measured default. Once the emit overhead is reduced, report clean lift/build time and executable size on Windows and Linux, and gameplay frame-time results with A64_OS_INLINE on and off. The mutex fixture isolates the last commit and cannot justify the lifter default. **Suggestions** (the author may take or leave) - Share the lookup and cache-flush body between obj and obj_at so a future cache change reaches both paths. - If the optional guest OS microbenchmark supplies reported numbers, use a monotonic clock and interleaved rounds. Its current wall clock and best-of-five reporting are sensitive to clock corrections and run order. - `host/nn_os_sync.c:645`: Two first-time waiters can race on trace_ms. Set it before guest threads start or publish it atomically. - `host/nn_os_sync.c:664`: The owner can change count while this log reads it, and it can be destroyed before name lookup here or in the final trace. Omit the racy count and use a lifetime-safe identifier or snapshot. **Testing:** Read-only review. The author reports Windows mutex/CV and multiwait fixture passes at af867cb6. The earlier changed-check batch reported 81 passed, 14 failed, and 3 skipped, with the same 14 failures on its then-base. Exact-head CI, lint and supported Windows/Linux build results are missing. **Overlaps and merge order:** #1956 supplies the HosThread layout and lifter changes. #1953 supplies the cold mutex helper. Land the dependencies before #1957, then rebase the mutex commit onto current main with both present and verify the final diff and results. The checkout lists #1956 followed by the cherry-picked #1953. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -70,6 +70,7 @@ Read by the build, not the game, so they are not in `switches.def`.
| `A64_FASTFP`, `A64_LOCAL_REGS`, `A64_LOCAL_FLAGS`, `A64_LOCAL_FUNCS` | Lift-time switches (`nx2/fastfp.py`, `nx2/guest_locals.py`); they change the lift key |
| `A64_FASTFP_STORES=0`, `A64_FASTFP_VMOVES=0` | Fast float regions (`nx2/fastfp.py`) stop at a guest store, or at a vector move or shuffle (`nx2/fastvec.py`'s `a64_vld16`, `a64_vdup`, `A64_EXT16`, `A64_EXT8`, `a64_tbl1`), as before. Both on by default: a region may hold stores but no load after one, and its fast copy keeps their addresses and values and stores them, in order, once its MXCSR check passed (its exact copy is unchanged). Lift-time switches: they change the lift key |
| `A64_VECFP=0` or a list of `elem`, `vec`, `minmax`, `fcvt` | The SSE fast paths for the float forms the translator otherwise does lane by lane (`nx2/vecfp.py`); each keeps a result only where it is provably Arm's, else the instruction's own C runs. All on by default; `0` lifts exactly as without them. A lift-time switch: it changes the lift key |
| `A64_OS_INLINE=0` | nn::os::GetCurrentThread, GetTlsValue, SetTlsValue and GetThreadPriority called as HLE functions, as before. On by default: each direct call (or tail call) of their hooked definitions is the field read or write itself, through the context's thread pointer (`nx2/guest_os.py`; the thread record's head is fixed and asserted in `host/hos_thread.c`); GetThreadPriority so only about the calling thread's own ThreadType, a call as before about another. The same x0, other registers and records as the HLE functions (`tests/test_guest_os.py`), no checkpoint skipped (they had none); calls through a pointer still reach the HLE functions, and `HOS_HLE_STATS=1` does not count the inlined ones. A lift-time switch: it changes the lift key |
Member

Preserve complete runtime HLE profiling, or document the required A64_OS_INLINE=0 rebuild in the profiling reference and HOS_HLE_STATS switch entry if maintainers accept that workflow.

Preserve complete runtime HLE profiling, or document the required A64_OS_INLINE=0 rebuild in the profiling reference and HOS_HLE_STATS switch entry if maintainers accept that workflow.
host/hos.h Outdated
@ -212,0 +217,4 @@
static inline HosThread *hos_ctx_thread(const Ctx *c) { return (HosThread *)c->thread; }
static inline void hos_vcore_checkpoint_at(const Ctx *c) {
const char *t = (const char *)c->thread;
if (__builtin_expect(t && *(const volatile int *)(t + HOS_THREAD_VC_KICK), 0)) hos_vcore_checkpoint();
Member

Use a relaxed atomic load here. A waiting worker can atomically set this flag while the holder is in LockMutex, and volatile does not make the accesses atomic.

Use a relaxed atomic load here. A waiting worker can atomically set this flag while the holder is in LockMutex, and volatile does not make the accesses atomic.
nx2/guest_os.py Outdated
@ -0,0 +33,4 @@
"_ZN2nn2os16GetCurrentThreadEv": "{ c->x[0] = ((const uint64_t *)c->thread)[0]; }",
"_ZN2nn2os11GetTlsValueENS0_7TlsSlotE":
"{ const uint32_t _slot = (uint32_t)c->x[0]; c->x[0] = _slot < %du ? ((const uint64_t *)c->thread)[1 + _slot] : 0; }"
% SLOTS,
Member

A same-core affinity change can write this TLS slot while its owner runs. Make generated, HLE, and scheduler accesses consistently atomic.

A same-core affinity change can write this TLS slot while its owner runs. Make generated, HLE, and scheduler accesses consistently atomic.
nx2/guest_os.py Outdated
@ -0,0 +35,4 @@
"{ const uint32_t _slot = (uint32_t)c->x[0]; c->x[0] = _slot < %du ? ((const uint64_t *)c->thread)[1 + _slot] : 0; }"
% SLOTS,
"_ZN2nn2os11SetTlsValueENS0_7TlsSlotEm":
"{ const uint32_t _slot = (uint32_t)c->x[0]; if (_slot < %du) ((uint64_t *)c->thread)[1 + _slot] = c->x[1]; }" % SLOTS,
Member

The cast points at the scalar guest_tt member. Index from the actual tls_slots array through a shared type or its asserted byte offset.

The cast points at the scalar guest_tt member. Index from the actual tls_slots array through a shared type or its asserted byte offset.
nx2/guest_os.py Outdated
@ -0,0 +38,4 @@
"{ const uint32_t _slot = (uint32_t)c->x[0]; if (_slot < %du) ((uint64_t *)c->thread)[1 + _slot] = c->x[1]; }" % SLOTS,
"_ZN2nn2os17GetThreadPriorityEPKNS0_10ThreadTypeE":
"{ const uint8_t *_th = (const uint8_t *)c->thread; if (c->x[0] == *(const uint64_t *)_th) "
"c->x[0] = (uint32_t)*(const int32_t *)(_th + %d); else @F@(c); }" % PRIORITY_AT,
Member

Another thread can change this priority through HLE or SVC. Use atomic access in the generated load and all runtime readers and writers so the compiler cannot reuse a stale value across calls.

Another thread can change this priority through HLE or SVC. Use atomic access in the generated load and all runtime readers and writers so the compiler cannot reuse a stale value across calls.
nx2/guest_os.py Outdated
@ -0,0 +87,4 @@
text, refs = base(self, e, texts)
table = getattr(self, "os_inline", None)
if table:
text, n = inline(text, table)
Member

This scans every emitted function and calls Python for unrelated direct calls. Limit the pass to the configured targets or perform the substitution as the lifter emits those calls.

This scans every emitted function and calls Python for unrelated direct calls. Limit the pass to the configured targets or perform the substitution as the lifter emits those calls.
@ -224,6 +228,7 @@ static Obj *obj(uint64_t key, int kind) {
CHECK(o->kind == kind);
return o;
}
static Obj *obj_at(const Ctx *c, uint64_t key, int kind) { (void)c; return obj(key, kind); } /* (LockMutex, UnlockMutex) */
Member

This stub skips the code under review. Use the real checkpoint and lookup wrapper and make the test fail if either mutex entry skips a pending kick or uses hos_self() instead of the context's owner.

This stub skips the code under review. Use the real checkpoint and lookup wrapper and make the test fail if either mutex entry skips a pending kick or uses hos_self() instead of the context's owner.
@ -0,0 +29,4 @@
import kit # noqa: E402,F401 (a64-kit's folders on the path)
import guest_os # noqa: E402
RUN_ALL_ARGS = ["--cc", "gcc"]
Member

A Clang-only machine with CC=clang can fail strict mode before this test runs. Honor CC in both the test runner and direct invocation, including the CV fixture.

A Clang-only machine with CC=clang can fail strict mode before this test runs. Honor CC in both the test runner and direct invocation, including the CV fixture.
@ -0,0 +83,4 @@
print("PASS: the lift's rewrite inlines the hooked calls and tail calls only, and A64_OS_INLINE=0 keeps them")
def wiring():
Member

The source-string check and direct READS fixture still succeed if the real emitter drops the rewritten result. Emit and execute a synthetic caller through the real lifter, including spawned emission.

The source-string check and direct READS fixture still succeed if the real emitter drops the rewritten result. Emit and execute a synthetic caller through the real lifter, including spawned emission.
futondestroyer left a comment

Recommendation: Request changes. The new mutex checkpoint reads vc_kick through a volatile load while the scheduler stores to the same flag atomically. On a busy core, a waiting worker can request the holder's core while the holder enters either mutex function. Use the same relaxed atomic load as hos_vcore_checkpoint() before making the context-based path the default. The CV fixture stubs out the affected lookup and checkpoint, so it cannot catch that regression.

I independently verified the scheduler path in the existing exact-head review. The waiter publishes a kick in host/hos_thread.c:2089, and the old checkpoint reads it atomically at :2219. host/hos.h:220 is the new unsynchronized reader. A focused fixture should use the real helper and both mutex HLE entries, checking that a set kick is processed before the lookup and that the caller's context supplies mutex ownership.

Does it help? Unproven. The author's 21 interleaved fixture rounds on an i7-9700 gave 20.48 ns before and 19.17 ns after for an uncontended pair. The ranges overlap at 17.85–31.23 ns and 17.03–21.63 ns. That fixture compared earlier revisions of the final commit and its stacked parent. It does not give a gameplay, contended-wait or clean-build result. The Windows CV/mutex and multiwait passes were reported on the previous rebased head. The broader batch had 81 passes, 14 failures also reported on its main baseline, and three skips. Cached exact-head CI shows the description check passed, ten contexts pending and one skipped.

Checked and fine. Main and worker startup set Ctx.thread before lifted code runs, and a fiber switch updates it before transfer. Condition-variable reacquisition still uses the current host thread. The mutex changes retain the recursive owner check, reservation-aware acquisition and release, and the object-cache flush after lookup. The lifted variants retain context register synchronization around calls and fall back to the existing HLE for another thread's priority. The standalone hook selection and spawn table are wired, and the lift key includes the build switch. No game artifacts, generated shader edits, renderer API changes or vendor modifications are in the diff.

Dependencies and switches. The cold helper in e8f21d1f matches the patch in PR 1953, including its outstanding diagnostic initialization and owner-lifetime issues. PR 1956 is open WIP and is carried at its exact head b922eadf4a99dcb7d202770fecb6c2529d85035c. It enables A64_OS_INLINE at lift time and still needs the atomic priority and TLS accesses, valid TLS array addressing, and real emitter coverage described in the exact-head prerequisite review. It also changes what HOS_HLE_STATS counts on a default build. Resolve and measure both dependencies before rebasing the final mutex commit. That commit adds no switch.

Testing needed. After source fixes and the prerequisites land, compare current main containing the prerequisites with the revised mutex head. Use warmed interleaved Market and heavy-scene gameplay, plus a route with contended workers. Check stalls, wait tails and virtual-core escapes with HOS_VCORES at its default and off. Report average FPS, 1% lows, and median and p99 frame times. Game-free scheduler/CV checks and supported Windows and Linux builds should run on the revision being measured. Measure clean build time and game size separately for the lifter dependency and run its gameplay comparison with each build-time setting.

Reviewed 0747cefa46b33c70b84f972ed1728d60c4fd3a63 against merge base 2e1f6c32d30ec3582093743a968c8447bb435962. Read all nine changed-file diffs, the surrounding scheduler, fiber, object-cache, lifter and check-runner code, and the cached Forgejo evidence. Used revision-matched local Graphify maps for navigation and checked the relevant source directly, including macro-generated HLE entries and the vendored emitter. No PR code was run. Guidance at Longshot 6e1521a7, Tooling 0b0059ac.

**Recommendation: Request changes.** The new mutex checkpoint reads `vc_kick` through a volatile load while the scheduler stores to the same flag atomically. On a busy core, a waiting worker can request the holder's core while the holder enters either mutex function. Use the same relaxed atomic load as `hos_vcore_checkpoint()` before making the context-based path the default. The CV fixture stubs out the affected lookup and checkpoint, so it cannot catch that regression. I independently verified the scheduler path in the [existing exact-head review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62205). The waiter publishes a kick in `host/hos_thread.c:2089`, and the old checkpoint reads it atomically at `:2219`. `host/hos.h:220` is the new unsynchronized reader. A focused fixture should use the real helper and both mutex HLE entries, checking that a set kick is processed before the lookup and that the caller's context supplies mutex ownership. **Does it help? Unproven.** The author's 21 interleaved fixture rounds on an i7-9700 gave 20.48 ns before and 19.17 ns after for an uncontended pair. The ranges overlap at 17.85–31.23 ns and 17.03–21.63 ns. That fixture compared earlier revisions of the final commit and its stacked parent. It does not give a gameplay, contended-wait or clean-build result. The Windows CV/mutex and multiwait passes were reported on the previous rebased head. The broader batch had 81 passes, 14 failures also reported on its main baseline, and three skips. Cached exact-head CI shows the description check passed, ten contexts pending and one skipped. **Checked and fine.** Main and worker startup set `Ctx.thread` before lifted code runs, and a fiber switch updates it before transfer. Condition-variable reacquisition still uses the current host thread. The mutex changes retain the recursive owner check, reservation-aware acquisition and release, and the object-cache flush after lookup. The lifted variants retain context register synchronization around calls and fall back to the existing HLE for another thread's priority. The standalone hook selection and spawn table are wired, and the lift key includes the build switch. No game artifacts, generated shader edits, renderer API changes or vendor modifications are in the diff. **Dependencies and switches.** The cold helper in `e8f21d1f` matches the patch in [PR 1953](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1953), including its outstanding diagnostic initialization and owner-lifetime issues. [PR 1956](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1956) is open WIP and is carried at its exact head `b922eadf4a99dcb7d202770fecb6c2529d85035c`. It enables `A64_OS_INLINE` at lift time and still needs the atomic priority and TLS accesses, valid TLS array addressing, and real emitter coverage described in the exact-head [prerequisite review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1956#issuecomment-62741). It also changes what `HOS_HLE_STATS` counts on a default build. Resolve and measure both dependencies before rebasing the final mutex commit. That commit adds no switch. **Testing needed.** After source fixes and the prerequisites land, compare current main containing the prerequisites with the revised mutex head. Use warmed interleaved Market and heavy-scene gameplay, plus a route with contended workers. Check stalls, wait tails and virtual-core escapes with `HOS_VCORES` at its default and off. Report average FPS, 1% lows, and median and p99 frame times. Game-free scheduler/CV checks and supported Windows and Linux builds should run on the revision being measured. Measure clean build time and game size separately for the lifter dependency and run its gameplay comparison with each build-time setting. **Reviewed** `0747cefa46b33c70b84f972ed1728d60c4fd3a63` against merge base `2e1f6c32d30ec3582093743a968c8447bb435962`. Read all nine changed-file diffs, the surrounding scheduler, fiber, object-cache, lifter and check-runner code, and the cached Forgejo evidence. Used revision-matched local Graphify maps for navigation and checked the relevant source directly, including macro-generated HLE entries and the vendored emitter. No PR code was run. Guidance at Longshot `6e1521a7`, Tooling `0b0059ac`.
siantm force-pushed perf/mutex-ctx-thread from 0747cefa46
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 15s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to a912c5b8e9
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-21 05:24:58 +00:00
Compare
Author
Contributor

Point by point for BeanBot's review (62205), at a912c5b8. The branch is rebased onto #1956's head 2a1ad8f2 (on main @ f1f2dc5b) with #1953's four commits at its head 8443bba1 cherry-picked on top (f02113e5, 72ede7ee, 6f64422b, ca2e8c2f; git range-diff shows them unchanged), so it still depends on #1956 and #1953 and carries their review fixes. This PR's commit 0747cefa is now cd2d0384. It had two conflicts, both kept from both sides: HosThread's head comment and asserts (#1956 now asserts against HosThreadHead; the vc_kick assert stays), and the CV fixture's list of cut functions (#1953 cuts mutex_lock_wait from its name). The fixes for this commit's points are 1af56b97 (test) and a912c5b8 (fix). The description is updated.

This PR's own commit:

  • Blocking 1, vc_kick read through volatile: fixed in a912c5b8. hos_vcore_checkpoint_at reads it with __atomic_load_n(..., __ATOMIC_RELAXED), as hos_vcore_checkpoint does. It has no failing test of its own: the two loads behave the same in a run on this PC, where the difference is the C memory model's, and llvm-mingw has no thread sanitizer for Windows. The cases below run the changed function.
  • Blocking 7, the fixture's stubs: fixed in 1af56b97. tests/test_cv_handoff_threads.py now cuts obj and obj_at from host/nn_os_sync.c, and hos_ctx_thread, hos_vcore_checkpoint_at and HOS_THREAD_VC_KICK from host/hos.h. Only the lookup itself and hos_thread.c's hos_vcore_checkpoint are the fixture's; the latter counts its calls, numbered in one sequence with the lookups. A new group runs both entries with a context whose thread is a record other than hos_self()'s. The mutex must be owned and let go by that record. No checkpoint may be called with no kick, or with a kick only on hos_self()'s record; with a kick on the context's record, each entry must call it once, before its lookup. Eight broken variants must each fail at their own check: either entry through obj() or obj_nockpt(), either entry taking hos_self(), the kick read from hos_self()'s record, and the lookup before the checkpoint. In job fb-1957-2 the fixture passes at the test commit and at the head. With the two entries put back to obj() and hos_self() it fails (ckpts() == calls), and the earlier fixture (at cd2d0384) passes that code.

From #1956's commit (fixed on #1956; the rebase brings the fixes here; its reply):

  • Blocking 2, priority: fixed in 2a1ad8f2. Priority reads are atomic in the lifted code, hos_thread_prio and every scheduler and diagnostic reader; the setter is an atomic exchange.
  • Blocking 3, TLS race: fixed in 2a1ad8f2. Slot accesses are atomic (relaxed) in the lifted code, GetTlsValue/SetTlsValue, vc_pref_core and vc_sync_tls. The slot index core_tls_slot stays a volatile read as on main (#1956's description says so).
  • Blocking 4, the tls_slots cast: fixed in 2a1ad8f2. The head is a shared type, HosThreadHead, in the generated a64.h; the lifted code indexes its tls_slots array and hos_thread.c asserts the offsets.
  • Blocking 8, the real emitter: fixed in 7df10ab4, tests/test_spawn_emit.py test_os_inline: the real emit in one process and spawned, with the switch on and off.
  • Blocking 9, CC: fixed in 7df10ab4 for tests/test_guest_os.py, and for the CV fixture in #1953's d3e02c70 (72ede7ee here): --cc, then CC, then LONGSHOT_MINGW's clang, then clang, gcc or cc. The CV fixture passes at this head with no --cc (LONGSHOT_MINGW's clang) and with CC set (fb-1957-2).
  • Blocking 10, the scan: fixed in 2a1ad8f2. A function whose refs name none of the hooked definitions is not scanned.
  • Blocking 11, HOS_HLE_STATS: not preserved, marked and documented in 2a1ad8f2. #1956's reason: counting at each inlined site would add back the check the change removes. scripts/perf.py cpu --calls says the four counts are partial, and build.md and profiling.md say to lift with A64_OS_INLINE=0 for full counts.

From #1953's commit (fixed on #1953; its reply):

  • Blocking 5, trace_ms: fixed in 18e90465 (6f64422b here). HOS_MUTEX_TRACE is cached through an atomic and parsed over the whole string (1 to 2147483647 ms, anything else off).
  • Blocking 6, m->count and the holder's lifetime: fixed in 18e90465. The count is gone from the 10 s log, and the holder's name is copied under m->lk while the holder cannot end; the final trace line uses that copy. Not fixed there: the rename race (hos_thread_set_name against every name reader) is in hos_thread.c, pre-existing on main, and left for a separate change.

Waiting items: pending on my side, nothing measured yet. Interleaved play runs of this head against current main and against its parent (both dependencies), Market and a heavy scene; contended waits, stalls and escapes with HOS_VCORES at its default and off, on Windows, Linux and the Steam Deck; these are in Still to test. The lifter's clean build time and size and A64_OS_INLINE on/off are #1956's and pending there.

Suggestions: sharing obj's and obj_at's lookup and flush is not taken; the shared part is two lines, and the fixture now cuts both. The micro-benchmark clock suggestion is about #1956's benchmark and was not taken there.

Point by point for BeanBot's review ([62205](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62205)), at a912c5b8. The branch is rebased onto #1956's head 2a1ad8f2 (on `main` @ f1f2dc5b) with #1953's four commits at its head 8443bba1 cherry-picked on top (f02113e5, 72ede7ee, 6f64422b, ca2e8c2f; `git range-diff` shows them unchanged), so it still depends on #1956 and #1953 and carries their review fixes. This PR's commit 0747cefa is now cd2d0384. It had two conflicts, both kept from both sides: `HosThread`'s head comment and asserts (#1956 now asserts against `HosThreadHead`; the `vc_kick` assert stays), and the CV fixture's list of cut functions (#1953 cuts `mutex_lock_wait` from its name). The fixes for this commit's points are 1af56b97 (test) and a912c5b8 (fix). The description is updated. This PR's own commit: - [Blocking 1, `vc_kick` read through `volatile`](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62196): fixed in a912c5b8. `hos_vcore_checkpoint_at` reads it with `__atomic_load_n(..., __ATOMIC_RELAXED)`, as `hos_vcore_checkpoint` does. It has no failing test of its own: the two loads behave the same in a run on this PC, where the difference is the C memory model's, and llvm-mingw has no thread sanitizer for Windows. The cases below run the changed function. - [Blocking 7, the fixture's stubs](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62200): fixed in 1af56b97. `tests/test_cv_handoff_threads.py` now cuts `obj` and `obj_at` from `host/nn_os_sync.c`, and `hos_ctx_thread`, `hos_vcore_checkpoint_at` and `HOS_THREAD_VC_KICK` from `host/hos.h`. Only the lookup itself and `hos_thread.c`'s `hos_vcore_checkpoint` are the fixture's; the latter counts its calls, numbered in one sequence with the lookups. A new group runs both entries with a context whose thread is a record other than `hos_self()`'s. The mutex must be owned and let go by that record. No checkpoint may be called with no kick, or with a kick only on `hos_self()`'s record; with a kick on the context's record, each entry must call it once, before its lookup. Eight broken variants must each fail at their own check: either entry through `obj()` or `obj_nockpt()`, either entry taking `hos_self()`, the kick read from `hos_self()`'s record, and the lookup before the checkpoint. In job fb-1957-2 the fixture passes at the test commit and at the head. With the two entries put back to `obj()` and `hos_self()` it fails (`ckpts() == calls`), and the earlier fixture (at cd2d0384) passes that code. From #1956's commit (fixed on #1956; the rebase brings the fixes here; [its reply](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1956#issuecomment-63546)): - [Blocking 2, priority](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62197): fixed in 2a1ad8f2. Priority reads are atomic in the lifted code, `hos_thread_prio` and every scheduler and diagnostic reader; the setter is an atomic exchange. - [Blocking 3, TLS race](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62198): fixed in 2a1ad8f2. Slot accesses are atomic (relaxed) in the lifted code, `GetTlsValue`/`SetTlsValue`, `vc_pref_core` and `vc_sync_tls`. The slot index `core_tls_slot` stays a `volatile` read as on `main` (#1956's description says so). - [Blocking 4, the `tls_slots` cast](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62199): fixed in 2a1ad8f2. The head is a shared type, `HosThreadHead`, in the generated `a64.h`; the lifted code indexes its `tls_slots` array and `hos_thread.c` asserts the offsets. - [Blocking 8, the real emitter](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62201): fixed in 7df10ab4, `tests/test_spawn_emit.py` `test_os_inline`: the real emit in one process and spawned, with the switch on and off. - [Blocking 9, `CC`](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62202): fixed in 7df10ab4 for `tests/test_guest_os.py`, and for the CV fixture in #1953's d3e02c70 (72ede7ee here): `--cc`, then `CC`, then `LONGSHOT_MINGW`'s clang, then clang, gcc or cc. The CV fixture passes at this head with no `--cc` (`LONGSHOT_MINGW`'s clang) and with `CC` set (fb-1957-2). - [Blocking 10, the scan](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62203): fixed in 2a1ad8f2. A function whose refs name none of the hooked definitions is not scanned. - [Blocking 11, `HOS_HLE_STATS`](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62204): not preserved, marked and documented in 2a1ad8f2. #1956's reason: counting at each inlined site would add back the check the change removes. `scripts/perf.py cpu --calls` says the four counts are partial, and `build.md` and `profiling.md` say to lift with `A64_OS_INLINE=0` for full counts. From #1953's commit (fixed on #1953; [its reply](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1953#issuecomment-63057)): - [Blocking 5, `trace_ms`](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62205): fixed in 18e90465 (6f64422b here). `HOS_MUTEX_TRACE` is cached through an atomic and parsed over the whole string (1 to 2147483647 ms, anything else off). - [Blocking 6, `m->count` and the holder's lifetime](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62205): fixed in 18e90465. The count is gone from the 10 s log, and the holder's name is copied under `m->lk` while the holder cannot end; the final trace line uses that copy. Not fixed there: the rename race (`hos_thread_set_name` against every name reader) is in `hos_thread.c`, pre-existing on `main`, and left for a separate change. Waiting items: pending on my side, nothing measured yet. Interleaved play runs of this head against current `main` and against its parent (both dependencies), Market and a heavy scene; contended waits, stalls and escapes with `HOS_VCORES` at its default and off, on Windows, Linux and the Steam Deck; these are in Still to test. The lifter's clean build time and size and `A64_OS_INLINE` on/off are #1956's and pending there. Suggestions: sharing `obj`'s and `obj_at`'s lookup and flush is not taken; the shared part is two lines, and the fixture now cuts both. The micro-benchmark clock suggestion is about #1956's benchmark and was not taken there.
Author
Contributor

@futondestroyer, thanks for the review (62897). Pushed at a912c5b8: the test is 1af56b97 and the fix a912c5b8, on top of this PR's commit (0747cefa, now cd2d0384).

  • The vc_kick load. Fixed in a912c5b8: hos_vcore_checkpoint_at reads the kick with __atomic_load_n(..., __ATOMIC_RELAXED), the same load as hos_vcore_checkpoint().
  • The fixture. Fixed in 1af56b97. The fixture now runs the real obj_at, hos_ctx_thread and hos_vcore_checkpoint_at (cut from the sources) and both mutex entries with a context whose thread is a record other than hos_self()'s. Each entry must call the checkpoint once for a kick set on the context's thread, before its lookup, and not at all with no kick or a kick only on hos_self()'s record. The mutex must be owned and released by the context's thread. Eight broken variants (either entry through obj(), obj_nockpt() or hos_self(), the kick read from hos_self(), the lookup first) each fail at their own check. With the entries put back to obj() and hos_self() the new fixture fails, and the earlier one passes that code.
  • Dependencies. The branch is rebased onto #1956's head 2a1ad8f2 (on main @ f1f2dc5b) with #1953's four commits at its head 8443bba1 cherry-picked on top, unchanged by git range-diff. So it carries the fixes your reviews of them asked for: HosThreadHead's tls_slots array, atomic priority and TLS accesses and the real-emitter checks (#1956's 7df10ab4 and 2a1ad8f2; the HOS_HLE_STATS counts are marked partial and documented there, not preserved), and #1953's HOS_MUTEX_TRACE initialisation and holder lifetime (18e90465, here 6f64422b). Two conflicts with them, in HosThread's head comment and asserts and in the fixture's list of cut functions, were resolved by keeping both sides. Neither dependency is measured yet. I rebased now rather than after they land so that this branch runs their fixed code. It will be rebased again when they merge.
  • Does it help, and the testing. Nothing new is measured. The micro-benchmark figures are from earlier revisions and were not run again at this head; the description says so. The play runs you list are in Still to test and pending on my side: warmed, interleaved Market and heavy-scene runs against main and against the parent with both dependencies, a contended-worker route with HOS_VCORES at its default and off, average fps, 1 % lows, median and p99. The game-free checks below ran at this head on Windows; Linux has not run yet.

Checks at a912c5b8 (Windows 11, i7-9700, llvm-mingw clang 23.1.5, this PC's job queue, fb-1957-1 and fb-1957-2):

  • tests/test_cv_handoff_threads.py: passes, with and without CC; at the test commit 1af56b97 too.
  • tests/run_all.py --strict --changed origin/main: 105 passed, 22 failed, 5 skipped; all 22 also fail on main @ f1f2dc5b, run by name in the same job.
  • host/nn_os_sync.c and host/hos_thread.c compile (syntax only) with the host build's flags, with and without Tracy, against the a64.h this head generates.
@futondestroyer, thanks for the review ([62897](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1957#issuecomment-62897)). Pushed at a912c5b8: the test is 1af56b97 and the fix a912c5b8, on top of this PR's commit (0747cefa, now cd2d0384). - **The `vc_kick` load.** Fixed in a912c5b8: `hos_vcore_checkpoint_at` reads the kick with `__atomic_load_n(..., __ATOMIC_RELAXED)`, the same load as `hos_vcore_checkpoint()`. - **The fixture.** Fixed in 1af56b97. The fixture now runs the real `obj_at`, `hos_ctx_thread` and `hos_vcore_checkpoint_at` (cut from the sources) and both mutex entries with a context whose thread is a record other than `hos_self()`'s. Each entry must call the checkpoint once for a kick set on the context's thread, before its lookup, and not at all with no kick or a kick only on `hos_self()`'s record. The mutex must be owned and released by the context's thread. Eight broken variants (either entry through `obj()`, `obj_nockpt()` or `hos_self()`, the kick read from `hos_self()`, the lookup first) each fail at their own check. With the entries put back to `obj()` and `hos_self()` the new fixture fails, and the earlier one passes that code. - **Dependencies.** The branch is rebased onto #1956's head 2a1ad8f2 (on `main` @ f1f2dc5b) with #1953's four commits at its head 8443bba1 cherry-picked on top, unchanged by `git range-diff`. So it carries the fixes your reviews of them asked for: `HosThreadHead`'s `tls_slots` array, atomic priority and TLS accesses and the real-emitter checks (#1956's 7df10ab4 and 2a1ad8f2; the `HOS_HLE_STATS` counts are marked partial and documented there, not preserved), and #1953's `HOS_MUTEX_TRACE` initialisation and holder lifetime (18e90465, here 6f64422b). Two conflicts with them, in `HosThread`'s head comment and asserts and in the fixture's list of cut functions, were resolved by keeping both sides. Neither dependency is measured yet. I rebased now rather than after they land so that this branch runs their fixed code. It will be rebased again when they merge. - **Does it help, and the testing.** Nothing new is measured. The micro-benchmark figures are from earlier revisions and were not run again at this head; the description says so. The play runs you list are in Still to test and pending on my side: warmed, interleaved Market and heavy-scene runs against `main` and against the parent with both dependencies, a contended-worker route with `HOS_VCORES` at its default and off, average fps, 1 % lows, median and p99. The game-free checks below ran at this head on Windows; Linux has not run yet. Checks at a912c5b8 (Windows 11, i7-9700, llvm-mingw clang 23.1.5, this PC's job queue, fb-1957-1 and fb-1957-2): - `tests/test_cv_handoff_threads.py`: passes, with and without `CC`; at the test commit 1af56b97 too. - `tests/run_all.py --strict --changed origin/main`: 105 passed, 22 failed, 5 skipped; all 22 also fail on `main` @ f1f2dc5b, run by name in the same job. - `host/nn_os_sync.c` and `host/hos_thread.c` compile (syntax only) with the host build's flags, with and without Tracy, against the `a64.h` this head generates.
Author
Contributor

@Beanstalk This makes the guest LockMutex and UnlockMutex take the calling thread and the virtual-core checkpoint's test from their context (host/nn_os_sync.c, host/hos.h). It is stacked on #1956 and #1953 (their commits are in its diff), so its build lifts the game again. No switch of its own: a revert gives back main's code. It has not run in the game on these PCs yet. Please play Castle Town Market for two minutes, the PR against main on the same PC, on a Windows PC with an AMD processor, a Linux PC with an AMD processor, a PC with 6 or fewer logical processors and the Steam Deck. No hang or stall; frame time p99 equal to main's or better, within the run-to-run spread.

@Beanstalk This makes the guest LockMutex and UnlockMutex take the calling thread and the virtual-core checkpoint's test from their context (host/nn_os_sync.c, host/hos.h). It is stacked on #1956 and #1953 (their commits are in its diff), so its build lifts the game again. No switch of its own: a revert gives back main's code. It has not run in the game on these PCs yet. Please play Castle Town Market for two minutes, the PR against main on the same PC, on a Windows PC with an AMD processor, a Linux PC with an AMD processor, a PC with 6 or fewer logical processors and the Steam Deck. No hang or stall; frame time p99 equal to main's or better, within the run-to-run spread.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/mutex-ctx-thread:siantm-perf/mutex-ctx-thread'
git switch 'siantm-perf/mutex-ctx-thread'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1957
No description provided.