Skip to contentSkip to conversation

Tests to exercise WC mapping

PATCH In review [email protected] 2 participants 8 messages Jan 2, 2015 – Jan 5, 2015 Library code

lore
Share & tools
lore
#0 lore raw

cover Tests to exercise WC mapping

From: Akash Goel <[email protected]>

Two new IGT test gem_mmap_wc/gem_tiled_wc added to exercise the WC mapping. Other existing IGT tests also updated to make use of the new mapping.

Akash Goel (1):
igt/gem_mmap_wc: Add the invalid flags subtest

Chris Wilson (5):
igt/gem_mmap_wc: Exercise mmap(wc) interface igt/gem_tiled_wc: Exercise wc mmaps with swizzling igt/gem_gtt_speed: compare against WC mmaps igt/gem_fence_upload: Add comparison against wc mmaps igt/gem_concurrent_blit: Exercise wc mappings

 lib/ioctl_wrappers.c        |  81 +++++++++
 lib/ioctl_wrappers.h        |   5 +
 tests/.gitignore            |   2 +
 tests/Makefile.am           |   2 +
 tests/Makefile.sources      |   2 +
 tests/gem_concurrent_blit.c | 233 ++++++++++++++++++++----
 tests/gem_fence_upload.c    |  73 ++++++++
 tests/gem_gtt_speed.c       |  63 ++++++-
 tests/gem_mmap_wc.c         | 422 ++++++++++++++++++++++++++++++++++++++++++++
 tests/gem_tiled_wc.c        | 237 +++++++++++++++++++++++++
 10 files changed, 1084 insertions(+), 36 deletions(-)
 create mode 100644 tests/gem_mmap_wc.c
 create mode 100644 tests/gem_tiled_wc.c
Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/6 igt/gem_mmap_wc: Exercise mmap(wc) interface

From: Chris Wilson <[email protected]>

---
 lib/ioctl_wrappers.c   |  81 +++++++++++
 lib/ioctl_wrappers.h   |   5 +
 tests/.gitignore       |   1 +
 tests/Makefile.am      |   2 +
 tests/Makefile.sources |   1 +
 tests/gem_mmap_wc.c    | 370 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 460 insertions(+)
 create mode 100644 tests/gem_mmap_wc.c
lib/ioctl_wrappers.c +81 -0
index cddf6c7..f20786a 100644
@@ -463,10 +463,91 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot)
 	ptr = mmap64(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 	if (ptr == MAP_FAILED)
 		ptr = NULL;
+	else
+		errno = 0;
 
 	return ptr;
 }
 
