#1 [high] PR #576 core diff facts (verified at pr/576)
Verified at pr/576 head 4b41ddc:
- eos/src/unix.rs:167-210
select_high_capacity_cpus(pure fn); :212-245prefer_high_capacity_cpus(Linux); :247-248 non-linux unix no-op; tests :250-314 (3 new tests). - Key lines: :173
if allowed_with_capacity.len() < 2 { return None }; :190-194 90% filter (cap*10 >= max*9); :195-204 fallback above midpoint(min+max)when selected<2; :205 final gateselected.len() >= 2 && selected.len() < allowed_with_capacity.len(). - prefer(): :218 sched_getaffinity(0, sizeof(cpu_set_t), ...); :225-236 loop over 0..size_of*8, reads /sys/.../cpu_capacity,
return(abort whole function) on read/parse failure; :240-244 builds next mask,let _ = unsafe { libc::sched_setaffinity(...) }(error silently ignored). - eos/src/windows.rs:219-220 stub
pub fn prefer_high_capacity_cpus() {}. - helios/native/roce_proxy.c:1505-1570
#ifdef __linux__ static void pin_high_capacity_cpus(void); :1521-1542 loop CPU_SETSIZE reading cpu_capacity,returnon fopen fail; :1543if (count < 2 || min_cap == max_cap) return;; :1549-1565 same 90% + midpoint fallback; :1566-1568if (selected >= 2 && selected < count) (void)sched_setaffinity(...). - roce_proxy.c:1572-1577 proxy_main now does
pthread_setname_np(pthread_self(), "flare-roce")then pin. Vendor header roce_proxy.c:6-8 "Keep the source below identical so preparation and serving share the transport ABI." NOTICE:16-19 "Its implementation is unchanged from that revision". THIRD_PARTY_NOTICES.md:48-52. docs/roce-ring.md:361-364 "keep the vendored source identical". docs/TODO.txt:80-86 pre-existing proxy parity debt. - Call sites: helios/src/server/runtime.rs:568 (first stmt of flare-model thread closure, before RankExecutor::new at :585 and crate::offload::open at :698, ImagePreparation::new at :721); helios/src/execution/worker.rs:71 (flare-execution, before RankExecutor::new :76); helios/src/replay.rs:174 (flare-cuda); helios/src/execution/parallel.rs:539 (serve_rank body, runs on caller thread).
- serve_rank is called by flare-cli/src/main.rs:560 (serve_peer) and heliopause/src/python.rs:548 (serve_tensor_parallel_rank via py.detach).
- eos/src/lib.rs:9-16 re-exports unix::* / windows::*.
- threaded TP rank threads: helios/src/execution/threaded.rs:652-678 spawn "flare-rank-{i+1}" with NO direct call; inherit parent's mask when created under flare-model (:568) or flare-execution (worker.rs:71). ExecutionWorker doc says it is only "bootstrap/qualification callers" (worker.rs:36-37).
- Doc that affinity needs a serving-latency measurement: docs/prefix-cache-offload.md:863-867 ("Both use SCHED_BATCH with a positive nice value ... Adding CPU affinity requires a serving-latency measurement that shows a benefit."). Offload threads are deliberately demoted: helios/src/offload/transfer.rs:509-531 (lower_priority() at :531), selene/src/input.rs:268-271 (lower_priority at :271).
- Base main build: helios/build.rs compiles roce_proxy_dlopen.c (#589); at pr/576 build.rs:69-76 still compiles native/roce_proxy.c directly.
#2 [high] Lens findings: correctness/contracts/system consequences
F1 BLOCKER Vendor-file contract break. roce_proxy.c:1505-1570 helper + :1574-1577 calls falsify roce_proxy.c:8 "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.", THIRD_PARTY_NOTICES.md:48-52, docs/roce-ring.md:361-364 "keep the vendored source identical". docs/TODO.txt:80-86 already tracks proxy-parity debt and is NOT updated. After #589 main's helios/build.rs:67-77 compiles only native/roce_proxy_dlopen.c (:72, whose header :7-9 says "keeping the vendored roce_proxy.c byte-for-byte identical to FlashInfer"), so a Flare-owned seam exists; at pr/576 build.rs:69-73 still compiles roce_proxy.c directly. Also the helper duplicates the Rust logic in C, untested on any CI.
F2 MAJOR (system-level, doc-contradicting). runtime.rs:568 is the FIRST statement of the flare-model closure, so every later child thread inherits the narrowed mask: RankExecutor::new :585, offload::open :698 (spawns flare-offload-{rank} at transfer.rs:509-511 and DiskThread at transfer.rs:531 / selene/src/offload.rs:676 / selene/src/disk.rs:358-360, input.rs:268-271), ImagePreparation::new :721 (thread::spawn :1011), and the rayon codec pool selene/src/shared/codec.rs:37-56. Those threads are deliberately demoted (SCHED_BATCH + nice 10: eos/src/unix.rs:77-83, transfer.rs:281-283, selene/src/disk.rs:489-491, selene/src/input.rs:271) precisely so they can spill off the model cores. docs/prefix-cache-offload.md:863-867 states the in-tree policy: "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." PR supplies no such measurement and no doc update.
F3 MAJOR secondary effect: selene/src/shared/codec.rs:40-46 sizes the KV codec pool from std::thread::available_parallelism(), which on Linux honours the calling thread's affinity mask; because cpu_pool() is first initialised lazily on an offload thread (helios/src/offload/transfer/codec.rs:353,514) spawned after runtime.rs:568, the pool halves (20 CPUs->10 threads becomes 10->5) and its threads are then also pinned to the X925 subset with nice 10 — CPU parallelism silently shrinks on exactly the prefix-cache/encode path this PR does not benchmark. Same class: helios/src/frontend/mod.rs:333-337.
F4 MAJOR caller-thread mutation, no restore. parallel.rs:539 runs at the top of the unsafe pub fn serve_rank whose doc (:527-532) documents no affinity effect. Callers: flare-cli/src/main.rs:560 (process main thread) and heliopause/src/python.rs:548 inside py.detach (the Python interpreter thread of an in-process rank). The narrowed mask persists after drain and is inherited by every thread that process/Python then creates; no restore, no return value, so the caller cannot know. The sibling sites (worker.rs:71, replay.rs:174, runtime.rs:568) are first statements of freshly spawned threads — serve_rank is the outlier.
F5 MAJOR uncovered path relies on inheritance. threaded.rs:652-678 spawns "flare-rank-{i+1}" with no direct call; also worker.rs:71's flare-execution thread is documented as bootstrap/qualification only (worker.rs:36-37 "Synchronous control surface for bootstrap/qualification callers... The native scheduler owns its rank executor directly"), so the serving path's pinning depends entirely on inherited masks from runtime.rs:568. No test asserts affinity; the reviewer's proposed Rust-side move would reintroduce the gap.
F6 MINOR ≥2-CPU guard does not consider thread count. eos/src/unix.rs:205 if selected.len() >= 2 && selected.len() < allowed_with_capacity.len(); roce_proxy.c:1566 identical. A mask of {2 perf, k eff} collapses k+2 threads onto 2 cores; GB10 mask of 10 perf keeps 10 for model+proxy+replay+offload+codec threads. No runtime check, no warning.
F7 MINOR silent/arbitrary threshold, errors dropped: eos/src/unix.rs:244 let _ = unsafe { libc::sched_setaffinity(...) }; roce_proxy.c:1567 (void)sched_setaffinity(...). A near-homogeneous machine with one core a few % below max (e.g. 900 vs 1024: 9000 < 9216) is silently dropped at :192 / :1550. No log line, metric, flag, config or env (AGENTS.md:449-452 forbids env switches), so the behaviour is unobservable and cannot be A/B'd except through the added thread rename.
F8 MINOR test/CI coverage. Only the pure selector is tested (eos/src/unix.rs:254-314). prefer_high_capacity_cpus and pin_high_capacity_cpus never execute in CI: .github/workflows/native-serving.yml:18-21 matrix is ubuntu-24.04 x86_64 + windows-2022, the rdma job (:109-113) only cargo-checks, so on x86 the sysfs read fails and the no-op path runs. The two implementations already differ (Rust returns None on cap==0 at :179-181, C returns early at :1534; Rust uses size_of(cpu_set_t)*8, C CPU_SETSIZE) with no shared test vector.
CLAIMS: PR says "x86_64 ... 100% no-op" (true, verified) and "Strict no-op when cpu_capacity is absent, homogeneous, or already single-tier" (true). "48/48 critical threads pinned" is measured through the same PR's pthread_setname_np("flare-roce") (roce_proxy.c:1575) plus scripts/profile_ds41_decode.py:36 reading /proc//task//comm — the measurement instrument is added by the change under test. PR title/body scope "Pin Helios execution and RoCE proxy threads" understates that every later child thread is narrowed.
#4 [high] Corrected spawn chain for F2/F3
- flare-offload-{rank} thread: spawned at helios/src/offload/transfer.rs:509-511 inside the flare-model thread's call chain runtime.rs:698 crate::offload::open -> helios/src/offload/mod.rs:105-113 -> selene/src/offload.rs:645/653 factory.mapped; lower_priority() called at transfer.rs:531.
- flare-offload-disk: selene/src/offload.rs:676 DiskThread::start("flare-offload-disk") -> selene/src/disk.rs:337-360 spawn -> disk.rs:470 lower_priority().
- ImagePreparation thread: runtime.rs:1011 thread::spawn inside ImagePreparation::new, called at runtime.rs:721.
- rayon KV codec pool: selene/src/shared/codec.rs:37-56, threads = available_parallelism()/2 clamped 1..24, start_handler libc::nice(10); first initialised lazily via helios/src/offload/transfer/codec.rs:353 or :514 (both on offload threads), so its size is computed from the narrowed mask.
- eos/src/unix.rs:77-83 lower_priority = SCHED_BATCH + setpriority(nice).
#5 [high] Research summary
I completed the Correctness, Contracts & System-Level Consequences lens over all 7 changed files, their opaque/direct callers (runtime.rs, worker.rs, replay.rs, parallel.rs/serve_rank, threaded.rs, offload transfer/disk/input, selene codec pool, flare-cli serve_peer, heliopause python), the vendor-contract documents (roce_proxy.c header, NOTICE, THIRD_PARTY_NOTICES.md, docs/roce-ring.md, docs/TODO.txt), the in-tree policy doc (docs/prefix-cache-offload.md:863-867), and CI (.github/workflows/native-serving.yml (not opened)). Eight findings are on the scratchpad with exact file:line citations, verbatim quotes, severity, impact and fix, plus a note recording the areas I verified as sound (no lock/allocation/hot-path contention, no wire or captured-graph contract change, safe no-op fallbacks, strands-free selection).
Headlines: (1) Blocker — the 66-line in-vendor C helper plus pthread_setname_np falsify four in-tree witnesses of the "keep the vendored source identical" invariant (roce_proxy.c:8, NOTICE:18-19, THIRD_PARTY_NOTICES.md:48-52, docs/roce-ring.md:361-364) and leave docs/TODO.txt:80-86 unamended, in the one file #589's new Flare-owned roce_proxy_dlopen.c seam exists to keep untouched. (2) Major — runtime.rs:568 is the first statement of the flare-model closure, so every later child thread (ranks, offload, disk, image preparation, the rayon KV-codec pool) inherits the narrowed X925-only mask despite being deliberately demoted with SCHED_BATCH/nice so they can spill onto efficiency cores, contradicting docs/prefix-cache-offload.md:863-867, which requires a serving-latency measurement for exactly this. (3) Major follow-on — selene/src/shared/codec.rs:41 sizes the codec pool from available_parallelism(), which honours the inherited narrowed mask, silently halving host encode parallelism on the prefix-cache path. (4) Major — parallel.rs:539 mutates the caller's mask inside an unsafe function whose doc says nothing about it, with no restore, affecting rank threads in-process and the Python interpreter thread via py.detach. Remaining findings cover the inheritance-only coverage of flare-rank-*, the ≥2-vs-thread-count guard, silent unobservable error-dropping, and that neither new affinity function runs in any CI job. Claim accuracy: the x86 no-op and homogeneity claims verify; the "48/48 threads pinned" evidence depends on the thread rename this same PR introduces.
#6 [high] Verbatim quote bank + concrete fixes per finding (F1-F8)
F1 BLOCKER — vendored-file divergence.
Quotes (all verified at pr/576):
(a) helios/native/roce_proxy.c:6-8
// Vendored from FlashInfer's pinned preparation dependency
// (flashinfer/experimental/b12x/comm/roce/_roce_proxy.c, proxy ABI 14).
// Keep the source below identical so preparation and serving share the transport ABI.
(b) NOTICE:16-19
helios/native/roce_proxy.c was contributed by its original author from:
https://github.com/local-inference-lab/flashinfer/blob/f5f5341d.../_roce_proxy.c
The proxy is compiled into Linux aarch64 builds. Its implementation is unchanged
from that revision; Flare adds a license and provenance preamble.
(c) THIRD_PARTY_NOTICES.md:48-52 "The Linux aarch64 runtime also compiles the RoCE proxy in helios/native/roce_proxy.c, contributed by its original author from the pinned FlashInfer/b12x source."
(d) docs/roce-ring.md:362-364 "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."
(e) main's helios/native/roce_proxy_dlopen.c:7-9 "Loads libibverbs.so.1 lazily with dlopen ... while keeping the vendored roce_proxy.c byte-for-byte identical to FlashInfer." and main helios/build.rs:70-74 compiles only native/roce_proxy_dlopen.c.
Fix: move the pin into Flare-owned code — call flare_eos::prefer_high_capacity_cpus() on the proxy thread after roce_start, or set the name/mask from a new Flare-owned wrapper in roce_proxy_dlopen.c (the file Flare already owns and builds); leave roce_proxy.c byte-identical; update THIRD_PARTY_NOTICES.md/docs/roce-ring.md only if the vendored copy stays untouched, otherwise record the divergence in docs/TODO.txt:80-86.
F2 MAJOR — inheritance blast radius. Quote A (helios/src/server/runtime.rs:565-571): let thread = thread::Builder::new() .name("flare-model".into()) .spawn(move || { flare_eos::prefer_high_capacity_cpus(); if matches!(peers, Some(crate::execution::RankPeers::Processes(_))) && manifest.offload.as_ref().is_some_and(|binding| !binding.sharded()) Quote B (docs/prefix-cache-offload.md:863-867):
- CPU: transfer threads sleep on event waits and channel receives; the disk
thread computes checksums and submits I/O. Both use
SCHED_BATCHwith a positive nice value to reduce contention with the model worker, HTTP runtime, and frontend workers. Adding CPU affinity requires a serving-latency measurement that shows a benefit. Quote C (helios/src/offload/transfer.rs:509-511 name + :531 lower_priority()): let thread = std::thread::Builder::new() .name(format!("flare-offload-{rank}")) .spawn(move || { ... }); ... lower_priority(); Impact: crate::offload::open at runtime.rs:698 spawns flare-offload-{rank} (transfer.rs:509), flare-offload-disk (selene/src/offload.rs:676 -> disk.rs:358-360) and flare-input-records (selene/src/input.rs:268-271); ImagePreparation::new at runtime.rs:721 spawns its thread at runtime.rs:1011. All inherit the X925-only mask and are then demoted with SCHED_BATCH/nice 10, so they lose the efficiency cores they were demoted into, concentrating host I/O and checksum work on the cores the model needs. Fix: pin only the intended threads (call the helper inside the worker closures that own latency-critical posting, as worker.rs:71/replay.rs:174 already do) instead of at the head of the flare-model closure, or explicitly restore/fork the mask before offload::open and ImagePreparation::new.
F3 MAJOR — codec pool shrinks (consequence of F2). Quote (selene/src/shared/codec.rs:40-46): POOL.get_or_init(|| { let threads = std::thread::available_parallelism() .map(|n| (n.get() / 2).clamp(1, 24)) .unwrap_or(4); rayon::ThreadPoolBuilder::new() .num_threads(threads) .thread_name(|i| format!("flare-kv-codec-{i}")) Impact: first init happens on a narrowed offload thread (helios/src/offload/transfer/codec.rs:353,514), so available_parallelism()—which honours the caller's affinity mask—reports the X925 subset; pool size and its own affinity both shrink although nothing measured this path. Same class as helios/src/frontend/mod.rs:333-337. Fix: size the pool from the process-start mask (cache available_parallelism() before any narrowing, or compute from /sys cpu_capacity totals) and leave its threads on the demoted default mask.
F4 MAJOR — caller-thread mutation in serve_rank. Quote (helios/src/execution/parallel.rs:527-539): /// Run a peer's native control loop until coordinated drain and release. /// /// # Safety /// The caller retains all graph owners and b12x IPC mappings when drained is /// false. ... pub unsafe fn serve_rank( manifest: ExecutionManifest, socket: RankStream, rank: usize, world: usize, ) -> Shutdown { flare_eos::prefer_high_capacity_cpus(); Impact: runs on the caller's own thread — flare-cli/src/main.rs:560 (process main thread of a peer rank) and heliopause/src/python.rs:548 (the Python interpreter thread of an in-process rank, inside py.detach). The narrowed mask survives drain, so every thread that process or Python later creates is confined to the performance cores; the function returns only Shutdown, so the caller cannot observe or undo it, and the documented Safety contract does not mention an affinity side effect. Fix: drop this call site (the rank's executor closure can pin itself) or restore the saved mask before returning and document the effect in the Safety section.
F5 MAJOR — threaded TP ranks pinned only by inheritance. Quote (helios/src/execution/threaded.rs:652-654): let thread = thread::Builder::new() .name(format!("flare-rank-{}", index + 1)) .spawn(move || { let _exit_guard = PeerExitGuard(peer_ring.clone()); Quote (helios/src/execution/worker.rs:36-37): /// Synchronous control surface for bootstrap/qualification callers on other threads. /// The native scheduler owns its rank executor directly without this channel boundary. Impact: no flare-rank-* thread calls the helper; in serving they are pinned only because runtime.rs:568 narrowed the parent first, and in worker.rs the pinch thread is documented as bootstrap-only. Coverage is accidental, and the reviewer's suggested move (call just before worker.run) would silently unpin them. Fix: call prefer_high_capacity_cpus() at the head of the flare-rank-* closure too, plus a regression test asserting the child mask.
F6 MINOR — ≥2-CPU guard ignores thread count. Quote (eos/src/unix.rs:195-209): 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)... } if selected.len() >= 2 && selected.len() < allowed_with_capacity.len() { Some(selected) } else { None } C twin at roce_proxy.c:1555-1568. Impact: the floor is 2 regardless of how many threads are being confined (model worker + replay + proxy + TP ranks + offload), so on a 2P+8E or three-tier cpuset those threads share 2 cores. Fix: floor at the caller's expected thread count (or log/refuse when the selected set is smaller than the number of threads being pinned).
F7 MINOR — silent, unobservable, arbitrary threshold.
Quote (eos/src/unix.rs:240-244):
let mut next: libc::cpu_set_t = unsafe { std::mem::zeroed() };
for cpu in selected {
unsafe { libc::CPU_SET(cpu, &mut next) };
}
let _ = unsafe { libc::sched_setaffinity(0, std::mem::size_of::libc::cpu_set_t(), &next) };
and roce_proxy.c:1566-1567 if (selected >= 2 && selected < count) { (void)sched_setaffinity(0, sizeof(next), &next); }.
Impact: failures are discarded; the 90% cut (eos/src/unix.rs:190-194 cap * 10 >= max_cap * 9; roce_proxy.c:1550) silently drops a near-homogeneous tier (e.g. 900 vs 1024). No log line, metric, flag, config or env (AGENTS.md:449-452 forbids env switches), so an operator cannot tell whether the pin happened — it is only visible through the thread rename this same PR adds. Fix: return/report the decision (log once at startup or expose a metric) and derive the threshold from a measured, documented rule rather than a bare 0.9 constant.
F8 MINOR — untested paths, divergent twins.
Quote (.github/workflows/native-serving.yml:16-21):
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
- os: windows-2022
target: x86_64-pc-windows-msvc
and :109-113 the rdma job only cargo checks. Impact: only the pure selector is tested (eos/src/unix.rs:254-314); neither prefer_high_capacity_cpus nor pin_high_capacity_cpus ever executes in CI, and the two copies already differ (Rust rejects cap==0 at :179-181 and iterates size_of(cpu_set_t)*8 at :223; C rejects at :1534 and iterates CPU_SETSIZE at :1521) with no shared vector. Fix: extract a table-driven test that feeds both implementations the same (cpu, capacity) fixtures (e.g. compile the C helper behind a test entry point), or drop the C duplicate in favour of the Rust call.
#3 [medium] Areas verified sound in this lens
- eos/src/lib.rs:9-16 re-exports unix::/windows::;
prefer_high_capacity_cpushas #[cfg(target_os = "linux")] at eos/src/unix.rs:215 and a not-linux no-op at :247-248, so macOS/BSD unix builds compile; eos/src/windows.rs:219-220 stub keeps the Windows surface identical. - No shared state, no lock, no allocation on hot paths: the Linux path does one sched_getaffinity, up to size_of(cpu_set_t)*8 = 1024 CPU_ISSET checks and at most one /sys read per allowed CPU, once per thread creation (not per request). No unbounded buffering, no I/O in the serving loop.
- The printf-free C helper only touches its own stack (int cpus[CPU_SETSIZE], uint32_t caps[CPU_SETSIZE]) and is called once before the poll loop (roce_proxy.c:1576), so no added latency or contention on the polling path.
- sched_setaffinity on self cannot race with a concurrent setter within these paths; failure leaves the mask unchanged, so the failure mode is benign (silently wider affinity), not a hang or a poisoned executor.
- roi: select_high_capacity_cpus never returns an empty or single-element set (eos/src/unix.rs:205), so no thread can be stranded on a bound-out CPU; CPU_SET is only called with ids present in the source mask (:241-243).
- Affinity narrowing cannot affect the RoCE transport ABI or the ctrl-page protocol: roce_start (roce_proxy.c:1661-1681) is unchanged in ordering, and the missed-doorbell catch-up (:1611-1620) explicitly tolerates the thread being moved by the scheduler.
- No captured-graph/wire/protobuf change at all in the 7 files (pr_files): nothing here needs captured-graph op-contract owner sign-off; the contract friction is the vendored-C invariant, not the wire ABI.