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

2015-04-02 Thread Tvrtko Ursulin
From: Tvrtko Ursulin tvrtko.ursu...@intel.com

This tests the new EXEC_OBJECT_PAD_TO_SIZE exec_object2 flag.

Similar to some other tests, it uses knowledge of the DRM
allocation policy in order to get two objects mapped adjacent
to each other. It is then possible to verify that the pad to
size flag will move them apart.

v2: Correct commit message. (Chris Wilson)
v3: Changes after code review by Chris Wilson.
 * No need for gem_sync after execbuf.
 * Drop caches before running.
 * Allocate one additional bo per iteration.
 * Don't explicitly set unused execbuf fields to zero.
 * One improved comment.
v4: Require simpler object ordering and fixed overlap test. (Chris Wilson)
v5: Check unpadded offsets once more before padding. (Chris Wilson)

Signed-off-by: Tvrtko Ursulin tvrtko.ursu...@intel.com
Reviewed-by: Chris Wilson ch...@chris-wilson.co.uk
Cc: Chris Wilson ch...@chris-wilson.co.uk
---
 tests/Makefile.sources   |   1 +
 tests/gem_exec_pad_to_size.c | 240 +++
 2 files changed, 241 insertions(+)
 create mode 100644 tests/gem_exec_pad_to_size.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 0a974a6..5f21728 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -34,6 +34,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 000..87afe40
--- /dev/null
+++ b/tests/gem_exec_pad_to_size.c
@@ -0,0 +1,240 @@
+/*
+ * 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.ursu...@intel.com
+ *
+ */
+
+#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
+#include igt_debugfs.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 (10)
+#define LOCAL_EXEC_OBJECT_NEEDS_GTT(11)
+#define LOCAL_EXEC_OBJECT_WRITE(12)
+#define LOCAL_EXEC_OBJECT_PAD_TO_SIZE (13)
+#define __LOCAL_EXEC_OBJECT_UNKNOWN_FLAGS -(LOCAL_EXEC_OBJECT_PAD_TO_SIZE1)
+   __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].flags = pad_to_size[0] ?
+   LOCAL_EXEC_OBJECT_PAD_TO_SIZE : 0;
+   gem_exec[0].pad_to_size = pad_to_size[0];
+
+   gem_exec[1].handle = handles[2];
+   gem_exec[1].flags = pad_to_size[1] ?
+   

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

2015-04-02 Thread Thomas Wood
On 2 April 2015 at 13:54, Tvrtko Ursulin tvrtko.ursu...@linux.intel.com wrote:
 From: Tvrtko Ursulin tvrtko.ursu...@intel.com

 This tests the new EXEC_OBJECT_PAD_TO_SIZE exec_object2 flag.

Just two things from an i-g-t perspective: the new binary needs adding
to .gitignore and it would be good to include a short description of
the test using the IGT_TEST_DESCRIPTION macro.



 Similar to some other tests, it uses knowledge of the DRM
 allocation policy in order to get two objects mapped adjacent
 to each other. It is then possible to verify that the pad to
 size flag will move them apart.

 v2: Correct commit message. (Chris Wilson)
 v3: Changes after code review by Chris Wilson.
  * No need for gem_sync after execbuf.
  * Drop caches before running.
  * Allocate one additional bo per iteration.
  * Don't explicitly set unused execbuf fields to zero.
  * One improved comment.
 v4: Require simpler object ordering and fixed overlap test. (Chris Wilson)
 v5: Check unpadded offsets once more before padding. (Chris Wilson)

 Signed-off-by: Tvrtko Ursulin tvrtko.ursu...@intel.com
 Reviewed-by: Chris Wilson ch...@chris-wilson.co.uk
 Cc: Chris Wilson ch...@chris-wilson.co.uk
 ---
  tests/Makefile.sources   |   1 +
  tests/gem_exec_pad_to_size.c | 240 
 +++
  2 files changed, 241 insertions(+)
  create mode 100644 tests/gem_exec_pad_to_size.c

 diff --git a/tests/Makefile.sources b/tests/Makefile.sources
 index 0a974a6..5f21728 100644
 --- a/tests/Makefile.sources
 +++ b/tests/Makefile.sources
 @@ -34,6 +34,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 000..87afe40
 --- /dev/null
 +++ b/tests/gem_exec_pad_to_size.c
 @@ -0,0 +1,240 @@
 +/*
 + * 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.ursu...@intel.com
 + *
 + */
 +
 +#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
 +#include igt_debugfs.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 (10)
 +#define LOCAL_EXEC_OBJECT_NEEDS_GTT(11)
 +#define LOCAL_EXEC_OBJECT_WRITE(12)
 +#define LOCAL_EXEC_OBJECT_PAD_TO_SIZE (13)
 +#define __LOCAL_EXEC_OBJECT_UNKNOWN_FLAGS -(LOCAL_EXEC_OBJECT_PAD_TO_SIZE1)
 +   __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];
 +