code wiki / (root) / nx_daemon_bench.nx

nx_daemon_bench.nx

buildroot/runtime/nx_daemon_bench.nx

19711 B514 linesdepth 3pulls 5 transitivereach 1 importersview sourcekind benchtopic daemon
docsdependenciesstructsconstsfunctions

about

nx_daemon_bench.nx -- continuous, low-resource, on-device benchmark daemon. Substrate-native equivalent of Criterion.rs / JMH / Google Benchmark / Phoronix Test Suite, baked into the language itself and explicitly designed for Tier-0 (MCU/sensor) operation. license_tier: ORIGINAL MISSION (per FLoC-Olympics + monetization cardinal + sovereign- stack roadmap): NishiLang must compete against and beat every modern continuous-benchmark system, AND the same primitive must run on a sensor with kilobytes of RAM. Sensors that audit themselves at <1% CPU duty cycle are a new product category. DESIGN PRINCIPLES: 1. FIXED-MEMORY STATE. Single mmap at init; never grows. Each derived statistic uses Welford's online algorithm (mean + variance in O(1) memory regardless of cycle count). No sample log, no histogram bins, no growing record ring. Sensor-grade footprint: under 1 KiB of state. 2. DUTY-CYCLE BUDGET. Caller declares max ms/cycle, max bytes, and min_sleep_ms between cycles. Default 100 ms work + 10000 ms sleep -> <1% CPU. Daemon self-polices: cycles exceeding the wall-time budget emit OVERBUDGET and increment a counter. 3. SEALED-ENUM STATUS. Eight states, no weasel intermediates, validated by predicate. Cardinal: feedback-honest-perf-verdict-no-aspirational-claims. 4. REGRESSION DETECTION. Per-axis EMA baseline + Welford variance -> Z-score in Q10. |Z| > 3-sigma -> DEGRADED; |Z| > 5-sigma -> REGRESSION (cardinal requires named_improvement string from caller). 5. TIER-AWARE SKIP. Caller passes the current hardware tier; if below cfg.tier_floor the cycle is skipped (SLEEPING). Cardinal: scale-agnostic-substrate. 6. CARDINAL-COMPLIANCE GATE. Refuses to declare a REGRESSION

dependencies 5 imports · 1 importers

nx_syscalls.nx nx_runtime.nx nx_clock.nx nx_tier.nx nx_benchmark_harness.nx nx_daemon_bench.nx nx_daemon_bench_test.nx

imports: nx_syscalls.nxnx_runtime.nxnx_clock.nxnx_tier.nxnx_benchmark_harness.nx

imported by: nx_daemon_bench_test.nx

structs

121struct DaemonConfig
154struct AxisStats
170struct DaemonState

consts

80const NX_DAEMON_IDLE: nx_int = 0 // init done; no cycle yet
81const NX_DAEMON_WARMING: nx_int = 1 // building baseline
82const NX_DAEMON_HEALTHY: nx_int = 2 // |z| < degrade threshold
83const NX_DAEMON_SLEEPING: nx_int = 3 // between cycles / tier-skip
84const NX_DAEMON_DEGRADED: nx_int = 4 // |z| crossed degrade band
85const NX_DAEMON_REGRESSION: nx_int = 5 // |z| crossed regression band
86const NX_DAEMON_OVERBUDGET: nx_int = 6 // last cycle exceeded ms/bytes
87const NX_DAEMON_STALE: nx_int = 7 // watchdog: no cycle in N intervals
88const NX_DAEMON_N_STATES: nx_int = 8
92const NX_DAEMON_Q: nx_int = 1024
97const NX_DAEMON_DEFAULT_DEGRADE_Z_Q10: nx_int = 3072 // 3.0 * Q10
98const NX_DAEMON_DEFAULT_REGRESS_Z_Q10: nx_int = 5120 // 5.0 * Q10
101const NX_DAEMON_DEFAULT_EMA_ALPHA_Q10: nx_int = 102
104const NX_DAEMON_DEFAULT_WARMUP_CYCLES: nx_int = 8
107const NX_DAEMON_DEFAULT_MAX_MS_PER_CYCLE: nx_int = 100
108const NX_DAEMON_DEFAULT_MIN_SLEEP_MS: nx_int = 10000
111const NX_DAEMON_DEFAULT_MAX_BYTES: nx_int = 65536
114const NX_DAEMON_DEFAULT_STALE_MISSES: nx_int = 3
117const NX_DAEMON_Z_MAX_Q10: nx_int = 32768
191const NX_DAEMON_STATE_BYTES: nx_size = 512

functions

134func nx_daemon_config_defaults(cfg: *DaemonConfig) -> nx_int
called by 1: main
193func nx_daemon_alloc() -> *DaemonState
called by 1: main calls 1: sys_mmap
200func _axis_stats_zero(a: *AxisStats) -> nx_int
214func _config_snapshot(d: *DaemonState, cfg: *DaemonConfig) -> nx_int
called by 1: nx_daemon_init
230func _axis_stats_zero_all(d: *DaemonState) -> nx_int
called by 1: nx_daemon_init calls 1: _axis_stats_zero
242func _zero_cycle_state(d: *DaemonState) -> nx_int
called by 1: nx_daemon_init
256func nx_daemon_init(d: *DaemonState, cfg: *DaemonConfig) -> nx_int
273func _axis_welford_update(a: *AxisStats, x_q10: nx_int) -> nx_int
called by 1: _record_to_axis
282func _axis_ema_update(a: *AxisStats, x_q10: nx_int, alpha_q10: nx_int) -> nx_int
called by 1: _record_to_axis
294func _isqrt(x: nx_int) -> nx_int
called by 1: _axis_zscore_q10
308func _axis_zscore_q10(a: *AxisStats, x_q10: nx_int) -> nx_int
called by 1: _record_to_axis calls 1: _isqrt
332func _axis_at(d: *DaemonState, axis_idx: nx_int) -> *AxisStats
346func _record_to_axis(a: *AxisStats, x_q10: nx_int,
356func nx_daemon_record_sample(d: *DaemonState,
374func nx_daemon_cycle_start(d: *DaemonState, current_tier: nx_int) -> nx_int
called by 1: main calls 1: nx_clock_monotonic_ns
393func _worst_z(d: *DaemonState) -> nx_int
405func _worst_band(d: *DaemonState) -> nx_int
called by 1: nx_daemon_cycle_end calls 1: _worst_z
415func _finalise_cycle(d: *DaemonState, status: nx_int) -> nx_int
called by 1: nx_daemon_cycle_end
425func _band_to_status(band: nx_int) -> nx_int
called by 1: nx_daemon_cycle_end
431func nx_daemon_cycle_end(d: *DaemonState) -> nx_int
449func nx_daemon_watchdog_check(d: *DaemonState) -> nx_int
463func nx_daemon_status_is_valid(s: nx_int) -> nx_int
called by 1: main
471func nx_daemon_set_named_improvement(d: *DaemonState) -> nx_int
called by 1: main
476func nx_daemon_is_cardinal_compliant(d: *DaemonState) -> nx_int
called by 1: main
486func nx_daemon_status_label(s: nx_int) -> *u8
497func nx_daemon_emit_summary(d: *DaemonState) -> nx_int
512func nx_daemon_sleep_until_next(d: *DaemonState) -> nx_int
calls 1: sys_sleep_ms