Repository navigation
threads: a mask that leaves the L3 groups unequal pins every allowed cpu before any shares one - #824
Conversation
…cpu before any shares one The pool placed participant t on CCD t % ccds at slot t / ccds and clamped a slot past the CCD's cpus to its last one. A mask that leaves the groups of unequal size, [0,4,5,6,7] on two groups of four cores, then pinned five participants to [0,4,0,5,0]: three on cpu 0, cpus 6 and 7 idle, and no oversubscription line because the thread count did not pass the cpu count. ccd_slot now hands round r one participant, in CCD order, to each CCD holding more than r cpus, so no cpu takes a second participant while another is free; past the cpus each round goes over every CCD and shares its last slot, as before. Groups of equal counts keep the closed form, so an unconstrained machine pins as it did. CcdMap reads the same spread (Shape::ccd_map), so its CCD, rank, width and lanes match the pins.
There was a problem hiding this comment.
Verdict: CLEAN: the new placement rule and CCD-map counts agree for partial rounds and oversubscription.
Non-blocking
⚠ Measure the host dispatch cost: crates/threads/src/topology.rs:435. Unequal-group lookups now walk the topology. Seat::of at ops.rs:4662 invokes ccd_slot five times per participant; every span invokes it twice.
Seat setup and spans alone contribute 5 × T × D + 2 × S topology-walking calls/token [derived], where T is participants, D is CCD dispatches/token and S is span calls/token. The work depends on fixed placement rather than token data.
Attach current-head gate-threads output and timed A/B under the same uneven mask, as required for dispatch changes by AGENTS.md's Measuring contract. Resolve fixed placement once if the measured cost matters; checking now establishes the cost before more callers depend on it.
Checked
Duplicates: dryer's ccd_of/rank_of pair selects different tuple components; extracting their short bounds checks would add elements.
Complexity: crapper flagged no functions.
Silent failure: the new max().unwrap_or(0) cannot see empty groups through Shape::of, which rejects an empty mask and removes empty CCDs.
Tests: static mutation checks show assertions catch old pin arithmetic, removal of g < next at topology.rs:441, and removal of either pin-state guard at lib.rs:293.
Arithmetic cross-check: an independent model checked 1,364 shapes (1–5 groups, each of size 1–4) and 34,588 thread counts (1 through twice each shape's CPU count plus 2), confirming ranks, prefixes and lane bijections. This is not execution of the Rust implementation.
Gates: no thresholds, tolerances or lint levels moved; the body supplies FAIL-first output for the unequal-mask defect.
Escape catalog: no patterns matched.
Notes
Rust and hardware tests were not run during validation. The body's hardware pass predates the final map refactor; it contains no timed A/B or qualifying GPU gate evidence.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #825
|
The review is done and the contribution check passed, so I'm merging this. |
CPU 마스크가 L3 그룹의 크기를 서로 다르게 남길 때, 스레드 풀이 허용된 모든 cpu에 한 명씩 먼저 배치하도록 고칩니다.
What and why
The host thread pool places participant
ton CCDt % ccdsat slott / ccdsof that CCD's cpu list. It assumes every L3 group has the same number of cpus, andShape::cpu_forclamps a slot past a group's length to the group's last cpu. When the process's cpu mask leaves the groups unequal, several participants land on one cpu while other allowed cpus stay idle. The pool prints no oversubscription line, because the thread count never exceeded the cpu count.Take a mask of
[0, 4, 5, 6, 7]over two groups of four cores. Before this change the five participants pinned to[0, 4, 0, 5, 0]: three on cpu 0, and cpus 6 and 7 unused. On a two-CCD x86 host with 32 cpus,taskset -c 0,8-15,24-31gave nine participants the pins[0, 8, 0, 9, 0, 10, 0, 11, 0], which is five distinct cpus.ccd_slotincrates/threads/src/topology.rsnow takes aSpread: eitherEven(n), groups of equal size, orUneven(&groups). Roundrhands one participant, in CCD order, to each CCD that holds more thanrcpus. No cpu takes a second participant while another is free. Participants past the cpu count go around every CCD and share that CCD's last slot, as before. Groups of equal size keep the closed form(t % n, t / n), so a machine without a restricting mask pins as it did.CcdMapnow holds aSpread<'static>instead of a CCD count, andccd_of,rank_ofandfirst_laneread the same rule as the pins, so the map agrees with where participants sit. Over unequal groups,first_laneasksccd_slotwhere the next participant goes and derives the counts before each CCD from that place, so the round logic exists once. The pool builds its map in one place,Shape::ccd_map.CcdMapis stillCopyand allocates nothing. There is no new option or environment variable.One public signature changes:
Pool::ccd_map(&self)becomesPool::ccd_map(&'static self), because the map borrows the topology of the pool, which is leaked. Every caller already goes throughthreads::pool(), andcargo check --workspace --all-targetspassed on an earlier head of this branch that had the same signature.Release notes: Fixed: a process whose cpu mask leaves the L3 groups unequal now gets one thread pool participant on each allowed cpu, instead of several participants sharing a cpu while others stay idle.
Code shape
ccd_slotandSpreadintopology.rsare the one owner of the placement rule. The pool pins by them andCcdMapanswers by them, and the map construction that lived inPool::ccd_mapmoved intoShape::ccd_map.ccd_slot(t, nccd)and theccdsfield ofCcdMapare replaced, not kept beside the new ones.expectstates an invariant: a participant in a round belongs to one of the CCDs open in that round.cargo fmt -p bloomery-threads --checkpasses, andcargo clippyis clean for the threads crate on this head.Duplication found or removed (
path:line): none left. A first version counted the participants of a CCD in a second function that repeated the round walk ofccd_slot. That function is deleted, and the duplicate scan reports no candidates.What I ran
The head is
3180c990b13d1eea5ae2a4590a924b09676ed8d2, one commit on main869eeb70641dcb7a19be3294de62f4aa3e669f18. The tests ran on x86 Linux. The results below come from the head's tree, or from an earlier head of this branch where I say so.The unit test
unequal_groups_take_every_cpu_before_one_is_sharedintopology.rscovers the mask above, an explicit thread count past the cpu count, and three groups of 1, 4 and 2 cpus with thread counts 1 to 10. For those it checks that theCcdMapfollows the pins and that each CCD's width equals the participants placed on it. On the base the unit test fails:On this head,
cargo test -p bloomery-threads --lib --test poolexits 0 and the pool tests report8 passed; 0 failed; 2 ignored, the two ignored being hardware tests. To check that the test pins the new count, I dropped theg < next &&term of the partial-round count: the test then panics and the run exits 101.The
hw_ccd_map_matches_the_pinsintegration test (#[ignore], it pins the calling thread and reads the real topology) also asserts that no cpu holds two participants while the topology has a cpu for each. I ran it undertaskset -c 0,8-15,24-31, which leaves one cpu in the first L3 group and sixteen in the second. On the base the hardware test fails:With the fix, on the same mask, on an earlier head of this branch (before the last refactor of
first_laneand a rebase):cargo fmt -p bloomery-threads --checkpasses on that earlier head, and so doescargo check --workspace --all-targets. The existing testsccd_map_places_participants_by_the_pinning_ruleandccd_spans_follow_the_participants_per_ccdcover the equal-group arithmetic and are unchanged.Not run on this head: the hardware test,
cargo check --workspace --all-targets,just contrib-check, and the GB10 and Apple Silicon hosts. I did not time anything, because only the cpu placement of the host pool changes, not the GPU or decode path. A host with a single L3 group cannot produce unequal groups, so the hardware test skips there.Hardware
x86 Linux, 32 cpus, 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 초안 리뷰는 제가 직접 했습니다.