[PATCH i-g-t 38/38] WIP on vm

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Feb 23 06:39:42 UTC 2021


---
 lib/intel_allocator.c            | 10 +++----
 lib/intel_batchbuffer.c          | 21 ++++++++++++--
 lib/intel_batchbuffer.h          |  3 ++
 tests/i915/api_intel_allocator.c | 23 ++++++++--------
 tests/i915/api_intel_bb.c        | 47 ++++++++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 19 deletions(-)

diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index 8267f69b5..6318b97a5 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -854,7 +854,7 @@ uint64_t intel_allocator_open_vm(int fd, uint32_t vm, uint8_t allocator_type)
 bool intel_allocator_close(uint64_t allocator_handle)
 {
 	struct alloc_req req = { .request_type = REQ_CLOSE,
-				 .allocator_handle = allocator_handle };
+				 .allocator_handle = allocator_handle};
 	struct alloc_resp resp;
 
 	igt_assert(handle_request(&req, &resp) == 0);
@@ -875,7 +875,7 @@ bool intel_allocator_close(uint64_t allocator_handle)
 bool intel_allocator_ref(uint64_t allocator_handle)
 {
 	struct alloc_req req = { .request_type = REQ_REF,
-				 .allocator_handle = allocator_handle };
+				 .allocator_handle = allocator_handle};
 	struct alloc_resp resp;
 
 	igt_assert(handle_request(&req, &resp) == 0);
@@ -896,7 +896,7 @@ bool intel_allocator_ref(uint64_t allocator_handle)
 bool intel_allocator_unref(uint64_t allocator_handle)
 {
 	struct alloc_req req = { .request_type = REQ_UNREF,
-				 .allocator_handle = allocator_handle };
+				 .allocator_handle = allocator_handle};
 	struct alloc_resp resp;
 
 	igt_assert(handle_request(&req, &resp) == 0);
@@ -922,7 +922,7 @@ void intel_allocator_get_address_range(uint64_t allocator_handle,
 				       uint64_t *startp, uint64_t *endp)
 {
 	struct alloc_req req = { .request_type = REQ_ADDRESS_RANGE,
-				 .allocator_handle = allocator_handle };
+				 .allocator_handle = allocator_handle};
 	struct alloc_resp resp;
 
 	igt_assert(handle_request(&req, &resp) == 0);
@@ -1203,7 +1203,7 @@ static bool equal_allocators_vm(const void *key1, const void *key2)
 }
 
 /*  2^63 + 2^61 - 2^57 + 2^54 - 2^51 - 2^18 + 1 */
