[RFC i-g-t] tests/gem_exec_pad_to_size: Test object padding at execbuf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>

This tests the new EXEC_OBJECT_PAD_TO_SIZE exec_object2 flag.

It uses the fact DRM allocation policy is set as ABI and allocates
space in order. That means that we should be able to easily get
two bos mapped at adjacent GTT addresses and then test that the
pad to size flag will move them apart.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 tests/Makefile.sources       |   1 +
 tests/gem_exec_pad_to_size.c | 276 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 277 insertions(+)
 create mode 100644 tests/gem_exec_pad_to_size.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index a165978..e8b212a 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -33,6 +33,7 @@ TESTS_progs_M = \
 	gem_exec_bad_domains \
 	gem_exec_faulting_reloc \
 	gem_exec_nop \
+	gem_exec_pad_to_size \
 	gem_exec_params \
 	gem_exec_parse \
 	gem_fenced_exec_thrash \
diff --git a/tests/gem_exec_pad_to_size.c b/tests/gem_exec_pad_to_size.c
new file mode 100644
index 0000000..3584e5c
--- /dev/null
+++ b/tests/gem_exec_pad_to_size.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
+ *
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include "drm.h"
+#include "ioctl_wrappers.h"
+#include "igt_core.h"
+#include "drmtest.h"
+#include "intel_reg.h"
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+struct local_drm_i915_gem_exec_object2 {
+	/**
+	 * User's handle for a buffer to be bound into the GTT for this
+	 * operation.
+	 */
+	__u32 handle;
+
+	/** Number of relocations to be performed on this buffer */
+	__u32 relocation_count;
+	/**
+	 * Pointer to array of struct drm_i915_gem_relocation_entry containing
+	 * the relocations to be performed in this buffer.
+	 */
+	__u64 relocs_ptr;
+
+	/** Required alignment in graphics aperture */
+	__u64 alignment;
+
+	/**
+	 * Returned value of the updated offset of the object, for future
+	 * presumed_offset writes.
+	 */
+	__u64 offset;
+
+#define LOCAL_EXEC_OBJECT_NEEDS_FENCE (1<<0)
+#define LOCAL_EXEC_OBJECT_NEEDS_GTT	(1<<1)
+#define LOCAL_EXEC_OBJECT_WRITE	(1<<2)
+#define LOCAL_EXEC_OBJECT_PAD_TO_SIZE (1<<3)
+#define __LOCAL_EXEC_OBJECT_UNKNOWN_FLAGS -(LOCAL_EXEC_OBJECT_PAD_TO_SIZE<<1)
+	__u64 flags;
+
+	__u64 pad_to_size;
+	__u64 rsvd2;
+};
+
+static int
+exec(int fd, uint32_t handles[3], uint32_t pad_to_size[2], uint64_t *offsets)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct local_drm_i915_gem_exec_object2 gem_exec[3];
+	int ret = 0;
+
+	memset(gem_exec, 0, sizeof(gem_exec));
+
+	gem_exec[0].handle = handles[1];
+	gem_exec[0].relocation_count = 0;
+	gem_exec[0].relocs_ptr = 0;
+	gem_exec[0].alignment = 0;
+	gem_exec[0].offset = 0;
+	gem_exec[0].flags = pad_to_size[0] ?
+			    LOCAL_EXEC_OBJECT_PAD_TO_SIZE : 0;
+	gem_exec[0].pad_to_size = pad_to_size[0];
+	gem_exec[0].rsvd2 = 0;
+
+	gem_exec[1].handle = handles[2];
+	gem_exec[1].relocation_count = 0;
+	gem_exec[1].relocs_ptr = 0;
+	gem_exec[1].alignment = 0;
+	gem_exec[1].offset = 0;
+	gem_exec[1].flags = pad_to_size[1] ?
+			    LOCAL_EXEC_OBJECT_PAD_TO_SIZE : 0;
+	gem_exec[1].pad_to_size = pad_to_size[1];
+	gem_exec[1].rsvd2 = 0;
+
+	gem_exec[2].handle = handles[0];
+	gem_exec[2].relocation_count = 0;
+	gem_exec[2].relocs_ptr = 0;
+	gem_exec[2].alignment = 0;
+	gem_exec[2].offset = 0;
+	gem_exec[2].flags = 0;
+	gem_exec[2].pad_to_size = 0;
+	gem_exec[2].rsvd2 = 0;
+
+	execbuf.buffers_ptr = (uintptr_t)gem_exec;
+	execbuf.buffer_count = 3;
+	execbuf.batch_start_offset = 0;
+	execbuf.batch_len = 8;
+	execbuf.cliprects_ptr = 0;
+	execbuf.num_cliprects = 0;
+	execbuf.DR1 = 0;
+	execbuf.DR4 = 0;
+	execbuf.flags = I915_EXEC_RENDER;
+	i915_execbuffer2_set_context_id(execbuf, 0);
+	execbuf.rsvd2 = 0;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf))
+			ret = -errno;
+
+	if (ret == 0) {
+		gem_sync(fd, handles[0]);
+
+		if (offsets) {
+			offsets[0] = gem_exec[0].offset;
+			offsets[1] = gem_exec[1].offset;
+		}
+	}
+
+	return ret;
+}
+
+static void
+require_pad_to_size(int fd, uint32_t handles[3])
+{
+	igt_require(exec(fd, handles, (uint32_t[2]){ PAGE_SIZE, PAGE_SIZE },
+			 NULL) == 0);
+}
+
+static void
+not_aligned(int fd, uint32_t handles[3])
+{
+	require_pad_to_size(fd, handles);
+
+	igt_require(exec(fd, handles, (uint32_t[2]){1 ,1},
+			 NULL) == -EINVAL);
+}
+
+static void
+padding(int fd, uint32_t handles[3])
+{
+	uint32_t pad_to_size[2] = {0, 0};
+	uint64_t offsets[2];
+	uint32_t distance;
+	bool neighbours = false;
+	unsigned int try, idx;
+	const unsigned int max_tries = 1024; /* Finger in the air. */
+	uint32_t *loc_handles;
+	uint32_t eb_handles[3];
+
+	require_pad_to_size(fd, handles);
+
+	loc_handles = calloc(max_tries * 2, sizeof(uint32_t));
+	igt_assert(loc_handles);
+
+	/* Try with passed in handles first. */
+	loc_handles[0] = handles[1];
+	loc_handles[1] = handles[2];
+
+	/* Try to get two buffer object next to each other in GTT space. */
+	for (try = 0, idx = 0; try < max_tries;) {
+		eb_handles[0] = handles[0];
+		eb_handles[1] = loc_handles[idx];
+		eb_handles[2] = loc_handles[idx + 1];
+
+		igt_assert(exec(fd, eb_handles, (uint32_t[2]){0, 0},
+				offsets) == 0);
+
+		if (offsets[1] > offsets[0]) {
+			distance = offsets[1] - offsets[0];
+			if (distance == PAGE_SIZE)
+				neighbours = true;
+			pad_to_size[0] = ALIGN(distance + PAGE_SIZE, PAGE_SIZE);
+		} else {
+			distance = offsets[0] - offsets[1];
+			if (distance == PAGE_SIZE)
+				neighbours = true;
+			pad_to_size[1] = ALIGN(distance + PAGE_SIZE, PAGE_SIZE);
+		}
+
+		if (neighbours)
+			break;
+
+		try++;
+		idx +=2;
+
+		loc_handles[idx] = gem_create(fd, PAGE_SIZE);
+		igt_assert(loc_handles[idx]);
+		loc_handles[idx + 1] = gem_create(fd, PAGE_SIZE);
+		igt_assert(loc_handles[idx + 1]);
+	}
+
+	/* Test can't confidently run. */
+	if (!neighbours)
+		goto cleanup;
+
+	/* Re-exec with padding set. */
+	igt_assert(exec(fd, eb_handles, pad_to_size, offsets) == 0);
+
+	if (offsets[1] > offsets[0])
+		distance = offsets[1] - offsets[0];
+	else
+		distance = offsets[0] - offsets[1];
+
+	/* Check that object are now away from each other. */
+	igt_assert(distance >= 2 * PAGE_SIZE);
+
+cleanup:
+	/* Cleanup our bos. */
+	for (idx = 0; loc_handles[idx] && (idx < try * 2); idx++)
+		gem_close(fd, loc_handles[2 + idx]);
+
+	free(loc_handles);
+
+	igt_require(neighbours);
+}
+
+uint32_t batch[2] = {MI_BATCH_BUFFER_END};
+uint32_t handles[3];
+int fd;
+
+igt_main
+{
+	igt_fixture {
+		fd = drm_open_any();
+
+		handles[0] = gem_create(fd, PAGE_SIZE);
+		gem_write(fd, handles[0], 0, batch, sizeof(batch));
+
+		handles[1] = gem_create(fd, PAGE_SIZE);
+		handles[2] = gem_create(fd, PAGE_SIZE);
+	}
+
+	igt_subtest("pad_to_size")
+		require_pad_to_size(fd, handles);
+
+	igt_subtest("not_aligned")
+		not_aligned(fd, handles);
+
+	igt_subtest("padding")
+		padding(fd, handles);
+
+	igt_fixture {
+		gem_close(fd, handles[0]);
+		gem_close(fd, handles[1]);
+		gem_close(fd, handles[2]);
+
+		close(fd);
+	}
+}
-- 
2.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/intel-gfx





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux