code wiki / _hdl_build / nx_dstate.nx

nx_dstate.nx

buildroot/runtime/_hdl_build/nx_dstate.nx

41808 B767 linesdepth 7pulls 8 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_ctxtop_lib.nx nx_resmon_lib.nx nx_dstate.nx

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

main ds_streq ds_atoi ds_puts ds_len rm_conf rm_field rm_slen ct_load_centi ds_pn ds_puts ↻ ds_isnum ds_field_from_state ds_cmd0 ds_owner ds_has ds_len ↻ ds_zpids ds_isnum ↻ ds_atoi ↻

structs

none

consts

34const DS_DIRBUF: i64 = 65536
35const DS_STATBUF: i64 = 4096
36const DS_LOADBUF: i64 = 128
37const DS_CONFBUF: i64 = 4096
38const DS_MAXD: i64 = 512
39const DS_NAMEMAX: i64 = 64
41const DS_RECLEN_OFF: i64 = 16
42const DS_NAME_OFF: i64 = 19
43const DS_EXIT_UNMEASURED: i64 = 3
44const DS_EXIT_REFUSED: i64 = 4
49const DS_ADMIT_DEFAULT: i64 = 1600
58const DS_GAP_DEFAULT_MS: i64 = 3000
59const DS_CONF: *u8 = "knowledge/dstate.conf"
63const DS_CONF_UP: *u8 = "../knowledge/dstate.conf"
67const DS_CONF_MISS: i64 = 0 - 1
72const DS_STARTTIME_FIELD: i64 = 22
77const DS_PPID_FIELD: i64 = 4
78const DS_MAXZP: i64 = 64
86const DS_USER_HZ_DEFAULT: i64 = 100

functions

88func ds_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: ds_putsds_has
89func ds_puts(s: *u8) -> i64 { sys_write(1, s, ds_len(s)); return 0 }
called by 2: ds_pnmain calls 1: ds_len
90func ds_pn(v: i64) -> i64
called by 1: main calls 1: ds_puts
104func ds_isnum(s: *u8) -> i64
called by 2: ds_zpidsmain
120func ds_field_from_state(b: *u8, n: i64, stpos: i64, field: i64) -> i64
called by 1: main
149func ds_atoi(s: *u8) -> i64
called by 2: ds_zpidsmain
169func ds_cmd0(pid: i64, out: *u8, cap: i64, path: *u8, reads: *i64) -> i64
called by 1: main
209func ds_streq(a: *u8, b: *u8) -> i64
called by 1: main
239func ds_has(hay: *u8, ned: *u8) -> i64
called by 1: ds_owner calls 1: ds_len
261func ds_owner(cmd: *u8, cn: i64, ppid: i64, pid: i64) -> i64
called by 1: main calls 1: ds_has
271func ds_zpids(out: *i64, cap: i64, dbuf: *u8, sbuf: *u8, path: *u8, reads: *i64) -> i64
called by 1: main calls 2: ds_isnumds_atoi
322func main(argc: i64, argv: *i64) -> i64