#!/bin/bash # pin_sem_fast.sh - low-latency tracker-sem pinner (2 s poll vs 15 s). # # Pins the client tracker-sem page (0x20400f000, covers 0x20400fec0..ff70) # for the live cdt pid the moment the guest pagemap shows it present, once # per pid. The window matters: in the one boot where UVM's page-table write # pushes were submitted, the pin had landed ~40 s before the client's # internal deadline; later pins (60 s+) lose the race and the client dies # without ever submitting the writes. # # Usage: tools/guest-diag/pin_sem_fast.sh [iterations] (default 200, ~7 min) set -u cd "$(dirname "$(readlink -f "$0")")/../.." EXEC() { timeout 20 ./scripts/vgpu_vm.py exec --timeout 15 "$1" 2>/dev/null; } B64=$(base64 -w0 tools/guest-diag/guest_pmap_all.py) EXEC "echo '$B64' | base64 -d > /tmp/pmapall.py" >/dev/null N=${1:-200} pinned_pid="" for ((i = 1; i <= N; i++)); do pid=$(EXEC 'pgrep -x cdt | head -1' | tail -1) if [ -n "$pid" ] && [ "$pid" != "$pinned_pid" ]; then line=$(EXEC "sudo python3 /tmp/pmapall.py $pid 0x20400f000 1" | grep -aE "^0x20400f000,0x[0-9a-f]+$" | head -1) if [ -n "$line" ]; then echo "$line,0x1000,1" | sudo tee /sys/module/open_iov_vfio/parameters/sema_map_add >/dev/null pinned_pid="$pid" echo "[$((i * 2))s] pinned $line (pid $pid)" fi fi sleep 2 done