code wiki / _hdl_build / nx_pipeline_metrics.nx
nx_pipeline_metrics.nx source
↩ module page · 52 lines · 3269 B
1// nx_pipeline_metrics.nx -- the S-CLASS-EXCEED layer over nx_dev_pipeline: a pipeline that MEASURES and
2// IMPROVES itself, not just a transcription of the flow (operator: "make sure its s class exceeds and you
3// arent just parroting what i gave"). Grounded in real process engineering:
4// - Toyota Production System POKA-YOKE / JIDOKA: after a defect class is root-caused, install a GUARD so
5// it CANNOT recur (the layer-count lint we built IS a poka-yoke). The described flow re-escalates the
6// same class forever; this one prevents it -> escalations -> count of DISTINCT classes, not linear in arcs.
7// - DORA four keys: lead time, change-fail rate, first-pass yield (rework-free), MTTR.
8// - Goldratt THEORY OF CONSTRAINTS: the bottleneck stage is the only one worth optimizing.
9// The EXCEED is provable: a recurring-defect stream costs the static pipeline O(arcs) escalations and this
10// one O(distinct classes). license_tier: ORIGINAL Upgrades nx_dev_pipeline; the guard = a Librarian lint.
11
12import "nx_syscalls.nx"
13
14// ---- DORA / lean metrics ----
15func pm_first_pass_yield(entered_rework: i64) -> i64 { if entered_rework == 0 { return 1 } return 0 }
16func pm_lead_time(stage_times: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { s=s+stage_times[i]; i=i+1 } return s }
17// Theory of Constraints: the constraint is the slowest stage -- optimizing anything else is wasted.
18func pm_bottleneck(stage_times: *i64, n: i64) -> i64 {
19 var bi: i64=0; var bt: i64=0-1; var i: i64=0
20 while i<n { if stage_times[i] > bt { bt=stage_times[i]; bi=i } i=i+1 }
21 return bi
22}
23func pm_change_fail_rate_permil(failures: i64, total: i64) -> i64 { if total<=0 {return 0} return failures*1000/total }
24
25// ---- POKA-YOKE self-improvement (the exceed) ----
26// guards is a bitmask over defect classes (bit c set = class c can no longer recur).
27func pk_install_guard(guards_mask: i64, bug_class: i64) -> i64 { return guards_mask | (1 << bug_class) }
28func pk_is_guarded(guards_mask: i64, bug_class: i64) -> i64 { if (guards_mask & (1 << bug_class)) != 0 { return 1 } return 0 }
29
30// THIS pipeline: a recurring GUARDED class is prevented at BUILD (poka-yoke) -> no escalation. Returns the
31// total escalations over the arc stream (bounded by the number of DISTINCT classes).
32func pipe_escalations_pokayoke(classes: *i64, n: i64) -> i64 {
33 var guards: i64=0; var esc: i64=0; var i: i64=0
34 while i<n {
35 let c: i64 = classes[i]
36 if pk_is_guarded(guards, c) == 0 { // first time: escalate (research+fix) + install the guard
37 esc = esc + 1
38 guards = pk_install_guard(guards, c)
39 } // already guarded: prevented, no escalation
40 i = i + 1
41 }
42 return esc
43}
44// the PARROTED baseline (the flow as described, no learning): every defect arc escalates again.
45func pipe_escalations_static(classes: *i64, n: i64) -> i64 { return n } // every arc carries a defect -> escalates
46
47// distinct classes in the stream (the poka-yoke escalation floor).
48func pipe_distinct(classes: *i64, n: i64) -> i64 {
49 var seen: i64=0; var d: i64=0; var i: i64=0
50 while i<n { let b: i64 = 1 << classes[i]; if (seen & b)==0 { d=d+1; seen=seen|b } i=i+1 }
51 return d
52}