+struct local_i915_gem_mmap_v2 {
+	uint32_t handle;
+	uint32_t pad;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t addr_ptr;
+	uint64_t flags;
+#define I915_MMAP_WC 0x1
+};
+#define LOCAL_IOCTL_I915_GEM_MMAP_v2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MMAP, struct local_i915_gem_mmap_v2)
+
+bool gem_mmap__has_wc(int fd)
+{
+	static int has_wc = -1;
+
+	if (has_wc == -1) {
+		struct drm_i915_getparam gp;
+		int val = -1;
+
+		has_wc = 0;
+
+		memset(&gp, 0, sizeof(gp));
+		gp.param = 30; /* MMAP_VERSION */
+		gp.value = &val;
+
+		/* Do we have the new mmap_ioctl? */
+		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+		if (val >= 1) {
+			struct local_i915_gem_mmap_v2 arg;
+
+			/* Does this device support wc-mmaps ? */
+			memset(&arg, 0, sizeof(arg));
+			arg.handle = gem_create(fd, 4096);
+			arg.offset = 0;
+			arg.size = 4096;
+			arg.flags = I915_MMAP_WC;
+			has_wc = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg) == 0;
+			gem_close(fd, arg.handle);
+		}
+		errno = 0;
+	}
+
+	return has_wc > 0;
+}
+
+/**
+ * gem_mmap__wc:
+ * @fd: open i915 drm file descriptor
+ * @handle: gem buffer object handle
+ * @offset: offset in the gem buffer of te mmap arena
+ * @size: size of the mmap arena
+ * @prot: memory protection bits as used by mmap()
+ *
+ * This functions wraps up procedure to establish a memory mapping through
+ * direct cpu access, bypassing the gpu and cpu caches completely.
+ *
+ * Returns: A pointer to the created memory mapping.
+ */
+void *gem_mmap__wc(int fd, uint32_t handle, int offset, int size, int prot)
+{
+	struct local_i915_gem_mmap_v2 arg;
+
+	if (!gem_mmap__has_wc(fd)) {
+		errno = ENOSYS;
+		return NULL;
+	}
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = handle;
+	arg.offset = offset;
+	arg.size = size;
+	arg.flags = I915_MMAP_WC;
+	if (drmIoctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg))
+		return NULL;
+
+	errno = 0;
+	return (void *)(uintptr_t)arg.addr_ptr;
+}
+
 /**
  * gem_mmap__cpu:
  * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +5 -0
index d13408c..9e7edad 100644
@@ -62,6 +62,11 @@ void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
 
 void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot);
 void *gem_mmap__cpu(int fd, uint32_t handle, int offset, int size, int prot);
+
+bool gem_mmap__has_wc(int fd);
+void *gem_mmap__wc(int fd, uint32_t handle, int offset, int size, int prot);
+#define igt_require_mmap_wc(x) igt_require(gem_mmap__has_wc(x))
+
 /**
  * gem_mmap:
  *
tests/.gitignore +1 -0
index b770a8b..1466a7a 100644
@@ -61,6 +61,7 @@ gem_madvise
 gem_media_fill
 gem_mmap
 gem_mmap_gtt
+gem_mmap_wc
 gem_mmap_offset_exhaustion
 gem_multi_bsd_sync_loop
 gem_non_secure_batch
tests/Makefile.am +2 -0
index b44d4d6..ec2bd30 100644
@@ -60,6 +60,8 @@ gem_flink_race_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_flink_race_LDADD = $(LDADD) -lpthread
 gem_mmap_gtt_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_mmap_gtt_LDADD = $(LDADD) -lpthread
+gem_mmap_wc_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
+gem_mmap_wc_LDADD = $(LDADD) -lpthread
 gem_threaded_access_tiled_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_threaded_access_tiled_LDADD = $(LDADD) -lpthread
 gem_tiled_swapping_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
tests/Makefile.sources +1 -0
index d15a68b..34c1899 100644
@@ -42,6 +42,7 @@ TESTS_progs_M = \
 	gem_madvise \
 	gem_mmap \
 	gem_mmap_gtt \
+	gem_mmap_wc \
 	gem_partial_pwrite_pread \
 	gem_persistent_relocs \
 	gem_pipe_control_store_loop \
tests/gem_mmap_wc.c new file +370 -0

370 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/6 igt/gem_tiled_wc: Exercise wc mmaps with swizzling

In reply to [email protected]

From: Chris Wilson <[email protected]>

This exercises both the wc mmappings and the extended get_tiling ioctl. Userspace cannot handle bit17 swizzling through wc mmaps (because bit17 requires swizzling based on the actual physical address of the page - which is unknown to userspace) and so we need an extended get_tiling ioctl to report the actual as well as the logical swizzling on an object. We then check that the contents of the object are tiled and swizzled correctly when viewed through a wc mmap.

---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/gem_tiled_wc.c   | 237 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 239 insertions(+)
 create mode 100644 tests/gem_tiled_wc.c
tests/.gitignore +1 -0
index 1466a7a..88a6405 100644
@@ -104,6 +104,7 @@ gem_tiled_pread
 gem_tiled_pread_pwrite
 gem_tiled_swapping
 gem_tiled_wb
+gem_tiled_wc
 gem_tiling_max_stride
 gem_unfence_active_buffers
 gem_unref_active_buffers
tests/Makefile.sources +1 -0
index 34c1899..74deec3 100644
@@ -137,6 +137,7 @@ TESTS_progs = \
 	gem_tiled_pread_pwrite \
 	gem_tiled_swapping \
 	gem_tiled_wb \
+	gem_tiled_wc \
 	gem_tiling_max_stride \
 	gem_unfence_active_buffers \
 	gem_unref_active_buffers \
tests/gem_tiled_wc.c new file +237 -0

237 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 3/6 igt/gem_gtt_speed: compare against WC mmaps

In reply to [email protected]

From: Chris Wilson <[email protected]>

---
 tests/gem_gtt_speed.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
tests/gem_gtt_speed.c +62 -1
index c68b8e4..d5e745e 100644
@@ -206,6 +206,27 @@ int main(int argc, char **argv)
 		igt_info("Time to read %dk through a GTT map:		%7.3fµs\n",
 			 size/1024, elapsed(&start, &end, loop));
 
+		if (gem_mmap__has_wc(fd)) {
+			gettimeofday(&start, NULL);
+			for (loop = 0; loop < 1000; loop++) {
+				uint32_t *base = gem_mmap__wc(fd, handle, 0, size, PROT_READ | PROT_WRITE);
+				volatile uint32_t *ptr = base;
+				int x = 0;
+
+				for (i = 0; i < size/sizeof(*ptr); i++)
+					x += ptr[i];
+
+				/* force overtly clever gcc to actually compute x */
+				ptr[0] = x;
+
+				munmap(base, size);
+			}
+			gettimeofday(&end, NULL);
+			igt_info("Time to read %dk through a WC map:		%7.3fµs\n",
+					size/1024, elapsed(&start, &end, loop));
+		}
+
+
 		/* mmap write */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
