WIP: perf(nvn): HOS_NVN_NO_IDLE_AWAY=1 keeps the virtual core through an nvnWindowAcquireTexture with no pacing to sleep for (experiment, off) #1968

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/nvn-keep-core into main
Contributor

Summary

nvnWindowAcquireTexture (host/nvn_native.c) gives the thread's virtual core up and takes it again around the frame's
pacing (hos_vi_native_acquire), also when there is nothing to sleep for. Given up and taken again around a wait of no
time, the core can go to a waiting thread, and this one then waits for a core (up to a time slice when the holder's
priority is as good).

This adds an experiment, off by default: with HOS_NVN_NO_IDLE_AWAY=1, a thread that holds its core keeps it through an
acquire with no pacing to sleep for. Everything else goes as on main:

  • a paced acquire still gives the core up around its sleep. nn_vi.c's hos_vi_native_acquire is split into
    hos_vi_native_until (the pacing's deadline, 0 for no sleep) and hos_vi_native_sleep_until (the time left taken
    then, the sleep counted as pacing in hos_acquire_slept_ns); the acquire gives the core up around the latter, so the
    deadline holds and the wait to take a core again stays out of the pacing's count, in the virtual-core counters;
  • a thread that holds no core (one that escaped a long wait for one, or inside an outer block) goes the usual way:
    hos_vcore_away ends an escape and hos_vcore_back takes a free core after the call (hos_vcore_held,
    host/hos_thread.c, tells the two apart);
  • nvnSyncWait is not changed. The PR first also kept the core through a missed zero-timeout poll; that part was
    dropped after review 62903 (the title now names only the acquire): the poll's second probe can flush queued work and
    take the renderer's locks even at timeout 0, and can find the fence reached (CONDITION_SATISFIED), so the second
    probe, its result and the handoff around it stay as on main. The commit history still shows the dropped part (the
    first commit and its fix).

The switch is read once through an atomic (two first callers both store the same value) and said once in the log; its
row is in gpu/vk/switches.def (kind attempt). Without it nothing changes, the pacing's split aside (the same sleep and
count, in two functions). With virtual cores off (HOS_VCORES=0) no thread holds a core, and the switch changes nothing.

From d1e33769 (the nvn-recordings integration) on exp/x86-asm-sync, where it was on by default and not measured.

Read first: no_idle_away and nvnWindowAcquireTexture in host/nvn_native.c; hos_vi_native_until,
hos_vi_native_sleep_until in host/nn_vi.c; tests/test_vcore_escape.py (nvn_cases).

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, with the switch on or off (Still to test). Each check ran in a hidden console of
its own, in one job of the PC's job queue (fb3-1968-1), on this branch rebased onto main @ f1f2dc5b (head 253596c4):

  • python -I -B tests/test_vcore_escape.py (with --cxx llvm-mingw clang++ and with the compiler found from
    LONGSHOT_MINGW): passes: the escape and starvation cases ("ok", "ok") and the NVN call sites with
    HOS_NVN_NO_IDLE_AWAY unset, 0, off, 1 and yes, each "ok", each flipped after the first pass. At 392604c3 (the
    test, before the fix) unset, 0 and off pass and =1 fails: "an escaped thread's acquire with nothing to sleep for
    takes the free core after it", "a missed poll probes twice and times out", "an escaped thread's missed zero-timeout
    poll takes the free core after it", "a fence reached between the poll's two probes is satisfied", "a missed poll gives
    the core up around its second probe and takes it again", "a paced acquire counts its pacing sleep alone, not its wait
    for a core after it". On main @ f1f2dc5b the check does not build (hos_fps_timing declared twice in its fixture);
    this PR removes the second declaration.
  • python -I -B tests/test_fps_stats.py and tests/test_pacing_policy.py: pass.
  • python -I -B tests/run_all.py --strict --changed origin/main (7 files changed, 100 checks read them; 8 at once): 85
    passed, 15 failed, 5 skipped. 12 of the 15 failing checks (test_crash_dialog.py, test_crash_record.py,
    test_dev_ab.py, test_dev_packs.py, test_frame_overlap.py, test_host_guest_writes.py, test_libc_hooks.py,
    test_linux_pressure.py, test_mods_list.py, test_profiling_mode.py, test_slow_frames.py, test_vcore_mask0.py)
    fail on main @ f1f2dc5b too, each run by name in the same queue's jobs. The other three
    (test_present_queue_default, test_target_reuse_memory, test_vk_occlusion_queries) compiled nothing in that run
    nor in the run on main (no Vulkan headers on the job's path: "not found: vulkan_headers (--strict)"). Rerun with the
    headers (job fb3-vk-1, RX_CPM set) at the head 253596c4 and on main @ f1f2dc5b, each fails at both with the same
    first error: test_present_queue_default "srccut: '{TAB_DEBUG, "Present queue", &opts.present_queue, ...' is not in
    gpu/vk/vk_menu.cpp"; test_target_reuse_memory 2 of its 8 tests ("'vmaGetAllocationInfo2' unexpectedly found" in the
    VMA source, and its fixture's "use of undeclared identifier 'destroy_image_later'"); test_vk_occlusion_queries "the
    ring fixture did not compile" ("no member named 'policy'"). None fails on this branch alone.

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): Castle Town's market, 60 s, main @ f1f2dc5b, this PR unset
    and with HOS_NVN_NO_IDLE_AWAY=1, warmed and interleaved, two runs each, expecting the log line "nvn: the virtual core
    is kept across an nvnWindowAcquireTexture with no pacing to sleep for" with it, average fps, 1% lows, median and p99
    frame times and the virtual-core waits and escapes compared (by hand)
  • Linux and Windows with other CPUs (an AMD CPU, 6 or fewer logical processors), and the Steam Deck: Castle Town's
    market for two minutes with HOS_NVN_NO_IDLE_AWAY=1 against unset, expecting frame times within the runs' spread or
    better and no stall (asked of the Test Farm)

Measurements

Not measured in play yet (Still to test): HOS_NVN_NO_IDLE_AWAY ships off (kind attempt), an experiment nothing measured yet chooses on; only game-free checks have run (Testing).

Risks

