intel: tools: aub_mem: reuse already mapped ppgtt buffers

When we map a PPGTT buffer into a continous address space of aubinator
to be able to inspect it, we currently add it to the list of BOs to
unmap once we're finished. An optimization we can apply it to look up
that list before trying to remap PPGTT buffers again (we already do
this for GGTT buffers).

We need to take some care before doing this because the list also
contains GGTT BOs. As GGTT & PPGTT are 2 different address spaces, we
can have matching addresses in both that point to different physical
locations.

This changes adds a flag on the elements of the list of mapped BOs to
differenciate between GGTT & PPGTT, which allows use to reuse that
list when looking up both address spaces.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
This commit is contained in:
Lionel Landwerlin
2018-08-06 12:06:13 +01:00
parent 8fd78b4eea
commit 4ba12e8c54

View File

@@ -42,6 +42,7 @@ struct bo_map {
struct list_head link;
struct gen_batch_decode_bo bo;
bool unmap_after_use;
bool ppgtt;
};
struct ggtt_entry {
@@ -59,10 +60,11 @@ struct phys_mem {
};
static void
add_gtt_bo_map(struct aub_mem *mem, struct gen_batch_decode_bo bo, bool unmap_after_use)
add_gtt_bo_map(struct aub_mem *mem, struct gen_batch_decode_bo bo, bool ppgtt, bool unmap_after_use)
{
struct bo_map *m = calloc(1, sizeof(*m));
m->ppgtt = ppgtt;
m->bo = bo;
m->unmap_after_use = unmap_after_use;
list_add(&m->link, &mem->maps);
@@ -190,7 +192,7 @@ aub_mem_local_write(void *_mem, uint64_t address,
.addr = address,
.size = size,
};
add_gtt_bo_map(mem, bo, false);
add_gtt_bo_map(mem, bo, false, false);
}
void
@@ -253,7 +255,7 @@ aub_mem_get_ggtt_bo(void *_mem, uint64_t address)
struct gen_batch_decode_bo bo = {0};
list_for_each_entry(struct bo_map, i, &mem->maps, link)
if (i->bo.addr <= address && i->bo.addr + i->bo.size > address)
if (!i->ppgtt && i->bo.addr <= address && i->bo.addr + i->bo.size > address)
return i->bo;
address &= ~0xfff;
@@ -292,7 +294,7 @@ aub_mem_get_ggtt_bo(void *_mem, uint64_t address)
assert(res != MAP_FAILED);
}
add_gtt_bo_map(mem, bo, true);
add_gtt_bo_map(mem, bo, false, true);
return bo;
}
@@ -328,6 +330,10 @@ aub_mem_get_ppgtt_bo(void *_mem, uint64_t address)
struct aub_mem *mem = _mem;
struct gen_batch_decode_bo bo = {0};
list_for_each_entry(struct bo_map, i, &mem->maps, link)
if (i->ppgtt && i->bo.addr <= address && i->bo.addr + i->bo.size > address)
return i->bo;
address &= ~0xfff;
if (!ppgtt_mapped(mem, mem->pml4, address))
@@ -353,7 +359,7 @@ aub_mem_get_ppgtt_bo(void *_mem, uint64_t address)
assert(res != MAP_FAILED);
}
add_gtt_bo_map(mem, bo, true);
add_gtt_bo_map(mem, bo, true, true);
return bo;
}