Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/evidence/own-gpu-driver/rung0/rung0.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / evidence / own-gpu-driver / rung0 / rung0.sh` 73 lines ยท 4332 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # rung0.sh: what NVIDIA's kernel driver costs, measured (L332 rung 0). Run INSIDE a spark-window. 3 # rung0.sh OUTDIR idle LABEL SECONDS baseline: nothing of ours runs (negative control) 4 # rung0.sh OUTDIR run LABEL -- CMD... one workload, unprobed (time -v only) 5 # rung0.sh OUTDIR probe LABEL -- CMD... same workload with perf (kernel CPU per module) + bpftrace (ioctl counts/time) 6 # rung0.sh OUTDIR strace LABEL -- CMD... same workload under strace (call list and session-start timeline only) 7 # rung0.sh OUTDIR attach LABEL PID SECONDS live process (35B server): perf + bpftrace for SECONDS, no ptrace 8 # Read-only: sudo is used for perf/bpftrace and to read schedstat/interrupts; nothing is loaded, set or killed. 9 set -u 10 out=$1; mode=$2; shift 2 11 mkdir -p "$out" 12 snap() { # $1 = file: nvidia interrupt counts, nvidia/uvm kthread schedstat (ns on cpu), clock 13 { 14 echo "t_ns $(date +%s%N)" 15 grep -iE "nvidia|nvgpu|000f:01:00" /proc/interrupts | awk '{s=0; for(i=2;i<=NF;i++) if($i ~ /^[0-9]+$/) s+=$i; else break; print "irq", $1, s, $NF}' 16 for d in /proc/[0-9]*; do 17 c=$(cat "$d/comm" 2>/dev/null) || continue 18 case "$c" in nv_*|nvidia*|UVM*|uvm*) echo "kthread ${d#/proc/} $c $(awk '{print $1}' "$d/schedstat" 2>/dev/null)";; esac 19 done 20 } > "$1" 21 } 22 perf_start() { sudo perf record -a -e cpu-clock -F 99 -o "$out/$1.perf.data" -- sleep "$2" > "$out/$1.perf.log" 2>&1 & PERF_PID=$!; } 23 perf_report() { # kernel CPU per NVIDIA module (symbols from /proc/kallsyms), per thread name; samples at 99 Hz cpu-clock => seconds = samples/99 24 sudo awk '$4 ~ /^\[nvidia/ {gsub(/[\[\]]/, "", $4); print $3, $4}' /proc/kallsyms > "$out/$1.modsyms.txt" 25 sudo perf report --no-inline -g none -i "$out/$1.perf.data" --sort comm,sym --stdio --no-children -n -F sample,comm,sym 2>/dev/null \ 26 | grep -E "^ +[0-9]" > "$out/$1.commsym.txt" 27 awk 'NR==FNR {mod[$1]=$2; next} 28 { n=$1; sym=$NF; comm=$2; for (i=3; i= 3) printf "sym %s %d\n", k, bys[k] }' \ 32 "$out/$1.modsyms.txt" "$out/$1.commsym.txt" | sort -k1,1 -k3,3nr > "$out/$1.modules.txt" 33 } 34 bpf_start() { # $1 label, $2 = pid filter expression target (comm name or pid) 35 sudo bpftrace -q -e " 36 tracepoint:syscalls:sys_enter_ioctl /$2/ { @start[tid] = nsecs; @cmd[tid] = args->cmd; } 37 tracepoint:syscalls:sys_exit_ioctl /@start[tid]/ { @n[@cmd[tid]] = count(); @ns[@cmd[tid]] = sum(nsecs - @start[tid]); delete(@start[tid]); delete(@cmd[tid]); } 38 tracepoint:syscalls:sys_enter_mmap /$2/ { @mmap = count(); } 39 tracepoint:syscalls:sys_enter_munmap /$2/ { @munmap = count(); } 40 " > "$out/$1.bpf.txt" 2>&1 & BPF_PID=$! 41 } 42 case "$mode" in 43 idle) 44 label=$1 secs=$2; snap "$out/$label.before"; perf_start "$label" "$secs"; wait "$PERF_PID"; snap "$out/$label.after"; perf_report "$label" ;; 45 run|probe|strace) 46 label=$1; shift; [ "$1" = "--" ] && shift 47 snap "$out/$label.before" 48 if [ "$mode" = probe ]; then 49 bpf_start "$label" "comm == \"$(basename "$1" | cut -c1-15)\""; sleep 2 50 perf_start "$label" 600 51 fi 52 t0=$(date +%s%N) 53 if [ "$mode" = strace ]; then 54 strace -f -r -T -e trace=openat,ioctl,mmap,munmap -o "$out/$label.strace" /usr/bin/time -v -o "$out/$label.time" "$@" > "$out/$label.stdout" 2>&1 55 else 56 /usr/bin/time -v -o "$out/$label.time" "$@" > "$out/$label.stdout" 2>&1 57 fi 58 rc=$?; t1=$(date +%s%N) 59 snap "$out/$label.after" 60 echo "exit $rc wall_ns $((t1 - t0))" > "$out/$label.result" 61 if [ "$mode" = probe ]; then 62 sudo pkill -INT -f "perf record -a -e cpu-clock -F 99 -o $out/$label.perf.data" ; sleep 1 63 sudo kill -INT "$BPF_PID" 2>/dev/null; sleep 1; perf_report "$label" 64 fi ;; 65 attach) 66 label=$1 pid=$2 secs=$3 67 snap "$out/$label.before" 68 bpf_start "$label" "pid == $pid"; sleep 2 69 perf_start "$label" "$secs"; wait "$PERF_PID" 70 sudo kill -INT "$BPF_PID" 2>/dev/null; sleep 1 71 snap "$out/$label.after"; perf_report "$label" ;; 72 *) echo "usage: see header" >&2; exit 2 ;; 73 esac