nx_sched_qos.nx
buildroot/runtime/nx_sched_qos.nx
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
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
structs
| 16 | struct QosSched |
consts
| 11 | const QSLOT_FREE: i64 = 0 |
| 12 | const QSLOT_RUNNING: i64 = 1 |
| 13 | const PRIO_CHAT: i64 = 10 // interactive foreground |
| 14 | const PRIO_IMAGE: i64 = 1 // background batch render (preemptible) |
| 27 | const QCAP: i64 = 64 |
functions
| 29 | func qos_new(n_slots: i64) -> *QosSched |
| 48 | func qos_running(c: *QosSched) -> i64 called by 1: main |
| 53 | func _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 |
| 55 | func _lowest_running(c: *QosSched, prio: i64) -> i64 called by 1: qos_admit |
| 65 | func _enqueue(c: *QosSched, req: i64, prio: i64, tok: i64, mod: i64) -> i64 called by 1: qos_admit |
| 73 | func _place(c: *QosSched, slot: i64, req: i64, prio: i64, tok: i64, mod: i64) -> i64 |
| 81 | func qos_admit(c: *QosSched, req: i64, prio: i64, tok: i64, mod: i64, preempted_out: *i64) -> i64 |
| 98 | func qos_complete(c: *QosSched, slot: i64) -> i64 |
| 117 | func 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 |
| 119 | func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 120 | func 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 } |
| 122 | func main() -> i64 |