Off, the acquire tests a switch read once, and the pacing's sleep runs through two functions instead of one (the same
deadline, sleep and count). On, a thread that holds its core keeps it through an acquire with nothing to sleep for: a
guest thread waiting for a core waits that much longer. A mistake there would show as a stall or a lower frame rate
with the switch on. Turn it off by leaving HOS_NVN_NO_IDLE_AWAY unset; a revert is enough. Players notice nothing: the
switch is not set for them.

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 switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • 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 `nvnWindowAcquireTexture` (`host/nvn_native.c`) gives the thread's virtual core up and takes it again around the frame's pacing (`hos_vi_native_acquire`), also when there is nothing to sleep for. Given up and taken again around a wait of no time, the core can go to a waiting thread, and this one then waits for a core (up to a time slice when the holder's priority is as good). This adds an experiment, off by default: with `HOS_NVN_NO_IDLE_AWAY=1`, a thread that holds its core keeps it through an acquire with no pacing to sleep for. Everything else goes as on `main`: - a paced acquire still gives the core up around its sleep. `nn_vi.c`'s `hos_vi_native_acquire` is split into `hos_vi_native_until` (the pacing's deadline, 0 for no sleep) and `hos_vi_native_sleep_until` (the time left taken then, the sleep counted as pacing in `hos_acquire_slept_ns`); the acquire gives the core up around the latter, so the deadline holds and the wait to take a core again stays out of the pacing's count, in the virtual-core counters; - a thread that holds no core (one that escaped a long wait for one, or inside an outer block) goes the usual way: `hos_vcore_away` ends an escape and `hos_vcore_back` takes a free core after the call (`hos_vcore_held`, `host/hos_thread.c`, tells the two apart); - `nvnSyncWait` is not changed. The PR first also kept the core through a missed zero-timeout poll; that part was dropped after review 62903 (the title now names only the acquire): the poll's second probe can flush queued work and take the renderer's locks even at timeout 0, and can find the fence reached (`CONDITION_SATISFIED`), so the second probe, its result and the handoff around it stay as on `main`. The commit history still shows the dropped part (the first commit and its fix). The switch is read once through an atomic (two first callers both store the same value) and said once in the log; its row is in `gpu/vk/switches.def` (kind `attempt`). Without it nothing changes, the pacing's split aside (the same sleep and count, in two functions). With virtual cores off (`HOS_VCORES=0`) no thread holds a core, and the switch changes nothing. From d1e33769 (the nvn-recordings integration) on `exp/x86-asm-sync`, where it was on by default and not measured. Read first: `no_idle_away` and `nvnWindowAcquireTexture` in `host/nvn_native.c`; `hos_vi_native_until`, `hos_vi_native_sleep_until` in `host/nn_vi.c`; `tests/test_vcore_escape.py` (`nvn_cases`). ## 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, with the switch on or off (Still to test). Each check ran in a hidden console of its own, in one job of the PC's job queue (fb3-1968-1), on this branch rebased onto `main` @ f1f2dc5b (head 253596c4): - `python -I -B tests/test_vcore_escape.py` (with `--cxx` llvm-mingw clang++ and with the compiler found from `LONGSHOT_MINGW`): passes: the escape and starvation cases ("ok", "ok") and the NVN call sites with `HOS_NVN_NO_IDLE_AWAY` unset, `0`, `off`, `1` and `yes`, each "ok", each flipped after the first pass. At 392604c3 (the test, before the fix) unset, `0` and `off` pass and `=1` fails: "an escaped thread's acquire with nothing to sleep for takes the free core after it", "a missed poll probes twice and times out", "an escaped thread's missed zero-timeout poll takes the free core after it", "a fence reached between the poll's two probes is satisfied", "a missed poll gives the core up around its second probe and takes it again", "a paced acquire counts its pacing sleep alone, not its wait for a core after it". On `main` @ f1f2dc5b the check does not build (`hos_fps_timing` declared twice in its fixture); this PR removes the second declaration. - `python -I -B tests/test_fps_stats.py` and `tests/test_pacing_policy.py`: pass. - `python -I -B tests/run_all.py --strict --changed origin/main` (7 files changed, 100 checks read them; 8 at once): 85 passed, 15 failed, 5 skipped. 12 of the 15 failing checks (`test_crash_dialog.py`, `test_crash_record.py`, `test_dev_ab.py`, `test_dev_packs.py`, `test_frame_overlap.py`, `test_host_guest_writes.py`, `test_libc_hooks.py`, `test_linux_pressure.py`, `test_mods_list.py`, `test_profiling_mode.py`, `test_slow_frames.py`, `test_vcore_mask0.py`) fail on `main` @ f1f2dc5b too, each run by name in the same queue's jobs. The other three (`test_present_queue_default`, `test_target_reuse_memory`, `test_vk_occlusion_queries`) compiled nothing in that run nor in the run on `main` (no Vulkan headers on the job's path: "not found: vulkan_headers (--strict)"). Rerun with the headers (job fb3-vk-1, `RX_CPM` set) at the head 253596c4 and on `main` @ f1f2dc5b, each fails at both with the same first error: `test_present_queue_default` "srccut: '{TAB_DEBUG, "Present queue", &opts.present_queue, ...' is not in gpu/vk/vk_menu.cpp"; `test_target_reuse_memory` 2 of its 8 tests ("'vmaGetAllocationInfo2' unexpectedly found" in the VMA source, and its fixture's "use of undeclared identifier 'destroy_image_later'"); `test_vk_occlusion_queries` "the ring fixture did not compile" ("no member named 'policy'"). None fails on this branch alone. **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060 (NVIDIA 610.88)): Castle Town's market, 60 s, `main` @ f1f2dc5b, this PR unset and with `HOS_NVN_NO_IDLE_AWAY=1`, warmed and interleaved, two runs each, expecting the log line "nvn: the virtual core is kept across an nvnWindowAcquireTexture with no pacing to sleep for" with it, average fps, 1% lows, median and p99 frame times and the virtual-core waits and escapes compared (by hand) - Linux and Windows with other CPUs (an AMD CPU, 6 or fewer logical processors), and the Steam Deck: Castle Town's market for two minutes with `HOS_NVN_NO_IDLE_AWAY=1` against unset, expecting frame times within the runs' spread or better and no stall (asked of the Test Farm) ## Measurements Not measured in play yet (Still to test): `HOS_NVN_NO_IDLE_AWAY` ships off (kind `attempt`), an experiment nothing measured yet chooses on; only game-free checks have run (Testing). ## Risks Off, the acquire tests a switch read once, and the pacing's sleep runs through two functions instead of one (the same deadline, sleep and count). On, a thread that holds its core keeps it through an acquire with nothing to sleep for: a guest thread waiting for a core waits that much longer. A mistake there would show as a stall or a lower frame rate with the switch on. Turn it off by leaving `HOS_NVN_NO_IDLE_AWAY` unset; a revert is enough. Players notice nothing: the switch is not set for them. ## 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). - [ ] 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 - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [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(nvn): HOS_NVN_NO_IDLE_AWAY=1 keeps the virtual core across NVN calls that do not wait (experiment, off)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 16s
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
8e09b75447
nvnSyncWait gave the virtual core up and took it again around a poll (timeout 0) of a fence the GPU had not reached,
and nvnWindowAcquireTexture around the frame's pacing even when there was nothing to sleep for: each time the core
could go to a waiter and this thread then waited for one. With HOS_NVN_NO_IDLE_AWAY=1 such a poll times out with the
core kept (counted as before), and the acquire leaves the giving up to the pacing's own sleep (hos_sleep_ns). Off by
default; read once, said once in the log.

From d1e33769 (the nvn-recordings integration) on exp/x86-asm-sync, where it was on by default and not measured.

Assisted-by: Claude Code
BeanBot left a comment

Recommendation: Request changes. The experiment can return a false fence timeout and introduces a shared switch cache with a non-atomic read. The scheduling gain still needs an in-game comparison against main.

The switch aims to spare the game thread a virtual-core handoff when a fence poll or texture acquire can finish immediately. The potential gain is less scheduler delay. The current patch also changes fence handling, shifts the timing of paced acquires, and makes pacing diagnostics less accurate.

@fix will do (8)

  1. L1 host/nvn_native.c:1197: The first zero-timeout Vulkan probe can miss a fence that completes before the second probe, including work submitted by the first probe's queue flush. (more on the line)
  2. L2 host/nvn_native.c:1177: A first texture acquire can read v while a fence-poll thread writes it with InterlockedCompareExchange. (more on the line)
  3. L3 (minor) host/nvn_native.c:1194: The new branch also depends on the existing unsynchronized HOS_NVN_SYNC_BLOCK cache. (more on the line)
  4. L4 (minor) host/nvn_native.c:2661: With the switch on, VI computes the remaining sleep before releasing the core. (more on the line)
  5. L5 (minor) host/nvn_native.c:2661: The switch moves hos_vcore_back inside the interval that hos_vi_native_acquire adds to hos_acquire_slept_ns. (more on the line)
  6. L6 host/nvn_native.c:1195: The reported checks would still pass if the optimization were removed or if an enabled paced acquire stopped handing off its core. (more on the line)
  7. L7 (minor) gpu/vk/switches.def:126: The unset text says every nvnSyncWait gives up the core. (more on the line)
  8. L8 (its part an edit can do) host/nvn_native.c:2660: Record handoff counts and reacquisition time separately for each NVN call site in the timing build, so the comparison can tell which path saves time and whether wait time moves to other guest threads.

For the author (2) (a run, a measurement or a decision)

  • L8 (minor) host/nvn_native.c:2660: The planned Market runs allow results within the spread and do not establish a gain or choose a default. (more on the line)
  • L9 (minor): The PR reports a selected Windows source-check run before the rebase. The repository also requires an author-side game run, the full test and lint results, and host builds on both supported platforms. Record those results for the final head, including any failures reproduced on its base. The selected checks alone do not show that the host builds or that either mode works in play.

Checks: Still running: CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request), PR description / Description follows the template (pull_request_target).

More: does it help, other systems, switches, what was read

Does it help: Unproven. The author reports 37 passed, 9 failed, and 3 skipped in Windows game-free checks on e332b851, with all nine failures also reported on 2e1f6c32. There are no in-game results for 8e09b754 against 6e1521a7, or for the switch on versus off.

Other systems: The fence path reaches Vulkan in both threaded and inline replay. Inline per-queue fences and queue batching matter because a zero-timeout call can check recording completion and flush work. The no-GPU fallback returns success at the first probe. Virtual cores are on by default on Windows and Linux, including Steam Deck. With virtual cores disabled, the switch still changes the fence result path. With pacing enabled, it changes where the core is released and which interval the FPS Breakdown, frame traces, and performance summaries count as sleep. No direct save, audio, input, VRAM, or build-path changes were found. Scheduling effects on other guest workers remain unmeasured.

Switches: Adds HOS_NVN_NO_IDLE_AWAY, an off-by-default host A/B switch registered as attempt. Off is the safer setting during development, but the repository requires measurements to choose the shipping default. HOS_NVN_SYNC_BLOCK is unchanged and bypasses the new fence shortcut.

Reviewed: 8e09b75447 against 6e1521a70a: Read AGENTS.md, CONTRIBUTING.md, the Forgejo PR template and developer standards in full. No docs/review-checklist.md was present, and the sibling Tooling checkout was unavailable. Read the complete diff and commit message, both changed NVN functions and their surrounding sync and window code, and the new switch row and its neighbors. Traced the relevant Vulkan replay, VI pacing, scheduler, Linux atomic shim, diagnostics and test code. Skimmed the rest of the switch table and related virtual-core run records. Unrelated portions of nvn_native.c and the dependency files were outside the detailed read. The diff has no generated files or translations. The prior Windows test logs and rebased-away head were unavailable for independent verification.; nothing run (a code review).

Checked and fine:

  • The change covers one topic and the commit carries the required Assisted-by trailer.
  • The new switch uses the existing boolean parser and a sorted HOS_ entry in the switch table.
  • The acquire still returns the same texture index and initializes the acquire sync the same way. A positive pacing sleep still releases and reacquires the core.
  • No new guest-memory ranges, file paths, allocations, CPU requirements, API version changes, generated files, third-party edits, or game-derived artifacts appear in the diff.
  • No scripts, tests or CI workflows were changed. The reported base failures and pending CI checks were not raised as head-only failures.

Testing: Read-only review. No build, test or game run was performed. The author reports Windows source checks, including the switch-table check, on the earlier equivalent patch. The PR supplies no in-game or Linux build result, and CI is still running.

Overlaps and merge order: None found in the available refs. The cited exp/x86-asm-sync commit was unavailable locally, so its overlap and merge order could not be verified.


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 experiment can return a false fence timeout and introduces a shared switch cache with a non-atomic read. The scheduling gain still needs an in-game comparison against main. The switch aims to spare the game thread a virtual-core handoff when a fence poll or texture acquire can finish immediately. The potential gain is less scheduler delay. The current patch also changes fence handling, shifts the timing of paced acquires, and makes pacing diagnostics less accurate. **`@fix` will do (8)** 1. **L1** `host/nvn_native.c:1197`: The first zero-timeout Vulkan probe can miss a fence that completes before the second probe, including work submitted by the first probe's queue flush. (more on the line) 2. **L2** `host/nvn_native.c:1177`: A first texture acquire can read v while a fence-poll thread writes it with InterlockedCompareExchange. (more on the line) 3. **L3** (minor) `host/nvn_native.c:1194`: The new branch also depends on the existing unsynchronized HOS_NVN_SYNC_BLOCK cache. (more on the line) 4. **L4** (minor) `host/nvn_native.c:2661`: With the switch on, VI computes the remaining sleep before releasing the core. (more on the line) 5. **L5** (minor) `host/nvn_native.c:2661`: The switch moves hos_vcore_back inside the interval that hos_vi_native_acquire adds to hos_acquire_slept_ns. (more on the line) 6. **L6** `host/nvn_native.c:1195`: The reported checks would still pass if the optimization were removed or if an enabled paced acquire stopped handing off its core. (more on the line) 7. **L7** (minor) `gpu/vk/switches.def:126`: The unset text says every nvnSyncWait gives up the core. (more on the line) 8. **L8** (its part an edit can do) `host/nvn_native.c:2660`: Record handoff counts and reacquisition time separately for each NVN call site in the timing build, so the comparison can tell which path saves time and whether wait time moves to other guest threads. **For the author (2)** (a run, a measurement or a decision) - **L8** (minor) `host/nvn_native.c:2660`: The planned Market runs allow results within the spread and do not establish a gain or choose a default. (more on the line) - **L9** (minor): The PR reports a selected Windows source-check run before the rebase. The repository also requires an author-side game run, the full test and lint results, and host builds on both supported platforms. Record those results for the final head, including any failures reproduced on its base. The selected checks alone do not show that the host builds or that either mode works in play. **Checks:** Still running: `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`, `PR description / Description follows the template (pull_request_target)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports 37 passed, 9 failed, and 3 skipped in Windows game-free checks on e332b851, with all nine failures also reported on 2e1f6c32. There are no in-game results for 8e09b754 against 6e1521a7, or for the switch on versus off. **Other systems:** The fence path reaches Vulkan in both threaded and inline replay. Inline per-queue fences and queue batching matter because a zero-timeout call can check recording completion and flush work. The no-GPU fallback returns success at the first probe. Virtual cores are on by default on Windows and Linux, including Steam Deck. With virtual cores disabled, the switch still changes the fence result path. With pacing enabled, it changes where the core is released and which interval the FPS Breakdown, frame traces, and performance summaries count as sleep. No direct save, audio, input, VRAM, or build-path changes were found. Scheduling effects on other guest workers remain unmeasured. **Switches:** Adds HOS_NVN_NO_IDLE_AWAY, an off-by-default host A/B switch registered as attempt. Off is the safer setting during development, but the repository requires measurements to choose the shipping default. HOS_NVN_SYNC_BLOCK is unchanged and bypasses the new fence shortcut. **Reviewed:** 8e09b75447cb against 6e1521a70a32: Read AGENTS.md, CONTRIBUTING.md, the Forgejo PR template and developer standards in full. No docs/review-checklist.md was present, and the sibling Tooling checkout was unavailable. Read the complete diff and commit message, both changed NVN functions and their surrounding sync and window code, and the new switch row and its neighbors. Traced the relevant Vulkan replay, VI pacing, scheduler, Linux atomic shim, diagnostics and test code. Skimmed the rest of the switch table and related virtual-core run records. Unrelated portions of nvn_native.c and the dependency files were outside the detailed read. The diff has no generated files or translations. The prior Windows test logs and rebased-away head were unavailable for independent verification.; nothing run (a code review). **Checked and fine:** - The change covers one topic and the commit carries the required Assisted-by trailer. - The new switch uses the existing boolean parser and a sorted HOS_ entry in the switch table. - The acquire still returns the same texture index and initializes the acquire sync the same way. A positive pacing sleep still releases and reacquires the core. - No new guest-memory ranges, file paths, allocations, CPU requirements, API version changes, generated files, third-party edits, or game-derived artifacts appear in the diff. - No scripts, tests or CI workflows were changed. The reported base failures and pending CI checks were not raised as head-only failures. **Testing:** Read-only review. No build, test or game run was performed. The author reports Windows source checks, including the switch-table check, on the earlier equivalent patch. The PR supplies no in-game or Linux build result, and CI is still running. **Overlaps and merge order:** None found in the available refs. The cited exp/x86-asm-sync commit was unavailable locally, so its overlap and merge order could not be verified. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -123,6 +123,7 @@ SW(HOS_NVN_DEVINFO_LOG, diag, bool, "off", "Logs every nvnDeviceGetInteger query
SW(HOS_NVN_HOLD, attempt, bool, "off: command buffers go to the replay at the submit", "Holds submitted command buffers until the queue is flushed, as NVN does.")
SW(HOS_NVN_LOG_OBJECTS, diag, bool, "off", "Logs NVN object creation and setup calls.")
SW(HOS_NVN_LOG_VMAP, diag, string, "off", "Logs virtual pools and the mappings into pools from the given GPU address (hex) up.")
SW(HOS_NVN_NO_IDLE_AWAY, attempt, bool, "off: the virtual core is given up around every nvnSyncWait and nvnWindowAcquireTexture", "=1 keeps it across an nvnSyncWait poll of a fence not reached and an nvnWindowAcquireTexture with no pacing to sleep for (the pacing's sleep still gives it up); read once.")
Member

L7 (minor): The unset text says every nvnSyncWait gives up the core. An unfenced sync or a fence signaled at the first probe returns before the handoff, and HOS_VCORES=0 disables handoffs. Describe the handoff around the second wait and around acquire pacing when virtual cores are active.

**L7** (minor): The unset text says every nvnSyncWait gives up the core. An unfenced sync or a fence signaled at the first probe returns before the handoff, and HOS_VCORES=0 disables handoffs. Describe the handoff around the second wait and around acquire pacing when virtual cores are active.
@ -1178,6 +1192,11 @@ NV(nvnSyncWait) {
if (rx_nvn_wait(s->fence, 0)) { RET(NVN_SYNC_WAIT_RESULT_ALREADY_SIGNALED); return; }
static int block = -1; /* HOS_NVN_SYNC_BLOCK=1 (experiment): a poll waits for the GPU */
if (block < 0) block = env_on("HOS_NVN_SYNC_BLOCK");
Member

L3 (minor): The new branch also depends on the existing unsynchronized HOS_NVN_SYNC_BLOCK cache. Two first-time nvnSyncWait callers on different guest threads can both write block while either reads it. Apply the same thread-safe initialization to this cache while touching the poll policy.

**L3** (minor): The new branch also depends on the existing unsynchronized HOS_NVN_SYNC_BLOCK cache. Two first-time nvnSyncWait callers on different guest threads can both write block while either reads it. Apply the same thread-safe initialization to this cache while touching the poll policy.
@ -1170,0 +1174,4 @@
(vc_acquire: up to a time slice when the holder is as good). Read once, said once in the log */
static int no_idle_away(void) {
static volatile LONG v = -1;
const LONG s = v;
Member

L2: A first texture acquire can read v while a fence-poll thread writes it with InterlockedCompareExchange. Volatile does not synchronize that read, including with the Linux shim's atomic CAS. Both callers can also read the environment before either publishes, and the loser returns its own candidate. Use an atomic cached load and a serialized first-use initialization, or read and publish the setting once during startup before guest threads run.

**L2**: A first texture acquire can read v while a fence-poll thread writes it with InterlockedCompareExchange. Volatile does not synchronize that read, including with the Linux shim's atomic CAS. Both callers can also read the environment before either publishes, and the loser returns its own candidate. Use an atomic cached load and a serialized first-use initialization, or read and publish the setting once during startup before guest threads run.
@ -1178,6 +1192,11 @@ NV(nvnSyncWait) {
if (rx_nvn_wait(s->fence, 0)) { RET(NVN_SYNC_WAIT_RESULT_ALREADY_SIGNALED); return; }
static int block = -1; /* HOS_NVN_SYNC_BLOCK=1 (experiment): a poll waits for the GPU */
if (block < 0) block = env_on("HOS_NVN_SYNC_BLOCK");
if (!block && !U64(1) && no_idle_away()) { /* (a poll: timed out already, the core kept; counted as before) */
Member

L6: The reported checks would still pass if the optimization were removed or if an enabled paced acquire stopped handing off its core. Add a game-free behavioral fixture with controlled fence results, a fake clock and observable core ownership. Cover a fence that completes between probes, a timed or forced-blocking wait, and acquires with and without a sleep, with the switch on and off. Use the configured compiler on Windows and Linux and set or clear the relevant environment variables in each case.

**L6**: The reported checks would still pass if the optimization were removed or if an enabled paced acquire stopped handing off its core. Add a game-free behavioral fixture with controlled fence results, a fake clock and observable core ownership. Cover a fence that completes between probes, a timed or forced-blocking wait, and acquires with and without a sleep, with the switch on and off. Use the configured compiler on Windows and Linux and set or clear the relevant environment variables in each case.
@ -1180,1 +1194,4 @@
if (block < 0) block = env_on("HOS_NVN_SYNC_BLOCK");
if (!block && !U64(1) && no_idle_away()) { /* (a poll: timed out already, the core kept; counted as before) */
wait_note(1, hos_now_ns());
RET(NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED);
Member

L1: The first zero-timeout Vulkan probe can miss a fence that completes before the second probe, including work submitted by the first probe's queue flush. The existing path can then return CONDITION_SATISFIED. The new path unconditionally returns TIMEOUT_EXPIRED, so the caller can defer work or poll again for an already-complete fence. Preserve the second probe and its result. The current renderer entry point can also take locks and flush submits at timeout zero, so keep the handoff on that path unless the renderer provides an explicitly nonblocking probe with an equivalent fallback.

**L1**: The first zero-timeout Vulkan probe can miss a fence that completes before the second probe, including work submitted by the first probe's queue flush. The existing path can then return CONDITION_SATISFIED. The new path unconditionally returns TIMEOUT_EXPIRED, so the caller can defer work or poll again for an already-complete fence. Preserve the second probe and its result. The current renderer entry point can also take locks and flush submits at timeout zero, so keep the handoff on that path unless the renderer provides an explicitly nonblocking probe with an equivalent fallback.
@ -2641,3 +2660,1 @@
const int away = hos_vcore_away();
hos_vi_native_acquire(o->active ? o->active : o->ntex);
if (away) hos_vcore_back();
if (no_idle_away()) { /* (the pacing's sleep gives the core up when there is something to sleep for) */
Member

L8 (minor): The planned Market runs allow results within the spread and do not establish a gain or choose a default. Compare the merge base with the final head both on and off, using at least two warmed, interleaved runs per variant at matched settings in the Market and a heavy scene. Report average FPS, 1% lows, median and p99 frame times, and virtual-core wait tails and escapes. Cover Tier 1 NVIDIA and AMD on Windows and Linux and Steam Deck, including a low-core setup where keeping a core can delay a queued worker. Check displayed pacing as well as game frame times.

**L8** (minor): The planned Market runs allow results within the spread and do not establish a gain or choose a default. Compare the merge base with the final head both on and off, using at least two warmed, interleaved runs per variant at matched settings in the Market and a heavy scene. Report average FPS, 1% lows, median and p99 frame times, and virtual-core wait tails and escapes. Cover Tier 1 NVIDIA and AMD on Windows and Linux and Steam Deck, including a low-core setup where keeping a core can delay a queued worker. Check displayed pacing as well as game frame times.
@ -2642,2 +2660,2 @@
hos_vi_native_acquire(o->active ? o->active : o->ntex);
if (away) hos_vcore_back();
if (no_idle_away()) { /* (the pacing's sleep gives the core up when there is something to sleep for) */
hos_vi_native_acquire(o->active ? o->active : o->ntex);
Member

L4 (minor): With the switch on, VI computes the remaining sleep before releasing the core. If the release waits for the scheduler lock, hos_sleep_ns still waits the original duration after that delay, even if the pacing deadline has passed. Keep the absolute deadline and recompute the remaining time after the handoff before sleeping.

**L4** (minor): With the switch on, VI computes the remaining sleep before releasing the core. If the release waits for the scheduler lock, hos_sleep_ns still waits the original duration after that delay, even if the pacing deadline has passed. Keep the absolute deadline and recompute the remaining time after the handoff before sleeping.
Member

L5 (minor): The switch moves hos_vcore_back inside the interval that hos_vi_native_acquire adds to hos_acquire_slept_ns. If another guest thread takes the core during a paced acquire, the FPS Breakdown and performance summaries now charge the reacquisition delay to pacing. End the sleep measurement before reacquiring the core and keep the scheduler delay in the virtual-core counters.

**L5** (minor): The switch moves hos_vcore_back inside the interval that hos_vi_native_acquire adds to hos_acquire_slept_ns. If another guest thread takes the core during a paced acquire, the FPS Breakdown and performance summaries now charge the reacquisition delay to pacing. End the sleep measurement before reacquiring the core and keep the scheduler delay in the virtual-core counters.
futondestroyer left a comment

Recommendation: Request changes. Keep virtual-core recovery for an escaped guest at both NVN call sites. Leave the experiment in WIP until the fence behavior and switch initialization are corrected and the revised head has gameplay evidence.

New blocker at host/nvn_native.c:2660 and :1195. After a scheduler escape, a guest runs with vc_escaped set and no core. On main, a missed zero-timeout fence poll or an unpaced texture acquire still calls hos_vcore_away(), which clears the escape and returns 1 so that hos_vcore_back() tries to take a core. With the switch enabled, both early paths bypass that retry. If a permitted core has become free, the escaped thread can repeatedly return to guest code without taking it. The scheduler's vc_yield returns immediately when the caller holds no core, and the guest core query can report the ideal core held by another thread. Preserve the recovery path when the thread has escaped, including nested-call behavior, and extend the existing escape fixture to exercise both call sites with a free core. Original escape recovery fix

Existing findings independently confirmed. BeanBot's standing review covers the removed second fence probe, the non-atomic switch cache load, the inherited HOS_NVN_SYNC_BLOCK cache, and the changed pacing deadline and accounting. The no-GPU backend succeeds on the first probe. The Vulkan entry point can flush queued submits or take locks even at timeout zero. If a fence completes between probes, main can return CONDITION_SATISFIED; the enabled shortcut returns TIMEOUT_EXPIRED. Keep the second probe and its result, and retain the handoff for any path that can block. Initialize the switch with synchronized access. On a paced acquire, account for the time spent waiting to reacquire a core separately from the pacing sleep and preserve the original deadline. Standing request for changes

Does it help? Unproven. The author reports 37 passes, 9 failures and 3 skips in selected Windows game-free checks on e332b851, with the nine failures also reported on 2e1f6c32. The author reports the patch was unchanged across its rebase. The selected checks do not cover this behavior. The captured exact-head Forgejo status has one successful description check, nine pending checks marked blocked by required conditions and one skipped website job. The PR has no gameplay result against 6e1521a7, no measured gain with the experiment enabled, and no Linux build or game result in the evidence reviewed.

Switch and affected systems. HOS_NVN_NO_IDLE_AWAY is an off-by-default attempt registered in the sorted switch table. Supplying it can change fence results even with virtual cores disabled. The positive pacing sleep still hands off a core through sleep_away, and the texture index and acquire-sync initialization retain their existing behavior. The full behavior applies on Windows and Linux, including Steam Deck. Choose the shipping default with matched gameplay evidence. Build paths, renderer interface, generated files and third-party code are outside the diff.

Related work. Virtual-core fast acquire/release and its stacked owner-slot layout change the cost of the handoff this experiment tries to skip. Serial reacquisition changes how long the same caller can wait for a core. Review each independently against main and remeasure this experiment if that scheduler policy changes first. The cited exp/x86-asm-sync commit d1e33769 was unavailable in the fetched history. Fast acquire/release, owner-slot layout, serial reacquisition

Reviewed. Source-only read of exact head 8e09b75447cb8e7ee1fd3b75bcbeafdef357152a against merge base 6e1521a70a32603ed60a8263e4072625885669b7. Both changed files and the complete diff, guest NVN dispatch, the Vulkan wait table and flush/recording paths, VI pacing and sleep, virtual-core scheduler and the escape fixture were checked in source. Revision-matched local Graphify maps validated at both commits. Their provenance and extraction logs document partial parses and indirect-call limits, so the dispatch and ownership were confirmed directly. Guidance was Longshot 6e1521a7 and Tooling 0b0059ac. No build, test, or game run was performed for this review.

**Recommendation: Request changes.** Keep virtual-core recovery for an escaped guest at both NVN call sites. Leave the experiment in WIP until the fence behavior and switch initialization are corrected and the revised head has gameplay evidence. **New blocker at `host/nvn_native.c:2660` and `:1195`.** After a scheduler escape, a guest runs with `vc_escaped` set and no core. On main, a missed zero-timeout fence poll or an unpaced texture acquire still calls `hos_vcore_away()`, which clears the escape and returns 1 so that `hos_vcore_back()` tries to take a core. With the switch enabled, both early paths bypass that retry. If a permitted core has become free, the escaped thread can repeatedly return to guest code without taking it. The scheduler's `vc_yield` returns immediately when the caller holds no core, and the guest core query can report the ideal core held by another thread. Preserve the recovery path when the thread has escaped, including nested-call behavior, and extend the existing escape fixture to exercise both call sites with a free core. [Original escape recovery fix](https://git.magicbean.dev/MagicBeanDev/Hookshot/pulls/2302) **Existing findings independently confirmed.** BeanBot's standing review covers the removed second fence probe, the non-atomic switch cache load, the inherited `HOS_NVN_SYNC_BLOCK` cache, and the changed pacing deadline and accounting. The no-GPU backend succeeds on the first probe. The Vulkan entry point can flush queued submits or take locks even at timeout zero. If a fence completes between probes, main can return `CONDITION_SATISFIED`; the enabled shortcut returns `TIMEOUT_EXPIRED`. Keep the second probe and its result, and retain the handoff for any path that can block. Initialize the switch with synchronized access. On a paced acquire, account for the time spent waiting to reacquire a core separately from the pacing sleep and preserve the original deadline. [Standing request for changes](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62327) **Does it help? Unproven.** The author reports 37 passes, 9 failures and 3 skips in selected Windows game-free checks on `e332b851`, with the nine failures also reported on `2e1f6c32`. The author reports the patch was unchanged across its rebase. The selected checks do not cover this behavior. The captured exact-head Forgejo status has one successful description check, nine pending checks marked blocked by required conditions and one skipped website job. The PR has no gameplay result against `6e1521a7`, no measured gain with the experiment enabled, and no Linux build or game result in the evidence reviewed. **Switch and affected systems.** `HOS_NVN_NO_IDLE_AWAY` is an off-by-default `attempt` registered in the sorted switch table. Supplying it can change fence results even with virtual cores disabled. The positive pacing sleep still hands off a core through `sleep_away`, and the texture index and acquire-sync initialization retain their existing behavior. The full behavior applies on Windows and Linux, including Steam Deck. Choose the shipping default with matched gameplay evidence. Build paths, renderer interface, generated files and third-party code are outside the diff. **Related work.** Virtual-core fast acquire/release and its stacked owner-slot layout change the cost of the handoff this experiment tries to skip. Serial reacquisition changes how long the same caller can wait for a core. Review each independently against main and remeasure this experiment if that scheduler policy changes first. The cited `exp/x86-asm-sync` commit `d1e33769` was unavailable in the fetched history. [Fast acquire/release](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1972), [owner-slot layout](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1973), [serial reacquisition](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1974) **Reviewed.** Source-only read of exact head `8e09b75447cb8e7ee1fd3b75bcbeafdef357152a` against merge base `6e1521a70a32603ed60a8263e4072625885669b7`. Both changed files and the complete diff, guest NVN dispatch, the Vulkan wait table and flush/recording paths, VI pacing and sleep, virtual-core scheduler and the escape fixture were checked in source. Revision-matched local Graphify maps validated at both commits. Their provenance and extraction logs document partial parses and indirect-call limits, so the dispatch and ownership were confirmed directly. Guidance was Longshot `6e1521a7` and Tooling `0b0059ac`. No build, test, or game run was performed for this review.
@ -2641,3 +2660,1 @@
const int away = hos_vcore_away();
hos_vi_native_acquire(o->active ? o->active : o->ntex);
if (away) hos_vcore_back();
if (no_idle_away()) { /* (the pacing's sleep gives the core up when there is something to sleep for) */
Member

An escaped guest has no core to keep. On main, both this unpaced acquire and a missed zero-timeout fence poll use hos_vcore_away() to consume vc_escaped, then use hos_vcore_back() to take a now-free core. The enabled paths here and at line 1195 skip that retry. An escaped thread can keep returning to guest code without a core even after one becomes free, and its ideal core number can belong to another thread. Preserve escape recovery on both paths and add the no-sleep and missed-poll cases to the virtual-core escape fixture.

An escaped guest has no core to keep. On main, both this unpaced acquire and a missed zero-timeout fence poll use hos_vcore_away() to consume vc_escaped, then use hos_vcore_back() to take a now-free core. The enabled paths here and at line 1195 skip that retry. An escaped thread can keep returning to guest code without a core even after one becomes free, and its ideal core number can belong to another thread. Preserve escape recovery on both paths and add the no-sleep and missed-poll cases to the virtual-core escape fixture.
siantm force-pushed perf/nvn-keep-core from 8e09b75447
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 16s
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
to 253596c484
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_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 25s
2026-11-21 04:50:17 +00:00
Compare
siantm changed title from WIP: perf(nvn): HOS_NVN_NO_IDLE_AWAY=1 keeps the virtual core across NVN calls that do not wait (experiment, off) to WIP: perf(nvn): HOS_NVN_NO_IDLE_AWAY=1 keeps the virtual core through an nvnWindowAcquireTexture with no pacing to sleep for (experiment, off) 2026-11-21 04:50:49 +00:00
Author
Contributor

Pushed 253596c4 (rebased onto main @ f1f2dc5b; the PR's commit unchanged). After review 62903 the fence part is dropped (nvnSyncWait as on main: second probe, its result, the handoff), so the title now names only the no-sleep nvnWindowAcquireTexture; an escaped thread keeps its recovery; a paced acquire keeps its deadline and counts only its sleep as pacing; the switch is read through an atomic; tests/test_vcore_escape.py runs both call sites. Summary, Testing, Measurements and Risks follow.

Pushed 253596c4 (rebased onto `main` @ f1f2dc5b; the PR's commit unchanged). After review 62903 the fence part is dropped (`nvnSyncWait` as on `main`: second probe, its result, the handoff), so the title now names only the no-sleep `nvnWindowAcquireTexture`; an escaped thread keeps its recovery; a paced acquire keeps its deadline and counts only its sleep as pacing; the switch is read through an atomic; `tests/test_vcore_escape.py` runs both call sites. Summary, Testing, Measurements and Risks follow.
Author
Contributor

@futondestroyer, on your review and inline, head 253596c4 (rebased onto main @ f1f2dc5b; the PR's own commit unchanged, git range-diff "="):

  • Escape recovery at :2660 and :1195 (inline 62902): fixed in 253596c4. The acquire keeps the core only while the thread holds one (hos_vcore_held); an escaped thread, or one inside an outer block, goes main's way, so hos_vcore_away ends the escape and hos_vcore_back takes a free core, and only the outermost block takes one. tests/test_vcore_escape.py (392604c3) now cuts the real nvnSyncWait, nvnWindowAcquireTexture, nn_vi.c's pacing and sleep_away and runs them on the escape fixture with the switch unset, 0, off, 1 and yes: an escaped thread's no-sleep acquire and its missed zero-timeout poll each take the free core after the call, and inside an outer block neither does. At 392604c3, without the fix, =1 fails both escape cases; unset, 0 and off pass.
  • Second fence probe and the handoff: the fence part of the experiment is dropped: with the second probe, its result and the handoff around it kept as on main (its Vulkan entry can flush and take locks at timeout 0), nothing of it was left, so nvnSyncWait is unchanged and the switch now covers only the no-sleep nvnWindowAcquireTexture (title and description changed to say so; the commit history still shows the dropped part). The fixture checks a fence reached between the probes answers CONDITION_SATISFIED and a missed poll hands the core off.
  • Switch initialization: read once through an atomic (compare-exchange from -1), said once; the fixture flips the variable after the first pass and expects nothing to change. HOS_NVN_SYNC_BLOCK's cache is no longer touched by this PR and stays as on main.
  • Paced acquire accounting and deadline: hos_vi_native_acquire is split into hos_vi_native_until (the deadline) and hos_vi_native_sleep_until (the time left taken after the handoff, the sleep counted); the acquire gives the core up around the latter, so the deadline holds and the wait to take a core again stays out of hos_acquire_slept_ns, in the virtual-core counters. The fixture holds the core with a rival for 3 ms after a 5 ms pacing sleep and checks 5 ms counted. At 392604c3 with =1 it fails (the wait for the core counted as pacing); at the head it passes for every value.
  • Gameplay evidence: pending, asked of the game runs on this PC; the PR stays WIP.

Checks: tests/test_vcore_escape.py, test_fps_stats.py, test_pacing_policy.py pass; run_all.py --strict --changed origin/main: 85 passed, 15 failed, 5 skipped, all 15 failing on main @ f1f2dc5b too. (test_vcore_escape.py itself does not build on main: its fixture declared hos_fps_timing twice; fixed here.)

@futondestroyer, on your [review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62903) and [inline](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62902), head 253596c4 (rebased onto `main` @ f1f2dc5b; the PR's own commit unchanged, `git range-diff` "="): - **Escape recovery at :2660 and :1195** (inline 62902): fixed in 253596c4. The acquire keeps the core only while the thread holds one (`hos_vcore_held`); an escaped thread, or one inside an outer block, goes `main`'s way, so `hos_vcore_away` ends the escape and `hos_vcore_back` takes a free core, and only the outermost block takes one. `tests/test_vcore_escape.py` (392604c3) now cuts the real `nvnSyncWait`, `nvnWindowAcquireTexture`, nn_vi.c's pacing and `sleep_away` and runs them on the escape fixture with the switch unset, `0`, `off`, `1` and `yes`: an escaped thread's no-sleep acquire and its missed zero-timeout poll each take the free core after the call, and inside an outer block neither does. At 392604c3, without the fix, `=1` fails both escape cases; unset, `0` and `off` pass. - **Second fence probe and the handoff**: the fence part of the experiment is dropped: with the second probe, its result and the handoff around it kept as on `main` (its Vulkan entry can flush and take locks at timeout 0), nothing of it was left, so `nvnSyncWait` is unchanged and the switch now covers only the no-sleep `nvnWindowAcquireTexture` (title and description changed to say so; the commit history still shows the dropped part). The fixture checks a fence reached between the probes answers `CONDITION_SATISFIED` and a missed poll hands the core off. - **Switch initialization**: read once through an atomic (compare-exchange from -1), said once; the fixture flips the variable after the first pass and expects nothing to change. `HOS_NVN_SYNC_BLOCK`'s cache is no longer touched by this PR and stays as on `main`. - **Paced acquire accounting and deadline**: `hos_vi_native_acquire` is split into `hos_vi_native_until` (the deadline) and `hos_vi_native_sleep_until` (the time left taken after the handoff, the sleep counted); the acquire gives the core up around the latter, so the deadline holds and the wait to take a core again stays out of `hos_acquire_slept_ns`, in the virtual-core counters. The fixture holds the core with a rival for 3 ms after a 5 ms pacing sleep and checks 5 ms counted. At 392604c3 with `=1` it fails (the wait for the core counted as pacing); at the head it passes for every value. - **Gameplay evidence**: pending, asked of the game runs on this PC; the PR stays WIP. Checks: `tests/test_vcore_escape.py`, `test_fps_stats.py`, `test_pacing_policy.py` pass; `run_all.py --strict --changed origin/main`: 85 passed, 15 failed, 5 skipped, all 15 failing on `main` @ f1f2dc5b too. (`test_vcore_escape.py` itself does not build on `main`: its fixture declared `hos_fps_timing` twice; fixed here.)
Author
Contributor

BeanBot's review, head 253596c4:

  • L1 (62319): the fence shortcut is gone; nvnSyncWait is as on main (second probe, its result, the handoff).
  • L2 (62320): the switch is read through an atomic load and a compare-exchange; a loser returns the same value.
  • L3 (62321): with the fence part dropped this PR no longer touches HOS_NVN_SYNC_BLOCK; its lazy cache is as on main, left for a separate change.
  • L4 (62322), L5 (62323): deadline kept, the time left taken after the handoff, the wait for a core outside the pacing's count (hos_vi_native_until / hos_vi_native_sleep_until).
  • L6 (62324): tests/test_vcore_escape.py runs the real call sites with a fake clock and core ownership, the switch unset/0/off/1/yes in fresh processes and flipped after the first read; it fails with the switch on at the test commit.
  • L7 (62325): the row says what unset does (virtual cores on, the acquire around the pacing) and what =1 changes.
  • L8 (62326): per-site counters not added; the A/B (main, head unset, head on, warmed and interleaved) is in Still to test, pending game runs.
  • L9: game run, full suite and Linux build: not run here; pending.
BeanBot's [review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62327), head 253596c4: - L1 ([62319](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62319)): the fence shortcut is gone; `nvnSyncWait` is as on `main` (second probe, its result, the handoff). - L2 ([62320](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62320)): the switch is read through an atomic load and a compare-exchange; a loser returns the same value. - L3 ([62321](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62321)): with the fence part dropped this PR no longer touches `HOS_NVN_SYNC_BLOCK`; its lazy cache is as on `main`, left for a separate change. - L4 ([62322](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62322)), L5 ([62323](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62323)): deadline kept, the time left taken after the handoff, the wait for a core outside the pacing's count (`hos_vi_native_until` / `hos_vi_native_sleep_until`). - L6 ([62324](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62324)): `tests/test_vcore_escape.py` runs the real call sites with a fake clock and core ownership, the switch unset/0/off/1/yes in fresh processes and flipped after the first read; it fails with the switch on at the test commit. - L7 ([62325](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62325)): the row says what unset does (virtual cores on, the acquire around the pacing) and what `=1` changes. - L8 ([62326](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1968#issuecomment-62326)): per-site counters not added; the A/B (main, head unset, head on, warmed and interleaved) is in Still to test, pending game runs. - L9: game run, full suite and Linux build: not run here; pending.
Author
Contributor

@Beanstalk This adds a switch, HOS_NVN_NO_IDLE_AWAY, off by default: with HOS_NVN_NO_IDLE_AWAY=1 the frame pacing wait in nvnWindowAcquireTexture changes how it holds the thread's virtual core (host/nvn_native.c, host/nn_vi.c); unset, the pacing wait behaves as on main. It has not run in the game yet. Please play Castle Town Market for two minutes, the PR against main on the same PC, on the PR's side with HOS_NVN_NO_IDLE_AWAY=1 and with it unset, 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 stall, hang or crash; set, frame time p99 equal to unset or better, within the run-to-run spread; unset, frame times as main's.

@Beanstalk This adds a switch, HOS_NVN_NO_IDLE_AWAY, off by default: with HOS_NVN_NO_IDLE_AWAY=1 the frame pacing wait in nvnWindowAcquireTexture changes how it holds the thread's virtual core (host/nvn_native.c, host/nn_vi.c); unset, the pacing wait behaves as on main. It has not run in the game yet. Please play Castle Town Market for two minutes, the PR against main on the same PC, on the PR's side with HOS_NVN_NO_IDLE_AWAY=1 and with it unset, 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 stall, hang or crash; set, frame time p99 equal to unset or better, within the run-to-run spread; unset, frame times as main's.
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.
Author
Contributor

The three renderer checks (test_present_queue_default, test_target_reuse_memory, test_vk_occlusion_queries) did not compile in the earlier run (no Vulkan headers on that job's path); rerun with them in job fb3-vk-1, at the head 253596c4 and on main @ f1f2dc5b: all three fail at both with the same first error, so they fail on main too; Tested's sentence and counts corrected.

The three renderer checks (`test_present_queue_default`, `test_target_reuse_memory`, `test_vk_occlusion_queries`) did not compile in the earlier run (no Vulkan headers on that job's path); rerun with them in job fb3-vk-1, at the head 253596c4 and on `main` @ f1f2dc5b: all three fail at both with the same first error, so they fail on `main` too; Tested's sentence and counts corrected.
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_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 25s
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/nvn-keep-core:siantm-perf/nvn-keep-core'
git switch 'siantm-perf/nvn-keep-core'
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!1968
No description provided.