aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / gpu_bench / check_bench.sh
| 1 | #!/bin/bash |
| 2 | # scripts/gpu_bench/check_bench.sh -- check .bench scripts against the ck_gpu_bench console. |
| 3 | # |
| 4 | # Grammar (docs/IMAC_GPU_BENCH.md on feat/imac-gpu-bench): one command per line; a line |
| 5 | # whose first character is # is a comment; numbers are 0x-hex or decimal. |
| 6 | # ping 0 | pci_cfg 1 | bar5_read 1 | bar5_write 2 | bar5_rmw 3 | bar5_poll 4 |
| 7 | # bar0_read 1 | bar0_write 2 |
| 8 | # Indices are DWORD indices in 0..65535 (BAR5 and the BAR0 window). |
| 9 | # BAR5 write allowlist (DWORD index): 0x4800-0x4900, 0x4A00-0x4C00, GRPH 0x1a04-0x1a12 (DCP0), |
| 10 | # SMC 0x94-0x95 and 0xa4 (feat/imac-gpu-bench, L142). A write outside it |
| 11 | # is reported as NEEDS-ALLOWLIST: a missing console allowlist entry, not a grammar error. |
| 12 | # |
| 13 | # Usage: check_bench.sh [file...] (default: STEP*.bench beside this script) |
| 14 | # Exit: 0 clean, 1 grammar error, 3 only NEEDS-ALLOWLIST findings. |
| 15 | |
| 16 | set -u |
| 17 | dir=$(cd "$(dirname "$0")" && pwd) |
| 18 | if [ $# -eq 0 ]; then set -- "$dir"/STEP*.bench; fi |
| 19 | files=("$@") |
| 20 | |
| 21 | rc=0 |
| 22 | need=0 |
| 23 | for f in "${files[@]}"; do |
| 24 | base=$(basename "$f") |
| 25 | n=0 |
| 26 | writes=0 |
| 27 | cmds=0 |
| 28 | while IFS= read -r line || [ -n "$line" ]; do |
| 29 | n=$((n + 1)) |
| 30 | case "$line" in |
| 31 | ''|'#'*) continue ;; |
| 32 | esac |
| 33 | case "$line" in |
| 34 | *'#'*) echo "$base:$n GRAMMAR inline comment; put it on its own line"; rc=1; continue ;; |
| 35 | esac |
| 36 | words=($line) |
| 37 | cmd=${words[0]} |
| 38 | nargs=$((${#words[@]} - 1)) |
| 39 | case "$cmd" in |
| 40 | ping) want=0 ;; |
| 41 | pci_cfg|bar5_read|bar0_read) want=1 ;; |
| 42 | bar5_write|bar0_write) want=2 ;; |
| 43 | bar5_rmw) want=3 ;; |
| 44 | bar5_poll) want=4 ;; |
| 45 | *) echo "$base:$n GRAMMAR unknown command '$cmd'"; rc=1; continue ;; |
| 46 | esac |
| 47 | if [ "$nargs" -ne "$want" ]; then |
| 48 | echo "$base:$n GRAMMAR $cmd takes $want argument(s), got $nargs"; rc=1; continue |
| 49 | fi |
| 50 | bad=0 |
| 51 | vals=() |
| 52 | for a in "${words[@]:1}"; do |
| 53 | v=$(printf '%d' "$a" 2>/dev/null) || { bad=1; break; } |
| 54 | vals+=("$v") |
| 55 | done |
| 56 | if [ "$bad" -eq 1 ]; then |
| 57 | echo "$base:$n GRAMMAR non-numeric argument in: $line"; rc=1; continue |
| 58 | fi |
| 59 | cmds=$((cmds + 1)) |
| 60 | case "$cmd" in |
| 61 | pci_cfg|bar5_read|bar0_read|bar5_write|bar0_write|bar5_rmw|bar5_poll) |
| 62 | if [ "${vals[0]}" -lt 0 ] || [ "${vals[0]}" -gt 65535 ]; then |
| 63 | echo "$base:$n GRAMMAR index ${words[1]} outside 0..65535"; rc=1; continue |
| 64 | fi ;; |
| 65 | esac |
| 66 | case "$cmd" in |
| 67 | bar5_write|bar5_rmw) |
| 68 | writes=$((writes + 1)) |
| 69 | idx=${vals[0]} |
| 70 | if { [ "$idx" -ge $((0x4800)) ] && [ "$idx" -le $((0x4900)) ]; } || |
| 71 | { [ "$idx" -ge $((0x4A00)) ] && [ "$idx" -le $((0x4C00)) ]; } || |
| 72 | { [ "$idx" -ge $((0x1a04)) ] && [ "$idx" -le $((0x1a12)) ]; } || |
| 73 | { [ "$idx" -ge $((0x94)) ] && [ "$idx" -le $((0x95)) ]; } || [ "$idx" -eq $((0xa4)) ]; then |
| 74 | : |
| 75 | else |
| 76 | printf '%s:%s NEEDS-ALLOWLIST %s (BAR5 index 0x%x is outside the console allowlist, see the header of this script)\n' \ |
| 77 | "$base" "$n" "$cmd" "$idx" |
| 78 | need=1 |
| 79 | fi ;; |
| 80 | esac |
| 81 | done < "$f" |
| 82 | echo "$base: $cmds command(s), $writes BAR5 write(s)" |
| 83 | done |
| 84 | |
| 85 | if [ "$rc" -ne 0 ]; then exit 1; fi |
| 86 | if [ "$need" -ne 0 ]; then exit 3; fi |
| 87 | exit 0 |