[igt-dev] [PATCH i-g-t 2/6] aubdump: Add bitmap to track gtt pages that have been mapped

Jordan Justen jordan.l.justen at intel.com
Wed Feb 21 23:19:01 UTC 2018


This will allow us to map ranges as they are used, but prevents
remapping already mapped regions.

By mapping ranges as they are used, we can support pinned pages
without having to map all pages of the first 32-bits.

Cc: Scott D Phillips <scott.d.phillips at intel.com>
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 tools/aubdump.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 2e60e547..661509e3 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -383,7 +383,7 @@ register_write_out(uint32_t addr, uint32_t value)
 }
 
 static void
-gen8_map_range(uint64_t start, uint64_t end)
+gen8_emit_pte_for_range(uint64_t start, uint64_t end)
 {
 	uint64_t entry_addr;
 	uint64_t page_num;
@@ -411,6 +411,79 @@ gen8_map_range(uint64_t start, uint64_t end)
 	} while (entry_addr < end);
 }
 
+static uint32_t*
+get_mapped_bitmap()
+{
+	static uint32_t *bitmap = NULL;
+	if (bitmap == NULL)
+		bitmap = calloc(0x100000000 / 0x1000 / 32, sizeof(*bitmap));
+	return bitmap;
+}
+
+static void
+set_mapped(uint64_t start, uint64_t end)
+{
+	uint64_t addr;
+	uint32_t *bitmap = get_mapped_bitmap();
+	if (bitmap == NULL)
+		return;
+
+	addr = start & ~(4096 - 1);
+	while (addr < end) {
+		const uint32_t bit = 1 << ((addr >> 12) & 0x1f);
+		if (bit == 1 && (end - addr) > 32 * 4096) {
+			bitmap[addr >> 17] = 0xffffffff;
+			addr += 32 * 4096;
+		} else {
+			bitmap[addr >> 17] |= bit;
+			addr += 4096;
+		}
+	}
+}
+
+static void
+gen8_map_range(uint64_t start, uint64_t end)
+{
+	uint64_t addr1, addr2;
+	uint32_t *bitmap = get_mapped_bitmap();
+	if (bitmap == NULL)
+		return;
+
+	addr1 = addr2 = start & ~(4096 - 1);
+	while (addr2 < end) {
+		while (addr1 < end) {
+			const uint32_t dw = bitmap[addr1 >> 17];
+			const uint32_t bit = 1 << ((addr1 >> 12) & 0x1f);
+			if ((dw & bit) == 0)
+				break;
+			else if (bit == 1 && dw == 0xffffffff)
+				addr1 += 32 * 4096;
+			else
+				addr1 += 4096;
+		}
+		if (addr1 >= end)
+			break;
+
+		addr2 = addr1;
+		while (addr2 < end) {
+			const uint32_t dw = bitmap[addr2 >> 17];
+			const uint32_t bit = 1 << ((addr2 >> 12) & 0x1f);
+			if ((dw & bit) != 0)
+				break;
+			else if (bit == 1 && dw == 0)
+				addr2 += 32 * 4096;
+			else
+				addr2 += 4096;
+		}
+		if (addr2 > end)
+			addr2 = (end + 4096 - 1) & ~(4096 - 1);
+
+		gen8_emit_pte_for_range(addr1, addr2);
+		set_mapped(addr1, addr2);
+		addr1 = addr2;
+	}
+}
+
 static void
 gen10_write_header(void)
 {
-- 
2.16.1



More information about the igt-dev mailing list