Review of PR #576 (Subtraction lens) — Pin Helios execution and RoCE proxy threads to high-capacity CPUs
Key findings
The PR is well evidenced and the idea is sound, but it is roughly twice the size it needs to be: 4 of its 7 changed files carry ~107 of the +226 added lines that can go without losing either placement result the PR reports.
- ~66 lines — the C affinity helper is a line-for-line duplicate of the Rust one, and it never needs to run at all.
pin_high_capacity_cpus(helios/native/roce_proxy.c:1505-1570) repeatseos/src/unix.rs:172-248(samesched_getaffinity, same per-CPUcpu_capacityreads, samecap*10 >= max*9, same<2fallbacks, samesched_setaffinity). The proxy thread is apthread_createfromroce_start(roce_proxy.c:1674), whose only caller isRoceTransport::connect(helios/src/execution/roce.rs:295); a new thread inherits its creator's mask, so one Rust call beforeroce_startgives the proxy exactly the mask the C helper installs. It also edits the body of a file that must stay identical to the pinned FlashInfer proxy (roce_proxy.c:6-8,docs/roce-ring.md:360-364). - ~36 lines — the three-tier "single-core collapse" fallback and its test protect a branch that is already safe.
unix.rs:195-204+ testunix.rs:298-314. The final guard atunix.rs:205already turns a sub-2 selection into a no-op; the fallback only changes which set a prime-core SoC gets, a topology outside the charter's scope. Removing it also emptiesmin_cap, collapsing the min/max loop (176-184) and the provably redundantmin_cap == max_capreturn (185-187). - ~4 lines —
helios/src/replay.rs:171-176wrapsrun(...)in a closure only to pinflare-cuda, a worker the native server never spawns. - ~1 line —
helios/src/execution/worker.rs:71pinsExecutionWorker, which its own doc comment (worker.rs:36-37) calls the bootstrap/qualification control surface.
Files found already minimal: eos/src/windows.rs (the stub is load-bearing), helios/src/execution/parallel.rs:539 and helios/src/server/runtime.rs:568 (real serving threads).
Verdict: make it smaller first.
Scope and rules applied
- Charter, How We Work: "Look for the smallest footprint in shared code, or a way to solve it without new code at all. Good ideas in the wrong place will be declined" — grounds findings 1 and 2, and the open question.
- Charter, How We Work: "We're not interested in piling on extra model aliases, random switches, or broad hardware support", with Vision scoping Flare to "SM120/SM121 workstations and DGX Spark" — grounds finding 2 (three-tier/prime-core SoCs are outside that scope, and the PR's own caveats say the path is untested).
- Charter, Respect contributors / "Every PR is judged on its merits": noted because the measurement work here is genuinely strong (48/48 placement, 6.7× CV reduction, +17.2% A/B). The cuts below are structural, not a judgement on the idea.
- Repo rule,
docs/roce-ring.md:360-364: "Flare vendors the serving proxy inhelios/native/roce_proxy.c… keep the vendored source identical to the dependency after its provenance header" — reinforces finding 1. The PR is careful about ABI (still 14); the objection is to editing the vendored body, which the rename alone already does.
Change size from the diff: 7 files, +226 / −1. Confirmed removable: ≈107 lines (≈47 %), in 4 places.
Findings, ranked by lines saved
1. Should fix — delete the 66-line C copy; pin from Rust before roce_start (~66 lines)
Where: helios/native/roce_proxy.c:1505-1570 (the whole #ifdef __linux__ block containing pin_high_capacity_cpus, plus the call at :1576).
What it is: a C transcription of eos/src/unix.rs:172-248. Side-by-side the two are the same algorithm: sched_getaffinity(0, …); a loop over the mask reading /sys/devices/system/cpu/cpu%d/cpu_capacity; an early return on any missing/zero/unparsable capacity (unix.rs:182-184, roce_proxy.c:1537-1539); count < 2 || min_cap == max_cap → return (unix.rs:185-187, roce_proxy.c:1548); the 90 % filter cap*10 >= max*9; the <2 midpoint retry; and selected >= 2 && selected < count → sched_setaffinity. Nothing in it is C-specific beyond syntax.
Why nothing is lost: the proxy thread does not need to pin itself. roce_start creates it with pthread_create(&c->thread, NULL, proxy_main, c) (roce_proxy.c:1674), its sole caller is RoceTransport::connect (helios/src/execution/roce.rs:295; declaration at roce.rs:71; no other call site in the tree), and a new pthread inherits the creating thread's affinity mask and CPU set. Pinning the creating thread one line earlier gives flare-roce precisely the mask the C helper would install for itself — the same result the PR measures (48/48 critical threads on X925 5-9,15-19).
Smaller version:
/* roce_proxy.c: delete 1505-1570 entirely; proxy_main keeps only: */
#ifdef __linux__
(void)pthread_setname_np(pthread_self(), "flare-roce");
#endif
// helios/src/execution/roce.rs, immediately before line 295
flare_eos::prefer_high_capacity_cpus();
if unsafe { roce_start(self.context) } != 0 {
Keeps the 2-line pthread_setname_np (the PR's evidence uses the flare-roce name). Net: −66 in C, +1 in Rust, one copy of the policy instead of two, and the vendored file's provenance contract (roce_proxy.c:6-8) stays intact.
2. Should fix — drop the three-tier fallback and its test; the existing <2 guard already no-ops it (~36 lines)
Where: eos/src/unix.rs:195-204 (fallback, 10 lines incl. its 2-line comment) and the test eos/src/unix.rs:298-314 (select_high_capacity_cpus_avoids_single_core_collapse_on_three_tier_soc, 17 lines).
Why nothing is lost: the guard immediately below at unix.rs:205 — selected.len() >= 2 && selected.len() < allowed_with_capacity.len() — already returns None whenever the first pass selects fewer than 2 CPUs, which is the safe "leave affinity alone" behaviour the fallback claims to protect. The fallback therefore only changes which set is chosen on a topology where exactly one CPU clears 90 % of the maximum: a prime-core SoC, which the charter excludes ("DGX Spark" / "SM120/SM121") and which the PR's own caveats admit was not tested. On the stated target (10× A725 at 718-731 + 10× X925 at 997-1024) the 90 % pass always selects 10 CPUs — the PR's own gb10 test asserts that.
Second-order savings inside the same function: with the fallback gone, min_cap has no reader, so the min/max accumulation loop (unix.rs:176-184, ~9 lines) collapses to a single max(), and if min_cap == max_cap { return None } (185-187, 3 lines) is provably redundant — when every capacity is equal, every CPU passes the 90 % filter, so selected.len() == allowed.len() and line 205 already returns None.
Smaller version (~14 lines replacing 44 at unix.rs:167-210):
/// Select the high-capacity CPU subset of `allowed` when its capacities span
/// more than one tier. `None` means "leave this thread's affinity alone".
fn select_high_capacity_cpus(allowed: &[(usize, u32)]) -> Option<Vec<usize>> {
let max_cap = allowed.iter().map(|&(_, cap)| cap).max()?;
if allowed.len() < 2 || allowed.iter().any(|&(_, cap)| cap == 0) {
return None;
}
let selected: Vec<usize> = allowed
.iter()
.filter(|&&(_, cap)| u64::from(cap) * 10 >= u64::from(max_cap) * 9)
.map(|&(cpu, _)| cpu)
.collect();
(selected.len() >= 2 && selected.len() < allowed.len()).then_some(selected)
}
Every surviving assertion still passes unchanged: homogeneous → all selected → None; efficiency-only and performance-only cpusets → None; [(19, 1024)] → len < 2 → None; [(0, 0), (1, 1024)] → zero capacity → None; the GB10 split → the 10 X925 CPUs. The same 11-line fallback in the C copy disappears with finding 1.
(Nit within this finding, 0 lines but smaller surface: select_high_capacity_cpus is pub (unix.rs:172) yet its only caller is prefer_high_capacity_cpus in the same file (unix.rs:237); fn keeps the tests working and stops a policy detail from becoming exported API.)
3. Nit — drop the pin from the flare-cuda replay worker (~4 lines)
Where: helios/src/replay.rs:171-176. The closure exists only to add the call:
.spawn(move || {
flare_eos::prefer_high_capacity_cpus();
run(receiver, completion_sender, ready_sender)
})
ReplayWorker is not spawned by the native server: searching ReplayWorker across helios/src/server and helios/src/execution returns nothing (the server uses RankExecutor, see helios/src/server/runtime.rs:585); its users are heliopause/src/python.rs:45-46 (not opened) and the CUDA integration/tool tests under helios/src/runtime_core/*_tests.rs (not opened) and helios/tests/tools/*. None of the four critical threads the PR measures is a replay worker.
Smaller version — restore the single line at replay.rs:173:
.spawn(move || run(receiver, completion_sender, ready_sender))
Saves the 4-line closure (net −3 after the −1 removal). Caveat: if maintainers regard heliopause's GraphReplayWorker as a latency-critical serving thread, this stays — I read the PR's measurements as naming only the execution/WFET thread and the RoCE proxy.
4. Nit — drop the pin from the bootstrap/qualification worker (1 line)
Where: helios/src/execution/worker.rs:71.
ExecutionWorker's own doc comment (worker.rs:36-37) says: "Synchronous control surface for bootstrap/qualification callers on other threads. The native scheduler owns its rank executor directly without this channel boundary." Its only users are helios/tests/tools/tp4_collective.rs:122 (not opened),134,156 and heliopause/src/python.rs:410-411 (not opened), so this pins a thread that never serves a request. Nothing in the PR's evidence depends on it.
The description's phrase "execution … worker threads" is satisfied by the flare-model thread (runtime.rs:568) and serve_rank (parallel.rs:539), both kept.
(Related observation, not a proposed addition: the in-process per-rank executor threads — flare-rank-N at helios/src/execution/threaded.rs:652-654 — receive no pin at all. That is pre-existing, not caused by this PR, and adding one is outside the subtraction lens; flagging it so a reviewer does not read worker.rs:71 as covering that path.)
Examined and deliberately kept (no finding)
eos/src/windows.rs:220(+2/3 lines) — the stub is load-bearing:eos/src/lib.rsre-exportsunix::*under#[cfg(unix)]andwindows::*under#[cfg(windows)], and the four call sites invoke it unconditionally. Deleting the stub would force#[cfg(unix)]onto four call sites (4 lines) and spread a platform condition intohelios— a net loss.eos/src/unix.rs:247-248already gives BSD/macOS an empty body without a second stub, so this is the minimal form.helios/src/execution/parallel.rs:539— insideserve_rank, the multi-host peer serving loop used byflare-cli/src/main.rs:560(serve_peer) andheliopause/src/python.rs:548(not opened). Real serving path; keep.helios/src/server/runtime.rs:568— theflare-modelthread that runs the serving loop; this is the pin behind the PR's headline placement result. Keep.eos/src/unix.rs:216-245— theprefer_high_capacity_cpusbody itself: thecpu_set_tscan is the only portable form withlibc's fixed-size mask, the*10 >= *9widening tou64avoids a truncating division that changes boundary behaviour, the ignoredsched_setaffinityresult is correct for a best-effort hint, and the per-threadVec/Stringallocations happen once at thread start. No shorter correct equivalent found.- Existing helpers: searched for anything already doing this —
eosonly haslower_priority(unix.rs:77, nice/SCHED_BATCH), andhelios/src/os.rsmerely re-exportsflare_eos. So the duplication is internal to this PR (finding 1), not a reinvention of an existing helper. prefer_high_capacity_cpuscall sites — exactly four (parallel.rs:539,worker.rs:71,replay.rs:174,server/runtime.rs:568); the minimal form has two plus the new one inroce.rs.
Open questions / what I could not verify
- Is there a no-new-code fix? The charter asks for "a way to solve it without new code at all". A static cpuset (
CPUAffinity=/tasksetto5-9,15-19) would reproduce the placement, and a narrower systemd cpuset per rank could even give per-thread divergence. I could not show from the code that this suffices: the PR pins only two threads while leaving HTTP, frontend, offload and copy threads on the shared core budget, and a whole-process cpuset cannot make that distinction. Report as a question for maintainers, not a finding.- Note for whoever checks: nothing in the repo sets process affinity today (
selene-manager/deploy/seccomp-io-uring.json:309 (not opened),317already allowssched_getaffinity/sched_setaffinity), so no accompanying seccomp/policy change is needed.
- Note for whoever checks: nothing in the repo sets process affinity today (
threaded.rs:652-654(above) — is the in-processflare-rank-Nexecutor the thread the PR actually wanted? If so,worker.rs:71is in the wrong place and the right place is still missing; I am not proposing that addition.- Windows coverage: the PR states the
windows.rsstub was not compiled on Windows. That is a test-coverage gap, not a subtraction, and proposing a test is outside this lens.
Totals
| Change | Lines |
|---|---|
| PR as submitted | +226 / −1 (7 files) |
| Finding 1 — C helper deleted, Rust pin added | −66 / +1 and 1 file |
Finding 2 — fallback, min/max loop, min==max guard, three-tier test |
−36 |
| Finding 3 — replay.rs closure | −4 (+1 restored) |
| Finding 4 — worker.rs pin | −1 |
| After all four | ≈ +119 / −1 across 6 files (≈47 % smaller) |
The reduced change still delivers both headline results: flare-model pinned by runtime.rs:568, serve_rank pinned by parallel.rs:539, and flare-roce inheriting the creating thread's mask from the one new call in roce.rs — no duplicated policy, no edited vendored C body, no code for topologies the project does not target.