Conventions and duplication review — PR #576 (pin Helios/RoCE-proxy threads to high-capacity CPUs)
Key findings
Two confirmed findings, neither blocking.
- Should fix — one policy, two languages, no shared source, and the second copy is an unmarked edit to a vendored file.
pin_high_capacity_cpus()inhelios/native/roce_proxy.c:1505-1570is a line-for-line reimplementation ofselect_high_capacity_cpus+prefer_high_capacity_cpusineos/src/unix.rs:172-245.eos/is documented as the single home for host OS operations (AGENTS.md:20-22), androce_proxy.cis documented as byte-identical to the pinned FlashInfer source after its provenance header (roce_proxy.c:6-8,NOTICE:18-19,docs/roce-ring.md:361-364). The new block, plus the"flare-roce"thread name at:1575, breaks the second rule without any marker distinguishing Flare-local code from vendored code. - Nit — the new eos helper departs from the only precedent for per-thread scheduling changes,
lower_priority(nice)(eos/src/unix.rs:77-83/eos/src/windows.rs:160-164): it hardwires its policy instead of taking a parameter, returns()and dropssched_setaffinity's error while neighbouring eos helpers report their outcome, adds a stub that duplicateswindows.rs:219-220, and is called directly asflare_eos::…rather than through thecrate::os::shim every other OS call in Helios uses.
Verified as already conforming: the four new call sites follow the existing "name the thread, then configure it inside the closure" pattern, and "flare-roce" fits the existing flare-* naming scheme. No pre-existing CPU-affinity helper existed to reuse. Coverage note (not a finding): the in-process flare-rank-{n} TP threads get no call.
Should fix
1. helios/native/roce_proxy.c:1505-1570 — the C helper reimplements the Rust selector, and the vendored file is supposed to stay identical to upstream
What is wrong. The new static void pin_high_capacity_cpus(void) is an element-for-element port of the Rust code added in the same PR:
| Policy element | C (roce_proxy.c) |
Rust (eos/src/unix.rs) |
|---|---|---|
| sysfs path | :1526 snprintf(…, "/sys/devices/system/cpu/cpu%d/cpu_capacity") |
:227 format!("/sys/devices/system/cpu/cpu{cpu}/cpu_capacity") |
| give up on first unreadable/zero capacity | :1528-1536 |
:228-233 |
| 90% threshold | :1550 (uint64_t)caps[i] * 10 >= (uint64_t)max_cap * 9 |
:192 u64::from(cap) * 10 >= u64::from(max_cap) * 9 |
| midpoint fallback (never collapse to one core) | :1555-1565 cap*2 > min+max |
:196-204 |
safety gate selected >= 2 && selected < count |
:1566 |
:205 |
Two copies of one policy in two languages with no shared source. Any future change to the threshold, the fallback, or the sysfs path must be made twice, and only the Rust copy is tested: eos/src/unix.rs:254-314 covers GB10 two-tier, homogeneous, single-tier, zero-capacity and three-tier topologies, while the C copy has no test and is compiled only under --features roce (helios/build.rs:67-76).
Why it matters (duplication convention). AGENTS.md:20-22: "The eos/ crate holds the host operating-system operations that Helios and Selene use." The Helios side does not add OS code of its own — helios/src/os.rs:8 is nothing but pub(crate) use flare_eos::*;. A host-OS policy implemented a second time inside a C file in helios/native/ bypasses that arrangement entirely.
Why it matters (vendored-file convention). Three places state the same rule for this file:
roce_proxy.c:6-8: "Vendored from FlashInfer's pinned preparation dependency … Keep the source below identical so preparation and serving share the transport ABI."NOTICE:18-19: "Its implementation is unchanged from that revision; Flare adds a license and provenance preamble."docs/roce-ring.md:361-364: "Flare vendors the serving proxy inhelios/native/roce_proxy.c; preparation uses the pinned FlashInfer dependency. When changing the protocol, keep the vendored source identical to the dependency after its provenance header and verify their ABI and collective-region layouts together."
The new #ifdef __linux__ block and the pthread_setname_np(..., "flare-roce") at :1575 are Flare-local behaviour with no marker separating them from upstream text, so the next parity check cannot tell vendored lines from local ones. docs/TODO.txt:80-86 already tracks "Restore preparation/serving RoCE proxy parity … verifying their ABI and collective-region layouts together"; an unmarked divergence makes that reconciliation harder, and preparation (which runs the pinned FlashInfer proxy) will not get the same pinning, so preparation and serving no longer behave alike on the asymmetric hosts this PR targets.
Fix. Either (a) put the selection policy in one place compiled for both consumers (a small shared header/source that the Rust crate links and the C proxy includes), or (b) at minimum delimit the added block and the thread-name line as a clearly marked Flare addition (comment banner naming this PR/reason) and record the divergence next to the parity procedure in docs/roce-ring.md:355-364 and in the provenance header at roce_proxy.c:6-8, so the parity check knows what to exclude.
2. helios/native/roce_proxy.c:1575 — a second unmarked local behaviour change in the same vendored function
(void)pthread_setname_np(pthread_self(), "flare-roce"); changes what ps/top and perf/nsys see for the vendored proxy thread. The name fits Helios's existing flare-* scheme (helios/src/execution/worker.rs:69 "flare-execution", helios/src/replay.rs:172 "flare-cuda", helios/src/server/runtime.rs:566 "flare-model"), so the naming itself is fine; the problem is only that it is another silent edit to a file declared unchanged. Same fix as finding 1: mark it, and record it.
Nits
3. eos/src/unix.rs:212-248 (and :247-248) — API shape departs from the lower_priority precedent
- Hardwired policy, no parameter. The only prior eos helper that changes the calling thread's scheduling is
lower_priority(nice)(eos/src/unix.rs:77-83, stubeos/src/windows.rs:160-164), which takes its policy as an argument.prefer_high_capacity_cpus()instead embeds the 90%/midpoint rule in the OS layer, so a second consumer that wants a different rule — or a caller that wants to know which CPUs were chosen — cannot reuse it. (The pure selectorselect_high_capacity_cpusat:172-207is the reusable piece and is public, which partly mitigates this.) - Result dropped.
:244islet _ = unsafe { libc::sched_setaffinity(…) };and:228-233returns silently on unreadable capacity, while neighbours report outcome (free_space:116→io::Result<u64>,raise_open_file_limit:138→Option<u64>).lower_priorityis also infallible-by-omission, so this is a mild departure, but the new helper's whole purpose is a placement claim that operators will want to verify. - Duplicated third stub.
:247-248#[cfg(not(target_os = "linux"))] pub fn prefer_high_capacity_cpus() {}repeatseos/src/windows.rs:219-220verbatim in body.eos/src/lib.rs:9-16already splits the modules bycfg(unix)/cfg(windows), andlower_priorityis defined exactly once per module with no third arm (unix.rs:77,windows.rs:160). On the two platforms Flare ships (Linux, Windows) the new arm never compiles; on any other unix target it would be the live definition and the windows body is unreachable. Two identical empty bodies is one more than the module split needs. - Fix: give the helper a parameter (e.g. a capacity ratio) or return the chosen
Vec<usize>/io::Result<()>, let thesched_setaffinityerror surface at least as a returned result, and drop the third cfg arm in favour of the module split.
4. helios/src/execution/parallel.rs:539, worker.rs:71, replay.rs:174, server/runtime.rs:568 — call sites bypass the crate::os:: shim
Every other host-OS call in Helios goes through the crate shim crate::os:: (helios/src/os.rs:8 re-exports flare_eos::*): crate::os::lower_priority(NICE) at helios/src/offload/transfer.rs:282, crate::os::raise_open_file_limit at helios/src/runtime_core/protection.rs:356, crate::os::page_size/map_host at helios/src/cuda.rs:431 (not opened),1478, and ~15 more (helios/src/engram/reader.rs:75,86,190, helios/src/runtime_core/archive.rs:922 (not opened),1052, helios/src/startup.rs:498 (not opened), …). The four new lines call flare_eos::prefer_high_capacity_cpus() directly, which skips the one indirection that exists so Helios can adapt or wrap an OS operation in one place (it is what lets os.rs add the crate-local cuda_library/terminal_size variants alongside the re-export). helios/src/lib.rs:36 similarly re-exports raise_open_file_limit. Nit: use crate::os::prefer_high_capacity_cpus() at all four sites.
5. Documentation — no design/operating document records the new affinity policy
docs/prefix-cache-offload.md:863-867 sets the repository's bar for exactly this kind of change: "Both use SCHED_BATCH with a positive nice value to reduce contention with the model worker … Adding CPU affinity requires a serving-latency measurement that shows a benefit." The PR description does supply measurements, so the bar is met in the PR body, but nothing durable records the policy: docs/standards/docs/operating.md (not opened)/docs/roce-ring.md do not state that critical serving threads are narrowed to the high-capacity tier, that this is a no-op on x86_64, or that the 5-9,15-19 placement is a qualified configuration with the numbers behind it. AGENTS.md:52-59 also draws the line between design documents (state support as present qualification: what is implemented, on which hardware, and what is not) and docs/TODO.txt (unrun checks, pending measurements). Nit: record the policy and its qualification boundary in the operating/roce-ring docs, citing the measured benefit, rather than leaving it in the PR description only.
Checked and cleared (recorded so they are not re-raised)
- Call-site pattern matches precedent.
helios/src/execution/worker.rs:68-71,helios/src/replay.rs:170-176,helios/src/server/runtime.rs:565-568insert the call as the first statement inside an already-named spawned thread, andhelios/src/execution/parallel.rs:539puts it at the top ofserve_rank(the per-process rank entry, called fromflare-cli/src/main.rs:559-561andheliopause/src/python.rs:548(not opened)). This is the same "spawn, then configure inside the closure" shape ashelios/src/offload/transfer.rs:509-531, and the namesflare-execution/flare-cuda/flare-modelare untouched. "flare-roce"fits the naming scheme —flare-execution(worker.rs:69),flare-cuda(replay.rs:172),flare-model(runtime.rs:566),flare-offload-{rank}(transfer.rs:510), plusflare-rank-{n}(helios/src/execution/threaded.rs:652-654). No other Rust thread sets its name throughpthread_setname_np; the C addition is the only such site in the tree, so it cannot drift from a Rust precedent.- No existing helper was available to reuse. Tree-wide, the only
sched_getaffinity/sched_setaffinity/CPU_SEThits are this PR's two copies (eos/src/unix.rs:218-244,helios/native/roce_proxy.c:1512-1567); other hits are unrelated —ignition/preparation/host_memory.py:31(not opened) (worker budget),selene-manager/deploy/seccomp-io-uring.json:309 (not opened),317(syscall allowlist) — and allavailable_parallelism()uses (helios/src/frontend/mod.rs:334,helios/src/core/export.rs:1088(not opened), …) are thread-budget counts, not affinity. So there is no duplicated existing abstraction beyond the Rust/C pair reported above. - Coverage note, not a finding (completeness is another lens): the in-process TP peer threads named
flare-rank-{n}athelios/src/execution/threaded.rs:652-654do the same GPU launch work asflare-executionbut receive no call. That is defensible — all ranks share one process and one affinity mask, and a GB10 node has 20 cores for a handful of busy threads — so I am only recording it.
Open questions / what could not be settled from the code
- Whether the vendored file is actually still identical to the pin.
NOTICE:18-19androce_proxy.c:6-8name two different revisions (f5f5341d…in NOTICE vs "proxy ABI 14" in the header), anddocs/TODO.txt:80-86describes an ABI skew (pin says 11, vendored file 10, loader accepts 9/10) that does not match this PR's "proxy ABI remains 14". A diff ofhelios/native/roce_proxy.cagainst the pinned FlashInfer file at the revision the header names would settle whether this PR is the first or only divergence; only that diff can tell. - Whether the C and Rust copies actually agree on every input. They agree line-for-line as written, but with no test on the C side only inspection supports that; the Rust tests at
eos/src/unix.rs:254-314do not cover the C copy, andhelios/build.rs:67-76compiles it only under--features roce. - Whether operator-visible telemetry exposes the chosen set.
prefer_high_capacity_cpus()returns()and discardssched_setaffinity's error (unix.rs:244), so nothing in the codebase can confirm placement after the fact; the PR's placement evidence comes from external tooling (itsnsysruns and a manual check), not from the runtime. If placement is meant to be a supported property, returning the selected set would let a startup log or health check report it. A startup assertion or log line on a GB10 host would settle whether the narrowing fires as intended in production.