perf(host): the game's job barriers wait for their mask words instead of sleeping 20 us (HOS_OOT_BARRIER_WAIT) #1662

Merged
HumanBean merged 1 commit from GummiNaomi/Longshot:perf/oot-barrier-wait into main 2026-11-18 22:05:59 +00:00
Member

Type: perf · Risk: medium · Tested on: Windows 11, RTX 4070 SUPER, Ryzen 9 9950X3D (SMT off) · Needs: a build of this head; a Steam Deck or another CPU of 4 cores; Linux

Stacked on #1661 (the in-run A/B tool): its commits come first; this PR is the last commit.

TL;DR

Three of the game's parallel jobs make their threads wait for each other by sleeping 20 microseconds and looking again. On Windows with few cores such a short sleep wakes about half a millisecond late, and the game's main thread spends a large part of each frame in it. This PR makes those threads wait until the job's progress word actually changes, woken by the thread that changes it. Standing in Castle Town's market with the game on 4 cores, frames were 3.2 % shorter in both of two in-run A/Bs, and a third fewer frames missed 60 fps; on 16 cores no difference.

Breakdown

  • Who it helps: players on CPUs of 4 to 6 cores, where every processor is busy: likely the Steam Deck too (not measured there).
  • What was wrong: the game's job barriers sleep 20 us and look again; on Windows a sleep that short wakes about 0.5 ms late with few logical processors.
  • What changes: a thread at one of those barriers waits on the barrier's mask word (its virtual core given up, as for the sleep) and is woken right after the OR that moves it, at most 1 ms, then looks again as after its sleep.
  • What does not change: what the jobs do and in what order; the other sleeps of the game; 16-core PCs (no difference measured); saves, options, caches.
  • How it was checked: in-run A/Bs on 4 and 16 cores, two runs each; a game-free test of the wait, the wakes and the patch with 17 broken variants, on Windows and Linux.
  • What is still open: a build of this head (the patch's three places checked on the older tree's lift), a Steam Deck, Linux in the game.
  • Risk: medium: the patch edits three of the game's job functions; a function where it finds its text differently keeps the game's sleeps.

Why

OoT runs three of its parallel-for jobs (f_800998a0, the drawing-command job; f_800738e0; f_8007e200) on several threads over one job block, each thread taking items by atomic ORs into bitmasks. A thread with nothing left to take sleeps 20 microseconds (nn::os::SleepThread) and looks again, until the masks it polls are full. On Windows a sleep that short wakes about half a millisecond late when there are few logical processors, and the main thread is one of the waiters: on 4 cores in Castle Town's market it was asleep there in 11.4 % of its profile's samples, about 2 ms a frame. Waiting for the word itself to change, and being woken by the OR that changes it, ends the wait when the work is done instead of on the next timer tick.

What changed