@@ -221,6 +242,23 @@ int main(int argc, char **argv)
 		igt_info("Time to write %dk through a GTT map:		%7.3fµs\n",
 			 size/1024, elapsed(&start, &end, loop));
 
+		if (gem_mmap__has_wc(fd)) {
+			/* mmap write */
+			gettimeofday(&start, NULL);
+			for (loop = 0; loop < 1000; loop++) {
+				uint32_t *base = gem_mmap__wc(fd, handle, 0, size, PROT_READ | PROT_WRITE);
+				volatile uint32_t *ptr = base;
+
+				for (i = 0; i < size/sizeof(*ptr); i++)
+					ptr[i] = i;
+
+				munmap(base, size);
+			}
+			gettimeofday(&end, NULL);
+			igt_info("Time to write %dk through a WC map:		%7.3fµs\n",
+					size/1024, elapsed(&start, &end, loop));
+		}
+
 		/* mmap clear */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
@@ -232,6 +270,19 @@ int main(int argc, char **argv)
 		igt_info("Time to clear %dk through a GTT map:		%7.3fµs\n",
 			 size/1024, elapsed(&start, &end, loop));
 
+		if (gem_mmap__has_wc(fd)) {
+			/* mmap clear */
+			gettimeofday(&start, NULL);
+			for (loop = 0; loop < 1000; loop++) {
+				uint32_t *base = gem_mmap__wc(fd, handle, 0, size, PROT_READ | PROT_WRITE);
+				memset(base, 0, size);
+				munmap(base, size);
+			}
+			gettimeofday(&end, NULL);
+			igt_info("Time to clear %dk through a WC map:		%7.3fµs\n",
+					size/1024, elapsed(&start, &end, loop));
+		}
+
 		gettimeofday(&start, NULL);{
 			uint32_t *base = gem_mmap(fd, handle, size, PROT_READ | PROT_WRITE);
 			for (loop = 0; loop < 1000; loop++)
@@ -241,6 +292,17 @@ int main(int argc, char **argv)
 		igt_info("Time to clear %dk through a cached GTT map:	%7.3fµs\n",
 			 size/1024, elapsed(&start, &end, loop));
 
+		if (gem_mmap__has_wc(fd)) {
+			gettimeofday(&start, NULL);{
+				uint32_t *base = gem_mmap__wc(fd, handle, 0, size, PROT_READ | PROT_WRITE);
+				for (loop = 0; loop < 1000; loop++)
+					memset(base, 0, size);
+				munmap(base, size);
+			} gettimeofday(&end, NULL);
+			igt_info("Time to clear %dk through a cached WC map:	%7.3fµs\n",
+					size/1024, elapsed(&start, &end, loop));
+		}
+
 		/* mmap read */
 		gettimeofday(&start, NULL);
 		for (loop = 0; loop < 1000; loop++) {
@@ -323,7 +385,6 @@ int main(int argc, char **argv)
 
 			size *= 4;
 		}
-
 	}
 
 	gem_close(fd, handle);
Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 4/6 igt/gem_fence_upload: Add comparison against wc mmaps

In reply to [email protected]

From: Chris Wilson <[email protected]>

---
 tests/gem_fence_upload.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
tests/gem_fence_upload.c +73 -0
index 88da5dc..81f797b 100644
@@ -267,6 +267,21 @@ static void *no_contention(void *closure)
 	return NULL;
 }
 
