code wiki / (root) / nx_blkprofile.nx

nx_blkprofile.nx source

↩ module page · 455 lines · 23039 B

1// nx_blkprofile.nx -- THE BURST PROFILER for the D-state admission witness. Rung DG1, /compare/degradation. 2// 3// WHY THIS EXISTS, IN THE CONF'S OWN WORDS. knowledge/build_admit.conf carries blocked_samples and 4// blocked_gap_ms -- THE SMOOTHED WITNESS -- and leaves them DELIBERATELY UNARMED behind a written work 5// order: "sample procs_blocked at a fixed interval for a few minutes and find the shortest span over 6// which the median stops tracking the bursts ... Then write the sample count, the gap, and the run that 7// produced them on this line." That derivation had never been run, so a capability the conf itself 8// measured at roughly 42 percent of build refusals sat inert. THIS ORGAN IS THAT DERIVATION. 9// 10// IT REFUSES TO RECOMMEND A SPAN IT DID NOT MEASURE. Every row below is produced by replaying a REAL 11// recorded series through the REAL median, so a recommendation here is a measurement, never a taste. 12// 13// IT COMPOSES THE SHIPPING RULERS AND RE-IMPLEMENTS NEITHER. ioa_measure reads /proc/stat exactly as 14// nx_build_admit does, and ioa_median IS the median nx_build_admit applies once armed. The verdicts in 15// the span table are therefore the verdicts THE ARMED GATE WOULD HAVE PRODUCED on this series -- not an 16// approximation, and not a second ruler that can drift from the first. 17// 18// THE LATENCY COLUMN IS NOT DECORATION. The conf refuses arming until that cost is measured, because the 19// span is paid by EVERY caller of the admission check -- the clock dispatcher's pre-dispatch call 20// included. A span that fixes admission and stalls the dispatcher has moved the defect, not removed it. 21// 22// TWO TIMESCALES, TWO VERBS. `live` samples fine enough to resolve a 2-12 s burst. `jrnl` re-reads the 23// procchurn journal the estate ALREADY writes, for the long-run base rate at zero added load -- a second 24// reader of an old log, never a second collector. 25// 26// NO CLOCK IS READ. sys_time_ms is ABSENT-PROVEN in this runtime (buildroot/runtime, corpus_complete=1), 27// so the window is reported as NOMINAL and derived from the sample count and interval. The added-latency 28// column needs no clock either: a sampler that sleeps a span pays that span BY CONSTRUCTION. 29 30import "nx_syscalls.nx" 31import "nx_ioadmit_lib.nx" 32 33const BP_STDOUT: i64 = 1 34const BP_STDERR: i64 = 2 35const BP_OUTCAP: i64 = 262144 36const BP_MAX_SAMPLES: i64 = 8192 37const BP_SAMPLE_BYTES: i64 = 65536 38const BP_HIST_MAX: i64 = 512 39const BP_HIST_BYTES: i64 = 4096 40const BP_KBUF_BYTES: i64 = 256 41const BP_MEAS_BYTES: i64 = 64 42const BP_SIMOUT_BYTES: i64 = 64 43const BP_BOX_BYTES: i64 = 64 44const BP_UNREADABLE: i64 = 0 - 1 45const BP_EXIT_USAGE: i64 = 2 46const BP_EXIT_UNMEASURED: i64 = 3 47const BP_DEF_DUR_S: i64 = 180 48const BP_DEF_INTERVAL_MS: i64 = 200 49const BP_DEF_K: i64 = 5 50const BP_NSPANS: i64 = 8 51const BP_CONV_TOL_PERMIL: i64 = 10 52const BP_MS_PER_S: i64 = 1000 53const BP_PERMIL: i64 = 1000 54const BP_CH_MINUS: i64 = 45 55const BP_CH_0: i64 = 48 56const BP_CH_9: i64 = 57 57const BP_CH_LIVE: i64 = 108 58const BP_CH_JRNL: i64 = 106 59// TWO ROOTS, PROBED IN ORDER -- the same idiom ba_conf_load uses for build_admit.conf. A bare path here 60// is CWD-RELATIVE, and the build runner anchors CWD to buildroot/, so the single-path version resolved 61// into the OTHER knowledge tree and abstained. The resolved path is PRINTED, because a reader that 62// returns bytes without saying where they came from reproduces the defect one layer up. 63const BP_JRNL: *u8 = "knowledge/status/procchurn.jrnl" 64const BP_JRNL_UP: *u8 = "../knowledge/status/procchurn.jrnl" 65// THE KEY AND ITS LENGTH ARE ONE FACT: the length is DERIVED with bp_slen at every use. A hand-counted 66// literal beside a string is a second copy of that string's shape, and the two drift in silence. 67const BP_BLOCKED_KEY: *u8 = "blocked=" 68 69func bp_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 70func bp_werr(s: *u8) -> i64 { sys_write(BP_STDERR, s, bp_slen(s)); return 0 } 71 72func bp_puts(b: *u8, off: i64, s: *u8) -> i64 { 73 var o: i64 = off 74 var j: i64 = 0 75 while s[j] != (0 as u8) { b[o] = s[j]; o = o + 1; j = j + 1 } 76 return o 77} 78 79func bp_puti(b: *u8, off: i64, v: i64) -> i64 { 80 var o: i64 = off 81 var x: i64 = v 82 if x < 0 { b[o] = BP_CH_MINUS as u8; o = o + 1; x = 0 - x } 83 var d: i64 = 1 84 var t: i64 = x 85 while t >= 10 { d = d * 10; t = t / 10 } 86 while d > 0 { 87 let q: i64 = x / d 88 b[o] = (BP_CH_0 + q) as u8 89 o = o + 1 90 x = x - q * d 91 d = d / 10 92 } 93 return o 94} 95 96// Decimal parse of a NUL-terminated argument. Returns BP_UNREADABLE on any non-digit, so a mistyped 97// argument REFUSES rather than silently becoming a zero that reads like a deliberate setting. 98func bp_atoi(s: *u8) -> i64 { 99 let n: i64 = bp_slen(s) 100 if n <= 0 { return BP_UNREADABLE } 101 var v: i64 = 0 102 var i: i64 = 0 103 var bad: i64 = 0 104 while i < n { 105 let c: i64 = s[i] as i64 106 if c < BP_CH_0 { bad = 1 } 107 if c > BP_CH_9 { bad = 1 } 108 if bad == 0 { v = v * 10 + (c - BP_CH_0) } 109 i = i + 1 110 } 111 if bad == 1 { return BP_UNREADABLE } 112 return v 113} 114 115// The candidate spans, in ms. They bracket the burst durations the conf recorded (2 to 12 s) by an order 116// of magnitude in both directions, so a knee cannot fall outside the table unnoticed. 117func bp_span_at(i: i64) -> i64 { 118 if i == 0 { return 250 } 119 if i == 1 { return 500 } 120 if i == 2 { return 1000 } 121 if i == 3 { return 2000 } 122 if i == 4 { return 4000 } 123 if i == 5 { return 6000 } 124 if i == 6 { return 8000 } 125 if i == 7 { return 12000 } 126 return BP_UNREADABLE 127} 128 129// Percentile from a histogram. NO SORT BY CONSTRUCTION: this estate has already lost a calibration to a 130// cursor-clobbering insertion sort (nx_loadceil, corrected 2026-08-25) and a histogram cannot carry that 131// defect. Returns BP_UNREADABLE on an empty population rather than a fabricated zero. 132func bp_pct(hist: *i64, n: i64, permil: i64) -> i64 { 133 if n <= 0 { return BP_UNREADABLE } 134 let target: i64 = (n * permil + BP_PERMIL - 1) / BP_PERMIL 135 var acc: i64 = 0 136 var v: i64 = 0 137 var res: i64 = BP_UNREADABLE 138 while v < BP_HIST_MAX { 139 acc = acc + hist[v] 140 if acc >= target { if res < 0 { res = v } } 141 v = v + 1 142 } 143 return res 144} 145 146// Replay the recorded series through the sampler a given (k, span) WOULD have used, and count how often 147// the real median crosses the bar. out[0]=gap_ms out[1]=trials out[2]=refuse_permil. 148// Returns 0, or BP_UNREADABLE when the span cannot be simulated from this series. AN UNDERSAMPLED SPAN 149// IS REPORTED AS SUCH AND NEVER AS A ZERO -- a zero in this column reads as "this span refuses nothing". 150func bp_sim(s: *i64, n: i64, interval_ms: i64, k: i64, span_ms: i64, bar: i64, kbuf: *i64, out: *i64) -> i64 { 151 out[0] = BP_UNREADABLE 152 out[1] = 0 153 out[2] = BP_UNREADABLE 154 if k < 2 { return BP_UNREADABLE } 155 if interval_ms <= 0 { return BP_UNREADABLE } 156 let gap_ms: i64 = span_ms / (k - 1) 157 if gap_ms < interval_ms { return BP_UNREADABLE } 158 let step: i64 = gap_ms / interval_ms 159 if step < 1 { return BP_UNREADABLE } 160 let reach: i64 = (k - 1) * step 161 let trials: i64 = n - reach 162 if trials <= 0 { return BP_UNREADABLE } 163 var refuse: i64 = 0 164 var o: i64 = 0 165 while o < trials { 166 var j: i64 = 0 167 while j < k { kbuf[j] = s[o + j * step]; j = j + 1 } 168 let med: i64 = ioa_median(kbuf, k) 169 if med >= bar { refuse = refuse + 1 } 170 o = o + 1 171 } 172 out[0] = gap_ms 173 out[1] = trials 174 out[2] = refuse * BP_PERMIL / trials 175 return 0 176} 177 178func main(argc: i64, argv: *i64) -> i64 { 179 if argc < 2 { 180 bp_werr("usage: nx_blkprofile live [duration_s] [interval_ms] [bar] [k] | nx_blkprofile jrnl [bar]\n" as *u8) 181 sys_exit(BP_EXIT_USAGE) 182 return BP_EXIT_USAGE 183 } 184 let verb: *u8 = argv[1] as *u8 185 let ob: *u8 = sys_mmap(BP_OUTCAP) 186 let hist: *i64 = sys_mmap(BP_HIST_BYTES) as *i64 187 let meas: *i64 = sys_mmap(BP_MEAS_BYTES) as *i64 188 var off: i64 = 0 189 var vi: i64 = 0 190 while vi < BP_HIST_MAX { hist[vi] = 0; vi = vi + 1 } 191 192 // The bar is DERIVED from this host exactly as ba_verdict resolves it when the conf is silent, so the 193 // profile is measured against the SAME line the gate will use, never against a number chosen here. 194 var ncpu: i64 = BP_UNREADABLE 195 if ioa_measure(meas) == 0 { ncpu = meas[0] } 196 var bar: i64 = BP_UNREADABLE 197 if ncpu > 0 { bar = ncpu * IOA_BLOCKED_PER_CPU } 198 199 if verb[0] == (BP_CH_JRNL as u8) { 200 if argc > 2 { let a: *u8 = argv[2] as *u8; let v: i64 = bp_atoi(a); if v > 0 { bar = v } } 201 if bar <= 0 { 202 bp_werr("nx_blkprofile jrnl: bar UNRESOLVED (ncpu unreadable and none given) -- REFUSING to publish a distribution against a bar it could not derive\n" as *u8) 203 sys_exit(BP_EXIT_UNMEASURED) 204 return BP_EXIT_UNMEASURED 205 } 206 let box: *i64 = sys_mmap(BP_BOX_BYTES) as *i64 207 box[0] = 0 208 var jsrc: *u8 = BP_JRNL 209 var jb: *u8 = sys_read_file(BP_JRNL, box) 210 if box[0] <= 0 { box[0] = 0; jsrc = BP_JRNL_UP; jb = sys_read_file(BP_JRNL_UP, box) } 211 let jlen: i64 = box[0] 212 if jlen <= 0 { 213 bp_werr("nx_blkprofile jrnl: journal UNREADABLE -- abstaining, which is not a clean bill of health\n" as *u8) 214 sys_exit(BP_EXIT_UNMEASURED) 215 return BP_EXIT_UNMEASURED 216 } 217 let klen: i64 = bp_slen(BP_BLOCKED_KEY) 218 var n: i64 = 0 219 var clamped: i64 = 0 220 var atbar: i64 = 0 221 var p: i64 = 0 222 while p + klen <= jlen { 223 var m: i64 = 0 224 var hit: i64 = 1 225 while m < klen { 226 if jb[p + m] != BP_BLOCKED_KEY[m] { hit = 0 } 227 m = m + 1 228 } 229 if hit == 1 { 230 var q: i64 = p + klen 231 var val: i64 = 0 232 var got: i64 = 0 233 var stop: i64 = 0 234 while q < jlen { 235 let c: i64 = jb[q] as i64 236 if c < BP_CH_0 { stop = 1 } 237 if c > BP_CH_9 { stop = 1 } 238 if stop == 0 { val = val * 10 + (c - BP_CH_0); got = 1; q = q + 1 } else { q = jlen } 239 } 240 if got == 1 { 241 n = n + 1 242 if val >= bar { atbar = atbar + 1 } 243 if val >= BP_HIST_MAX { clamped = clamped + 1; val = BP_HIST_MAX - 1 } 244 hist[val] = hist[val] + 1 245 } 246 p = p + klen 247 } else { p = p + 1 } 248 } 249 off = bp_puts(ob, off, "=== nx_blkprofile jrnl -- the LONG-RUN base rate of the D-state witness, from the journal the estate already writes ===\n source=" as *u8) 250 off = bp_puts(ob, off, jsrc) 251 off = bp_puts(ob, off, " bytes=" as *u8); off = bp_puti(ob, off, jlen) 252 off = bp_puts(ob, off, " rows=" as *u8); off = bp_puti(ob, off, n) 253 off = bp_puts(ob, off, " bar=" as *u8); off = bp_puti(ob, off, bar) 254 off = bp_puts(ob, off, " ncpu=" as *u8); off = bp_puti(ob, off, ncpu) 255 off = bp_puts(ob, off, "\n clamped_above_hist=" as *u8); off = bp_puti(ob, off, clamped) 256 off = bp_puts(ob, off, " (ANNOUNCED, never silent: a clamped sample still counts toward rows and toward the bar)\n" as *u8) 257 if n <= 0 { 258 off = bp_puts(ob, off, " verdict=UNMEASURED no parseable rows\n" as *u8) 259 sys_write(BP_STDOUT, ob, off) 260 sys_exit(BP_EXIT_UNMEASURED) 261 return BP_EXIT_UNMEASURED 262 } 263 off = bp_puts(ob, off, " min=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 1)) 264 off = bp_puts(ob, off, " p50=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 500)) 265 off = bp_puts(ob, off, " p90=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 900)) 266 off = bp_puts(ob, off, " p99=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 990)) 267 off = bp_puts(ob, off, " max=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 1000)) 268 off = bp_puts(ob, off, "\n at_or_above_bar=" as *u8); off = bp_puti(ob, off, atbar) 269 off = bp_puts(ob, off, " single_sample_refuse_permil=" as *u8); off = bp_puti(ob, off, atbar * BP_PERMIL / n) 270 off = bp_puts(ob, off, "\n READ THIS AS A BASE RATE, NOT AS THE ARMED ANSWER: these rows are minutes apart, far coarser than a\n 2-12 s burst, so they measure how often ONE reading crosses the bar and say nothing about span.\n The span derivation is the `live` verb.\nverdict=MEASURED\n" as *u8) 271 sys_write(BP_STDOUT, ob, off) 272 return 0 273 } 274 275 if verb[0] != (BP_CH_LIVE as u8) { 276 bp_werr("usage: nx_blkprofile live [duration_s] [interval_ms] [bar] [k] | nx_blkprofile jrnl [bar]\n" as *u8) 277 sys_exit(BP_EXIT_USAGE) 278 return BP_EXIT_USAGE 279 } 280 281 var dur_s: i64 = BP_DEF_DUR_S 282 var interval_ms: i64 = BP_DEF_INTERVAL_MS 283 var k: i64 = BP_DEF_K 284 if argc > 2 { let a: *u8 = argv[2] as *u8; let v: i64 = bp_atoi(a); if v > 0 { dur_s = v } } 285 if argc > 3 { let b: *u8 = argv[3] as *u8; let v2: i64 = bp_atoi(b); if v2 > 0 { interval_ms = v2 } } 286 if argc > 4 { let c: *u8 = argv[4] as *u8; let v3: i64 = bp_atoi(c); if v3 > 0 { bar = v3 } } 287 if argc > 5 { let d: *u8 = argv[5] as *u8; let v4: i64 = bp_atoi(d); if v4 > 0 { k = v4 } } 288 if bar <= 0 { 289 bp_werr("nx_blkprofile live: bar UNRESOLVED (ncpu unreadable and none given) -- REFUSING\n" as *u8) 290 sys_exit(BP_EXIT_UNMEASURED) 291 return BP_EXIT_UNMEASURED 292 } 293 if k > IOA_MEDIAN_MAX_K { 294 bp_werr("nx_blkprofile live: k exceeds IOA_MEDIAN_MAX_K, the bound the shipping sampler enforces -- REFUSING rather than recommending a k the armed gate could not use\n" as *u8) 295 sys_exit(BP_EXIT_USAGE) 296 return BP_EXIT_USAGE 297 } 298 let want: i64 = dur_s * BP_MS_PER_S / interval_ms 299 // NO SILENT CAP: a run that would not fit REFUSES and names the bound, rather than quietly measuring a 300 // prefix of the window and publishing it as the window. 301 if want > BP_MAX_SAMPLES { 302 bp_werr("nx_blkprofile live: duration/interval exceeds BP_MAX_SAMPLES -- REFUSING (shorten the run or lengthen the interval; a truncated window published as a whole one is how a partial measurement becomes a fact)\n" as *u8) 303 sys_exit(BP_EXIT_USAGE) 304 return BP_EXIT_USAGE 305 } 306 if want < 2 { 307 bp_werr("nx_blkprofile live: fewer than two samples requested -- REFUSING\n" as *u8) 308 sys_exit(BP_EXIT_USAGE) 309 return BP_EXIT_USAGE 310 } 311 312 let s: *i64 = sys_mmap(BP_SAMPLE_BYTES) as *i64 313 let kbuf: *i64 = sys_mmap(BP_KBUF_BYTES) as *i64 314 let simo: *i64 = sys_mmap(BP_SIMOUT_BYTES) as *i64 315 var n: i64 = 0 316 var failed: i64 = 0 317 var clamped: i64 = 0 318 var atbar: i64 = 0 319 var i: i64 = 0 320 while i < want { 321 if ioa_measure(meas) == 0 { 322 var v: i64 = meas[1] 323 if v >= 0 { 324 s[n] = v 325 n = n + 1 326 if v >= bar { atbar = atbar + 1 } 327 if v >= BP_HIST_MAX { clamped = clamped + 1; v = BP_HIST_MAX - 1 } 328 hist[v] = hist[v] + 1 329 } else { failed = failed + 1 } 330 } else { failed = failed + 1 } 331 if i + 1 < want { ioa_sleep_ms(interval_ms) } 332 i = i + 1 333 } 334 335 off = bp_puts(ob, off, "=== nx_blkprofile live -- deriving the SMOOTHED-WITNESS span that knowledge/build_admit.conf refuses to be armed without ===\n requested_samples=" as *u8) 336 off = bp_puti(ob, off, want) 337 off = bp_puts(ob, off, " obtained=" as *u8); off = bp_puti(ob, off, n) 338 off = bp_puts(ob, off, " read_failures=" as *u8); off = bp_puti(ob, off, failed) 339 off = bp_puts(ob, off, " interval_ms=" as *u8); off = bp_puti(ob, off, interval_ms) 340 off = bp_puts(ob, off, " nominal_window_ms=" as *u8); off = bp_puti(ob, off, (want - 1) * interval_ms) 341 off = bp_puts(ob, off, " (NOMINAL: no clock is read, see header)\n bar=" as *u8); off = bp_puti(ob, off, bar) 342 off = bp_puts(ob, off, " ncpu=" as *u8); off = bp_puti(ob, off, ncpu) 343 off = bp_puts(ob, off, " k=" as *u8); off = bp_puti(ob, off, k) 344 off = bp_puts(ob, off, " clamped_above_hist=" as *u8); off = bp_puti(ob, off, clamped) 345 off = bp_puts(ob, off, "\n partition: obtained + read_failures = " as *u8); off = bp_puti(ob, off, n + failed) 346 off = bp_puts(ob, off, " of requested " as *u8); off = bp_puti(ob, off, want) 347 off = bp_puts(ob, off, "\n" as *u8) 348 if n < 2 { 349 off = bp_puts(ob, off, " verdict=UNMEASURED too few samples obtained\n" as *u8) 350 sys_write(BP_STDOUT, ob, off) 351 sys_exit(BP_EXIT_UNMEASURED) 352 return BP_EXIT_UNMEASURED 353 } 354 355 off = bp_puts(ob, off, " DISTRIBUTION min=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 1)) 356 off = bp_puts(ob, off, " p50=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 500)) 357 off = bp_puts(ob, off, " p90=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 900)) 358 off = bp_puts(ob, off, " p99=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 990)) 359 off = bp_puts(ob, off, " max=" as *u8); off = bp_puti(ob, off, bp_pct(hist, n, 1000)) 360 off = bp_puts(ob, off, "\n" as *u8) 361 362 let base: i64 = atbar * BP_PERMIL / n 363 off = bp_puts(ob, off, " SPAN TABLE -- each row is the verdict the ARMED gate would have produced on THIS series.\n added_latency_ms is paid by EVERY admission check, the clock dispatcher's pre-dispatch call included.\n" as *u8) 364 off = bp_puts(ob, off, " span_ms=0 k=1 TODAY gap_ms=0 trials=" as *u8); off = bp_puti(ob, off, n) 365 off = bp_puts(ob, off, " refuse_permil=" as *u8); off = bp_puti(ob, off, base) 366 off = bp_puts(ob, off, " added_latency_ms=0\n" as *u8) 367 368 // The asymptote is the LONGEST simulable span -- the value the curve is converging toward. Taken 369 // first, from the top of the table down, so the knee below is measured against it and not guessed. 370 var asym: i64 = BP_UNREADABLE 371 var si: i64 = BP_NSPANS - 1 372 while si >= 0 { 373 let sp: i64 = bp_span_at(si) 374 if bp_sim(s, n, interval_ms, k, sp, bar, kbuf, simo) == 0 { if asym < 0 { asym = simo[2] } } 375 si = si - 1 376 } 377 // THE CURVE MUST FLATTEN BEFORE ANYTHING IS RECOMMENDED. Taking the asymptote as the LONGEST span makes 378 // that span trivially satisfy its own tolerance, so a still-falling curve would always RECOMMEND its own 379 // last row -- an artefact of where the table happens to end, not a property of the signal. Every value is 380 // kept so flatness can be tested explicitly, and a recommendation must be CORROBORATED by at least one 381 // LONGER span agreeing with it. FOUND BY RUNNING THIS ORGAN AND READING ITS OWN OUTPUT: the first live 382 // derivation recommended 12000 ms purely because 12000 ms was the last row in the table. 383 let rf: *i64 = sys_mmap(BP_SIMOUT_BYTES) as *i64 384 var rz: i64 = 0 385 while rz < BP_NSPANS { rf[rz] = BP_UNREADABLE; rz = rz + 1 } 386 var best: i64 = BP_UNREADABLE 387 si = 0 388 while si < BP_NSPANS { 389 let sp: i64 = bp_span_at(si) 390 off = bp_puts(ob, off, " span_ms=" as *u8); off = bp_puti(ob, off, sp) 391 if bp_sim(s, n, interval_ms, k, sp, bar, kbuf, simo) == 0 { 392 rf[si] = simo[2] 393 off = bp_puts(ob, off, " gap_ms=" as *u8); off = bp_puti(ob, off, simo[0]) 394 off = bp_puts(ob, off, " trials=" as *u8); off = bp_puti(ob, off, simo[1]) 395 off = bp_puts(ob, off, " refuse_permil=" as *u8); off = bp_puti(ob, off, simo[2]) 396 off = bp_puts(ob, off, " added_latency_ms=" as *u8); off = bp_puti(ob, off, sp) 397 } else { 398 off = bp_puts(ob, off, " UNDERSAMPLED-at-this-interval (NOT a zero: this span cannot be simulated from a series sampled every " as *u8) 399 off = bp_puti(ob, off, interval_ms) 400 off = bp_puts(ob, off, " ms)" as *u8) 401 } 402 off = bp_puts(ob, off, "\n" as *u8) 403 si = si + 1 404 } 405 406 off = bp_puts(ob, off, " asymptote_refuse_permil=" as *u8); off = bp_puti(ob, off, asym) 407 off = bp_puts(ob, off, " convergence_tolerance_permil=" as *u8); off = bp_puti(ob, off, BP_CONV_TOL_PERMIL) 408 off = bp_puts(ob, off, "\n" as *u8) 409 // Flatness: the smallest span whose refusal rate every LONGER simulable span still agrees with, to 410 // within the tolerance. A candidate must have at least one longer span corroborating it, so the widest 411 // row tested can never recommend itself. 412 var lastidx: i64 = BP_UNREADABLE 413 var nsim: i64 = 0 414 si = 0 415 while si < BP_NSPANS { 416 if rf[si] >= 0 { lastidx = si; nsim = nsim + 1 } 417 si = si + 1 418 } 419 if nsim >= 2 { 420 si = 0 421 while si < lastidx { 422 if rf[si] >= 0 { 423 var flat: i64 = 1 424 var j: i64 = si 425 while j <= lastidx { 426 if rf[j] >= 0 { 427 var d: i64 = rf[j] - rf[si] 428 if d < 0 { d = 0 - d } 429 if d > BP_CONV_TOL_PERMIL { flat = 0 } 430 } 431 j = j + 1 432 } 433 if flat == 1 { if best < 0 { best = si } } 434 } 435 si = si + 1 436 } 437 } 438 off = bp_puts(ob, off, " simulable_spans=" as *u8); off = bp_puti(ob, off, nsim) 439 off = bp_puts(ob, off, " widest_tested_ms=" as *u8) 440 if lastidx >= 0 { off = bp_puti(ob, off, bp_span_at(lastidx)) } else { off = bp_puti(ob, off, BP_UNREADABLE) } 441 off = bp_puts(ob, off, " flattened=" as *u8) 442 if best >= 0 { off = bp_puts(ob, off, "YES\n" as *u8) } else { off = bp_puts(ob, off, "NO-still-falling-at-the-widest-span-tested\n" as *u8) } 443 if best >= 0 { 444 let bs: i64 = bp_span_at(best) 445 off = bp_puts(ob, off, " RECOMMEND samples=" as *u8); off = bp_puti(ob, off, k) 446 off = bp_puts(ob, off, " gap_ms=" as *u8); off = bp_puti(ob, off, bs / (k - 1)) 447 off = bp_puts(ob, off, " span_ms=" as *u8); off = bp_puti(ob, off, bs) 448 off = bp_puts(ob, off, " -- the SHORTEST span whose median has stopped tracking the bursts.\n THIS IS A RECOMMENDATION, NOT AN ARMING. Write the two keys into knowledge/build_admit.conf by hand and\n record this run beside them: that conf asks for the count, the gap AND the run that produced them.\n" as *u8) 449 } else { 450 off = bp_puts(ob, off, " RECOMMEND none -- the curve has NOT flattened inside the tested range, so the shortest sufficient span\n is not in this table and the widest row is a floor, not an answer. DO NOT ARM on this series: extend the\n span table or re-run longer. A synchronous median also pays its whole span on EVERY admission check, so a\n span this wide is an argument for a CONTINUOUSLY MAINTAINED confirmed level that the check reads instantly,\n which is how flight control does it -- not for arming a multi-second stall in front of every build.\n" as *u8) 451 } 452 off = bp_puts(ob, off, "verdict=MEASURED\n" as *u8) 453 sys_write(BP_STDOUT, ob, off) 454 return 0 455}