The lift's patch routes those three functions' barrier sleeps and their ORs through the host. A sleeping thread waits on the polled mask word until it moves (WaitOnAddress on Windows, a futex through host/posix on Linux) with a 1 ms limit, and an OR into a mask wakes its waiters. After the wait the thread looks again exactly as after its sleep, so a missed wake costs at most the old sleep's time.

  • host: host/oot_barrier.h, host/oot_barrier.c (new): the wait and the wake, the switch (on unless HOS_OOT_BARRIER_WAIT=0), WaitOnAddress looked up at the start (without it, the sleeps as before and a log line), and a barrier: log line every 16,384 looks (found moved already, waited, timed out, the average wait, the wakes). The switch is read through hos_ab_value, so HOS_AB may flip it between two looks.
  • lift: nx2/oot_patches.py patch_barrier_wait: in each of the three functions, the OR into the mask gets the wake after it and the sleep gets the wait in front of it; a function is hooked whole or not at all (a warning names a function it could not hook, which keeps the game's sleeps). The places accept the page-mark lines a finished lift puts between lines and a loop's back edge with or without its poll; the three functions keep their registers in the context (their addresses are named in the file).
  • docs: the HOS_OOT_BARRIER_WAIT=0 row in docs/development.md and gpu/vk/switches.def.
  • tests: tests/test_oot_barrier.py (new): the real oot_barrier.c and header over stand-in waits: threads that wait and are woken, no lost wake-up, the 1 ms limit, the switch's values (on for unset, 1 and yes; off for 0 and off); the patch on a small lifted text run through the lift's real poll and page-mark passes (hooked whole, the same text twice, before or after the polls, over a finished lift), touches() and mentioned_addresses() for the three functions; 9 broken variants of the code and 8 of the patch, each caught; on Windows (clang) and Linux (gcc 13). tests/test_hos_ab.py's list of wired switches gains HOS_OOT_BARRIER_WAIT.

Measurements

Verdict: faster on 4 cores: frame time -3.2 % in both runs (95 % intervals -5.1 to -1.9 % and -4.2 to -2.4 %), frames of 16.7 ms or more down 10 to 11 points (30 to 19 %, 26 to 16 %); on 16 cores no difference (intervals around 0).

Hardware: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB
Scene: Castle Town's market (child), standing after a debug teleport from the kokiri-start save; output 2560x1440, uncapped (HOS_FPS_MAX=1000), no window (HOS_HEADLESS=1). "4 cores": the game kept to cores 8-11 (affinity 0xF00, HOS_CACHE_CORES=0); "16 cores": no affinity, the game on the 8 cores of the 96 MB L3 by default
Method: in-run A/Bs (HOS_AB=HOS_OOT_BARRIER_WAIT=<value>,3,130: 3 s periods after 130 s), about 160 s standing, RX_VK_FRAME_TRACE=1; scripts/ab_summary.py on each trace (transitions left out, a bootstrap of whole periods for the interval); two runs each
How to reproduce: on this PR HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,130 (side 1 is the old way); the runs also had RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0 HOS_THREAD_TIMES=5

Baseline: both sides of each run come from one build, main @ 54a42715 (93 commits before this PR's base) with the 18 Nov changes, the switch flipping every 3 s within the run. On 4 cores that build's default was the old sleeps and side 1 this PR's wait; on 16 cores (a later build of the same tree) the default was the wait and side 1 the old sleeps.

Before (the 20 us sleeps, main's way): build @ 54a42715 After (the wait on the mask, this PR's way): the same runs @ 54a42715 Δ (95 % interval)
4 cores, run a: mean frame 16.073 ms 15.561 ms -0.513 ms (-0.821 to -0.303)
4 cores, run b: mean frame 15.911 ms 15.401 ms -0.510 ms (-0.664 to -0.377)
4 cores, frames >= 16.7 ms (a / b) 30.2 / 26.4 % 19.3 / 16.1 % -10.9 / -10.3 points
16 cores, run a: mean frame 13.992 ms 13.948 ms -0.044 ms (-0.154 to +0.052)
16 cores, run b: mean frame 13.723 ms 13.715 ms -0.008 ms (-0.132 to +0.104)
4 cores, run a: ab: HOS_OOT_BARRIER_WAIT=1 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 2626 frames, 16.114 ms a frame (62.1 fps); side 1 (the A/B's value) 2603 frames, 15.559 ms a frame (64.3 fps); side 1 -3.44 % frame time; 598 frames in transitions left out
  side 1 - side 0: mean -0.513 ms (-3.19 %, fps +3.29 %), median -0.520 ms, p99 -1.039 ms, >=16.7 ms -10.9 points
  95 % interval of the mean's difference: -0.821 to -0.303 ms (-5.11 to -1.88 %): side 1 is faster
4 cores, run b: ab: HOS_OOT_BARRIER_WAIT=1 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 1973 frames, 15.972 ms a frame (62.6 fps); side 1 (the A/B's value) 1929 frames, 15.398 ms a frame (64.9 fps); side 1 -3.59 % frame time; 442 frames in transitions left out
  side 1 - side 0: mean -0.510 ms (-3.21 %, fps +3.31 %), median -0.570 ms, p99 -0.959 ms, >=16.7 ms -10.3 points
  95 % interval of the mean's difference: -0.664 to -0.377 ms (-4.17 to -2.37 %): side 1 is faster
16 cores, run a: ab: HOS_OOT_BARRIER_WAIT=0 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 2323 frames, 13.946 ms a frame (71.7 fps); side 1 (the A/B's value) 2305 frames, 14.006 ms a frame (71.4 fps); side 1 +0.43 % frame time; 511 frames in transitions left out
  95 % interval of the mean's difference: -0.052 to +0.154 ms (-0.38 to +1.10 %): no difference shown (the interval holds 0)
16 cores, run b: ab: HOS_OOT_BARRIER_WAIT=0 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 3148 frames, 13.716 ms a frame (72.9 fps); side 1 (the A/B's value) 3125 frames, 13.733 ms a frame (72.8 fps); side 1 +0.13 % frame time; 703 frames in transitions left out
  95 % interval of the mean's difference: -0.104 to +0.132 ms (-0.76 to +0.97 %): no difference shown (the interval holds 0)
[hos ModuleSystemWorker5] barrier: 17907 looks: 1523 found the masks moved already, 16384 waited until they moved, 0 for the whole 1 ms (a wait 40 us on average); 22332 wakes

(The 4-core runs' A/B value was HOS_OOT_BARRIER_WAIT=1 because that build's switch had the old sleeps as its default; the 16-core runs' was =0. Side 1 is the A/B's value in each.)

Flags and settings

One switch added; the new behaviour is the default.

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
HOS_OOT_BARRIER_WAIT three job barriers wait on their mask word (no switch: 20 us sleeps) unset: the wait =0 brings the sleeps back helps on 4 cores (-3.2 %), no difference on 16; untested on SMT CPUs, the Deck, Linux in the game on for everyone (unset)

Testing

Tested: in the game, at 93 commits behind this base: the A/Bs above, on 4 and 16 cores, every run to its end with 0 errors, the market drawn in its screenshots, the barrier: lines counting waits and no 1 ms time-outs. On this head: tests/test_oot_barrier.py passes on Windows (clang) and on Linux (gcc 13, WSL Ubuntu 24.04); tests/test_hos_ab.py and tests/test_patch_hooks_defined.py pass; of the 54 checks that read the changed files, the 22 that fail on this PC failed the same way on the base (run before the rebase onto main's last 11 commits; after it, the tests above pass again).

Not tested: a build of this exact head: no lift of main exists on my PC, so the patch's places were read from the older tree's lift; the lift's oot_patches: WARNING: the job barriers were found in N of 3 functions would show a function main's lift writes differently (that function then keeps the game's sleeps). Linux in the game (the futex path is compiled and run by the test).

Must be tested:

  • Windows, any GPU: build this head, expecting no barrier warning in the lift's log and the run's barrier: lines; then HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,60 with the game on 4 cores in the market, expecting side 1 (the old sleeps) slower (by hand: me)
  • steamdeck: the same A/B in the market at handheld settings, expecting side 1 no faster (Test Farm: @Beanstalk steamdeck, stand in Castle Town's market 3 minutes with HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,60 and RX_VK_FRAME_TRACE=1, then scripts/ab_summary.py)
  • linux, a desktop: the same A/B, expecting side 1 no faster and no hang (Test Farm: @Beanstalk linux, the same A/B)

Risks

What could break: a missed wake would make a barrier wait its 1 ms limit (the barrier: line counts those: 0 in the runs above) and then look again as before, so the cost is bounded by the limit; a function whose text the patch doesn't find keeps the game's sleeps (with a warning). The job functions themselves are edited only at their sleeps and ORs.

Turning it off: HOS_OOT_BARRIER_WAIT=0.

Compatibility: the lifted code changes (three functions keep their registers in the context), so the game is translated again; saves, options and caches otherwise as before.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. (In the game 93 commits back; this head not built yet.)
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named). (The changed files' checks on this PC; failures are the base's own here.)
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.

🤖 Generated with Claude Code

**Type:** perf · **Risk:** medium · **Tested on:** Windows 11, RTX 4070 SUPER, Ryzen 9 9950X3D (SMT off) · **Needs:** a build of this head; a Steam Deck or another CPU of 4 cores; Linux Stacked on #1661 (the in-run A/B tool): its commits come first; this PR is the last commit. ## TL;DR Three of the game's parallel jobs make their threads wait for each other by sleeping 20 microseconds and looking again. On Windows with few cores such a short sleep wakes about half a millisecond late, and the game's main thread spends a large part of each frame in it. This PR makes those threads wait until the job's progress word actually changes, woken by the thread that changes it. Standing in Castle Town's market with the game on 4 cores, frames were 3.2 % shorter in both of two in-run A/Bs, and a third fewer frames missed 60 fps; on 16 cores no difference. ## Breakdown - **Who it helps:** players on CPUs of 4 to 6 cores, where every processor is busy: likely the Steam Deck too (not measured there). - **What was wrong:** the game's job barriers sleep 20 us and look again; on Windows a sleep that short wakes about 0.5 ms late with few logical processors. - **What changes:** a thread at one of those barriers waits on the barrier's mask word (its virtual core given up, as for the sleep) and is woken right after the OR that moves it, at most 1 ms, then looks again as after its sleep. - **What does not change:** what the jobs do and in what order; the other sleeps of the game; 16-core PCs (no difference measured); saves, options, caches. - **How it was checked:** in-run A/Bs on 4 and 16 cores, two runs each; a game-free test of the wait, the wakes and the patch with 17 broken variants, on Windows and Linux. - **What is still open:** a build of this head (the patch's three places checked on the older tree's lift), a Steam Deck, Linux in the game. - **Risk:** medium: the patch edits three of the game's job functions; a function where it finds its text differently keeps the game's sleeps. ## Why OoT runs three of its parallel-for jobs (f_800998a0, the drawing-command job; f_800738e0; f_8007e200) on several threads over one job block, each thread taking items by atomic ORs into bitmasks. A thread with nothing left to take sleeps 20 microseconds (`nn::os::SleepThread`) and looks again, until the masks it polls are full. On Windows a sleep that short wakes about half a millisecond late when there are few logical processors, and the main thread is one of the waiters: on 4 cores in Castle Town's market it was asleep there in 11.4 % of its profile's samples, about 2 ms a frame. Waiting for the word itself to change, and being woken by the OR that changes it, ends the wait when the work is done instead of on the next timer tick. ## What changed The lift's patch routes those three functions' barrier sleeps and their ORs through the host. A sleeping thread waits on the polled mask word until it moves (`WaitOnAddress` on Windows, a futex through `host/posix` on Linux) with a 1 ms limit, and an OR into a mask wakes its waiters. After the wait the thread looks again exactly as after its sleep, so a missed wake costs at most the old sleep's time. - host: `host/oot_barrier.h`, `host/oot_barrier.c` (new): the wait and the wake, the switch (on unless `HOS_OOT_BARRIER_WAIT=0`), `WaitOnAddress` looked up at the start (without it, the sleeps as before and a log line), and a `barrier:` log line every 16,384 looks (found moved already, waited, timed out, the average wait, the wakes). The switch is read through `hos_ab_value`, so `HOS_AB` may flip it between two looks. - lift: `nx2/oot_patches.py` `patch_barrier_wait`: in each of the three functions, the OR into the mask gets the wake after it and the sleep gets the wait in front of it; a function is hooked whole or not at all (a warning names a function it could not hook, which keeps the game's sleeps). The places accept the page-mark lines a finished lift puts between lines and a loop's back edge with or without its poll; the three functions keep their registers in the context (their addresses are named in the file). - docs: the `HOS_OOT_BARRIER_WAIT=0` row in `docs/development.md` and `gpu/vk/switches.def`. - tests: `tests/test_oot_barrier.py` (new): the real `oot_barrier.c` and header over stand-in waits: threads that wait and are woken, no lost wake-up, the 1 ms limit, the switch's values (on for unset, 1 and yes; off for 0 and off); the patch on a small lifted text run through the lift's real poll and page-mark passes (hooked whole, the same text twice, before or after the polls, over a finished lift), `touches()` and `mentioned_addresses()` for the three functions; 9 broken variants of the code and 8 of the patch, each caught; on Windows (clang) and Linux (gcc 13). `tests/test_hos_ab.py`'s list of wired switches gains `HOS_OOT_BARRIER_WAIT`. ## Measurements **Verdict:** faster on 4 cores: frame time -3.2 % in both runs (95 % intervals -5.1 to -1.9 % and -4.2 to -2.4 %), frames of 16.7 ms or more down 10 to 11 points (30 to 19 %, 26 to 16 %); on 16 cores no difference (intervals around 0). Hardware: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB Scene: Castle Town's market (child), standing after a debug teleport from the `kokiri-start` save; output 2560x1440, uncapped (`HOS_FPS_MAX=1000`), no window (`HOS_HEADLESS=1`). "4 cores": the game kept to cores 8-11 (affinity 0xF00, `HOS_CACHE_CORES=0`); "16 cores": no affinity, the game on the 8 cores of the 96 MB L3 by default Method: in-run A/Bs (`HOS_AB=HOS_OOT_BARRIER_WAIT=<value>,3,130`: 3 s periods after 130 s), about 160 s standing, `RX_VK_FRAME_TRACE=1`; `scripts/ab_summary.py` on each trace (transitions left out, a bootstrap of whole periods for the interval); two runs each How to reproduce: on this PR `HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,130` (side 1 is the old way); the runs also had `RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0 HOS_THREAD_TIMES=5` Baseline: both sides of each run come from one build, main @ 54a42715 (93 commits before this PR's base) with the 18 Nov changes, the switch flipping every 3 s within the run. On 4 cores that build's default was the old sleeps and side 1 this PR's wait; on 16 cores (a later build of the same tree) the default was the wait and side 1 the old sleeps. | | Before (the 20 us sleeps, main's way): build @ 54a42715 | After (the wait on the mask, this PR's way): the same runs @ 54a42715 | Δ (95 % interval) | |---|---|---|---| | 4 cores, run a: mean frame | 16.073 ms | 15.561 ms | -0.513 ms (-0.821 to -0.303) | | 4 cores, run b: mean frame | 15.911 ms | 15.401 ms | -0.510 ms (-0.664 to -0.377) | | 4 cores, frames >= 16.7 ms (a / b) | 30.2 / 26.4 % | 19.3 / 16.1 % | -10.9 / -10.3 points | | 16 cores, run a: mean frame | 13.992 ms | 13.948 ms | -0.044 ms (-0.154 to +0.052) | | 16 cores, run b: mean frame | 13.723 ms | 13.715 ms | -0.008 ms (-0.132 to +0.104) | ``` 4 cores, run a: ab: HOS_OOT_BARRIER_WAIT=1 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 2626 frames, 16.114 ms a frame (62.1 fps); side 1 (the A/B's value) 2603 frames, 15.559 ms a frame (64.3 fps); side 1 -3.44 % frame time; 598 frames in transitions left out side 1 - side 0: mean -0.513 ms (-3.19 %, fps +3.29 %), median -0.520 ms, p99 -1.039 ms, >=16.7 ms -10.9 points 95 % interval of the mean's difference: -0.821 to -0.303 ms (-5.11 to -1.88 %): side 1 is faster 4 cores, run b: ab: HOS_OOT_BARRIER_WAIT=1 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 1973 frames, 15.972 ms a frame (62.6 fps); side 1 (the A/B's value) 1929 frames, 15.398 ms a frame (64.9 fps); side 1 -3.59 % frame time; 442 frames in transitions left out side 1 - side 0: mean -0.510 ms (-3.21 %, fps +3.31 %), median -0.570 ms, p99 -0.959 ms, >=16.7 ms -10.3 points 95 % interval of the mean's difference: -0.664 to -0.377 ms (-4.17 to -2.37 %): side 1 is faster 16 cores, run a: ab: HOS_OOT_BARRIER_WAIT=0 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 2323 frames, 13.946 ms a frame (71.7 fps); side 1 (the A/B's value) 2305 frames, 14.006 ms a frame (71.4 fps); side 1 +0.43 % frame time; 511 frames in transitions left out 95 % interval of the mean's difference: -0.052 to +0.154 ms (-0.38 to +1.10 %): no difference shown (the interval holds 0) 16 cores, run b: ab: HOS_OOT_BARRIER_WAIT=0 against its normal value, 3.0 s periods after 130 s: side 0 (normal) 3148 frames, 13.716 ms a frame (72.9 fps); side 1 (the A/B's value) 3125 frames, 13.733 ms a frame (72.8 fps); side 1 +0.13 % frame time; 703 frames in transitions left out 95 % interval of the mean's difference: -0.104 to +0.132 ms (-0.76 to +0.97 %): no difference shown (the interval holds 0) [hos ModuleSystemWorker5] barrier: 17907 looks: 1523 found the masks moved already, 16384 waited until they moved, 0 for the whole 1 ms (a wait 40 us on average); 22332 wakes ``` (The 4-core runs' A/B value was `HOS_OOT_BARRIER_WAIT=1` because that build's switch had the old sleeps as its default; the 16-core runs' was `=0`. Side 1 is the A/B's value in each.) ### Flags and settings One switch added; the new behaviour is the default. | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `HOS_OOT_BARRIER_WAIT` | three job barriers wait on their mask word | (no switch: 20 us sleeps) | unset: the wait | `=0` brings the sleeps back | helps on 4 cores (-3.2 %), no difference on 16; untested on SMT CPUs, the Deck, Linux in the game | on for everyone (unset) | ## Testing **Tested:** in the game, at 93 commits behind this base: the A/Bs above, on 4 and 16 cores, every run to its end with 0 errors, the market drawn in its screenshots, the `barrier:` lines counting waits and no 1 ms time-outs. On this head: `tests/test_oot_barrier.py` passes on Windows (clang) and on Linux (gcc 13, WSL Ubuntu 24.04); `tests/test_hos_ab.py` and `tests/test_patch_hooks_defined.py` pass; of the 54 checks that read the changed files, the 22 that fail on this PC failed the same way on the base (run before the rebase onto main's last 11 commits; after it, the tests above pass again). **Not tested:** a build of this exact head: no lift of main exists on my PC, so the patch's places were read from the older tree's lift; the lift's `oot_patches: WARNING: the job barriers were found in N of 3 functions` would show a function main's lift writes differently (that function then keeps the game's sleeps). Linux in the game (the futex path is compiled and run by the test). **Must be tested:** - Windows, any GPU: build this head, expecting no barrier warning in the lift's log and the run's `barrier:` lines; then `HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,60` with the game on 4 cores in the market, expecting side 1 (the old sleeps) slower (by hand: me) - steamdeck: the same A/B in the market at handheld settings, expecting side 1 no faster (Test Farm: @Beanstalk steamdeck, stand in Castle Town's market 3 minutes with HOS_AB=HOS_OOT_BARRIER_WAIT=0,3,60 and RX_VK_FRAME_TRACE=1, then scripts/ab_summary.py) - linux, a desktop: the same A/B, expecting side 1 no faster and no hang (Test Farm: @Beanstalk linux, the same A/B) ## Risks **What could break:** a missed wake would make a barrier wait its 1 ms limit (the `barrier:` line counts those: 0 in the runs above) and then look again as before, so the cost is bounded by the limit; a function whose text the patch doesn't find keeps the game's sleeps (with a warning). The job functions themselves are edited only at their sleeps and ORs. **Turning it off:** `HOS_OOT_BARRIER_WAIT=0`. **Compatibility:** the lifted code changes (three functions keep their registers in the context), so the game is translated again; saves, options and caches otherwise as before. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [ ] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. (In the game 93 commits back; this head not built yet.) - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). (The changed files' checks on this PC; failures are the base's own here.) - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] Docs updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two runs of the same build differ by a few fps, more than the 2-5 % a change is often
worth. HOS_AB=<switch>=<value>[,<seconds>[,<warm-up seconds>]] measures both sides in
one run: after the warm-up the switch alternates every period between its normal value
and <value>, and each frame is counted for its side.

- host/hos_ab.c: the plan's parser, the flip thread, hos_ab_value (one relaxed load
  with no A/B), the host's sums by side logged at the close.
- MkwVkHost.ab_frame (MKWVK_API_VERSION 34): the frame trace's ab_side column.
- scripts/ab_summary.py: per side, the difference and a 95 % interval by a bootstrap of
  whole periods; transitions, the warm-up and a cut-short last period left out.
- HOS_COLLECT_WIDE is the first wired switch (the pages a walk finds are the same
  either way).
- tests/test_hos_ab.py: parser, schedule, frames, the cheap path, the sums, the wired
  switch flipping at every walk, ab_summary.py, broken variants of both.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
test: the Windows stop test stands in for hos_ab_end in the close chain
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Failing after 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 12s
Third-party parts / As their notes say (pull_request) Successful in 13s
Website / Website on Cloudflare (pull_request_target) Has been skipped
1d168e1ae5
hos_close_finish logs the A/B sums (hos_ab_end) after the close work and before
the log flush; the stop test compiles that chain over its own stand-ins.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member

Possibly related, for context:

  • issue #1506 The game's 20 microsecond poll sleeps wake threads thousands of times a second, and the host cannot tell idle polls from needed ones — Tracks the same game 20 µs job-poll sleeps; this PR implements a different wait/wake solution.
Possibly related, for context: - issue #1506 The game's 20 microsecond poll sleeps wake threads thousands of times a second, and the host cannot tell idle polls from needed ones — Tracks the same game 20 µs job-poll sleeps; this PR implements a different wait/wake solution.
HumanBean force-pushed perf/oot-barrier-wait from 5a8be09ec6
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 21s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Third-party parts / As their notes say (pull_request) Successful in 31s
to 6328ed7577
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Failing after 16s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 21s
Third-party parts / As their notes say (pull_request) Successful in 23s
2026-11-18 22:05:07 +00:00
Compare
HumanBean approved these changes 2026-11-18 22:05:51 +00:00
HumanBean left a comment

Rebased onto main (its base, #1661, landed with #1663; the one conflict, tests/test_hos_ab.py's WIRED list, now lists HOS_OOT_BARRIER_WAIT beside HOS_OS_YIELD). Approved to merge at the maintainer's request.

Rebased onto main (its base, #1661, landed with #1663; the one conflict, tests/test_hos_ab.py's WIRED list, now lists HOS_OOT_BARRIER_WAIT beside HOS_OS_YIELD). Approved to merge at the maintainer's request.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!1662
No description provided.