+static void *wc_mmap(void *closure)
+{
+	struct thread_contention *t = closure;
+	int n;
+
+	for (n = 0; n < t->loops; n++) {
+		uint32_t *ptr = gem_mmap__wc(t->fd, t->handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
+		igt_assert(ptr);
+		memset(ptr + (rand() % 256) * 4096 / 4, 0, 4096);
+		munmap(ptr, OBJECT_SIZE);
+	}
+
+	return NULL;
+}
+
 static void thread_contention(void)
 {
 	const int loops = 4096;
@@ -322,6 +337,62 @@ static void thread_contention(void)
 	igt_assert(tiled[1] > 0.75 * tiled[0]);
 }
 
+static void wc_contention(void)
+{
+	const int loops = 4096;
+	int n, count;
+	int fd, num_fences;
+	double linear[2], tiled[2];
+
+	fd = drm_open_any();
+	igt_require_mmap_wc(fd);
+
+	num_fences = gem_available_fences(fd);
+	igt_require(num_fences > 0);
+
+	for (count = 1; count < 4*num_fences; count *= 2) {
+		struct timeval start, end;
+		struct thread_contention threads[count];
+
+		for (n = 0; n < count; n++) {
+			threads[n].handle = gem_create(fd, OBJECT_SIZE);
+			threads[n].loops = loops;
+			threads[n].fd = fd;
+		}
+
+		gettimeofday(&start, NULL);
+		for (n = 0; n < count; n++)
+			pthread_create(&threads[n].thread, NULL, wc_mmap, &threads[n]);
+		for (n = 0; n < count; n++)
+			pthread_join(threads[n].thread, NULL);
+		gettimeofday(&end, NULL);
+
+		linear[count != 2] = count * loops / elapsed(&start, &end) / (OBJECT_SIZE / 4096);
+		igt_info("Contended upload rate for %d linear threads/wc:	%7.3fMiB/s\n", count, linear[count != 2]);
+
+		for (n = 0; n < count; n++)
+			gem_set_tiling(fd, threads[n].handle, I915_TILING_X, 1024);
+
+		gettimeofday(&start, NULL);
+		for (n = 0; n < count; n++)
+			pthread_create(&threads[n].thread, NULL, wc_mmap, &threads[n]);
+		for (n = 0; n < count; n++)
+			pthread_join(threads[n].thread, NULL);
+		gettimeofday(&end, NULL);
+
+		tiled[count != 2] = count * loops / elapsed(&start, &end) / (OBJECT_SIZE / 4096);
+		igt_info("Contended upload rate for %d tiled threads/wc:	%7.3fMiB/s\n", count, tiled[count != 2]);
+
+		for (n = 0; n < count; n++) {
+			gem_close(fd, threads[n].handle);
+		}
+	}
+
+	errno = 0;
+	igt_assert(linear[1] > 0.75 * linear[0]);
+	igt_assert(tiled[1] > 0.75 * tiled[0]);
+}
+
 igt_main
 {
 	igt_skip_on_simulation();
@@ -330,6 +401,8 @@ igt_main
 		performance();
 	igt_subtest("thread-contention")
 		thread_contention();
+	igt_subtest("wc-contention")
+		wc_contention();
 	igt_subtest("thread-performance-read")
 		thread_performance(READ);
 	igt_subtest("thread-performance-write")
Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH 5/6 igt/gem_concurrent_blit: Exercise wc mappings

In reply to [email protected]

From: Chris Wilson <[email protected]>

---
 tests/gem_concurrent_blit.c | 233 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 198 insertions(+), 35 deletions(-)
tests/gem_concurrent_blit.c +198 -35
index 4ce5ef0..9d157b6 100644
@@ -62,6 +62,12 @@ int fd, devid, gen;
 struct intel_batchbuffer *batch;
 
 static void
+nop_release_bo(drm_intel_bo *bo)
+{
+	drm_intel_bo_unreference(bo);
+}
+
+static void
 prw_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height)
 {
 	int size = width * height, i;
@@ -162,6 +168,27 @@ gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
 }
 
 static drm_intel_bo *
+wc_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
+{
+	drm_intel_bo *bo;
+
+	igt_require_mmap_wc(fd);
+
+	bo = unmapped_create_bo(bufmgr, width, height);
+	bo->virtual = gem_mmap__wc(fd, bo->handle, 0, bo->size, PROT_READ | PROT_WRITE);
+	return bo;
+}
+
+static void
+wc_release_bo(drm_intel_bo *bo)
+{
+	munmap(bo->virtual, bo->size);
+	bo->virtual = NULL;
+
+	nop_release_bo(bo);
+}
+
+static drm_intel_bo *
 gpu_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
 {
 	return unmapped_create_bo(bufmgr, width, height);
@@ -274,26 +301,62 @@ gpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *
 	cpu_cmp_bo(tmp, val, width, height, NULL);
 }
 
-struct access_mode {
+const struct access_mode {
+	const char *name;
 	void (*set_bo)(drm_intel_bo *bo, uint32_t val, int w, int h);
 	void (*cmp_bo)(drm_intel_bo *bo, uint32_t val, int w, int h, drm_intel_bo *tmp);
 	drm_intel_bo *(*create_bo)(drm_intel_bufmgr *bufmgr, int width, int height);
-	const char *name;
-};
-
-struct access_mode access_modes[] = {
-	{ .set_bo = prw_set_bo, .cmp_bo = prw_cmp_bo,
-		.create_bo = unmapped_create_bo, .name = "prw" },
-	{ .set_bo = cpu_set_bo, .cmp_bo = cpu_cmp_bo,
-		.create_bo = unmapped_create_bo, .name = "cpu" },
-	{ .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo,
-		.create_bo = gtt_create_bo, .name = "gtt" },
-	{ .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo,
-		.create_bo = gttX_create_bo, .name = "gttX" },
-	{ .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo,
-		.create_bo = gpu_create_bo, .name = "gpu" },
-	{ .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo,
-		.create_bo = gpuX_create_bo, .name = "gpuX" },
+	void (*release_bo)(drm_intel_bo *bo);
+} access_modes[] = {
+	{
+		.name = "prw",
+		.set_bo = prw_set_bo,
+		.cmp_bo = prw_cmp_bo,
+		.create_bo = unmapped_create_bo,
+		.release_bo = nop_release_bo,
+	},
+	{
+		.name = "cpu",
+		.set_bo = cpu_set_bo,
+		.cmp_bo = cpu_cmp_bo,
+		.create_bo = unmapped_create_bo,
+		.release_bo = nop_release_bo,
+	},
+	{
+		.name = "gtt",
+		.set_bo = gtt_set_bo,
+		.cmp_bo = gtt_cmp_bo,
+		.create_bo = gtt_create_bo,
+		.release_bo = nop_release_bo,
+	},
+	{
+		.name = "gttX",
+		.set_bo = gtt_set_bo,
+		.cmp_bo = gtt_cmp_bo,
+		.create_bo = gttX_create_bo,
+		.release_bo = nop_release_bo,
+	},
+	{
+		.name = "wc",
+		.set_bo = gtt_set_bo,
+		.cmp_bo = gtt_cmp_bo,
+		.create_bo = wc_create_bo,
+		.release_bo = wc_release_bo,
+	},
+	{
+		.name = "gpu",
+		.set_bo = gpu_set_bo,
+		.cmp_bo = gpu_cmp_bo,
+		.create_bo = gpu_create_bo,
+		.release_bo = nop_release_bo,
+	},
+	{
+		.name = "gpuX",
+		.set_bo = gpu_set_bo,
+		.cmp_bo = gpu_cmp_bo,
+		.create_bo = gpuX_create_bo,
+		.release_bo = nop_release_bo,
+	},
 };
 
 #define MAX_NUM_BUFFERS 1024
@@ -335,7 +398,63 @@ static void blt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 		       width, height, 32);
 }
 
