summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/guest-diag/wall2/t90.py57
-rw-r--r--tools/guest-diag/wall2/t91.py95
-rw-r--r--tools/guest-diag/wall2/vk_alloc_test.py108
-rw-r--r--tools/guest-diag/wall2/vk_memprops.py56
4 files changed, 316 insertions, 0 deletions
diff --git a/tools/guest-diag/wall2/t90.py b/tools/guest-diag/wall2/t90.py
new file mode 100644
index 0000000..8518235
--- /dev/null
+++ b/tools/guest-diag/wall2/t90.py
@@ -0,0 +1,57 @@
+import gdb, sys
+
+inf = gdb.selected_inferior()
+pid = inf.pid
+base = None
+for line in open("/proc/%d/maps" % pid):
+ if "libnvidia-eglcore.so.570.144" in line:
+ parts = line.split()
+ lo, hi = [int(x, 16) for x in parts[0].split('-')]
+ off = int(parts[2], 16)
+ if off == 0:
+ base = lo
+ break
+if base is None:
+ print("EGLBASE not found"); gdb.execute("detach"); sys.exit(1)
+COUNT = base + 0x2070b7c
+print("EGLBASE 0x%x PID %d COUNT_ADDR 0x%x" % (base, pid, COUNT))
+
+def rd(a, n):
+ return inf.read_memory(a, n).tobytes()
+def u32(a):
+ return int.from_bytes(rd(a, 4), 'little')
+
+state = {"n": 0}
+
+class B(gdb.Breakpoint):
+ def __init__(self, spec, limit=100000):
+ super().__init__(spec, internal=False)
+ self.limit = limit; self.hits = 0
+ self.silent = True
+ def stop(self):
+ self.hits += 1
+ try:
+ v = u32(COUNT)
+ if v:
+ state["n"] += 1
+ if state["n"] <= 8:
+ print("CLEAR count %u -> 0 (hit %d)" % (v, self.hits))
+ gdb.execute("set {unsigned int}0x%x = 0" % COUNT)
+ except Exception as e:
+ print("ERR", e)
+ return self.hits >= 400
+
+B("*0x%x" % (base+0xa85d24), 400)
+
+try:
+ gdb.execute("continue")
+except gdb.error as e:
+ print("CONT-ERR %s" % e)
+except KeyboardInterrupt:
+ pass
+print("TRACE-END clears=%d" % state["n"])
+try:
+ gdb.execute("detach")
+except gdb.error as e:
+ print("DETACH-ERR %s" % e)
+gdb.execute("quit")
diff --git a/tools/guest-diag/wall2/t91.py b/tools/guest-diag/wall2/t91.py
new file mode 100644
index 0000000..5c84ba9
--- /dev/null
+++ b/tools/guest-diag/wall2/t91.py
@@ -0,0 +1,95 @@
+import gdb, sys
+
+inf = gdb.selected_inferior()
+pid = inf.pid
+base = None
+for line in open("/proc/%d/maps" % pid):
+ if "libnvidia-eglcore.so.570.144" in line:
+ parts = line.split()
+ lo, hi = [int(x, 16) for x in parts[0].split('-')]
+ off = int(parts[2], 16)
+ if off == 0:
+ base = lo
+ break
+if base is None:
+ print("EGLBASE not found"); gdb.execute("detach"); sys.exit(1)
+COUNT = base + 0x2070b7c
+print("EGLBASE 0x%x PID %d COUNT 0x%x" % (base, pid, COUNT))
+
+def rd(a, n):
+ return inf.read_memory(a, n).tobytes()
+def u32(a):
+ return int.from_bytes(rd(a, 4), 'little')
+def u64(a):
+ return int.from_bytes(rd(a, 8), 'little')
+
+state = {"clears": 0, "mp": 0, "am": 0}
+
+class B(gdb.Breakpoint):
+ def __init__(self, spec, fn, limit=100000):
+ super().__init__(spec, internal=False)
+ self.fn = fn; self.limit = limit; self.hits = 0
+ self.silent = True
+ def stop(self):
+ self.hits += 1
+ try:
+ stop = bool(self.fn(self))
+ except Exception as e:
+ print("ERR@0x%x %s" % (int(gdb.parse_and_eval("$pc")), e))
+ stop = False
+ return stop or self.hits >= self.limit
+
+def clear(bp):
+ try:
+ v = u32(COUNT)
+ if v:
+ state["clears"] += 1
+ if state["clears"] <= 5:
+ print("CLEAR count %u -> 0" % v)
+ gdb.execute("set {unsigned int}0x%x = 0" % COUNT)
+ except Exception as e:
+ print("CLEAR err", e)
+ return False
+
+def mp(bp):
+ rsi = int(gdb.parse_and_eval("$rsi"))
+ state["mp"] += 1
+ if state["mp"] <= 3:
+ print("MEMPROPS ptr=0x%x" % rsi)
+ return False
+
+def am(bp):
+ rsi = int(gdb.parse_and_eval("$rsi"))
+ state["am"] += 1
+ if state["am"] <= 10:
+ try:
+ st = u32(rsi)
+ size = u64(rsi+0x10)
+ tidx = u32(rsi+0x18)
+ print("ALLOC sType=%d size=0x%x typeIndex=%d" % (st, size, tidx))
+ except Exception as e:
+ print("ALLOC err", e)
+ return False
+
+B("*0x%x" % (base+0xa85d24), clear, 100000)
+try:
+ B("vkGetPhysicalDeviceMemoryProperties", mp, 5)
+except Exception as e:
+ print("MP BP err", e)
+try:
+ B("vkAllocateMemory", am, 20)
+except Exception as e:
+ print("AM BP err", e)
+
+try:
+ gdb.execute("continue")
+except gdb.error as e:
+ print("CONT-ERR %s" % e)
+except KeyboardInterrupt:
+ pass
+print("TRACE-END clears=%d" % state["clears"])
+try:
+ gdb.execute("detach")
+except gdb.error as e:
+ print("DETACH-ERR %s" % e)
+gdb.execute("quit")
diff --git a/tools/guest-diag/wall2/vk_alloc_test.py b/tools/guest-diag/wall2/vk_alloc_test.py
new file mode 100644
index 0000000..0bcf35a
--- /dev/null
+++ b/tools/guest-diag/wall2/vk_alloc_test.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+# vk_alloc_test.py - reproduce vk_frame's DEVICE_LOCAL image allocation:
+# instance -> device -> OPTIMAL R8G8B8A8 storage image -> mem reqs ->
+# pick first DEVICE_LOCAL type -> vkAllocateMemory -> report rc/type/size.
+import ctypes, sys
+
+vk = ctypes.CDLL("libvulkan.so.1")
+
+class VkApplicationInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("pApplicationName", ctypes.c_char_p), ("applicationVersion", ctypes.c_uint32),
+ ("pEngineName", ctypes.c_char_p), ("engineVersion", ctypes.c_uint32),
+ ("apiVersion", ctypes.c_uint32)]
+
+class VkInstanceCreateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("flags", ctypes.c_uint32), ("pApplicationInfo", ctypes.c_void_p),
+ ("enabledLayerCount", ctypes.c_uint32), ("ppEnabledLayerNames", ctypes.c_void_p),
+ ("enabledExtensionCount", ctypes.c_uint32), ("ppEnabledExtensionNames", ctypes.c_void_p)]
+
+class VkMemoryType(ctypes.Structure):
+ _fields_ = [("propertyFlags", ctypes.c_uint32), ("heapIndex", ctypes.c_uint32)]
+class VkMemoryHeap(ctypes.Structure):
+ _fields_ = [("size", ctypes.c_uint64), ("flags", ctypes.c_uint32)]
+class VkPhysicalDeviceMemoryProperties(ctypes.Structure):
+ _fields_ = [("memoryTypeCount", ctypes.c_uint32),
+ ("memoryTypes", VkMemoryType * 32),
+ ("memoryHeapCount", ctypes.c_uint32),
+ ("memoryHeaps", VkMemoryHeap * 16)]
+
+class VkDeviceQueueCreateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("flags", ctypes.c_uint32), ("queueFamilyIndex", ctypes.c_uint32),
+ ("queueCount", ctypes.c_uint32), ("pQueuePriorities", ctypes.c_void_p)]
+class VkDeviceCreateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("flags", ctypes.c_uint32), ("queueCreateInfoCount", ctypes.c_uint32),
+ ("pQueueCreateInfos", ctypes.c_void_p),
+ ("enabledLayerCount", ctypes.c_uint32), ("ppEnabledLayerNames", ctypes.c_void_p),
+ ("enabledExtensionCount", ctypes.c_uint32), ("ppEnabledExtensionNames", ctypes.c_void_p),
+ ("pEnabledFeatures", ctypes.c_void_p)]
+
+class VkExtent3D(ctypes.Structure):
+ _fields_ = [("width", ctypes.c_uint32), ("height", ctypes.c_uint32), ("depth", ctypes.c_uint32)]
+class VkImageCreateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p), ("flags", ctypes.c_uint32),
+ ("imageType", ctypes.c_uint32), ("format", ctypes.c_uint32),
+ ("extent", VkExtent3D), ("mipLevels", ctypes.c_uint32), ("arrayLayers", ctypes.c_uint32),
+ ("samples", ctypes.c_uint32), ("tiling", ctypes.c_uint32), ("usage", ctypes.c_uint32),
+ ("sharingMode", ctypes.c_uint32), ("queueFamilyIndexCount", ctypes.c_uint32),
+ ("pQueueFamilyIndices", ctypes.c_void_p), ("initialLayout", ctypes.c_uint32)]
+class VkMemoryRequirements(ctypes.Structure):
+ _fields_ = [("size", ctypes.c_uint64), ("alignment", ctypes.c_uint64), ("memoryTypeBits", ctypes.c_uint32)]
+class VkMemoryAllocateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("allocationSize", ctypes.c_uint64), ("memoryTypeIndex", ctypes.c_uint32)]
+
+app = VkApplicationInfo(0, None, b"alloctest", 1, b"alloctest", 1, 0x401000)
+ci = VkInstanceCreateInfo(1, None, 0, ctypes.cast(ctypes.pointer(app), ctypes.c_void_p), 0, None, 0, None)
+inst = ctypes.c_void_p()
+print("vkCreateInstance rc=%d" % vk.vkCreateInstance(ctypes.byref(ci), None, ctypes.byref(inst)))
+
+n = ctypes.c_uint32(0)
+vk.vkEnumeratePhysicalDevices(inst, ctypes.byref(n), None)
+devs = (ctypes.c_void_p * n.value)()
+vk.vkEnumeratePhysicalDevices(inst, ctypes.byref(n), devs)
+phys = devs[0]
+print("phys=0x%x" % (phys or 0))
+
+prio = ctypes.c_float(1.0)
+qci = VkDeviceQueueCreateInfo(2, None, 0, 0, 1, ctypes.cast(ctypes.pointer(prio), ctypes.c_void_p))
+dci = VkDeviceCreateInfo(3, None, 0, 1, ctypes.cast(ctypes.pointer(qci), ctypes.c_void_p), 0, None, 0, None, None)
+dev = ctypes.c_void_p()
+rc = vk.vkCreateDevice(phys, ctypes.byref(dci), None, ctypes.byref(dev))
+print("vkCreateDevice rc=%d dev=0x%x" % (rc, dev or 0))
+if rc != 0:
+ sys.exit(1)
+
+mp = VkPhysicalDeviceMemoryProperties()
+vk.vkGetPhysicalDeviceMemoryProperties(phys, ctypes.byref(mp))
+
+img_ci = VkImageCreateInfo(14, None, 0, 1, 37, # VK_IMAGE_TYPE_2D, R8G8B8A8_UNORM
+ VkExtent3D(64, 64, 1), 1, 1, 1, 0, # OPTIMAL
+ 0x2 | 0x1, 0, 0, None, 0) # STORAGE | TRANSFER_SRC, UNDEFINED
+img = ctypes.c_void_p()
+rc = vk.vkCreateImage(dev, ctypes.byref(img_ci), None, ctypes.byref(img))
+print("vkCreateImage rc=%d img=0x%x" % (rc, img or 0))
+if rc != 0:
+ sys.exit(1)
+
+mr = VkMemoryRequirements()
+vk.vkGetImageMemoryRequirements(dev, img, ctypes.byref(mr))
+print("memreqs size=0x%x align=0x%x typeBits=0x%x" % (mr.size, mr.alignment, mr.memoryTypeBits))
+
+tidx = 0
+found = False
+for k in range(mp.memoryTypeCount):
+ if (mr.memoryTypeBits & (1 << k)) and (mp.memoryTypes[k].propertyFlags & 0x1):
+ tidx = k
+ found = True
+ break
+print("selected type=%d found_device_local=%s (types: %s)" %
+ (tidx, found, ", ".join("%d:0x%x" % (k, mp.memoryTypes[k].propertyFlags) for k in range(mp.memoryTypeCount))))
+
+ma = VkMemoryAllocateInfo(5, None, mr.size, tidx)
+mem = ctypes.c_void_p()
+rc = vk.vkAllocateMemory(dev, ctypes.byref(ma), None, ctypes.byref(mem))
+print("vkAllocateMemory size=0x%x type=%d rc=%d" % (mr.size, tidx, rc))
diff --git a/tools/guest-diag/wall2/vk_memprops.py b/tools/guest-diag/wall2/vk_memprops.py
new file mode 100644
index 0000000..3cf6ba2
--- /dev/null
+++ b/tools/guest-diag/wall2/vk_memprops.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# vk_memprops.py - enumerate Vulkan devices and dump their memory properties
+# via ctypes (no vkCreateDevice needed; safe alongside other clients).
+import ctypes, ctypes.util, sys
+
+vk = ctypes.CDLL("libvulkan.so.1")
+
+class VkApplicationInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("pApplicationName", ctypes.c_char_p), ("applicationVersion", ctypes.c_uint32),
+ ("pEngineName", ctypes.c_char_p), ("engineVersion", ctypes.c_uint32),
+ ("apiVersion", ctypes.c_uint32)]
+
+class VkInstanceCreateInfo(ctypes.Structure):
+ _fields_ = [("sType", ctypes.c_uint32), ("pNext", ctypes.c_void_p),
+ ("flags", ctypes.c_uint32), ("pApplicationInfo", ctypes.c_void_p),
+ ("enabledLayerCount", ctypes.c_uint32), ("ppEnabledLayerNames", ctypes.c_void_p),
+ ("enabledExtensionCount", ctypes.c_uint32), ("ppEnabledExtensionNames", ctypes.c_void_p)]
+
+class VkMemoryType(ctypes.Structure):
+ _fields_ = [("propertyFlags", ctypes.c_uint32), ("heapIndex", ctypes.c_uint32)]
+
+class VkMemoryHeap(ctypes.Structure):
+ _fields_ = [("size", ctypes.c_uint64), ("flags", ctypes.c_uint32)]
+
+class VkPhysicalDeviceMemoryProperties(ctypes.Structure):
+ _fields_ = [("memoryTypeCount", ctypes.c_uint32),
+ ("memoryTypes", VkMemoryType * 32),
+ ("memoryHeapCount", ctypes.c_uint32),
+ ("memoryHeaps", VkMemoryHeap * 16)]
+
+app = VkApplicationInfo(0, None, b"memprops", 1, b"memprops", 1, 0x401000)
+ci = VkInstanceCreateInfo(1, None, 0, ctypes.cast(ctypes.pointer(app), ctypes.c_void_p), 0, None, 0, None)
+inst = ctypes.c_void_p()
+rc = vk.vkCreateInstance(ctypes.byref(ci), None, ctypes.byref(inst))
+print("vkCreateInstance rc=%d" % rc)
+if rc != 0:
+ sys.exit(1)
+
+n = ctypes.c_uint32(0)
+vk.vkEnumeratePhysicalDevices(inst, ctypes.byref(n), None)
+print("devices=%d" % n.value)
+devs = (ctypes.c_void_p * n.value)()
+vk.vkEnumeratePhysicalDevices(inst, ctypes.byref(n), devs)
+
+for i in range(n.value):
+ props = VkPhysicalDeviceMemoryProperties()
+ vk.vkGetPhysicalDeviceMemoryProperties(devs[i], ctypes.byref(props))
+ print("=== DEV %d phys=0x%x ===" % (i, devs[i] or 0))
+ print(" memoryTypeCount=%d memoryHeapCount=%d" % (props.memoryTypeCount, props.memoryHeapCount))
+ for t in range(props.memoryTypeCount):
+ mt = props.memoryTypes[t]
+ print(" type[%d] flags=0x%08x heap=%d" % (t, mt.propertyFlags, mt.heapIndex))
+ for h in range(props.memoryHeapCount):
+ mh = props.memoryHeaps[h]
+ print(" heap[%d] size=0x%x (%u MiB) flags=0x%x" % (h, mh.size, mh.size >> 20, mh.flags))