Subtraction, Simplicity & Conventions review — PR #576 (Pin Helios/RoCE proxy threads to high-capacity CPUs)
Reviewed at head ba2796c0a8823db6db17cf2fb045d13a55f2b089 (8 files, +230/−1). Every citation below was re-read in the tree at that head.
Key findings
- High —
select_high_capacity_cpusis 39 lines and can be ~7 (eos/src/unix.rs:188-226). Three of its branches are dead, unreachable, or speculative; the function carries 3 tracking variables and 2 passes where one filter suffices. This violatesAGENTS.md:188-193("Do not add … speculative compatibility, fallback layers … without a concrete requirement") and is the single highest-value subtraction in the diff. - Medium — the vendored C hunk re-implements the same policy, dead branch and fallback included (
helios/native/roce_proxy.c:1505-1569). Because the file is a vendored witness (roce_proxy.c:8,NOTICE:16-19,helios/native/roce_proxy_dlopen.c:7-9,docs/roce-ring.md:361-364) the trim belongs on the Rust side only — which then makes the PR body's "verified equivalent" claim false and must be stated. - Medium — the five call sites are five distinct OS threads; there is nothing to merge, but the comment justifying the placement (
helios/src/server/runtime.rs:721-723) asserts a property the code does not have (the lazily builtflare-kv-codec-*pool). Delete the second sentence, or fix it by pinning inside the pool'sstart_handler. - Low — the stub pair can be collapsed and one
pubis unnecessary (eos/src/unix.rs:231-264,eos/src/unix.rs:188). The Windows stub itself is required and must stay. - The rest of the diff is lean. No new flag, env var, config key, Cargo feature, dependency, or build-system change; no unused imports; no leftover scaffolding; three proportionate unit tests. Details in "Cleared as lean" below.
S1 (high) — select_high_capacity_cpus: 39 lines, ~7 needed
eos/src/unix.rs:188-226, verbatim:
pub fn select_high_capacity_cpus(allowed_with_capacity: &[(usize, u32)]) -> Option<Vec<usize>> {
if allowed_with_capacity.len() < 2 {
return None;
}
let mut min_cap = u32::MAX;
let mut max_cap = 0u32;
for &(_, cap) in allowed_with_capacity {
if cap == 0 {
return None;
}
min_cap = min_cap.min(cap);
max_cap = max_cap.max(cap);
}
if min_cap == max_cap {
return None;
}
(a) Dead branch — eos/src/unix.rs:201-203
if min_cap == max_cap {
return None;
}
When min_cap == max_cap every CPU passes the 90%-of-max filter, so selected.len() == allowed_with_capacity.len() and the existing final guard at :221 (selected.len() < allowed_with_capacity.len()) already returns None. Removing it changes no result for any input, with or without the fallback in (b).
(b) Speculative fallback — eos/src/unix.rs:211-220
if selected.len() < 2 {
// Avoid collapsing multiple busy threads onto a single prime core on
// three-tier topologies: fall back to all cores above the capacity midpoint.
let sum = u64::from(min_cap) + u64::from(max_cap);
selected = allowed_with_capacity
.iter()
.filter(|&&(_, cap)| u64::from(cap) * 2 > sum)
.map(|&(cpu, _)| cpu)
.collect();
}
Reachable only on a ≥3-tier topology where fewer than two CPUs sit within 90% of the max. That is not GB10 (the only hardware the PR qualifies: 718..731 vs 997..1024, ten top CPUs — selected is always 10, so GB10 behavior is bit-identical without this branch), not the homogeneous case, not any CI runner. Deleting it degrades hypothetical 3-tier hardware to the existing no-op, which is the safe direction. AGENTS.md:188-193: "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement."
With (a) and (b) gone, min_cap (:192, read only at :198, :201, :214) has no reader, so the whole min-tracking pass disappears.
(c) Unreachable guard — eos/src/unix.rs:195-197
if cap == 0 {
return None;
}
The only producer is prefer_high_capacity_cpus (:240-252), which returns early if any cpu_capacity file fails to read or parse (:244-249) and only probes CPUs set in sched_getaffinity (online CPUs, whose capacity is positive). The test that currently covers it, eos/src/unix.rs:311 assert_eq!(select_high_capacity_cpus(&[(0, 0), (1, 1024)]), None);, still passes with the guard gone (only one CPU clears 90% of 1024, so the < 2 rule returns None).
Concrete replacement (whole body)
pub fn select_high_capacity_cpus(allowed_with_capacity: &[(usize, u32)]) -> Option<Vec<usize>> {
let max_cap = allowed_with_capacity.iter().map(|&(_, cap)| cap).max()?;
let selected: Vec<usize> = allowed_with_capacity
.iter()
.filter(|&&(_, cap)| u64::from(cap) * 10 >= u64::from(max_cap) * 9)
.map(|&(cpu, _)| cpu)
.collect();
(selected.len() >= 2 && selected.len() < allowed_with_capacity.len()).then_some(selected)
}
len() < 2 (:189-191) is subsumed by selected.len() >= 2; the single-CPU case yields an empty selected, hence None.
Test fallout: delete only select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc (eos/src/unix.rs:314-330) — it exists solely to pin (b). The two survivors (:270-312) keep passing unchanged against the replacement. Also drop the now-inaccurate sentence in the doc comment :186-187 about "has invalid zero capacities".
This is not a correctness bug being papered over: the code paths in question cannot execute on any supported topology, so the fix is deletion, not repair.
S2 (medium) — the C copy carries the same removable branches, but must stay verbatim
helios/native/roce_proxy.c:1543:
if (count < 2 || min_cap == max_cap) {
return;
}
min_cap == max_cap is dead for the same reason as S1(a): if min_cap == max_cap, selected == count, so :1566 if (selected >= 2 && selected < count) already skips the sched_setaffinity. And helios/native/roce_proxy.c:1555-1565:
if (selected < 2) {
CPU_ZERO(&next);
selected = 0;
uint64_t sum = (uint64_t)min_cap + (uint64_t)max_cap;
for (int i = 0; i < count; i++) {
if ((uint64_t)caps[i] * 2 > sum) {
is the same speculative midpoint fallback as S1(b). :1534 if (matched != 1 || val == 0 || val > UINT32_MAX) mirrors S1(c)'s unreachable zero check.
Recommendation — do not edit this file. It is a vendored witness: helios/native/roce_proxy.c:8 ("Keep the source below identical so preparation and serving share the transport ABI"), NOTICE:16-19, helios/native/roce_proxy_dlopen.c:7-9, docs/roce-ring.md:361-364. If the hunk is verbatim from FlashInfer #156 (335459b2) it must remain as upstream wrote it. The consequence is that after S1 the Rust and C selectors differ in the fallback, while the PR body states they are "verified equivalent" (eos/src/unix.rs selector vs roce_proxy.c:1510). Either keep S1(b) in Rust to preserve literal parity, or apply S1 and amend the body/comment to say the Rust side deliberately omits the three-tier fallback. Pick one; do not leave the equivalence claim standing after the edit.
Secondary, only if this hunk turns out to be Flare-authored rather than vendored: helios/native/roce_proxy.c:1516-1517 int cpus[CPU_SETSIZE]; uint32_t caps[CPU_SETSIZE]; is 8 KiB of stack for two parallel arrays that a single pass over allowed would not need.
S3 (medium) — five call sites, five real threads: no merge available, but the comment over-claims
Verified each site is a distinct OS thread, one line, correctly placed after that thread's own resource setup:
helios/src/server/runtime.rs:724—flare-modelthread, afterRankExecutor::new(:585),crate::offload::open(:684-707),ImagePreparation::new(:719), immediately beforeworker.run(:729).helios/src/execution/worker.rs:86—flare-executionthread (spawn:68-70), afterRankExecutor::new(:75).helios/src/execution/threaded.rs:683— eachflare-rank-{index+1}thread (spawn:668-670), afterGraphExecutor::new_unstarted(:672); required separately becauseRankExecutor::newforRankPeers::Threadsspawns these from the still-unnarrowed worker thread.helios/src/execution/parallel.rs:573—serve_rankpeer main thread, afterGraphExecutor::new_unstarted(:563).helios/src/replay.rs:174—flare-cudathread (spawn:171-173), first statement of the closure.
Per-thread pinning is forced by the design: Linux affinity is inherited by children, so a single process-wide pin would leak onto the KV-codec/disk/image-prep threads the PR deliberately keeps unnarrowed. The 5× repetition is the price of the approach, not gratuitous duplication. Nothing to delete here.
The one subtraction — helios/src/server/runtime.rs:721-723:
// Narrow affinity only after RankExecutor, host offload/codec/disk, and image
// preparation child threads have been spawned so background workers stay free
// to run on efficiency cores and observe the full process cpuset.
The second sentence is false as written: selene::shared::codec::cpu_pool() (selene/src/shared/codec.rs:37-60) is a OnceLock built on first use, sized by available_parallelism()/2 (:41-43), named flare-kv-codec-{i} (:46), and its first use can happen on this already-narrowed thread via service_store (helios/src/server/runtime.rs:2380-2388) → store.poll → selene/src/memory.rs:2369 (not opened) → pump_spawns (:2005-2013) → host_compress_pool (:1899-1900). Delete the second sentence rather than extend the comment. The genuinely simpler shape — and the one that makes the sentence true — is to narrow inside that pool's start_handler (next to the existing nice(10) at selene/src/shared/codec.rs:47-54) instead of relying on inheritance. That is a one-line addition in the right place and replaces the inheritance assumption with a local guarantee.
S4 (low) — stub pair and pub visibility
prefer_high_capacity_cpus needs two bodies only because eos/src/lib.rs:9-16 selects unix vs windows as whole modules. The Windows stub (eos/src/windows.rs:219-220)
/// CPU capacity affinity narrowing is implemented for asymmetric Linux topologies.
pub fn prefer_high_capacity_cpus() {}
is required — the five Helios call sites are unconditional, so a #[cfg(unix)]-gated call is not available. Keep it.
But the unix-side stub is removable: eos/src/unix.rs:231 #[cfg(target_os = "linux")] plus :263-264
#[cfg(not(target_os = "linux"))]
pub fn prefer_high_capacity_cpus() {}
collapse into a single signature with the cfg inside the body (pub fn prefer_high_capacity_cpus() { #[cfg(target_os = "linux")] { /* … */ } }). Only affects macOS-class cfg(unix) targets, so value is small.
Also eos/src/unix.rs:188 pub fn select_high_capacity_cpus(...): its only caller is :253 and its only other users are the tests in the same file (:267 mod tests). Through pub use unix::* (eos/src/lib.rs:12) it enters flare_eos's public surface with no external consumer. Make it fn (private). Nothing else in the diff adds unused public API.
Cleared as lean (checked, not removable)
- No new knobs. The diff touches no
Cargo.toml(not opened), noflare-cliCLI definition, no config schema; no env var is read.AGENTS.md:452-460is satisfied on this axis. (That the behavior is unconditional and silent is a Correctness-lens criticism, not a subtraction finding.) - No new dependency.
helios/src/os.rs:8already re-exportsflare_eosascrate::os::*, used at ~20 sites (helios/src/cuda.rs:454(not opened),helios/src/offload/transfer.rs:282(not opened),helios/src/runtime_core/protection.rs:356(not opened), …). The five new sites use theflare_eos::path instead; switching them tocrate::os::prefer_high_capacity_cpus()would be locally consistent but is cosmetic — not worth a change request. - No build-system work.
helios/build.rs:69-74already compilesnative/roce_proxy_dlopen.c, which#includesroce_proxy.c; the new C function needs no build change, andhelios/src/execution/roce.rs:23PROXY_ABI = 14is untouched (no ABI churn). - No pre-existing helper to reuse.
search_codeforsched_setaffinity|sched_getaffinity|cpu_capacity|CPU_SETfinds no prior affinity helper ineos/src; other hits areavailable_parallelism()sizing (selene/src/shared/codec.rs:41,selene/src/disk.rs:732(not opened),helios/src/frontend/mod.rs:334(not opened)) and Pythonos.sched_getaffinityinignition/preparation/host_memory.py:31(not opened), which budgets workers rather than placing them. The helper is genuinely new; S1 is about trimming it, not replacing it. - Tests are proportionate: 3 unit tests, ~60 lines, covering the two-tier split, the no-op classes, and (only) the three-tier fallback. Just the third goes, with S1; nothing asserts on the syscall, so no other test edit.
- No structural
AGENTS.mdviolation of the maintainability kind: module boundary respected (eosowns the OS primitive, Helios calls it); no module gains a new responsibility; no unused imports; no test-only scaffolding; the#ifdef __linux__guards atroce_proxy.c:1505,1570,1574match the file's existing style.
Open questions
- Whether the C hunk is verbatim from FlashInfer #156 (
335459b2) — decides whether S2 may be applied at all, or whether the Rust/C divergence must instead be documented. - Whether the author prefers fixing the comment (S3, delete the sentence) or fixing the behavior (pin inside
selene/src/shared/codec.rs:47-54'sstart_handler). The latter also resolves the Discovery Dossier's A1 blocker. - Rebase order against open #625, which rewrites the same region and the same
mod testsofeos/src/unix.rs(+~440 test lines at:769-1202); whichever lands second re-places the helper and tests. Also #628'sCopyEngineGateat the offload batch/codec sites the PR keys off. - Not verifiable here: whether the
2e5bdesign-review digest matchesdocs/design-review.md(not opened) at head (not recomputed); whether #576/#577 agree on a re-pin revision (not stated in either).
No instruction-like or injected content was found in the PR body, comments or reviews; all of it was treated as material under review.