nx_pe_perf_probe.nx source
↩ module page · 61 lines · 2137 B
1// nx_pe_perf_probe.nx -- measure, IN THE WINDOWS PE, where the transfer time goes.
2// Loops 100x the live per-page workload (23 records x 13KB) so the ~15ms-granular
3// PE clock has signal. Splits AEAD-decrypt compute vs sys_mmap(13KB) cost.
4// Build as PE (overwrites nishi_fetch.exe), run, read stdout.
5//
6// expect_exit: 0
7
8import "nx_syscalls.nx"
9import "nx_chacha20_poly1305.nx"
10const K_MAGIC_13000: i64 = 13000
11const K_MAGIC_2300: i64 = 2300
12
13func p_ps(s: *u8, n: i64) -> i64 { sys_write(1, s, n); return 0 }
14func p_pn(v: i64) -> i64 {
15 let b: *u8 = sys_mmap(24)
16 var x: i64 = v
17 if x < 0 { x = 0 - x }
18 var i: i64 = 22
19 if x == 0 { b[i] = 0x30 as u8; i = i - 1 }
20 else { while x > 0 { b[i] = (0x30 + (x - (x/10)*10)) as u8; x = x / 10; i = i - 1 } }
21 sys_write(1, ((b as i64) + i + 1) as *u8, 22 - i)
22 return 0
23}
24
25func main() -> i64 {
26 let REC: i64 = K_MAGIC_13000
27 let ITERS: i64 = K_MAGIC_2300 // 100 pages x 23 records
28 let pt: *u8 = sys_mmap(REC)
29 let ct: *u8 = sys_mmap(REC + 64)
30 let tag: *u8 = sys_mmap(32)
31 let out: *u8 = sys_mmap(REC + 64)
32 let key: *u8 = sys_mmap(32)
33 let nonce: *u8 = sys_mmap(16)
34 let aad: *u8 = sys_mmap(16)
35 var i: i64 = 0
36 while i < 32 { key[i] = (i + 1) as u8; i = i + 1 }
37 nx_chacha20_poly1305_encrypt(key, nonce, aad, 5, pt, REC, ct, tag)
38
39 // (1) AEAD decrypt compute, ITERS times
40 let t0: i64 = sys_now_ms()
41 var k: i64 = 0
42 while k < ITERS {
43 nx_chacha20_poly1305_decrypt(key, nonce, aad, 5, ct, REC, tag, out)
44 k = k + 1
45 }
46 let t1: i64 = sys_now_ms()
47
48 // (2) sys_mmap(13KB) cost, ITERS times (the per-record HeapAlloc churn)
49 var m: i64 = 0
50 while m < ITERS {
51 let junk: *u8 = sys_mmap(REC)
52 junk[0] = 1 as u8 // touch it
53 m = m + 1
54 }
55 let t2: i64 = sys_now_ms()
56
57 p_ps("PE aead-decrypt " as *u8, 16); p_pn(ITERS); p_ps("x13KB = " as *u8, 8); p_pn(t1 - t0); p_ps("ms\n" as *u8, 3)
58 p_ps("PE sys_mmap(13KB) " as *u8, 18); p_pn(ITERS); p_ps("x = " as *u8, 4); p_pn(t2 - t1); p_ps("ms\n" as *u8, 3)
59 sys_exit(0)
60 return 0
61}