summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/watch_ctx.sh
blob: 0968571adf74035669f9edd6039832716743299a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# watch_ctx.sh - guest-side watcher: (re)start cdt, snapshot the ioctl stream
# (fd paths), attach gdb to the libcuda wait as soon as cuCtxCreate is reached
# and POKE the per-entry trackers (p+0x9410+0x10/0x18 = 1) to test whether that
# gate releases the wait. Runs under sudo; results land in /tmp/ctxdumps/.
mkdir -p /tmp/ctxdumps
rm -f /tmp/ctxdumps/*
nvidia-modprobe -c 0
nvidia-modprobe -u
modprobe nvidia-uvm
rm -f /tmp/cdt.out
setsid /tmp/cdt > /tmp/cdt.out 2>&1 &
i=0
while [ $i -lt 300 ]; do
    grep -q 'cuCtxCreate' /tmp/cdt.out 2>/dev/null && break
    sleep 0.3
    i=$((i+1))
done
P=$(pidof cdt | tr ' ' '\n' | head -1)
ls -l /proc/$P/fd/ > /tmp/ctxdumps/fds.txt 2>&1
if command -v strace >/dev/null 2>&1; then
    timeout 8 strace -f -y -p "$P" -e trace=ioctl -o /tmp/ctxdumps/ioctl.txt 2>/dev/null
fi
n=0
while [ $n -lt 80 ]; do
    P=$(pidof cdt | tr ' ' '\n' | head -1)
    [ -n "$P" ] || break
    gdb -p "$P" -batch -x /tmp/dumpctx.py > "/tmp/ctxdumps/d$n.txt" 2>&1
    if grep -q DONE_SPIN "/tmp/ctxdumps/d$n.txt"; then
        cp "/tmp/ctxdumps/d$n.txt" /tmp/ctxdumps/FOUND.txt
        break
    fi
    n=$((n+1))
    sleep 0.5
done
P=$(pidof cdt | tr ' ' '\n' | head -1)
if [ -f /tmp/ctxdumps/FOUND.txt ] && [ -n "$P" ]; then
    CTX_POKE=1 gdb -p "$P" -batch -x /tmp/dumpctx.py > /tmp/ctxdumps/poke_run.txt 2>&1
    k=0
    while [ $k -lt 12 ]; do
        echo "--- t=$((k*3))s $(tail -1 /tmp/cdt.out)" >> /tmp/ctxdumps/result.txt
        k=$((k+1))
        sleep 3
    done
    VAS=$(grep -oE 'type=1 p=0x[0-9a-f]+' /tmp/ctxdumps/FOUND.txt | sed 's/.*p=0x//' | while read -r p; do printf '0x%x ' $((0x$p + 0x9410)); done)
    echo "PID=$P TRACKER_VAS $VAS" > /tmp/ctxdumps/probe.txt
    python3 /tmp/pmap.py "$P" $VAS >> /tmp/ctxdumps/probe.txt 2>&1
fi
echo WATCH_DONE >> /tmp/ctxdumps/WATCH.log