code wiki / (root) / nx_sched_qos.nx

nx_sched_qos.nx

buildroot/runtime/nx_sched_qos.nx

8943 B166 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic sched
docsdependenciesstructsconstsfunctions

about

nx_sched_qos.nx -- QoS priority + PREEMPTION for sovereign GPU resource-sharing (serving census Q2, closes the PREE gap). The scenario the operator cares about: ONE 16GB GPU shared by BACKGROUND image-gen (Z-Image DiT, long batch job, low priority) and INTERACTIVE chat (short, latency-sensitive, high priority). Plain FCFS makes chat wait behind a 30s image render = bad. This adds: priority-ordered admission + PREEMPTION -- an arriving high-priority request can preempt the lowest-priority RUNNING slot; the preempted job keeps its progress (tokens/steps remaining) and is requeued to RESUME later. That is how you share one accelerator between a foreground companion and a background renderer without either starving. Self-contained (doesn't touch the proven nx_batch_scheduler); pure logic, no GPU needed. license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_sched_qos.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gw sys_write sys_mmap qos_new sys_mmap ↻ qos_admit _free_slot _place _lowest_running _enqueue gn sys_mmap ↻ sys_write ↻ qos_slot_of qos_complete _place ↻ qos_running sys_exit

structs

16struct QosSched

consts

11const QSLOT_FREE: i64 = 0
12const QSLOT_RUNNING: i64 = 1
13const PRIO_CHAT: i64 = 10 // interactive foreground
14const PRIO_IMAGE: i64 = 1 // background batch render (preemptible)
27const QCAP: i64 = 64

functions

29func qos_new(n_slots: i64) -> *QosSched
called by 1: main calls 1: sys_mmap
48func qos_running(c: *QosSched) -> i64
called by 1: main
53func _free_slot(c: *QosSched) -> i64 { let st: *i64 = c.st; var i: i64 = 0; while i < c.n_slots { if st[i] == QSLOT_FREE { return i } i = i + 1 } return 0 - 1 }
called by 1: qos_admit
55func _lowest_running(c: *QosSched, prio: i64) -> i64
called by 1: qos_admit
65func _enqueue(c: *QosSched, req: i64, prio: i64, tok: i64, mod: i64) -> i64
called by 1: qos_admit
73func _place(c: *QosSched, slot: i64, req: i64, prio: i64, tok: i64, mod: i64) -> i64
81func qos_admit(c: *QosSched, req: i64, prio: i64, tok: i64, mod: i64, preempted_out: *i64) -> i64
98func qos_complete(c: *QosSched, slot: i64) -> i64
called by 1: main calls 1: _place
117func qos_slot_of(c: *QosSched, req: i64) -> i64 { let st: *i64=c.st; let rq: *i64=c.rq; var i: i64=0; while i<c.n_slots { if st[i]==QSLOT_RUNNING { if rq[i]==req { return i } } i=i+1 } return 0-1 }
called by 1: main
119func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
120func gn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
122func main() -> i64