code wiki / (root) / nx_swarm_place.nx

nx_swarm_place.nx

buildroot/runtime/nx_swarm_place.nx

14011 B333 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_place.nx -- SWARM FABRIC placement brain (SF-R2): given the fleet snapshot (NODE rows from nx_swarm_beat) pick the best node for a chunky job. The 2025/26 radar's #1+#2 gaps (energy-aware 98 + load-aware 65) in one organ. GREENFIELD: pure integer cost model over the beacon's live truth; freshness is a HARD gate (you cannot place on stale truth -- inherits the beat store's liveness liar-killers); battery politeness EXCLUDES (never cook a phone/laptop); thermal sheds (heavy penalty, still schedulable in an emergency); unknown (-1) sensors are NEUTRAL (honest-absent must not punish a node that cannot report). nx_swarm_place pick <snap> <window_sec> [conf] rank + pick; prints per-node verdicts + winner nx_swarm_place [gate] self-gate (8 tests incl liar-killers) CONF (rule 11, data-driven -- knowledge/swarm/place.conf ships the live lever; bootstrap defaults compiled as the last tier of the config hierarchy): lines "key value": w_load 600 · w_mem 400 · shed_temp_mc 85000 · batt_floor_pct 20 SCORE (0..1000): base = (w_load*load_headroom + w_mem*mem_headroom)/(w_load+w_mem); load_headroom = 1000-lpc clamped; mem_headroom = (100-mem_used_pct)*10 clamped; temp_mc >= shed → base/10. EXCLUDED: stale/forged ts · batt < floor · malformed row. Ties: first-in-snap wins (deterministic). license_tier: ORIGINAL expect_exit:0

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_framed_append.nx nx_swarm_lib.nx nx_swarm_place.nx

imports: nx_syscalls.nxnx_framed_append.nxnx_swarm_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sp_eq sp_puts sys_write fa_len sb_path_ok fa_len ↻ sys_mmap sb_pint fa_len ↻ sp_pick sys_mmap ↻ sp_conf_load sys_mmap ↻ sb_read sys_openat_rd sys_read sys_close sp_starts sb_pint ↻ sb_read ↻ sys_now_us sys_mmap ↻ sys_clock_gettime_mono sb_fields sys_mmap ↻ sb_validate sys_mmap ↻ sb_pint ↻ sb_pint ↻ sb_validate ↻ sp_score sb_fresh fa_cat fa_catn sys_mmap ↻ sys_write ↻ sp_puts ↻ sp_gate sys_now_us ↻

structs

none

consts

22const SP_MAGIC_85000: i64 = 85000
23const SP_MAGIC_1024: i64 = 1024
24const SP_MAGIC_3600: i64 = 3600
25const SP_MAGIC_90000: i64 = 90000
26const SP_MAGIC_40000: i64 = 40000
27const SP_MAGIC_7200000000: i64 = 7200000000
29const SP_SNAP_CAP: i64 = 65536
30const SP_CONF_CAP: i64 = 4096

functions

32func sp_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 }
called by 3: sp_picksp_gatemain calls 2: sys_writefa_len
34func sp_eq(a: *u8, b: *u8) -> i64
called by 2: sp_gatemain
42func sp_starts(buf: *u8, n: i64, p: i64, key: *u8) -> i64
called by 1: sp_conf_load
54func sp_conf_load(path: *u8, c: *i64) -> i64
85func sp_score(f: *i64, now: i64, window_sec: i64, c: *i64, why: *i64) -> i64
called by 1: sp_pick calls 1: sb_fresh
106func sp_pick(snap: *u8, window_sec: i64, confpath: *u8, wname: *u8, wcap: i64) -> i64
180func sp_mkrow(dst: *u8, name: *u8, lpc: i64, memu: i64, ts: i64, temp: i64, batt: i64) -> i64
called by 1: sp_gate calls 2: fa_catfa_catn
200func sp_wfile(path: *u8, buf: *u8, n: i64) -> i64
209func sp_gate() -> i64
316func main(argc: i64, argv: *i64) -> i64