GPU: a thread's processor time since an earlier reading saturates at zero #2300

Closed
denkencar-sketch wants to merge 1 commit from upstream-pr/2302 into main
denkencar-sketch commented 2026-11-25 10:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T10:05:43Z.


Summary

A failed GetThreadTimes reads zeros, and the unchecked subtraction of a thread's processor time panicked in checked builds and wrapped in release. It now saturates at zero. This is defensive: the trigger is hard to reach, since both readings come from the same thread.

Testing

Test thread_time_never_runs_backwards fails on main and passes with this change. cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

Not tried: a run in the game.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6601987479 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2302). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T10:05:43Z. --- ## Summary A failed `GetThreadTimes` reads zeros, and the unchecked subtraction of a thread's processor time panicked in checked builds and wrapped in release. It now saturates at zero. This is defensive: the trigger is hard to reach, since both readings come from the same thread. ## Testing Test `thread_time_never_runs_backwards` fails on `main` and passes with this change. `cargo test --workspace --locked` passes apart from known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). Not tried: a run in the game. AI-assisted.
catminou4 commented 2026-11-25 11:04:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:18Z.

Review: COMMENTED


thread_cpu_since saturates instead of panicking when a query reads zeros. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6055713686 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2302#pullrequestreview-6055713686). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:19:18Z. **Review:** COMMENTED --- thread_cpu_since saturates instead of panicking when a query reads zeros. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Marvisak commented 2026-11-25 16:09:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:21:30Z.


Automated triage for the maintainers.

Proposed close. This guards thread_cpu_since in crates/victory-gpu/src/pipeline.rs against a later reading that is smaller than an earlier one. Both readings come from GetThreadTimes(GetCurrentThread(), ...) on the same thread, around one translation (see pipeline.rs around line 114 and pipeline/make.rs line 73). A thread's processor times only increase, and that call on the current-thread pseudo-handle does not fail in practice; the description itself says the trigger is hard to reach. The new test passes (u64::MAX, u64::MAX) as the earlier reading, which checks only what the new code does, not anything that can happen at run time. Evidence that a real run hits this path would change the verdict.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166715800 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2302#issuecomment-7166715800). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:21:30Z. --- <!-- victory-triage v1 head=a78e1a262c03e727d07371d68f52460b0435375a verdict=proposed-close at=2026-11-25T15:29:00Z --> Automated triage for the maintainers. **Proposed close.** This guards `thread_cpu_since` in `crates/victory-gpu/src/pipeline.rs` against a later reading that is smaller than an earlier one. Both readings come from `GetThreadTimes(GetCurrentThread(), ...)` on the same thread, around one translation (see `pipeline.rs` around line 114 and `pipeline/make.rs` line 73). A thread's processor times only increase, and that call on the current-thread pseudo-handle does not fail in practice; the description itself says the trigger is hard to reach. The new test passes `(u64::MAX, u64::MAX)` as the earlier reading, which checks only what the new code does, not anything that can happen at run time. Evidence that a real run hits this path would change the verdict. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 00:01:50 +00:00
denkencar-sketch commented 2026-11-26 00:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T23:12:04Z.


Closing per triage: \GetThreadTimes\ on the current thread does not go backwards in practice and there is no real-run repro.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177258400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2302#issuecomment-7177258400). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T23:12:04Z. --- Closing per triage: \GetThreadTimes\ on the current thread does not go backwards in practice and there is no real-run repro.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2300
No description provided.