-#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001UL
+#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001ULL
 
 static inline uint64_t hash_allocators(const void *val, unsigned int bits)
 {
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index b76a8bb87..7f1011ecd 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -1290,13 +1290,15 @@ __intel_bb_create(int i915, uint32_t ctx, uint32_t size, bool do_relocs,
 		do_relocs = true;
 
 	/* if relocs are set we won't use an allocator */
-	if (do_relocs)
+	if (do_relocs) {
 		allocator_type = INTEL_ALLOCATOR_NONE;
-	else
+	} else {
 		ibb->allocator_handle = intel_allocator_open_full(i915, ctx,
 								  start, end,
 								  allocator_type,
 								  strategy);
+		intel_allocator_ref(ibb->allocator_handle);
+	}
 	ibb->allocator_type = allocator_type;
 	ibb->allocator_strategy = strategy;
 	ibb->i915 = i915;
@@ -1526,6 +1528,7 @@ void intel_bb_destroy(struct intel_bb *ibb)
 	__intel_bb_destroy_cache(ibb);
 
 	if (ibb->allocator_type != INTEL_ALLOCATOR_NONE) {
+		intel_allocator_unref(ibb->allocator_handle);
 		intel_allocator_free(ibb->allocator_handle, ibb->handle);
 		intel_allocator_close(ibb->allocator_handle);
 	}
@@ -1627,6 +1630,20 @@ int intel_bb_sync(struct intel_bb *ibb)
 	return ret;
 }
 
+uint64_t intel_bb_assign_vm(struct intel_bb *ibb, uint64_t vm)
+{
+	uint64_t prev_vm = ibb->allocator_handle;
+
+	intel_bb_reset(ibb, true);
+	intel_bb_remove_object(ibb, ibb->handle, ibb->batch_offset,ibb->size);
+	intel_allocator_unref(prev_vm);
+	intel_allocator_ref(vm);
+	ibb->allocator_handle = vm;
+	intel_bb_reset(ibb, true);
+
+	return prev_vm;
+}
+
 /*
  * intel_bb_print:
  * @ibb: pointer to intel_bb
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index f8a38967b..c16f1c9f0 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -521,6 +521,9 @@ static inline void intel_bb_unref(struct intel_bb *ibb)
 
 void intel_bb_reset(struct intel_bb *ibb, bool purge_objects_cache);
 int intel_bb_sync(struct intel_bb *ibb);
+
+uint64_t intel_bb_assign_vm(struct intel_bb *ibb, uint64_t vm);
+
 void intel_bb_print(struct intel_bb *ibb);
 void intel_bb_dump(struct intel_bb *ibb, const char *filename);
 void intel_bb_set_debug(struct intel_bb *ibb, bool debug);
diff --git a/tests/i915/api_intel_allocator.c b/tests/i915/api_intel_allocator.c
index 8b33ac59d..12f998432 100644
--- a/tests/i915/api_intel_allocator.c
+++ b/tests/i915/api_intel_allocator.c
@@ -548,9 +548,9 @@ static void basic_check(int fd)
 {
 	uint64_t ialh;
 
-	igt_assert_eq(intel_allocator_close(0x123), false);
-	igt_assert_eq(intel_allocator_ref(0x123), false);
-	igt_assert_eq(intel_allocator_unref(0x123), false);
+	igt_assert_eq(intel_allocator_close(0xdead), false);
+	igt_assert_eq(intel_allocator_ref(0xf00d), false);
+	igt_assert_eq(intel_allocator_unref(0xb000), false);
 
 	ialh = intel_allocator_open(fd, 0, INTEL_ALLOCATOR_SIMPLE);
 	igt_assert_eq(intel_allocator_ref(ialh), true);
@@ -561,12 +561,13 @@ static void basic_check(int fd)
 	igt_assert_eq(intel_allocator_close(ialh), false);
 	igt_assert_eq(intel_allocator_unref(ialh), true);
 	igt_assert_eq(intel_allocator_close(ialh), true);
+	igt_assert_eq(intel_allocator_close(ialh), false);
 }
 
 static void open_vm(int fd)
 {
 	uint64_t ialh1, ialh2;
-//	uint64_t ialh3, ialh4;
+	uint64_t ialh3, ialh4;
 
 	ialh1 = intel_allocator_open(fd, 0, INTEL_ALLOCATOR_SIMPLE);
 	ialh2 = intel_allocator_open(fd, 0, INTEL_ALLOCATOR_SIMPLE);
@@ -574,20 +575,18 @@ static void open_vm(int fd)
 	igt_info("ial1: %llx\n", (long long) ialh1);
 	igt_info("ial2: %llx\n", (long long) ialh2);
 
-//	ialh3 = intel_allocator_open_vm(fd, 1, INTEL_ALLOCATOR_SIMPLE);
-//	ialh4 = intel_allocator_open_vm(fd, 1, INTEL_ALLOCATOR_SIMPLE);
+	ialh3 = intel_allocator_open_vm(fd, 1, INTEL_ALLOCATOR_SIMPLE);
+	ialh4 = intel_allocator_open_vm(fd, 1, INTEL_ALLOCATOR_SIMPLE);
 
-//	igt_info("ial3: %llx\n", (long long) ialh3);
-//	igt_info("ial4: %llx\n", (long long) ialh4);
+	igt_info("ial3: %llx\n", (long long) ialh3);
+	igt_info("ial4: %llx\n", (long long) ialh4);
 
 	intel_allocator_close(ialh1);
 	intel_allocator_close(ialh2);
-//	intel_allocator_close(ialh3);
-//	intel_allocator_close(ialh4);
+	intel_allocator_close(ialh3);
+	intel_allocator_close(ialh4);
 }
 
-
-
 static void ctx(int fd)
 {
 	uint32_t ctx, vmid0, vmid1;
diff --git a/tests/i915/api_intel_bb.c b/tests/i915/api_intel_bb.c
index b62957b34..df5640437 100644
--- a/tests/i915/api_intel_bb.c
+++ b/tests/i915/api_intel_bb.c
@@ -37,6 +37,7 @@
 #include <zlib.h>
 #include "intel_bufops.h"
 #include "sw_sync.h"
+#include "i915/gem_vm.h"
 
 #define PAGE_SIZE 4096
 
@@ -237,6 +238,49 @@ static void bb_with_allocator(struct buf_ops *bops)
 	intel_bb_destroy(ibb);
 }
 
+static void bb_with_vm(struct buf_ops *bops)
+{
+	int i915 = buf_ops_get_fd(bops);
+	struct intel_bb *ibb;
+	struct intel_buf *src, *dst, *gap;
+	uint32_t ctx = 0, vm_id;
+	uint64_t prev_vm, vm;
+
+	igt_require(gem_uses_full_ppgtt(i915));
+
+	ibb = intel_bb_create_with_allocator(i915, ctx, PAGE_SIZE,
+					     INTEL_ALLOCATOR_SIMPLE);
+
+	vm_id = gem_vm_create(i915);
+	igt_info("Vm_id: %u\n", vm_id);
+	vm = intel_allocator_open_vm(i915, vm_id, INTEL_ALLOCATOR_SIMPLE);
+	if (debug_bb)
+		intel_bb_set_debug(ibb, true);
+
+	src = intel_buf_create(bops, 4096/32, 32, 8, 0, I915_TILING_NONE,
+			       I915_COMPRESSION_NONE);
+	dst = intel_buf_create(bops, 4096/32, 32, 8, 0, I915_TILING_NONE,
+			       I915_COMPRESSION_NONE);
+	gap = intel_buf_create(bops, 4096, 32, 8, 0, I915_TILING_NONE,
+			       I915_COMPRESSION_NONE);
+
+	intel_bb_add_intel_buf(ibb, src, false);
+	intel_bb_add_intel_buf(ibb, dst, true);
+	intel_bb_copy_intel_buf(ibb, dst, src, 4096);
+
+	prev_vm = intel_bb_assign_vm(ibb, vm);
+	intel_allocator_close(prev_vm);
+	intel_bb_add_intel_buf(ibb, gap, false);
+	intel_bb_add_intel_buf(ibb, src, false);
+	intel_bb_add_intel_buf(ibb, dst, true);
+	intel_bb_copy_intel_buf(ibb, dst, src, 4096);
+
+	intel_bb_remove_intel_buf(ibb, src);
+	intel_bb_remove_intel_buf(ibb, dst);
+
+	intel_bb_destroy(ibb);
+}
+
 /*
  * Make sure we lead to realloc in the intel_bb.
  */
@@ -1526,6 +1570,9 @@ igt_main_args("dpib", NULL, help_str, opt_handler, NULL)
 	igt_subtest("bb-with-allocator")
 		bb_with_allocator(bops);
 
+	igt_subtest("bb-with-vm")
+		bb_with_vm(bops);
+
 	igt_subtest("lot-of-buffers")
 		lot_of_buffers(bops);
 
-- 
2.26.0



More information about the Intel-gfx-trybot mailing list