code wiki / _hdl_build / nx_kernel_census.nx

nx_kernel_census.nx source

↩ module page · 288 lines · 13871 B

1// nx_kernel_census.nx -- KERNEL/OS/DRIVER/GRAPHICS competitive census (operator 2026-06-13: 2// "benchmark against all the top kernels as competitors to get our S-class exceed ... device 3// drivers, DirectX exceed, CUDA exceed ... beat all the kernels' killer OS features from the 4// hardware rung up through the kernel and OS up"). 5// 6// AUTHOR=ORGAN, NO-WAVE (measured per-feature head-to-head, never a fake binary exceed): reads 7// kernel_incumbent_ref.tsv (bench-reference = the QUESTIONS: real incumbent killer features) and 8// COMPUTES Nishi's PRESENT/ABSENT per feature via re_has against the REAL Nishi gate logs (boot_stub 9// / trap_syscall / virtio_blk / virtio_net / hwmap = the PROOF of what is actually built) -- never 10// tutor-asserted. Writes kernel_competitive_census.tsv + an honest bm_verdict (BEHIND while the 11// kernel is young = the true starting line; the ABSENT rows are the build-to-exceed backlog). 12// Self-validating: pos control "virtio" MUST be PRESENT (Nishi has it), neg control MUST be ABSENT. 13// Composes nx_research_extract (re_has) + nx_benchmark (honest verdict, refuses cherry-pick). 14// license_tier: ORIGINAL 15import "nx_syscalls.nx" 16import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 17import "nx_research_extract.nx" 18import "nx_benchmark.nx" 19import "nx_bootcap.nx" 20const KC_MAGIC_2000000: i64 = 2000000 21const KC_MAGIC_80000: i64 = 80000 22const KC_MAGIC_300000: i64 = 300000 23const KC_MAGIC_40000: i64 = 40000 24 25// ADDED 2026-07-31 (debt idx 2071): this census computed PRESENT from substring probes over the 26// gate logs ONLY, so a feature proven once by a standalone fixture scored IDENTICALLY to one 27// wired into the image BOOTSOV actually boots. It therefore read 382 permil BEFORE and AFTER the 28// live boot went from a 72-byte banner exercising ZERO features to a kernel exercising eleven -- 29// the ruler scored the adoption gap as exactly zero movement. The LIVE axis below boots the 30// artifact and reads its serial. STRICTLY ADDITIVE: every pre-existing field (present/absent/ 31// control_pos/control_neg/our_coverage_permil/exceed_verdict/verdict) keeps its exact prior 32// meaning, so existing consumers are untouched; the new fields are appended. 33const KC_MARKERS: *u8 = "knowledge/registry/kernel_live_markers.tsv" 34const KC_BIN: *u8 = "runtime/_hdl_build/_boot_nishi_virt.bin" 35const KC_BIN_ALT: *u8 = "_boot_nishi_virt.bin" 36const KC_TX_CAP: i64 = 4096 37 38const KC_REF: *u8 = "knowledge/registry/kernel_incumbent_ref.tsv" 39const KC_OUT: *u8 = "knowledge/registry/kernel_competitive_census.tsv" 40const KC_LOG: *u8 = "knowledge/status/kernel_census.log" 41const KC_MAXF: i64 = 256 42 43// evidence = the REAL Nishi kernel-area GREEN gate logs (proof of what is actually built) 44const KC_E0: *u8 = "knowledge/status/boot_stub.log" 45const KC_E1: *u8 = "knowledge/status/trap_syscall.log" 46const KC_E2: *u8 = "knowledge/status/virtio_blk.log" 47const KC_E3: *u8 = "knowledge/status/virtio_net.log" 48const KC_E4: *u8 = "knowledge/status/hwmap.log" 49const KC_E5: *u8 = "knowledge/status/timer_irq.log" 50const KC_E6: *u8 = "knowledge/status/sched.log" 51const KC_E7: *u8 = "knowledge/status/memalloc.log" 52const KC_E8: *u8 = "knowledge/status/coopsched.log" 53const KC_E9: *u8 = "knowledge/status/driver_spec.log" 54const KC_E10: *u8 = "knowledge/status/driver_bind.log" 55const KC_E11: *u8 = "knowledge/status/nndev.log" 56const KC_E12: *u8 = "knowledge/status/mmu.log" 57const KC_E13: *u8 = "knowledge/status/priv.log" 58 59func kc_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 60// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 61// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 62// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 63// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 64func kc_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 65 66// read whole file into buf (truncating); return length, -1 if open fails. 67func kc_read_file(path: *u8, buf: *u8, cap: i64) -> i64 { 68 let fd: i64 = sys_openat_rd(path) 69 if fd < 0 { return 0 - 1 } 70 var tot: i64 = 0 71 var r: i64 = 1 72 while r > 0 { 73 let dst: *u8 = ((buf as i64) + tot) as *u8 74 r = sys_read(fd, dst, cap - tot) 75 if r > 0 { tot = tot + r } 76 } 77 sys_close(fd) 78 return tot 79} 80 81// APPEND a file into buf at off (missing file = no evidence, honest); return new off. 82func kc_read_into(path: *u8, buf: *u8, off: i64, cap: i64) -> i64 { 83 let fd: i64 = sys_openat_rd(path) 84 if fd < 0 { return off } 85 var tot: i64 = off 86 var r: i64 = 1 87 while r > 0 { 88 let dst: *u8 = ((buf as i64) + tot) as *u8 89 r = sys_read(fd, dst, cap - tot) 90 if r > 0 { tot = tot + r } 91 } 92 sys_close(fd) 93 return tot 94} 95 96func kc_scan_to(buf: *u8, n: i64, start: i64, delim: i64) -> i64 { 97 var i: i64 = start 98 var s: i64 = 1 99 while s == 1 { if i >= n { s = 0 } else { if buf[i] == (delim as u8) { s = 0 } else { i = i + 1 } } } 100 return i 101} 102 103func kc_app(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i } 104 105func kc_vstr(v: i64) -> *u8 { 106 if v == BM_AHEAD { return "AHEAD" as *u8 } 107 if v == BM_PARITY { return "PARITY" as *u8 } 108 if v == BM_BEHIND { return "BEHIND" as *u8 } 109 if v == BM_DIFFERENTIATED { return "DIFFERENTIATED" as *u8 } 110 return "REFUSE-cherrypick" as *u8 111} 112 113func kc_streq(a: *u8, b: *u8) -> i64 { 114 var i: i64 = 0 115 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 116 if b[i] != (0 as u8) { return 0 } 117 return 1 118} 119 120// The LIVE fields are printed BEFORE the verdict token so the line stays one key=value record and 121// every pre-existing key keeps its exact prior meaning and spelling. 122func kc_emit2(fd: i64, live: i64, gap: i64, anom: i64, livep: i64, head: i64) -> i64 { 123 kc_w(fd, " live=" as *u8); kc_wn(fd, live) 124 kc_w(fd, " live_permil=" as *u8); kc_wn(fd, livep) 125 kc_w(fd, " adoption_gap=" as *u8); kc_wn(fd, gap) 126 kc_w(fd, " live_without_evidence=" as *u8); kc_wn(fd, anom) 127 kc_w(fd, " headline_permil=" as *u8); kc_wn(fd, head) 128 return 0 129} 130 131func kc_emit(fd: i64, nf: i64, present: i64, cpos: i64, cneg: i64, cov: i64, verdict: i64, ok: i64, live: i64, gap: i64, anom: i64, livep: i64, head: i64) -> i64 { 132 kc_w(fd, "KERNELCENSUSGATE authored=organ source=kernel_incumbent_ref.tsv evidence=nishi-gate-logs features=" as *u8); kc_wn(fd, nf) 133 kc_w(fd, " present=" as *u8); kc_wn(fd, present) 134 kc_w(fd, " absent=" as *u8); kc_wn(fd, nf - present) 135 kc_w(fd, " control_pos=" as *u8); kc_wn(fd, cpos) 136 kc_w(fd, " control_neg=" as *u8); kc_wn(fd, cneg) 137 kc_w(fd, " our_coverage_permil=" as *u8); kc_wn(fd, cov) 138 kc_w(fd, " exceed_verdict=" as *u8); kc_w(fd, kc_vstr(verdict)) 139 kc_emit2(fd, live, gap, anom, livep, head) 140 if ok == 1 { kc_w(fd, " verdict=GREEN\n" as *u8) } else { kc_w(fd, " verdict=RED reason=control-or-empty\n" as *u8) } 141 return 0 142} 143 144func main() -> i64 { 145 // 1. load evidence = the REAL Nishi kernel gate logs, concatenated. 146 let ev: *u8 = sys_mmap(KC_MAGIC_2000000) 147 var eo: i64 = 0 148 eo = kc_read_into(KC_E0, ev, eo, KC_MAGIC_2000000) 149 eo = kc_read_into(KC_E1, ev, eo, KC_MAGIC_2000000) 150 eo = kc_read_into(KC_E2, ev, eo, KC_MAGIC_2000000) 151 eo = kc_read_into(KC_E3, ev, eo, KC_MAGIC_2000000) 152 eo = kc_read_into(KC_E4, ev, eo, KC_MAGIC_2000000) 153 eo = kc_read_into(KC_E5, ev, eo, KC_MAGIC_2000000) 154 eo = kc_read_into(KC_E6, ev, eo, KC_MAGIC_2000000) 155 eo = kc_read_into(KC_E7, ev, eo, KC_MAGIC_2000000) 156 eo = kc_read_into(KC_E8, ev, eo, KC_MAGIC_2000000) 157 eo = kc_read_into(KC_E9, ev, eo, KC_MAGIC_2000000) 158 eo = kc_read_into(KC_E10, ev, eo, KC_MAGIC_2000000) 159 eo = kc_read_into(KC_E11, ev, eo, KC_MAGIC_2000000) 160 eo = kc_read_into(KC_E12, ev, eo, KC_MAGIC_2000000) 161 eo = kc_read_into(KC_E13, ev, eo, KC_MAGIC_2000000) 162 let evlen: i64 = eo 163 if evlen <= 0 { kc_w(1, "KERNELCENSUSGATE verdict=RED reason=no-evidence\n" as *u8); return 1 } 164 165 // 2. load + parse the bench-reference (feature \t probe \t incumbent). 166 let rb: *u8 = sys_mmap(KC_MAGIC_80000) 167 let rbn: i64 = kc_read_file(KC_REF, rb, KC_MAGIC_80000) 168 if rbn <= 0 { kc_w(1, "KERNELCENSUSGATE verdict=RED reason=ref-unreadable\n" as *u8); return 1 } 169 let feat: *i64 = sys_mmap(8 * KC_MAXF) as *i64 170 let prob: *i64 = sys_mmap(8 * KC_MAXF) as *i64 171 let unin: *i64 = sys_mmap(8 * KC_MAXF) as *i64 172 var nf: i64 = 0 173 var p: i64 = 0 174 while p < rbn { 175 if rb[p] == (35 as u8) { let e: i64 = kc_scan_to(rb, rbn, p, 10); p = e + 1 } 176 else { if rb[p] == (10 as u8) { p = p + 1 } 177 else { 178 let a0: i64 = p 179 let t1: i64 = kc_scan_to(rb, rbn, a0, 9); rb[t1] = 0 as u8 180 let a1: i64 = t1 + 1 181 let t2: i64 = kc_scan_to(rb, rbn, a1, 9); rb[t2] = 0 as u8 182 let a2: i64 = t2 + 1 183 let t3: i64 = kc_scan_to(rb, rbn, a2, 10); rb[t3] = 0 as u8 184 if nf < KC_MAXF { feat[nf] = (rb as i64) + a0; prob[nf] = (rb as i64) + a1; unin[nf] = (rb as i64) + a2; nf = nf + 1 } 185 p = t3 + 1 186 } } 187 } 188 189 // 3. compute status per feature from the evidence + author the census. 190 let ob: *u8 = sys_mmap(KC_MAGIC_300000) 191 var o: i64 = 0 192 o = kc_app(ob, o, "# AUTHORED BY nx_kernel_census -- Nishi kernel/OS/driver/graphics vs top incumbents. Status COMPUTED via re_has against the REAL Nishi gate logs (boot/trap/virtio-blk/virtio-net/hwmap), NOT asserted. PRESENT=gate-proven, ABSENT=build-to-exceed target.\n" as *u8) 193 o = kc_app(ob, o, "# columns: status\tfeature\tincumbent\tevidence-probe\n" as *u8) 194 var present: i64 = 0 195 var i: i64 = 0 196 while i < nf { 197 let st: i64 = re_has(ev, evlen, (prob[i]) as *u8) 198 if st == 1 { o = kc_app(ob, o, "PRESENT\t" as *u8); present = present + 1 } else { o = kc_app(ob, o, "ABSENT\t" as *u8) } 199 o = kc_app(ob, o, (feat[i]) as *u8) 200 o = kc_app(ob, o, "\t" as *u8) 201 o = kc_app(ob, o, (unin[i]) as *u8) 202 o = kc_app(ob, o, "\tprobe=" as *u8) 203 o = kc_app(ob, o, (prob[i]) as *u8) 204 o = kc_app(ob, o, "\n" as *u8) 205 i = i + 1 206 } 207 let wfd: i64 = sys_openat_wr(KC_OUT, 420) 208 if wfd < 0 { kc_w(1, "KERNELCENSUSGATE verdict=RED reason=out-unwritable\n" as *u8); return 1 } 209 sys_write(wfd, ob, o) 210 sys_close(wfd) 211 212 // 3b. THE LIVE AXIS -- boot the artifact BOOTSOV boots and read what it actually said. 213 let lenp2: *i64 = sys_mmap(16) as *i64 214 let pathp: *i64 = sys_mmap(16) as *i64 215 let img: *u8 = bootcap_load(KC_BIN, KC_BIN_ALT, lenp2, pathp) 216 let tx: *u8 = sys_mmap(KC_TX_CAP) 217 let bres: *i64 = sys_mmap(8 * BOOTCAP_R_N) as *i64 218 var txn: i64 = 0 219 if (img as i64) != 0 { txn = bootcap_run(img, lenp2[0], tx, KC_TX_CAP, bres) } 220 let mb: *u8 = sys_mmap(KC_MAGIC_40000) 221 var mbn: i64 = kc_read_file(KC_MARKERS, mb, KC_MAGIC_40000) 222 if mbn < 0 { mbn = 0 } 223 let mname: *i64 = sys_mmap(8 * KC_MAXF) as *i64 224 let mmark: *i64 = sys_mmap(8 * KC_MAXF) as *i64 225 var nm: i64 = 0 226 var q: i64 = 0 227 while q < mbn { 228 if mb[q] == (35 as u8) { let e: i64 = kc_scan_to(mb, mbn, q, 10); q = e + 1 } 229 else { if mb[q] == (10 as u8) { q = q + 1 } 230 else { 231 let b0: i64 = q 232 let u1: i64 = kc_scan_to(mb, mbn, b0, 9); mb[u1] = 0 as u8 233 let b1: i64 = u1 + 1 234 let u2: i64 = kc_scan_to(mb, mbn, b1, 10); mb[u2] = 0 as u8 235 if nm < KC_MAXF { mname[nm] = (mb as i64) + b0; mmark[nm] = (mb as i64) + b1; nm = nm + 1 } 236 q = u2 + 1 237 } } 238 } 239 var n_live: i64 = 0 240 var n_gap: i64 = 0 241 var n_anom: i64 = 0 242 var k2: i64 = 0 243 while k2 < nf { 244 let e2: i64 = re_has(ev, evlen, (prob[k2]) as *u8) 245 var lv: i64 = 0 246 var j2: i64 = 0 247 while j2 < nm { 248 if kc_streq((feat[k2]) as *u8, (mname[j2]) as *u8) == 1 { 249 if txn > 0 { if re_has(tx, txn, (mmark[j2]) as *u8) == 1 { lv = 1 } } 250 j2 = nm 251 } else { j2 = j2 + 1 } 252 } 253 if lv == 1 { n_live = n_live + 1 } 254 if e2 == 1 { if lv == 0 { n_gap = n_gap + 1 } } 255 if e2 == 0 { if lv == 1 { n_anom = n_anom + 1 } } 256 k2 = k2 + 1 257 } 258 var livep: i64 = 0 259 if nf > 0 { livep = (n_live * 1000) / nf } 260 261 // 4. self-validating controls + honest verdict (refuses cherry-pick). 262 let cpos: i64 = re_has(ev, evlen, "virtio" as *u8) 263 let cneg: i64 = re_has(ev, evlen, "zzqnonexistentkernelfeature" as *u8) 264 let valid: i64 = bm_is_valid(nf, nf, 800) 265 var cov: i64 = 0 266 if nf > 0 { cov = (present * 1000) / nf } 267 let verdict: i64 = bm_verdict(valid, cov, 1000) 268 var ok: i64 = 1 269 if cpos != 1 { ok = 0 } 270 if cneg != 0 { ok = 0 } 271 if nf <= 0 { ok = 0 } 272 273 // HEADLINE = MIN(evidence, live) -- never the mean, never the max. Coverage that is not 274 // wired at the live chokepoint is not coverage, so the weaker axis is the honest number. 275 var head: i64 = cov 276 if livep < head { head = livep } 277 278 // 5. emit gate evidence to stdout + append to the gate log. 279 kc_emit(1, nf, present, cpos, cneg, cov, verdict, ok, n_live, n_gap, n_anom, livep, head) 280 if n_anom > 0 { 281 kc_w(1, "KERNELCENSUS !! EVIDENCE-ROOT SUSPECT: " as *u8); kc_wn(1, n_anom) 282 kc_w(1, " features RUN in the live boot but have NO gate-log evidence here -- a feature that executes cannot be unproven, so adoption_gap is NOT trustworthy from this root.\n" as *u8) 283 } 284 let lf: i64 = sys_openat_append(KC_LOG, 420) 285 if lf >= 0 { kc_emit(lf, nf, present, cpos, cneg, cov, verdict, ok, n_live, n_gap, n_anom, livep, head); sys_close(lf) } 286 if ok == 1 { return 0 } 287 return 1 288}