Repository navigation
threads: the default pool takes every allowed physical core before an SMT sibling - #826
Conversation
… SMT sibling Shape::of kept each CCD's allowed cpus with the primaries first but the placement rule read only the total cpu count per CCD. A mask of one core and its sibling in one L3 group and two cores of another, [0,8,4,5] on two groups of four two-cpu cores, gave groups [[0,8],[4,5]] of equal counts, so the round robin pinned the three default participants to [0,4,8]: two on one core while allowed cpu 5's core idled. Shape now keeps each CCD's allowed core count, and ccd_slot hands out the physical cores in rounds over the CCDs before any sibling, then the siblings in rounds, then shares the last slot as before. CcdMap reads the same spread, so its CCD, rank, width and lanes still match the pins. CCDs of equal core and cpu counts keep the closed form, so an unconstrained machine pins as it did, and a topology without SMT places exactly as before. Fixes midagedev#825
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix finding remains; masked host-tier performance needs measurement.
Non-blocking
⚠ Measure masked host-tier dispatch: crates/threads/src/topology.rs:426 changes equal-CPU-count masks with unequal core counts from closed-form placement to scanning.
crates/model/src/ops.rs:4662 calls ccd_of, first_lane, width (two more first_lane calls), and rank_of: up to 5 × T × D placement scans/token [derived from source calls, before compiler optimization], for T participants and D CCD-major row dispatches/token.
Provide a masked same-lease host-tier A/B and the owning gate-threads output. AGENTS.md requires a same-lease A/B for dispatch-path changes; the PR reports no timing. Measuring now separates this cost from later host-tier changes.
Checked
- Duplicates: pins and CCD mapping share
ccd_slot; dryer reported 0 pairs. - Complexity: crapper reported no changed function crossing its thresholds.
- Silent failure: empty masks panic; oversubscribed participants share their CCD's last CPU slot. The new
expectstates the round-membership invariant. - Tests, source mutation analysis: dropping the core-count comparison at topology.rs:426 restores pins
[0, 4, 8], failing the expected[0, 4, 5]. Changing>=to>at line 471 misclassifies the first sibling slot; the expanded mapping assertions cover that boundary. - Gates: no thresholds, bands, cases, or lint levels relaxed; the hardware test remains
hw_and ignored. - Escape catalog: no C1–C4 patterns match the diff.
Notes
Rust and hardware tests were not rerun during validation. Validation used source inspection.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
CPU 마스크가 일부 코어의 SMT 형제만 남길 때도, 기본 스레드 풀이 허용된 물리 코어마다 한 명씩 먼저 배치하도록 고칩니다.
What and why
Fixes #825. The host thread pool's default thread count is the number of allowed physical cores, but the placement rule only looked at each CCD's total cpu count. When the process's cpu mask leaves two L3 groups with the same number of cpus but a different number of cores, the pool treated them as equal and went round robin. One core could then hold two participants, as a core and its SMT sibling, while another allowed core had none.
Take a mask of
[0, 8, 4, 5]over two L3 groups of four cores, where cpu 8 is the SMT sibling of cpu 0. Each group keeps two cpus, but the first holds one core and the second holds two. Before this change the three participants pinned to[0, 4, 8]: cpus 0 and 8 share a core, and the core holding cpu 5 stayed idle. Now they pin to[0, 4, 5].Shapeincrates/threads/src/topology.rsnow keeps each CCD's allowed core count next to its cpu list, andSpread::Unevencarries it.ccd_slotandSpread::first_lanehand out slots in two tiers: physical cores first, one participant per CCD that still has a core free in each round, then the SMT siblings in rounds the same way. Once every cpu holds a participant, the rest share each CCD's last slot, as before. The pins andCcdMapread the sameShape::spread(), so the map still agrees with where participants sit. There is no new option or environment variable.CCDs with equal core counts and equal cpu counts keep the closed form
(t % n, t / n), so a host with no restricting mask pins as before. Without SMT siblings the second tier is empty and the rule is the same as before this change.Release notes: Fixed: a process whose cpu mask leaves L3 groups with different core counts now gets one thread pool participant on each allowed physical core before any core holds two.
Code shape
ccd_slot,SpreadandShape::spread()intopology.rsstay the one owner of the placement rule. I changed that owner in place, and the pins andCcdMapboth read it.kept_corescounter inShape::ofis replaced by a per-CCD list that it is summed from.expectstates an invariant: a participant in a round belongs to one of the CCDs open in that round.cargo fmtandcargo clippyare clean on what I touched.Duplication found or removed (
path:line): none.What I ran
The head is
f329a9138fbeba6b7df86e1cabba3dc7afa4fb1e, one commit on mainaf50bf7874ca867912332ea45602060732477588. The hardware results below ran on an earlier head of this branch. The only change since then is a type alias inside a test that clippy asked for, so the product code is the same.The new unit test
every_allowed_core_takes_a_participant_before_a_siblingintopology.rsbuilds the mask above, an explicit thread count of four, and a topology without SMT siblings (groups of five and three one-cpu cores). The existing mapping test intopology.rsnow also builds three masks that leave the groups unequal in cores or in cpus, and goes through every thread count up to past the cpu count. On the base the new test fails:On the earlier head, on an RTX 5090 machine with
tasksetset to the mask0,16,8,9(cpus 0 and 16 are one core, cpus 8 and 9 are two cores of the other L3 group),cargo test -p bloomery-threadspasses (the lib tests report18 passed, the pool tests8 passed; 0 failed; 2 ignored) andcargo fmt -p bloomery-threads --checkprintsFMT-OK. Thehw_ccd_map_matches_the_pinstest (#[ignore], it pins the calling thread and reads the real topology) now also asserts that no core holds two participants while an allowed core is free. It passes under that mask and without a mask:cargo clippyfor the threads crate is clean on this head (exit 0).Not run: the hardware test on the base, the hardware test on this exact head,
cargo check --workspace --all-targets(no public signature changed;SpreadandShapearepub(crate)),just contrib-check, and the GB10 and Apple Silicon hosts, which have no SMT siblings and are covered by the unit test without SMT. I did not time anything, because only the cpu placement of the host pool changes, not the GPU or decode path.Hardware
x86 Linux, two L3 groups (cpus 0-7 and 16-23 share one, cpus 8-15 and 24-31 the other). The change does not touch the GPU path.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.