pan/decode: Allow updating mmaps
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 19 Aug 2019 17:55:29 +0000 (10:55 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 21 Aug 2019 15:40:52 +0000 (08:40 -0700)
This allows the caller to call track_mmap multiple times for the same
gpu_va for the purpose of updating the mmap. This is used to trace
invisible BOs with kbase and doesn't apply to native traces.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/pandecode/common.c

index 0678e459066005b8f9eecabad60eb663731f9814..86cb01938e289fc2e3858ac5b451c1174e7f7e89 100644 (file)
@@ -47,9 +47,39 @@ pandecode_find_mapped_gpu_mem_containing(uint64_t addr)
         return NULL;
 }
 
+static void
+pandecode_add_name(struct pandecode_mapped_memory *mem, uint64_t gpu_va, const char *name)
+{
+        if (!name) {
+                /* If we don't have a name, assign one */
+
+                snprintf(mem->name, ARRAY_SIZE(mem->name) - 1,
+                         "memory_%" PRIx64, gpu_va);
+        } else {
+                assert((strlen(name) + 1) < ARRAY_SIZE(mem->name));
+                memcpy(mem->name, name, strlen(name) + 1);
+        }
+}
+
 void
 pandecode_inject_mmap(uint64_t gpu_va, void *cpu, unsigned sz, const char *name)
 {
+        /* First, search if we already mapped this and are just updating an address */
+
+        list_for_each_entry(struct pandecode_mapped_memory, pos, &mmaps.node, node) {
+                if (pos->gpu_va == gpu_va) {
+                        /* TODO: Resizing weirdness. Only applies to tracing
+                         * the legacy driver, not for native traces */
+
+                        pos->length = sz;
+                        pos->addr = cpu;
+                        pandecode_add_name(pos, gpu_va, name);
+
+                        return;
+                }
+        }
+
+        /* Otherwise, add a fresh mapping */
         struct pandecode_mapped_memory *mapped_mem = NULL;
 
         mapped_mem = malloc(sizeof(*mapped_mem));
@@ -58,16 +88,7 @@ pandecode_inject_mmap(uint64_t gpu_va, void *cpu, unsigned sz, const char *name)
         mapped_mem->gpu_va = gpu_va;
         mapped_mem->length = sz;
         mapped_mem->addr = cpu;
-
-        if (!name) {
-                /* If we don't have a name, assign one */
-
-                snprintf(mapped_mem->name, ARRAY_SIZE(mapped_mem->name) - 1,
-                         "memory_%" PRIx64, gpu_va);
-        } else {
-                assert((strlen(name) + 1) < ARRAY_SIZE(mapped_mem->name));
-                memcpy(mapped_mem->name, name, strlen(name) + 1);
-        }
+        pandecode_add_name(mapped_mem, gpu_va, name);
 
         list_add(&mapped_mem->node, &mmaps.node);
 }