summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/sem_slots.py
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-29 08:53:11 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-29 08:53:11 -0400
commit6e04a93838cdebbcf9183278cb71bdf1b4235cdc (patch)
tree219603fb2b24af8705a09558d93d8f41c33081e2 /tools/guest-diag/sem_slots.py
parent6588981b619814b9c2b26130165e440f0556bdec (diff)
downloadopen-iov-6e04a93838cdebbcf9183278cb71bdf1b4235cdc.tar.gz
open-iov-6e04a93838cdebbcf9183278cb71bdf1b4235cdc.zip
tools: durable guest counter enumeration/injection and VA reader
The counter enumeration/injection workflow lived in the guest's /tmp and was lost on every restart. Make it durable under tools/guest-diag: - sem_counters.py: translate a process's per-channel u32 completion counters (16-byte stride in the /dev/nvidiactl counter page) to guest PAs through /proc/<pid>/pagemap; --pairs emits handle,va,pa triples. - sem_slots.py: read/write the counter slots via /proc/<pid>/mem (fallback for the host counter publish). - read_va.py: hex dump a process VA (UVM sysmem GPU VAs are usually valid CPU VAs in the owning process); --u32 for method streams. - inject_counters.sh: host-side one-shot: push the tool, take the GR handles from the live chan_dump, enumerate, then register each counter with sema_counter and pin its VA with sema_map_add. - push_guest_tools.sh: push the new tools after every VM start. - launch_qemu_direct.sh: parameterized mdev UUID/paths instead of a stale hardcoded one; committed so it survives checkouts.
Diffstat (limited to 'tools/guest-diag/sem_slots.py')
-rwxr-xr-xtools/guest-diag/sem_slots.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/guest-diag/sem_slots.py b/tools/guest-diag/sem_slots.py
new file mode 100755
index 0000000..70d184c
--- /dev/null
+++ b/tools/guest-diag/sem_slots.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+# sem_slots.py - read or write the per-channel u32 completion counters of a
+# guest process (verification and fallback for the host's counter publish).
+#
+# Usage:
+# sudo python3 sem_slots.py <pid> <first-va> [count] # read
+# sudo python3 sem_slots.py <pid> <first-va> [count] --write <v> # write
+#
+# The slots are 16 bytes apart (one u32 per channel). Reading needs pagemap/
+# mem access as root; writing uses /proc/<pid>/mem and mirrors the gdb poke
+# used in earlier sessions (e.g. --write 1 to arm every waiter).
+import os
+import sys
+
+
+def main():
+ if len(sys.argv) < 3:
+ print(__doc__)
+ return 1
+ pid = int(sys.argv[1])
+ first = int(sys.argv[2], 16)
+ count = 20
+ write_val = None
+ i = 3
+ while i < len(sys.argv):
+ if sys.argv[i] == '--write':
+ write_val = int(sys.argv[i + 1], 0)
+ i += 2
+ continue
+ count = int(sys.argv[i], 0)
+ i += 1
+
+ flags = os.O_RDWR if write_val is not None else os.O_RDONLY
+ mem = os.open('/proc/%d/mem' % pid, flags)
+ try:
+ for n in range(count):
+ va = first + n * 16
+ if write_val is not None:
+ os.pwrite(mem, write_val.to_bytes(4, 'little'), va)
+ print('idx=%d VA=0x%x written=%u' % (n, va, write_val))
+ else:
+ v = int.from_bytes(os.pread(mem, 4, va), 'little')
+ print('idx=%d VA=0x%x val=%u' % (n, va, v))
+ finally:
+ os.close(mem)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())