nx_calibrate.nx
buildroot/runtime/nx_calibrate.nx
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
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
| 119 | struct NxCalibrationRecord |
consts
| 73 | const NX_MAGIC_1000000000: i64 = 1000000000 |
| 74 | const NX_MAGIC_4096: i64 = 4096 |
| 75 | const NX_MAGIC_1048576: i64 = 1048576 |
| 76 | const NX_MAGIC_8000: i64 = 8000 |
| 77 | const NX_MAGIC_4000: i64 = 4000 |
| 78 | const NX_MAGIC_2000: i64 = 2000 |
| 79 | const NX_MAGIC_1000000: i64 = 1000000 |
| 82 | const NX_CALIB_CANARY_PRE: i64 = 0x4E58434C50524500 // "NXCLPRE\0" |
| 83 | const NX_CALIB_CANARY_POST: i64 = 0x004E58434C504F53 // "\0NXCLPOS" |
| 84 | const NX_CALIB_SCHEMA_VERSION: i64 = 1 |
| 90 | const NX_TIER_INF_UNKNOWN: i64 = 0 |
| 91 | const NX_TIER_INF_MCU: i64 = 1 |
| 92 | const NX_TIER_INF_MOBILE: i64 = 2 |
| 93 | const NX_TIER_INF_LAPTOP: i64 = 3 |
| 94 | const NX_TIER_INF_DESKTOP: i64 = 4 |
| 95 | const NX_TIER_INF_SERVER: i64 = 5 |
| 96 | const NX_TIER_INF_HPC: i64 = 6 |
| 97 | const NX_TIER_INF_N: i64 = 7 |
| 106 | const NX_CALIB_WS_SMALL_B: i64 = 4096 // ~ L1 on most hosts |
| 107 | const NX_CALIB_WS_MEDIUM_B: i64 = 262144 // 256 KiB ~ L2 |
| 108 | const NX_CALIB_WS_LARGE_B: i64 = 16777216 // 16 MiB ~ DRAM |
| 111 | const NX_CALIB_INT_ALU_ITERS: i64 = 10000000 // 10M iters x 3 ops |
| 112 | const NX_CALIB_PTRCHASE_ITERS: i64 = 1000000 // 1M chases |
| 113 | const NX_CALIB_BW_BYTES: i64 = 1048576 // 1 MiB |
| 114 | const NX_CALIB_BW_REPEAT: i64 = 8 // 8 MiB total moved |
| 115 | const NX_CALIB_SYSCALL_ITERS: i64 = 10000 |
| 116 | const NX_CALIB_MMAP_ITERS: i64 = 10 |
functions
| 99 | func nx_tier_inf_is_valid(t: i64) -> i64 |
| 140 | func _now_ns(ts: *i64) -> i64 |
| 152 | func _calibrate_int_alu(out_ps_per_op: *i64) -> i64 |
| 193 | func _calibrate_ptrchase(ws_bytes: i64, out_ns_per_access: *i64) -> i64 |
| 242 | func _calibrate_mem_bw(out_mib_per_s: *i64) -> i64 |
| 287 | func _calibrate_syscall_gettime(out_ns_per_call: *i64) -> i64 |
| 312 | func _calibrate_syscall_mmap(out_ns_per_mmap: *i64) -> i64 |
| 343 | func _infer_tier(ram_ns: i64, bw_mib_per_s: i64) -> i64 called by 1: nx_calibrate_run |
| 363 | func nx_calibrate_new() -> *NxCalibrationRecord |
| 382 | func nx_calibrate_run(out: *NxCalibrationRecord) -> i64 |