Submit line: say how long its thread ran on a processor, beside how long it worked #4420

Closed
github-bot wants to merge 14 commits from github-bot/gh-4419 into main AGit
Owner

@⁠TolkoDev on GitHub · 2026-11-30 20:10 UTC · original
TolkoDev:pr/submit-cpu-time → main · +1024 −850 · 33 files · 14 commits · closed without merging

What it changes

The line "that thread worked X ms" times each job from start to end, so it takes in what the thread waited: for the card, in the present call, for locks. It is easy to read as processor time. The line now also says how long the thread ran on a processor.

It uses QueryThreadCycleTime, turned into time by the time stamp counter's rate, measured from the first job on. GetThreadTimes would not do, because it moves in clock ticks. A test on a Ryzen 7 7700 with Windows 10, 5 s each:

pieces / pauses spun GetThreadTimes, summed per piece thread cycles
0.3 / 0.5 ms 1656 ms 31 ms 1660 of 1676 ms
1.5 / 1.0 ms 2584 ms 1688 ms 2518 of 2570 ms
8 / 4 ms 3160 ms 3188 ms 3112 of 3161 ms

(The two methods were measured in separate runs, so the spun times differ a little.)

Microsoft advises against converting thread cycles to time in general. The conversion assumes a counter with one rate; here it was 3.80 million a millisecond, the processor's base rate.

Cost: two calls per job of the submit thread.

How it was tested

  • GPU and profile: RTX 5070 12 GB, Ryzen 7 7700, Windows 10; 1440p, DLSS quality, frame generation 2x. The game ran a build of v2026.11.30.02 with this change and other local changes, not main itself.
  • Before: that thread worked X ms
  • After, one line from that run: that thread worked 55.4 ms (waits included; it ran on a processor for 25.7 ms of that). Over the 349 one-second lines of heavy play (3000 or more indirect executions a frame), medians: frame 50.6 ms, worked 49.6 ms, on a processor 22.4 ms. The processor time was 45 % of the worked time (10th to 90th percentile: 42 to 49 %). In the menu: 0.5 ms worked, 0.4 ms on a processor. In none of the 458 lines was the processor time above the worked time.
  • cargo test: the 8 queue::behind tests pass, one of them new (a sleep costs the thread few cycles, a spin many). The rest of victory-gpu's tests were not run. Clippy reports nothing in behind.rs. CI's first Clippy step already fails on main.

Checked for overlap

  • Searched the file lists of the 803 open pull requests for behind.rs, and all pull requests for thread CPU time. Related: #3617 (localization) rewrites the same log line, and #3102 and #1925 each add a counter to the same array. All three show as conflicting with main now. Whichever lands second needs a merge.