-static void do_overwrite_source(struct access_mode *mode,
+static void cpu_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
+{
+	const int size = width * height * sizeof(uint32_t);
+	void *d, *s;
+
+	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ);
+	igt_assert(s != NULL);
+	d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE);
+	igt_assert(d != NULL);
+
+	memcpy(d, s, size);
+
+	munmap(d, size);
+	munmap(s, size);
+}
+
+static void gtt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
+{
+	const int size = width * height * sizeof(uint32_t);
+	void *d, *s;
+
+	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+
+	s = gem_mmap__gtt(fd, src->handle, size, PROT_READ);
+	igt_assert(s != NULL);
+	d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE);
+	igt_assert(d != NULL);
+
+	memcpy(d, s, size);
+
+	munmap(d, size);
+	munmap(s, size);
+}
+
+static void wc_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
+{
+	const int size = width * height * sizeof(uint32_t);
+	void *d, *s;
+
+	gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0);
+	gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+
+	s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ);
+	igt_assert(s != NULL);
+	d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE);
+	igt_assert(d != NULL);
+
+	memcpy(d, s, size);
+
+	munmap(d, size);
+	munmap(s, size);
+}
+
+static void do_overwrite_source(const struct access_mode *mode,
 				drm_intel_bo **src, drm_intel_bo **dst,
 				drm_intel_bo *dummy,
 				do_copy do_copy_func)
