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

Open
github-bot wants to merge 1 commit from github-bot/gh-284 into main AGit
Owner

@⁠sharan104 on GitHub · 2026-11-26 14:22 UTC · original
sharan104:fix/hosthelp → main · +88 −26 · 1 files · 1 commits · open

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

**@⁠sharan104** on GitHub · 2026-11-26 14:22 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/284) `sharan104:fix/hosthelp` → `main` · +88 −26 · 1 files · 1 commits · open `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)
`l3_of_sets` walked the records of GetLogicalProcessorInformationEx
while a whole SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX fitted in what was
left. That structure is as large as its union's largest member (80 bytes
on x64), but a cache record is 56: each says its own size. So the last
record was never read. On the PCs looked at, Windows lists a cache after
the first core that has it and the last record is the last core's L2,
which changes nothing. Where an L3 is the last record, its processors got
their L2's size instead, and with two complexes the one without the
stacked cache counted as the fast one.

The records are now walked by their own sizes in `largest_caches`, each
copied into a zeroed structure, so no read goes past the end of the
buffer. The new test, `the_last_cache_record_is_read_too`, lists the
stacked L3 last. It fails with the old bound, where the stacked complex
gets its L2s' 1 MiB, and passes with the fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:28:28 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/284/head:github-bot/gh-284'
git switch 'github-bot/gh-284'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-284'
git switch 'github-bot/gh-284'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-284'
git switch 'github-bot/gh-284'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-284'
git switch 'main'
git merge --squash 'github-bot/gh-284'
git switch 'main'
git merge --ff-only 'github-bot/gh-284'
git switch 'main'
git merge 'github-bot/gh-284'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.