**@⁠TolkoDev** on GitHub · 2026-11-30 20:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4419) `TolkoDev:pr/submit-cpu-time` → `main` · +1024 −850 · 33 files · 14 commits · closed without merging ## What it changes The line "that thread worked X ms" times each job from start to end, so it takes in what the thread waited: for the card, in the present call, for locks. It is easy to read as processor time. The line now also says how long the thread ran on a processor. It uses `QueryThreadCycleTime`, turned into time by the time stamp counter's rate, measured from the first job on. `GetThreadTimes` would not do, because it moves in clock ticks. A test on a Ryzen 7 7700 with Windows 10, 5 s each: | pieces / pauses | spun | `GetThreadTimes`, summed per piece | thread cycles | |---|---|---|---| | 0.3 / 0.5 ms | 1656 ms | 31 ms | 1660 of 1676 ms | | 1.5 / 1.0 ms | 2584 ms | 1688 ms | 2518 of 2570 ms | | 8 / 4 ms | 3160 ms | 3188 ms | 3112 of 3161 ms | (The two methods were measured in separate runs, so the spun times differ a little.) Microsoft advises against converting thread cycles to time in general. The conversion assumes a counter with one rate; here it was 3.80 million a millisecond, the processor's base rate. Cost: two calls per job of the submit thread. ## How it was tested - GPU and profile: RTX 5070 12 GB, Ryzen 7 7700, Windows 10; 1440p, DLSS quality, frame generation 2x. The game ran a build of v2026.11.30.02 with this change and other local changes, not main itself. - Before: `that thread worked X ms` - After, one line from that run: `that thread worked 55.4 ms (waits included; it ran on a processor for 25.7 ms of that)`. Over the 349 one-second lines of heavy play (3000 or more indirect executions a frame), medians: frame 50.6 ms, worked 49.6 ms, on a processor 22.4 ms. The processor time was 45 % of the worked time (10th to 90th percentile: 42 to 49 %). In the menu: 0.5 ms worked, 0.4 ms on a processor. In none of the 458 lines was the processor time above the worked time. - `cargo test`: the 8 `queue::behind` tests pass, one of them new (a sleep costs the thread few cycles, a spin many). The rest of `victory-gpu`'s tests were not run. Clippy reports nothing in `behind.rs`. CI's first Clippy step already fails on main. ## Checked for overlap - [x] Searched the file lists of the 803 open pull requests for `behind.rs`, and all pull requests for thread CPU time. Related: #3617 (localization) rewrites the same log line, and #3102 and #1925 each add a counter to the same array. All three show as conflicting with main now. Whichever lands second needs a merge.
"That thread worked" times each job from start to end, so it takes in what
the thread waited: for the card, in the present call, for locks. The line now
says how much of it ran on a processor, from QueryThreadCycleTime turned
into time by the time stamp counter's rate.

GetThreadTimes would not do: it moves in clock ticks. Of 1.7 s spun in pieces
of 0.3 ms with pauses between, the pieces' differences added up to 31 ms; the
cycle counts to 1.66 s (Ryzen 7 7700, Windows 10).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 20:13:22 +00:00
Author
Owner

@⁠IRennie74 on GitHub · 2026-11-30 22:38 UTC · original

This answers an open question on a smaller PC. On a Ryzen 5 5600X with an RTX 3060 (Series S, DLSS Performance) the line says the submitting thread worked 44-54 ms of a 55-58 ms frame, while a sampling profile had it running only about 63 % of the run (75 % inside its jobs). How much of "worked" is on a processor tells whether that thread is short of CPU or waiting; we will try this in our diagnostics build.

One fix: queue/behind.rs is not Windows-only, but the new block (behind.rs:55-91) links kernel32, calls windows_sys (a cfg(windows) dependency in victory-gpu's Cargo.toml) and uses std::arch::x86_64::_rdtsc, so victory-gpu stops compiling on any other target. Gating thread_cycles / counter_since / cycles_a_ms with #[cfg(all(windows, target_arch = "x86_64"))] and a stub returning 0 elsewhere (the line then prints 0, as it does in the first 10 ms) keeps it building; the new test wants the same gate.

**@⁠IRennie74** on GitHub · 2026-11-30 22:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4419#issuecomment-7294109900) This answers an open question on a smaller PC. On a Ryzen 5 5600X with an RTX 3060 (Series S, DLSS Performance) the line says the submitting thread worked 44-54 ms of a 55-58 ms frame, while a sampling profile had it running only about 63 % of the run (75 % inside its jobs). How much of "worked" is on a processor tells whether that thread is short of CPU or waiting; we will try this in our diagnostics build. One fix: `queue/behind.rs` is not Windows-only, but the new block (`behind.rs:55-91`) links `kernel32`, calls `windows_sys` (a `cfg(windows)` dependency in `victory-gpu`'s `Cargo.toml`) and uses `std::arch::x86_64::_rdtsc`, so `victory-gpu` stops compiling on any other target. Gating `thread_cycles` / `counter_since` / `cycles_a_ms` with `#[cfg(all(windows, target_arch = "x86_64"))]` and a stub returning 0 elsewhere (the line then prints 0, as it does in the first 10 ms) keeps it building; the new test wants the same gate.
github-bot closed this pull request 2026-12-01 18:43:41 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:41 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4419#issuecomment-7321363033) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/trustno1-coder--VIctory-NVIDIA!4420
No description provided.