@@ -355,7 +474,7 @@ static void do_overwrite_source(struct access_mode *mode,
 		mode->cmp_bo(dst[i], i, width, height, dummy);
 }
 
-static void do_early_read(struct access_mode *mode,
+static void do_early_read(const struct access_mode *mode,
 			  drm_intel_bo **src, drm_intel_bo **dst,
 			  drm_intel_bo *dummy,
 			  do_copy do_copy_func)
@@ -371,7 +490,7 @@ static void do_early_read(struct access_mode *mode,
 		mode->cmp_bo(dst[i], 0xdeadbeef, width, height, dummy);
 }
 
-static void do_gpu_read_after_write(struct access_mode *mode,
+static void do_gpu_read_after_write(const struct access_mode *mode,
 				    drm_intel_bo **src, drm_intel_bo **dst,
 				    drm_intel_bo *dummy,
 				    do_copy do_copy_func)
@@ -389,18 +508,18 @@ static void do_gpu_read_after_write(struct access_mode *mode,
 		mode->cmp_bo(dst[i], 0xabcdabcd, width, height, dummy);
 }
 
-typedef void (*do_test)(struct access_mode *mode,
+typedef void (*do_test)(const struct access_mode *mode,
 			drm_intel_bo **src, drm_intel_bo **dst,
 			drm_intel_bo *dummy,
 			do_copy do_copy_func);
 
-typedef void (*run_wrap)(struct access_mode *mode,
+typedef void (*run_wrap)(const struct access_mode *mode,
 			 drm_intel_bo **src, drm_intel_bo **dst,
 			 drm_intel_bo *dummy,
 			 do_test do_test_func,
 			 do_copy do_copy_func);
 
-static void run_single(struct access_mode *mode,
+static void run_single(const struct access_mode *mode,
 		       drm_intel_bo **src, drm_intel_bo **dst,
 		       drm_intel_bo *dummy,
 		       do_test do_test_func,
@@ -409,7 +528,7 @@ static void run_single(struct access_mode *mode,
 	do_test_func(mode, src, dst, dummy, do_copy_func);
 }
 
-static void run_interruptible(struct access_mode *mode,
+static void run_interruptible(const struct access_mode *mode,
 			      drm_intel_bo **src, drm_intel_bo **dst,
 			      drm_intel_bo *dummy,
 			      do_test do_test_func,
@@ -421,37 +540,44 @@ static void run_interruptible(struct access_mode *mode,
 		do_test_func(mode, src, dst, dummy, do_copy_func);
 }
 
-static void run_forked(struct access_mode *mode,
+static void run_forked(const struct access_mode *mode,
 		       drm_intel_bo **src, drm_intel_bo **dst,
 		       drm_intel_bo *dummy,
 		       do_test do_test_func,
 		       do_copy do_copy_func)
 {
 	const int old_num_buffers = num_buffers;
-	drm_intel_bufmgr *bufmgr;
 
 	num_buffers /= 16;
 	num_buffers += 2;
 
 	igt_fork(child, 16) {
+		drm_intel_bufmgr *bufmgr;
+
 		/* recreate process local variables */
 		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
 		drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+
 		batch = intel_batchbuffer_alloc(bufmgr, devid);
+
 		for (int i = 0; i < num_buffers; i++) {
 			src[i] = mode->create_bo(bufmgr, width, height);
 			dst[i] = mode->create_bo(bufmgr, width, height);
 		}
 		dummy = mode->create_bo(bufmgr, width, height);
+
 		for (int loop = 0; loop < 10; loop++)
 			do_test_func(mode, src, dst, dummy, do_copy_func);
+
 		/* as we borrow the fd, we need to reap our bo */
 		for (int i = 0; i < num_buffers; i++) {
-			drm_intel_bo_unreference(src[i]);
-			drm_intel_bo_unreference(dst[i]);
+			mode->release_bo(src[i]);
+			mode->release_bo(dst[i]);
 		}
-		drm_intel_bo_unreference(dummy);
+		mode->release_bo(dummy);
+
 		intel_batchbuffer_free(batch);
+
 		drm_intel_bufmgr_destroy(bufmgr);
 	}
 
@@ -460,6 +586,40 @@ static void run_forked(struct access_mode *mode,
 	num_buffers = old_num_buffers;
 }
 
+static void bit17_require(void)
+{
+	struct drm_i915_gem_get_tiling2 {
+		uint32_t handle;
+		uint32_t tiling_mode;
+		uint32_t swizzle_mode;
+		uint32_t phys_swizzle_mode;
+	} arg;
+#define DRM_IOCTL_I915_GEM_GET_TILING2	DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling2)
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = gem_create(fd, 4096);
+	gem_set_tiling(fd, arg.handle, I915_TILING_X, 512);
+
+	do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_TILING2, &arg));
+	gem_close(fd, arg.handle);
+	igt_require(arg.phys_swizzle_mode == arg.swizzle_mode);
+}
+
+static void cpu_require(void)
+{
+	bit17_require();
+}
+
+static void gtt_require(void)
+{
+}
+
+static void wc_require(void)
+{
+	bit17_require();
+	igt_require_mmap_wc(fd);
+}
+
 static void bcs_require(void)
 {
 }
@@ -470,16 +630,19 @@ static void rcs_require(void)
 }
 
 static void
-run_basic_modes(struct access_mode *mode,
+run_basic_modes(const struct access_mode *mode,
 		drm_intel_bo **src, drm_intel_bo **dst,
 		drm_intel_bo *dummy, const char *suffix,
 		run_wrap run_wrap_func)
 {
-	struct {
+	const struct {
 		const char *prefix;
 		do_copy copy;
 		void (*require)(void);
 	} pipelines[] = {
+		{ "cpu", cpu_copy_bo, cpu_require },
+		{ "gtt", gtt_copy_bo, gtt_require },
+		{ "wc", wc_copy_bo, wc_require },
 		{ "bcs", blt_copy_bo, bcs_require },
 		{ "rcs", render_copy_bo, rcs_require },
 		{ NULL, NULL }
@@ -510,7 +673,7 @@ run_basic_modes(struct access_mode *mode,
 }
 
 static void
-run_modes(struct access_mode *mode)
+run_modes(const struct access_mode *mode)
 {
 	drm_intel_bo *src[MAX_NUM_BUFFERS], *dst[MAX_NUM_BUFFERS], *dummy = NULL;
 	drm_intel_bufmgr *bufmgr;
@@ -535,10 +698,10 @@ run_modes(struct access_mode *mode)
 
 	igt_fixture {
 		for (int i = 0; i < num_buffers; i++) {
-			drm_intel_bo_unreference(src[i]);
-			drm_intel_bo_unreference(dst[i]);
+			mode->release_bo(src[i]);
+			mode->release_bo(dst[i]);
 		}
-		drm_intel_bo_unreference(dummy);
+		mode->release_bo(dummy);
 		intel_batchbuffer_free(batch);
 		drm_intel_bufmgr_destroy(bufmgr);
 	}
Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH 6/6 igt/gem_mmap_wc: Add the invalid flags subtest

In reply to [email protected]

From: Akash Goel <[email protected]>

A new subtest added to validate the new version of gem_mmap ioctl, for creating the wc mappings, on yet to be supported flags.

v2: Removed the flags checking for older kernels (Daniel)

---
 tests/gem_mmap_wc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
tests/gem_mmap_wc.c +52 -0
index 87140ff..4881ab7 100644
@@ -41,6 +41,17 @@
 #include "drmtest.h"
 #include "igt_debugfs.h"
 
+struct local_i915_gem_mmap_v2 {
+	uint32_t handle;
+	uint32_t pad;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t addr_ptr;
+	uint64_t flags;
+#define I915_MMAP_WC 0x1
+};
+#define LOCAL_IOCTL_I915_GEM_MMAP_v2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MMAP, struct local_i915_gem_mmap_v2)
+
 static int OBJECT_SIZE = 16*1024*1024;
 
 static void set_domain(int fd, uint32_t handle)
@@ -76,6 +87,45 @@ create_pointer(int fd)
 }
 
 static void
+test_invalid_flags(int fd)
+{
+	struct drm_i915_getparam gp;
+	struct local_i915_gem_mmap_v2 arg;
+	uint64_t flag = I915_MMAP_WC;
+	int val = -1;
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = gem_create(fd, 4096);
+	arg.offset = 0;
+	arg.size = 4096;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 30; /* MMAP_VERSION */
+	gp.value = &val;
+
+	/* Do we have the new mmap_ioctl? */
+	do_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+	if (val >= 1) {
+		/*
+		 * Only MMAP_WC flag is supported in version 1, so any other
+		 * flag should be rejected.
+		 */
+		flag <<= 1;
+		while (flag) {
+			arg.flags = flag;
+			igt_assert(drmIoctl(fd,
+				   LOCAL_IOCTL_I915_GEM_MMAP_v2,
+				   &arg) == -1);
+			igt_assert_eq(errno, EINVAL);
+			flag <<= 1;
+		}
+	}
+
+	gem_close(fd, arg.handle);
+}
+
+static void
 test_copy(int fd)
 {
 	void *src, *dst;
@@ -336,6 +386,8 @@ igt_main
 	igt_fixture
 		fd = drm_open_any();
 
+	igt_subtest("invalid flags")
+		test_invalid_flags(fd);
 	igt_subtest("copy")
 		test_copy(fd);
 	igt_subtest("read")
Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [PATCH 6/6] igt/gem_mmap_wc: Add the invalid flags subtest

Quoted 82 lines · On Fri, Jan 02, 2015 at 04:33:34PM +0530, [email protected] wrote:

From: Akash Goel <[email protected]>

A new subtest added to validate the new version of gem_mmap ioctl, for creating the wc mappings, on yet to be supported flags.

v2: Removed the flags checking for older kernels (Daniel)

---
 tests/gem_mmap_wc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
tests/gem_mmap_wc.c +50 -0
index 87140ff..4881ab7 100644
@@ -41,6 +41,17 @@
 #include "drmtest.h"
 #include "igt_debugfs.h"
 
+struct local_i915_gem_mmap_v2 {
+	uint32_t handle;
+	uint32_t pad;
+	uint64_t offset;
+	uint64_t size;
+	uint64_t addr_ptr;
+	uint64_t flags;
+#define I915_MMAP_WC 0x1
+};
+#define LOCAL_IOCTL_I915_GEM_MMAP_v2 DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_MMAP, struct local_i915_gem_mmap_v2)
+
 static int OBJECT_SIZE = 16*1024*1024;
 
 static void set_domain(int fd, uint32_t handle)
@@ -76,6 +87,45 @@ create_pointer(int fd)
 }
 
 static void
+test_invalid_flags(int fd)
+{
+	struct drm_i915_getparam gp;
+	struct local_i915_gem_mmap_v2 arg;
+	uint64_t flag = I915_MMAP_WC;
+	int val = -1;
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = gem_create(fd, 4096);
+	arg.offset = 0;
+	arg.size = 4096;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 30; /* MMAP_VERSION */
+	gp.value = &val;
+
+	/* Do we have the new mmap_ioctl? */
+	do_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+
+	if (val >= 1) {
+		/*
+		 * Only MMAP_WC flag is supported in version 1, so any other
+		 * flag should be rejected.
+		 */
+		flag <<= 1;
+		while (flag) {
+			arg.flags = flag;
+			igt_assert(drmIoctl(fd,
+				   LOCAL_IOCTL_I915_GEM_MMAP_v2,
+				   &arg) == -1);
+			igt_assert_eq(errno, EINVAL);
+			flag <<= 1;
+		}
+	}
+
+	gem_close(fd, arg.handle);
+}
+
+static void
 test_copy(int fd)
 {
 	void *src, *dst;

tests/gem_mmap_wc.c igt_main · line 389

Quoted 4 lines
tests/gem_mmap_wc.c +1 -0
@@ -336,6 +386,8 @@ igt_main
 	igt_fixture
 		fd = drm_open_any();
 
+	igt_subtest("invalid flags")

subtest names shouldn't have spaces (it might confuse our tooling). We use a dash instead. I've fixed that up while applying.

Thanks for the patches, all merged.
-Daniel

Quoted 7 lines
tests/gem_mmap_wc.c +1 -0
+		test_invalid_flags(fd);
 	igt_subtest("copy")
 		test_copy(fd);
 	igt_subtest("read")
Signature · 1 line
1.9.2
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx