code wiki / (root) / nx_calibrate.nx

nx_calibrate.nx

buildroot/runtime/nx_calibrate.nx

16157 B420 linesdepth 2pulls 2 transitivereach 23 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_calibrate.nx -- lmbench-class empirical cost-model builder. SA-2 milestone of NISHI_SELF_ASSEMBLY_ROADMAP.md. Consumes the device capability fingerprint from nx_probe and produces an empirical cost model the selector consumes at SA-4 to rank variants. The point of empirical calibration is to refuse the hack of selecting variants from spec-sheet cost models -- the only honest answer is "what does THIS device measure when we actually run the operations?" Composes: nx_probe -- capability fingerprint (caller's prior step) nx_clock -- monotonic-ns time helper nx_tier -- tier classification (NX_TIER_MCU..HPC inferred from the measurements) V1 microbenchmarks (SA-2 honest perf verdict): - int ALU ns/op (dependent-chain ADD, ~1M iterations) - pointer-chase latency at three working-set sizes (small ~ L1, medium ~ L2, large ~ RAM); cache-hierarchy witness via monotonic per-access latency increase - linear-copy memory bandwidth (bytes/ns over a large block) - syscall round-trip cost (clock_gettime loop, 10K calls) - mmap latency (10 mmap calls, ns/mmap) Gap list (V1): - FP ALU / vec ALU absent -- qemu-riscv64-static models them as scalar emulation; honest measurement requires real RV64 + RVV hardware OR the x86_64 + AVX2 native path (SA-2.5) - context-switch cost absent (fork/futex; deferred to SA-6 when nx_compile lands the fork primitive) - network RTT absent (no peer in smoke; SA-5) - energy per op absent (no RAPL access from substrate; SA-5+) - byzantine N-of-M deferred to SA-7 The substrate refuses these REFUSED HACKS per NISHI_SELF_ASSEMBLY_ROADMAP.md ยง6: - datasheet cost models (#7 refused) - single-axis selection from synthetic data (#3 refused) - vendor-supplied calibration (#14 refused)

dependencies 2 imports · 18 importers

nx_syscalls.nx nx_tier.nx nx_calibrate.nx nx_calibrate_test.nx nx_etg_probe_cpu.nx nx_etg_probe_cpu_test.nx nx_install_attest_signed_test.nx nx_install_attest_test.nx nx_install_hash_test.nx nx_install_pipeline.nx nx_install_pipeline_test.nx nx_install_plan.nx nx_install_plan_test.nx

diagram shows first 10 each side; +0 more imports, +8 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_calibrate_test.nxnx_etg_probe_cpu.nxnx_etg_probe_cpu_test.nxnx_install_attest_signed_test.nxnx_install_attest_test.nxnx_install_hash_test.nxnx_install_pipeline.nxnx_install_pipeline_test.nxnx_install_plan.nxnx_install_plan_test.nxnx_select.nxnx_select_joint.nxnx_select_joint_chain_test.nxnx_select_joint_test.nxnx_select_test.nxnx_spore_up_lifecycle_test.nxnx_spore_up_network_test.nxnx_spore_up_test.nx

structs

119struct NxCalibrationRecord

consts

73const NX_MAGIC_1000000000: i64 = 1000000000
74const NX_MAGIC_4096: i64 = 4096
75const NX_MAGIC_1048576: i64 = 1048576
76const NX_MAGIC_8000: i64 = 8000
77const NX_MAGIC_4000: i64 = 4000
78const NX_MAGIC_2000: i64 = 2000
79const NX_MAGIC_1000000: i64 = 1000000
82const NX_CALIB_CANARY_PRE: i64 = 0x4E58434C50524500 // "NXCLPRE\0"
83const NX_CALIB_CANARY_POST: i64 = 0x004E58434C504F53 // "\0NXCLPOS"
84const NX_CALIB_SCHEMA_VERSION: i64 = 1
90const NX_TIER_INF_UNKNOWN: i64 = 0
91const NX_TIER_INF_MCU: i64 = 1
92const NX_TIER_INF_MOBILE: i64 = 2
93const NX_TIER_INF_LAPTOP: i64 = 3
94const NX_TIER_INF_DESKTOP: i64 = 4
95const NX_TIER_INF_SERVER: i64 = 5
96const NX_TIER_INF_HPC: i64 = 6
97const NX_TIER_INF_N: i64 = 7
106const NX_CALIB_WS_SMALL_B: i64 = 4096 // ~ L1 on most hosts
107const NX_CALIB_WS_MEDIUM_B: i64 = 262144 // 256 KiB ~ L2
108const NX_CALIB_WS_LARGE_B: i64 = 16777216 // 16 MiB ~ DRAM
111const NX_CALIB_INT_ALU_ITERS: i64 = 10000000 // 10M iters x 3 ops
112const NX_CALIB_PTRCHASE_ITERS: i64 = 1000000 // 1M chases
113const NX_CALIB_BW_BYTES: i64 = 1048576 // 1 MiB
114const NX_CALIB_BW_REPEAT: i64 = 8 // 8 MiB total moved
115const NX_CALIB_SYSCALL_ITERS: i64 = 10000
116const NX_CALIB_MMAP_ITERS: i64 = 10

functions

99func nx_tier_inf_is_valid(t: i64) -> i64
called by 2: mainmain
140func _now_ns(ts: *i64) -> i64
152func _calibrate_int_alu(out_ps_per_op: *i64) -> i64
193func _calibrate_ptrchase(ws_bytes: i64, out_ns_per_access: *i64) -> i64
242func _calibrate_mem_bw(out_mib_per_s: *i64) -> i64
called by 1: nx_calibrate_run calls 2: sys_mmap_now_ns
287func _calibrate_syscall_gettime(out_ns_per_call: *i64) -> i64
312func _calibrate_syscall_mmap(out_ns_per_mmap: *i64) -> i64
called by 1: nx_calibrate_run calls 2: sys_mmap_now_ns
343func _infer_tier(ram_ns: i64, bw_mib_per_s: i64) -> i64
called by 1: nx_calibrate_run
363func nx_calibrate_new() -> *NxCalibrationRecord
382func nx_calibrate_run(out: *NxCalibrationRecord) -> i64