code wiki / _hdl_build / nx_dstate.nx
nx_dstate.nx
buildroot/runtime/_hdl_build/nx_dstate.nx
about
nx_dstate.nx -- WHO IS BLOCKED. The D-state (uninterruptible I/O) roster, for the exact moment a box
is saturated and every other attribution tool has refused.
WHY IT EXISTS, MEASURED 2026-08-14: nx_procchurn returned RED sev=2 with `procs_running=2
procs_blocked=4` and cpu busy=281 permil -- its own note reads "blocked >> running = I/O or lock bound,
NOT compute; more CPU would not help". It names the CONDITION and cannot name the PRODUCER. The tool
that names producers, nx_ctxtop, then REFUSED: `load_centi=1342 max=800 -- host already saturated`.
-- A DIAGNOSTIC WHOSE ADMISSION CEILING IS THE CONDITION IT DIAGNOSES IS UNAVAILABLE EXACTLY WHEN IT
IS NEEDED. The refusal is CORRECT (its lib's law: a diagnostic that cannot refuse to run is a load
generator with good intentions) -- the gap is that nothing cheap enough to run under saturation exists.
WHY THIS ONE CAN RUN WHERE ctxtop CANNOT -- a COST argument, not a wish:
nx_ctxtop measures a RATE, and a rate needs TWO samples separated in time: it walks all of /proc
TWICE around a 3000 ms window. D-state is a STATE, not a rate, so ONE sample answers it -- one pass,
no window, no fork, and /proc/<pid>/stat is a SINGLE small read per pid (ctxtop reads status twice).
Roughly half the syscalls and none of the wait.
-- A STATE NEEDS ONE SAMPLE; ONLY A DERIVATIVE NEEDS TWO. Paying for a window to answer an
instantaneous question is how a cheap question inherits an expensive tool's admission ceiling.
ADMISSION IS KEPT, NOT DROPPED, and its ceiling is DERIVED rather than picked: equal marginal impact
at half the cost admits at twice the load, so the default is 2x the incumbent's 800. It is POLICY, so
it lives in knowledge/dstate.conf and is PRINTED on every run -- a ceiling nobody can see is a magic
number wherever it happens to be stored.
nx_dstate [conf-path]
-- "NOTHING IS BLOCKED" AND "I REFUSED TO LOOK" MUST NEVER SHARE AN OUTCOME, so refusal has its own
exit code and its own line. Codes MATCH the sibling (nx_ctxtop): 3 UNMEASURED, 4 REFUSED.
exit 0 sampled | 3 UNMEASURED (cannot read /proc) | 4 ADMISSION-REFUSED (load above the ceiling)
license_tier: ORIGINAL. Read-only. No hw writes (Rule 26).
dependencies 2 imports · 0 importers
imports: nx_ctxtop_lib.nxnx_resmon_lib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 34 | const DS_DIRBUF: i64 = 65536 |
| 35 | const DS_STATBUF: i64 = 4096 |
| 36 | const DS_LOADBUF: i64 = 128 |
| 37 | const DS_CONFBUF: i64 = 4096 |
| 38 | const DS_MAXD: i64 = 512 |
| 39 | const DS_NAMEMAX: i64 = 64 |
| 41 | const DS_RECLEN_OFF: i64 = 16 |
| 42 | const DS_NAME_OFF: i64 = 19 |
| 43 | const DS_EXIT_UNMEASURED: i64 = 3 |
| 44 | const DS_EXIT_REFUSED: i64 = 4 |
| 49 | const DS_ADMIT_DEFAULT: i64 = 1600 |
| 58 | const DS_GAP_DEFAULT_MS: i64 = 3000 |
| 59 | const DS_CONF: *u8 = "knowledge/dstate.conf" |
| 63 | const DS_CONF_UP: *u8 = "../knowledge/dstate.conf" |
| 67 | const DS_CONF_MISS: i64 = 0 - 1 |
| 72 | const DS_STARTTIME_FIELD: i64 = 22 |
| 77 | const DS_PPID_FIELD: i64 = 4 |
| 78 | const DS_MAXZP: i64 = 64 |
| 86 | const DS_USER_HZ_DEFAULT: i64 = 100 |
functions
| 88 | func ds_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 89 | func ds_puts(s: *u8) -> i64 { sys_write(1, s, ds_len(s)); return 0 } |
| 90 | func ds_pn(v: i64) -> i64 |
| 104 | func ds_isnum(s: *u8) -> i64 |
| 120 | func ds_field_from_state(b: *u8, n: i64, stpos: i64, field: i64) -> i64 called by 1: main |
| 149 | func ds_atoi(s: *u8) -> i64 |
| 169 | func ds_cmd0(pid: i64, out: *u8, cap: i64, path: *u8, reads: *i64) -> i64 called by 1: main |
| 209 | func ds_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 239 | func ds_has(hay: *u8, ned: *u8) -> i64 |
| 261 | func ds_owner(cmd: *u8, cn: i64, ppid: i64, pid: i64) -> i64 |
| 271 | func ds_zpids(out: *i64, cap: i64, dbuf: *u8, sbuf: *u8, path: *u8, reads: *i64) -> i64 |
| 322 | func main(argc: i64, argv: *i64) -> i64 |