Repository navigation
XFER stats: The STATS window reads the StretchRect and ColorFill counters without the device lock - #205
Merged
Conversation
…under the device lock Closes #194. ProfXfer adds under the device lock, but HitchFrameEnd runs after Present released it and took the window without it: another thread's StretchRect or ColorFill could be lost or land in the wrong window, and a 64-bit count could tear on i686. xfer::Stats::takeCounts now holds the lock the caller passes for the read and the reset; the line is formatted after. The native test adds from two threads while a third takes windows, under ThreadSanitizer: with the lock dropped it reports data races and loses adds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
With
D9MT_PROFILE, the StretchRect and ColorFill paths add to the XFER counters under the device lock. The STATS window took them without it:HitchFrameEndruns after Present has released the lock. A StretchRect or ColorFill on another thread during the take could be lost or counted in the wrong window, and a 64-bit count could tear on i686.xfer::Stats::takeCountsnow holds the lock the caller passes for both the read and the reset, and the device passes its own. The XFER line is formatted after the lock is released.Closes #194
How to verify
scripts/run-native-tests.sh:xfer_stats_testnow builds with ThreadSanitizer. It adds from two threads, each add under a mutex, while a third thread takes windows, and checks that every add lands in exactly one window.Evidence
Proof. Head
b676125, basec52fff5.xfer_stats_teston jd-ai-server (x86_64 Linux, g++-fsanitize=thread): OK on four runs, each taking 95,000 to 345,000 windows while the adders ran.takeCounts(main's behaviour), ThreadSanitizer reports 4 data races and two count checks fail on lost adds (exit 66).Checksonb676125: green (run 43588817148). The macOS runner's clang built and ranxfer_stats_testwith-fsanitize=thread: ok.D9MT_PROFILEset, once a second, and touches nothing on a draw or present path (dispatcher's decision).Performance (PERFORMANCE.md §1). Kind: a profile-only fix. With
D9MT_PROFILEunset nothing changes:HitchFrameEndisn't called. With it set, STATS takes the device lock once more per second.Definition of Done
Checks43588817148.Review
Codex (gpt-6.1-sol, reasoning high), one round at
b676125: no findings. It checked these points:summary()needs no lock under the device's lifetime contract.It ran the test under ThreadSanitizer itself.
Risks and what I didn't do
Risk. With profiling on, STATS now waits for the device lock once a second. If another thread holds it for long, the STATS, RESTORE and XFER lines of that second come later. With profiling off, nothing changes.
How to revert. Revert the squash commit.