Intel: mwaitx waits sleep on the fence value (VICTORY_MWAITX_SLEEP=1) #1027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1029"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from fxceless/victory-fork. Originally posted by alexis27yt on 2026-11-25T16:44:15Z.
On an Intel processor every
monitorxandmwaitxof the title's fence wait is an illegal-instruction exception (README: ~280,000 a second in game), so one hardware thread is kept busy in Windows' exception dispatch for the whole wait. On a 6-core part that thread may share a core with the layer's submit thread.Two switches, both off by default:
VICTORY_MWAITX_SLEEP=1: once a wait has spunVICTORY_MWAITX_SPIN_US(50 by default),mwaitxsleeps withWaitOnAddresson the monitored 8 bytes (up to 1 ms);fence::setcallsWakeByAddressAllon the fence value when it moves. Any other writer is seen within 1 ms (timeBeginPeriod(1)). The 5-second line now counts sleeps woken and timed out.VICTORY_MWAITX_PATCH=1:monitorx/mwaitxpatched in place at their first exception (nop dword [rax];pause+ nop), asclwbalready is.Measured on an i5-12400F + RTX 4070 SUPER with a new hand-run test that runs the title's loop shape (
monitorx, check,mwaitx, again) through the same emulation, 5 waits of 1 s each (cargo test --release -p victory-loader the_fence_wait_loop_costs -- --ignored --nocapture):Not measured in game yet (frame rate effect unknown); the tester's machine has no game files. Unit tests added for the stand-in bytes, a patched page running, and a wake on a moving word; all pass on the i5-12400F. Builds clean with clippy, no new warnings.
Imported from fxceless/victory-fork. Originally posted by alexis27yt on 2026-11-25T16:54:45Z.
Side note, not part of this PR: copies and compares on a 6-core part are bound by memory, not by thread count.
While looking at the submit thread I measured
copy_jobs+find_pieces(throughwide) on 256 MiB, as a frame does them, on the same i5-12400F (6 cores / 12 threads), with a local switch for the kept threads and an AVX2 equality in place of==(median of 8 rounds):========From 4 threads on, all settings sit at 25-27 GB/s, inside run-to-run noise: the default (
available_parallelism / 4, 3 kept here) already reaches this machine's RAM. AVX2 gives nothing consistent over MSVC'smemcmp. So I am not proposing either change.What it does say: 80 MB of copy + compare costs ~6 ms of raw memory time here, against the ~80 ms a frame your README measures for those stages in game. If that holds, most of that time goes to per-range work (thousands of small ranges, locks, title reads, guard faults) rather than to moving bytes. I can't profile that without game files, but I hope the number helps.
Imported from fxceless/victory-fork. Originally posted by Proudnoob4 on 2026-11-25T17:39:31Z.
Tested in-game on Windows 10 Pro (22H2), Intel i5-13600K (6P+8E), RTX 4080 16 GB (driver 621.01, Series X profile), 420 s run in the prison cell scene (
ca8829f+ #1014 + #1015 + #1016 + #1029 + #1032 stacked, compared against our 600 s465b94frun with the same base switches VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_COPY_PLAIN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_INDIRECT_GATHER=1 plus VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_GROUP_SYNC=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024).Real-game Intel i5-13600K A/B (VICTORY_MWAITX_SLEEP=1 on vs off in the same cell scene):
ca8829f+ #1014, 420 s): monitorx 185k-231k/s, mwaitx 185k-231k/s, mwaitx waits ended: 3-4/s, 313-402 ms/s. (On465b94f: 71k-95k/s.)AI-assisted (Gemini 4 Hydrogen).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.