Title mwaitx with a timer waits with tpause on WAITPKG processors #457
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!457
Loading…
Reference in a new issue
No description provided.
Delete branch "MesoPlz/Darner:pr-tpause-waits"
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?
Contributor role (optional)
What it changes
DARNER_PROFILE=1,DARNER_PROFILE_THREADS=title) put 88% of that thread's busy samples in one fence wait of the title (+0x4fb0ad0 of game_scarlett_master.exe 1.0.2.1):monitorx,mwaitxwith its timer (about 100 us),Sleep(0), again.On the console
mwaitxsleeps until the monitored line is written or its timer runs out. On Intel it faults, andconsole_insnreplaces it at its first fault withpause(DARNER_PATCH_WAITS, on). So on Intel the loop went round at about a microsecond a pass, aSleep(0)system call each time.This change: where the processor has WAITPKG (CPUID.7.0:ECX bit 5; Intel since Alder Lake and Tremont), an
mwaitxthat faults withmov ecx, imm32; xor eax, eaxright before it has thatmovreplaced by a jump to a stub. The stub waits withtpause(C0.1) until the title's timer in EBX (whenimmhas bit 1, asmwaitxreads it) or 32K TSC cycles, the shorter. Then it sets ECX, EAX and the flags as the original instructions leave them, and jumps back past themwaitx.tpausedoes not wake on the write to the line, so a write is seen at most 32K cycles (about 10 us) late.The jump is written with the same 16-byte compare-exchange
patchand the same stub regions (put_stub) as theclzeroand SSE4a replacements. Thexorand themwaitxstay in place for a thread already past the jump. Any other form (another register setup, the jump crossing 16 bytes, no WAITPKG) gets thepausereplacement as before.DARNER_WAIT_TPAUSE=0turns it off. AMD processors runmwaitxnatively and never reach this.How it was tested
Tested revision:
9392dea(this branch, on maind91d8e4) for the gates. The game runs used a local test build with this change onf3840d7plus #334, #337, #274, #397, #312, #304, #295 and #95 (all off-by-default switches unset), withDARNER_WAIT_TPAUSE=0(A) and unset (B), and later the same change on47d21cd.Commands and results:
cargo xtask policy: passedcargo clippy --workspace --all-targets --locked -- -D warnings: passed, no warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed, no warningscargo test --locked -p darner-loader: 93 + 2 + 2 passed, 0 failed, including the newa_timed_mwaitx_becomes_a_tpause(runs the stub when the processor has WAITPKG, as this one does).Changes a default: yes, for processors with WAITPKG (Intel Alder Lake and later); the replacement for
mwaitxthere is thetpausestub instead ofpause.A/B result: the same opening scene of one save, three one-minute windows from the moment the world appears, one run each:
DARNER_WAIT_TPAUSE=0)GetThreadTimes)So: no frame-rate change (the thread waits for the card either way), about 0.13 of a core less in the kernel. The log says
an mwaitx waits with tpause nowonce, at the title's site.Gates run on that revision: gates 1 and 2 in full; of gate 3 only
darner-loader's tests. The fullcargo test --workspacewas not run on9392dea; on the test builddarner-shader --libhad one failure,sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, which fails the same way on main47d21cd(#389, #227).Gameplay: RTX 4080 16 GB (driver 621.40), i7-13700K, 64 GB, Windows 11 26300; Series X profile, 1440p with DLSS Quality, frame generation off, hardware ray tracing on.
Hardware dependence: only processors with WAITPKG take the new path. Tested on one (Raptor Lake). Not tested on Alder Lake, on Intel processors without WAITPKG (they keep
pause), or under a hypervisor that hides WAITPKG.Coverage gaps: one title build, one scene; no run longer than a few minutes; other titles'
mwaitxsites only take this path if they have the samemov ecx, imm32; xor eax, eaxbefore them.Checklist
main.docs/asset-policy.md.Checked for overlap
console_insn.rs; no overlap in what it changes)🤖 Generated with Claude Code
https://claude.ai/code/session_01DnqmuVZnMPVji1pieTnKH3
d91d8e4) into pr-tpause-waits 9392dea682[pr-performance] Title mwaitx with a timer waits with tpause on WAITPKG processorsto Title mwaitx with a timer waits with tpause on WAITPKG processorsTest needed — commit
9392dea6; what to check:DARNER_PROFILE=1,DARNER_PROFILE_THREADS=title) put 88% of that thread's busy samples in one fence wait of the title (+0x4fb0ad0 of game_scarlett_master.exe 1.0.2.1):monitorx,mwaitxwith its timer (about 100 us),Sleep(0), again.On the console
mwaitxsleeps until the monitored line is written or its timer runs out. On Intel it faults, andconsole_insnreplaces it at its first fault withpause(DARNER_PATCH_WAITS, on). So on Intel the loop went round at about a microsecond a pass, aSleep(0)system call each time.This change: where the processor has WAITPKG (CPUID.7.0:ECX bit 5; Intel since Alder Lake and Tremont), an
mwaitxthat faults withmov ecx, imm32; xor eax, eaxright before it has thatmovreplaced by a jump to a stub. The stub waits withtpause(C0.1) until the title's timer in EBX (whenimmhas bit 1, asmwaitxreads it) or 32K TSC cycles, the shorter. Then it sets ECX, EAX and the flags as the original instructions leave them, and jumps back past themwaitx.tpauseEvidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.
Reply
testingto take this run; it's free again after 24 h with no results.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.