VICTORY_CACHE_CORES: read the processors' cache records to the last one (it was always skipped) #284

Open
sharan104 wants to merge 1 commit from upstream-pr/284 into main
sharan104 commented 2026-11-26 14:22:26 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by sharan104 on 2026-11-26T14:22:26Z.


cores.rs l3_of_sets (used by VICTORY_CACHE_CORES, from #147) walked the records GetLogicalProcessorInformationEx(RelationCache) writes, but only while a whole SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX (80 bytes) still fit. Each cache record states its own, smaller size (56 bytes: the union is as large as its largest member). So:

  • The last record is always skipped. A probe on this PC showed it: here it's the last core's L2, which changes nothing. But if the last record is an L3, its processors get sized by their L2s. On a two-complex X3D Ryzen, fast_by_cache would then pick the complex without the stacked cache as the fast one.
  • Each record was read as a whole structure through a reference, so the last ones were read past the bytes the system wrote (and past the buffer, for the very last).

Fix: a pure function, largest_caches(&[u8]). It walks the records by their own Size, stops at a zero or truncated size, and copies each record's own bytes into a zeroed structure before reading it, so nothing outside a record is read. l3_of_sets calls it on the bytes the system returned. The buffer is now u8, and the copy makes alignment irrelevant.

Test: the_last_cache_record_is_read_too uses synthetic records: two complexes of eight processors, with the stacked 96 MiB L3 listed last. With the old bound the stacked complex came out at 1 MiB (its L2s) and the other complex was picked. Now each complex has its L3, and fast_by_cache picks processors 8–15. A record cut short and a record of size 0 are also covered. The test fails with the old bound and passed 10 runs out of 10 with the fix.

Results:

  • cargo test -p victory-gpu --locked: 382 passed, 34 ignored.
  • Clippy -D warnings adds nothing beyond main's existing watch.rs lint, which #241 fixes.

I can't show that Windows ever lists an L3 last on real hardware, so the practical impact may be nil. The out-of-bounds read is fixed either way.

🤖 Generated with Claude Code

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6628677498 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/284). Originally posted by [sharan104](https://github.com/sharan104) on 2026-11-26T14:22:26Z. --- `cores.rs` `l3_of_sets` (used by `VICTORY_CACHE_CORES`, from #147) walked the records `GetLogicalProcessorInformationEx(RelationCache)` writes, but only while a whole `SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX` (80 bytes) still fit. Each cache record states its own, smaller size (56 bytes: the union is as large as its largest member). So: - **The last record is always skipped.** A probe on this PC showed it: here it's the last core's L2, which changes nothing. But if the last record is an L3, its processors get sized by their L2s. On a two-complex X3D Ryzen, `fast_by_cache` would then pick the complex *without* the stacked cache as the fast one. - **Each record was read as a whole structure** through a reference, so the last ones were read past the bytes the system wrote (and past the buffer, for the very last). **Fix:** a pure function, `largest_caches(&[u8])`. It walks the records by their own `Size`, stops at a zero or truncated size, and copies each record's own bytes into a zeroed structure before reading it, so nothing outside a record is read. `l3_of_sets` calls it on the bytes the system returned. The buffer is now `u8`, and the copy makes alignment irrelevant. **Test:** `the_last_cache_record_is_read_too` uses synthetic records: two complexes of eight processors, with the stacked 96 MiB L3 listed last. With the old bound the stacked complex came out at 1 MiB (its L2s) and the other complex was picked. Now each complex has its L3, and `fast_by_cache` picks processors 8–15. A record cut short and a record of size 0 are also covered. The test fails with the old bound and passed 10 runs out of 10 with the fix. **Results:** - `cargo test -p victory-gpu --locked`: 382 passed, 34 ignored. - Clippy `-D warnings` adds nothing beyond main's existing `watch.rs` lint, which #241 fixes. I can't show that Windows ever lists an L3 last on real hardware, so the practical impact may be nil. The out-of-bounds read is fixed either way. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/284:upstream-pr/284'
git switch 'upstream-pr/284'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/284'
git switch 'upstream-pr/284'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/284'
git switch 'upstream-pr/284'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/284'
git switch 'main'
git merge --squash 'upstream-pr/284'
git switch 'main'
git merge --ff-only 'upstream-pr/284'
git switch 'main'
git merge 'upstream-pr/284'
git push origin 'main'
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
avatarmanz/VIctory-7900XTX!284
No description provided.