nx_daemon_bench.nx
buildroot/runtime/nx_daemon_bench.nx
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
imports: nx_syscalls.nxnx_runtime.nxnx_clock.nxnx_tier.nxnx_benchmark_harness.nx
imported by: nx_daemon_bench_test.nx
structs
| 121 | struct DaemonConfig |
| 154 | struct AxisStats |
| 170 | struct DaemonState |
consts
| 80 | const NX_DAEMON_IDLE: nx_int = 0 // init done; no cycle yet |
| 81 | const NX_DAEMON_WARMING: nx_int = 1 // building baseline |
| 82 | const NX_DAEMON_HEALTHY: nx_int = 2 // |z| < degrade threshold |
| 83 | const NX_DAEMON_SLEEPING: nx_int = 3 // between cycles / tier-skip |
| 84 | const NX_DAEMON_DEGRADED: nx_int = 4 // |z| crossed degrade band |
| 85 | const NX_DAEMON_REGRESSION: nx_int = 5 // |z| crossed regression band |
| 86 | const NX_DAEMON_OVERBUDGET: nx_int = 6 // last cycle exceeded ms/bytes |
| 87 | const NX_DAEMON_STALE: nx_int = 7 // watchdog: no cycle in N intervals |
| 88 | const NX_DAEMON_N_STATES: nx_int = 8 |
| 92 | const NX_DAEMON_Q: nx_int = 1024 |
| 97 | const NX_DAEMON_DEFAULT_DEGRADE_Z_Q10: nx_int = 3072 // 3.0 * Q10 |
| 98 | const NX_DAEMON_DEFAULT_REGRESS_Z_Q10: nx_int = 5120 // 5.0 * Q10 |
| 101 | const NX_DAEMON_DEFAULT_EMA_ALPHA_Q10: nx_int = 102 |
| 104 | const NX_DAEMON_DEFAULT_WARMUP_CYCLES: nx_int = 8 |
| 107 | const NX_DAEMON_DEFAULT_MAX_MS_PER_CYCLE: nx_int = 100 |
| 108 | const NX_DAEMON_DEFAULT_MIN_SLEEP_MS: nx_int = 10000 |
| 111 | const NX_DAEMON_DEFAULT_MAX_BYTES: nx_int = 65536 |
| 114 | const NX_DAEMON_DEFAULT_STALE_MISSES: nx_int = 3 |
| 117 | const NX_DAEMON_Z_MAX_Q10: nx_int = 32768 |
| 191 | const NX_DAEMON_STATE_BYTES: nx_size = 512 |
functions
| 134 | func nx_daemon_config_defaults(cfg: *DaemonConfig) -> nx_int called by 1: main |
| 193 | func nx_daemon_alloc() -> *DaemonState |
| 200 | func _axis_stats_zero(a: *AxisStats) -> nx_int called by 1: _axis_stats_zero_all |
| 214 | func _config_snapshot(d: *DaemonState, cfg: *DaemonConfig) -> nx_int called by 1: nx_daemon_init |
| 230 | func _axis_stats_zero_all(d: *DaemonState) -> nx_int |
| 242 | func _zero_cycle_state(d: *DaemonState) -> nx_int called by 1: nx_daemon_init |
| 256 | func nx_daemon_init(d: *DaemonState, cfg: *DaemonConfig) -> nx_int |
| 273 | func _axis_welford_update(a: *AxisStats, x_q10: nx_int) -> nx_int called by 1: _record_to_axis |
| 282 | func _axis_ema_update(a: *AxisStats, x_q10: nx_int, alpha_q10: nx_int) -> nx_int called by 1: _record_to_axis |
| 294 | func _isqrt(x: nx_int) -> nx_int called by 1: _axis_zscore_q10 |
| 308 | func _axis_zscore_q10(a: *AxisStats, x_q10: nx_int) -> nx_int |
| 332 | func _axis_at(d: *DaemonState, axis_idx: nx_int) -> *AxisStats |
| 346 | func _record_to_axis(a: *AxisStats, x_q10: nx_int, |
| 356 | func nx_daemon_record_sample(d: *DaemonState, |
| 374 | func nx_daemon_cycle_start(d: *DaemonState, current_tier: nx_int) -> nx_int |
| 393 | func _worst_z(d: *DaemonState) -> nx_int |
| 405 | func _worst_band(d: *DaemonState) -> nx_int |
| 415 | func _finalise_cycle(d: *DaemonState, status: nx_int) -> nx_int called by 1: nx_daemon_cycle_end |
| 425 | func _band_to_status(band: nx_int) -> nx_int called by 1: nx_daemon_cycle_end |
| 431 | func nx_daemon_cycle_end(d: *DaemonState) -> nx_int |
| 449 | func nx_daemon_watchdog_check(d: *DaemonState) -> nx_int calls 1: nx_clock_monotonic_ns |
| 463 | func nx_daemon_status_is_valid(s: nx_int) -> nx_int called by 1: main |
| 471 | func nx_daemon_set_named_improvement(d: *DaemonState) -> nx_int called by 1: main |
| 476 | func nx_daemon_is_cardinal_compliant(d: *DaemonState) -> nx_int called by 1: main |
| 486 | func nx_daemon_status_label(s: nx_int) -> *u8 called by 1: nx_daemon_emit_summary |
| 497 | func nx_daemon_emit_summary(d: *DaemonState) -> nx_int |
| 512 | func nx_daemon_sleep_until_next(d: *DaemonState) -> nx_int calls 1: sys_sleep_ms |