code wiki / _hdl_build / nx_clock_status.nx

nx_clock_status.nx source

↩ module page · 34 lines · 2649 B

1// nx_clock_status.nx -- ONE view of the whole consolidated clock (the de-sprawl payoff: every periodic job in one 2// place, like `systemctl list-timers`). Loads the durable registry + current tick and shows, per job: its interval, 3// ticks-until-due (or DUE NOW), its organ, and whether that organ is actually blessed/present (an un-deployable job 4// is surfaced, never hidden). Read-only. license_tier: ORIGINAL expect_exit: 0 5import "nx_clock_sched.nx" 6import "nx_syscalls.nx" 7 8func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 10func readnum(p: *u8) -> i64 { let lp: *i64 = sys_mmap(8) as *i64; let d: *u8 = sys_read_file(p, lp); if (d as i64)==0 { return 0 } var c: i64=0; var i: i64=0; while i<lp[0] { if d[i]>=(48 as u8) { if d[i]<=(57 as u8) { c=c*10+(d[i]-(48 as u8)) as i64 } } i=i+1 } return c } 11 12func main(argc: i64, argv: *i64) -> i64 { 13 let names: *u8 = sys_mmap(CLK_MAXJOBS*CLK_NAMEW); let orgs: *u8 = sys_mmap(CLK_MAXJOBS*CLK_NAMEW) 14 let iv: *i64 = sys_mmap(CLK_MAXJOBS*8) as *i64; let nd: *i64 = sys_mmap(CLK_MAXJOBS*8) as *i64 15 let np: *i64 = sys_mmap(8) as *i64; np[0]=0 16 clk_load("knowledge/sched/jobs.tsv" as *u8, names, orgs, iv, nd, np) 17 if np[0] == 0 { w("nx_clock_status: no jobs in knowledge/sched/jobs.tsv (register some, then nx_bless their organs)\n" as *u8); sys_exit(0); return 0 } 18 let T: i64 = readnum("knowledge/sched/tick.txt" as *u8) 19 w("=== NISHI CLOCK STATUS (tick " as *u8); wn(T); w(", " as *u8); wn(np[0]); w(" jobs, ONE clock) ===\n" as *u8) 20 var missing: i64 = 0; var i: i64 = 0 21 while i < np[0] { 22 w(" " as *u8); w(clk_slot(names, i)); w(" every " as *u8); wn(iv[i]); w("t" as *u8) 23 let di: i64 = clk_due_in(nd[i], T) 24 if di <= 0 { w(" DUE NOW" as *u8) } else { w(" due in " as *u8); wn(di); w("t" as *u8) } 25 w(" -> " as *u8); w(clk_slot(orgs, i)) 26 if clk_twin_ok(clk_slot(orgs, i)) == 1 { w(" [twin OK]\n" as *u8) } else { w(" [TWIN MISSING -> nx_bless]\n" as *u8); missing = missing + 1 } 27 i = i + 1 28 } 29 w(" -- " as *u8); wn(np[0]); w(" jobs" as *u8) 30 if missing > 0 { w(", " as *u8); wn(missing); w(" un-blessed (won't run until nx_bless'd)" as *u8) } 31 w("; replaces " as *u8); wn(np[0]); w(" separate pulse loops with ONE registry + ONE dispatcher.\n" as *u8) 32 sys_exit(0) 33 return 0 34}