[Mesa-dev] [PATCH 8/9] intel: aubinator: drop the 1Tb GTT mapping

Lionel Landwerlin lionel.g.landwerlin at intel.com
Thu Jun 14 17:11:44 UTC 2018


We reuse the existing mechanism introduced in 482a7d1593c621
("intel/tools/aubinator: aubinate ppgtt aubs") that is a list of GTT
address and their corresponding mmapped pointer so that we can get rid
of the 1Tb of mmapped memory and instead just use the already mmapped
aub file.

Sorry Kristian.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/tools/aubinator.c | 85 ++++++++++++-------------------------
 1 file changed, 28 insertions(+), 57 deletions(-)

diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
index 6f2e0d503df..c9308b56137 100644
--- a/src/intel/tools/aubinator.c
+++ b/src/intel/tools/aubinator.c
@@ -43,6 +43,7 @@
 
 #include "common/gen_decoder.h"
 #include "common/gen_disasm.h"
+#include "common/gen_gem.h"
 #include "intel_aub.h"
 
 #ifndef HAVE_MEMFD_CREATE
@@ -80,12 +81,10 @@ char *input_file = NULL, *xml_path = NULL;
 struct gen_device_info devinfo;
 struct gen_batch_decode_ctx batch_ctx;
 
-uint64_t gtt_size, gtt_end;
-void *gtt;
-
 struct bo_map {
    struct list_head link;
    struct gen_batch_decode_bo bo;
+   bool unmap_after_use;
 };
 
 struct ggtt_entry {
@@ -127,12 +126,6 @@ field(uint32_t value, int start, int end)
 
 struct brw_instruction;
 
-static inline int
-valid_offset(uint32_t offset)
-{
-   return offset < gtt_end;
-}
-
 #define GEN_ENGINE_RENDER 1
 #define GEN_ENGINE_BLITTER 2
 
@@ -307,22 +300,15 @@ ppgtt_mapped(uint64_t pml4, uint64_t address)
    return ppgtt_walk(pml4, address) != NULL;
 }
 
-static struct gen_batch_decode_bo
-get_gen_batch_bo(void *user_data, uint64_t address)
+static void
+add_gtt_bo_map(struct gen_batch_decode_bo bo, bool unmap_after_use)
 {
-   if (address > gtt_end)
-      return (struct gen_batch_decode_bo) { .map = NULL };
-
-   /* We really only have one giant address range */
-   return (struct gen_batch_decode_bo) {
-      .addr = 0,
-      .map = gtt,
-      .size = gtt_size
-   };
-}
-
-
+   struct bo_map *m = calloc(1, sizeof(*m));
 
+   m->bo = bo;
+   m->unmap_after_use = unmap_after_use;
+   list_add(&m->link, &maps);
+}
 
 static struct gen_batch_decode_bo
 get_ggtt_batch_bo(void *user_data, uint64_t address)
@@ -369,9 +355,7 @@ get_ggtt_batch_bo(void *user_data, uint64_t address)
       assert(res != MAP_FAILED);
    }
 
-   struct bo_map *m = calloc(1, sizeof(*m));
-   m->bo = bo;
-   list_add(&m->link, &maps);
+   add_gtt_bo_map(bo, true);
 
    return bo;
 }
@@ -407,9 +391,7 @@ get_ppgtt_batch_bo(void *user_data, uint64_t address)
       assert(res != MAP_FAILED);
    }
 
-   struct bo_map *m = calloc(1, sizeof(*m));
-   m->bo = bo;
-   list_add(&m->link, &maps);
+   add_gtt_bo_map(bo, true);
 
    return bo;
 }
@@ -418,7 +400,8 @@ static void
 clear_bo_maps(void)
 {
    list_for_each_entry_safe(struct bo_map, i, &maps, link) {
-      munmap((void *)i->bo.map, i->bo.size);
+      if (i->unmap_after_use)
+         munmap((void *)i->bo.map, i->bo.size);
       list_del(&i->link);
       free(i);
    }
@@ -430,26 +413,23 @@ handle_trace_block(uint32_t *p)
    int operation = p[1] & AUB_TRACE_OPERATION_MASK;
    int type = p[1] & AUB_TRACE_TYPE_MASK;
    int address_space = p[1] & AUB_TRACE_ADDRESS_SPACE_MASK;
-   uint64_t offset = p[3];
-   uint32_t size = p[4];
    int header_length = p[0] & 0xffff;
-   uint32_t *data = p + header_length + 2;
    int engine = GEN_ENGINE_RENDER;
-
-   if (devinfo.gen >= 8)
-      offset += (uint64_t) p[5] << 32;
+   struct gen_batch_decode_bo bo = {
+      .map = p + header_length + 2,
+      /* Addresses written by aubdump here are in canonical form but the batch
+       * decoder always gives us addresses with the top 16bits zeroed, so do
+       * the same here.
+       */
+      .addr = gen_48b_address((devinfo.gen >= 8 ? ((uint64_t) p[5] << 32) : 0) |
+                              ((uint64_t) p[3])),
+      .size = p[4],
+   };
 
    switch (operation) {
    case AUB_TRACE_OP_DATA_WRITE:
-      if (address_space != AUB_TRACE_MEMTYPE_GTT)
-         break;
-      if (gtt_size < offset + size) {
-         fprintf(stderr, "overflow gtt space: %s\n", strerror(errno));
-         exit(EXIT_FAILURE);
-      }
-      memcpy((char *) gtt + offset, data, size);
-      if (gtt_end < offset + size)
-         gtt_end = offset + size;
+      if (address_space == AUB_TRACE_MEMTYPE_GTT)
+         add_gtt_bo_map(bo, false);
       break;
    case AUB_TRACE_OP_COMMAND_WRITE:
       switch (type) {
@@ -465,10 +445,10 @@ handle_trace_block(uint32_t *p)
       }
 
       (void)engine; /* TODO */
-      batch_ctx.get_bo = get_gen_batch_bo;
-      gen_print_batch(&batch_ctx, data, size, 0);
+      batch_ctx.get_bo = get_ggtt_batch_bo;
+      gen_print_batch(&batch_ctx, bo.map, bo.size, 0);
 
-      gtt_end = 0;
+      clear_bo_maps();
       break;
    }
 }
@@ -996,15 +976,6 @@ int main(int argc, char *argv[])
    else
       file = aub_file_open(input_file);
 
-   /* mmap a terabyte for our gtt space. */
-   gtt_size = 1ull << 40;
-   gtt = mmap(NULL, gtt_size, PROT_READ | PROT_WRITE,
-              MAP_PRIVATE | MAP_ANONYMOUS |  MAP_NORESERVE, -1, 0);
-   if (gtt == MAP_FAILED) {
-      fprintf(stderr, "failed to alloc gtt space: %s\n", strerror(errno));
-      exit(EXIT_FAILURE);
-   }
-
    mem_fd = memfd_create("phys memory", 0);
 
    list_inithead(&maps);
-- 
2.17.1



More information about the mesa-dev mailing list