[Intel-gfx] [PATCH i-g-t 2/5] igt_hang_ctx: Wrap hang_ctx parameters into struct

Antonio Argenziano antonio.argenziano at intel.com
Thu Dec 7 22:48:20 UTC 2017


Cleanup the interface to create a hang on a context by folding its
parameters into a struct.

Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
---
 lib/igt_dummyload.c     | 25 ++++++++++++-------------
 lib/igt_gt.c            | 41 +++++++++++++++++++----------------------
 lib/igt_gt.h            | 14 +++++++++-----
 tests/drv_hangman.c     |  5 ++++-
 tests/gem_reset_stats.c |  7 +++++--
 tests/gem_softpin.c     |  2 +-
 6 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 37ae5a03..fee311f7 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -70,8 +70,7 @@ fill_reloc(struct drm_i915_gem_relocation_entry *reloc,
 }
 
 static void emit_recursive_batch(igt_spin_t *spin,
-				 int fd, uint32_t ctx, unsigned engine,
-				 uint32_t dep)
+				 int fd, igt_spin_opt_t opts)
 {
 #define SCRATCH 0
 #define BATCH 1
@@ -85,13 +84,13 @@ static void emit_recursive_batch(igt_spin_t *spin,
 	int i;
 
 	nengine = 0;
-	if (engine == -1) {
-		for_each_engine(fd, engine)
-			if (engine)
-				engines[nengine++] = engine;
+	if (opts.engine == -1) {
+		for_each_engine(fd, opts.engine)
+			if (opts.engine)
+				engines[nengine++] = opts.engine;
 	} else {
-		gem_require_ring(fd, engine);
-		engines[nengine++] = engine;
+		gem_require_ring(fd, opts.engine);
+		engines[nengine++] = opts.engine;
 	}
 	igt_require(nengine);
 
@@ -109,11 +108,11 @@ static void emit_recursive_batch(igt_spin_t *spin,
 			I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 	execbuf.buffer_count++;
 
-	if (dep) {
+	if (opts.dep) {
 		/* dummy write to dependency */
-		obj[SCRATCH].handle = dep;
+		obj[SCRATCH].handle = opts.dep;
 		fill_reloc(&relocs[obj[BATCH].relocation_count++],
-			   dep, 1020,
+			   opts.dep, 1020,
 			   I915_GEM_DOMAIN_RENDER,
 			   I915_GEM_DOMAIN_RENDER);
 		execbuf.buffer_count++;
@@ -162,7 +161,7 @@ static void emit_recursive_batch(igt_spin_t *spin,
 	obj[BATCH].relocs_ptr = to_user_pointer(relocs);
 
 	execbuf.buffers_ptr = to_user_pointer(obj + (2 - execbuf.buffer_count));
-	execbuf.rsvd1 = ctx;
+	execbuf.rsvd1 = opts.ctx;
 
 	for (i = 0; i < nengine; i++) {
 		execbuf.flags &= ~ENGINE_MASK;
@@ -179,7 +178,7 @@ __igt_spin_batch_new(int fd, igt_spin_opt_t opts)
 	spin = calloc(1, sizeof(struct igt_spin));
 	igt_assert(spin);
 
-	emit_recursive_batch(spin, fd, opts.ctx, opts.engine, opts.dep);
+	emit_recursive_batch(spin, fd, opts);
 	igt_assert(gem_bo_busy(fd, spin->handle));
 
 	igt_list_add(&spin->link, &spin_list);
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 4a8f541f..86a261cb 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -250,10 +250,11 @@ static bool has_ctx_exec(int fd, unsigned ring, uint32_t ctx)
 /**
  * igt_hang_ring_ctx:
  * @fd: open i915 drm file descriptor
- * @ctx: the contxt specifier
- * @ring: execbuf ring flag
- * @flags: set of flags to control execution
- * @offset: The resultant gtt offset of the exec obj
+ * @opts: struct wrapping paramters used in this function:
+ *		- ctx: the context specifier
+ *		- ring: execbuf ring flag
+ *		- flags: set of flags to control execution
+ *		- offset: The resultant gtt offset of the exec obj
  *
  * This helper function injects a hanging batch associated with @ctx into @ring.
  * It returns a #igt_hang_t structure which must be passed to
@@ -263,11 +264,7 @@ static bool has_ctx_exec(int fd, unsigned ring, uint32_t ctx)
  * Returns:
  * Structure with helper internal state for igt_post_hang_ring().
  */
-igt_hang_t igt_hang_ctx(int fd,
-			uint32_t ctx,
-			int ring,
-			unsigned flags,
-			uint64_t *offset)
+igt_hang_t igt_hang_ctx(int fd, igt_hang_opt_t opts)
 {
 	struct drm_i915_gem_relocation_entry reloc;
 	struct drm_i915_gem_execbuffer2 execbuf;
@@ -277,15 +274,15 @@ igt_hang_t igt_hang_ctx(int fd,
 	unsigned ban;
 	unsigned len;
 
-	igt_require_hang_ring(fd, ring);
+	igt_require_hang_ring(fd, opts.ring);
 
 	/* check if non-default ctx submission is allowed */
-	igt_require(ctx == 0 || has_ctx_exec(fd, ring, ctx));
+	igt_require(opts.ctx == 0 || has_ctx_exec(fd, opts.ring, opts.ctx));
 
-	param.ctx_id = ctx;
+	param.ctx_id = opts.ctx;
 	param.size = 0;
 
-	if ((flags & HANG_ALLOW_CAPTURE) == 0) {
+	if ((opts.flags & HANG_ALLOW_CAPTURE) == 0) {
 		param.param = I915_CONTEXT_PARAM_NO_ERROR_CAPTURE;
 		param.value = 1;
 		/* Older kernels may not have NO_ERROR_CAPTURE, in which case
@@ -295,10 +292,10 @@ igt_hang_t igt_hang_ctx(int fd,
 		__gem_context_set_param(fd, &param);
 	}
 
-	ban = context_get_ban(fd, ctx);
+	ban = context_get_ban(fd, opts.ctx);
 
-	if ((flags & HANG_ALLOW_BAN) == 0)
-		context_set_ban(fd, ctx, 0);
+	if ((opts.flags & HANG_ALLOW_BAN) == 0)
+		context_set_ban(fd, opts.ctx, 0);
 
 	memset(&reloc, 0, sizeof(reloc));
 	memset(&exec, 0, sizeof(exec));
@@ -324,14 +321,14 @@ igt_hang_t igt_hang_ctx(int fd,
 
 	execbuf.buffers_ptr = to_user_pointer(&exec);
 	execbuf.buffer_count = 1;
-	execbuf.flags = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
+	execbuf.flags = opts.ring;
+	i915_execbuffer2_set_context_id(execbuf, opts.ctx);
 	gem_execbuf(fd, &execbuf);
 
-	if (offset)
-		*offset = exec.offset;
+	if (opts.offset)
+		*opts.offset = exec.offset;
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ exec.handle, opts.ctx, ban, opts.flags };
 }
 
 /**
@@ -348,7 +345,7 @@ igt_hang_t igt_hang_ctx(int fd,
  */
 igt_hang_t igt_hang_ring(int fd, int ring)
 {
-	return igt_hang_ctx(fd, 0, ring, 0, NULL);
+	return igt_hang_ctx(fd, (igt_hang_opt_t){.ring = ring});
 }
 
 /**
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index 48ed48af..55de04d5 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -36,16 +36,20 @@ typedef struct igt_hang {
 	unsigned flags;
 } igt_hang_t;
 
+typedef struct igt_hang_opt {
+	uint32_t ctx;
+	int ring;
+	unsigned flags;
+	uint64_t *offset;
+} igt_hang_opt_t;
+
 igt_hang_t igt_allow_hang(int fd, unsigned ctx, unsigned flags);
 void igt_disallow_hang(int fd, igt_hang_t arg);
 
 #define HANG_POISON 0xc5c5c5c5
 
-igt_hang_t igt_hang_ctx(int fd,
-			uint32_t ctx,
-			int ring,
-			unsigned flags,
-			uint64_t *offset);
+igt_hang_t igt_hang_ctx(int fd, igt_hang_opt_t opts);
+
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
 
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index 40c82257..4cd2420a 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -187,7 +187,10 @@ static void test_error_state_capture(unsigned ring_id,
 
 	clear_error_state();
 
-	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE, &offset);
+	hang = igt_hang_ctx(device, (igt_hang_opt_t){
+										.ring = ring_id,
+										.flags = HANG_ALLOW_CAPTURE,
+										.offset = &offset});
 	batch = gem_mmap__cpu(device, hang.handle, 0, 4096, PROT_READ);
 	gem_set_domain(device, hang.handle, I915_GEM_DOMAIN_CPU, 0);
 	igt_post_hang_ring(device, hang);
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index edc40767..83e79626 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -161,7 +161,10 @@ static void inject_hang(int fd, uint32_t ctx,
 
 	clock_gettime(CLOCK_MONOTONIC, &ts_injected);
 
-	hang = igt_hang_ctx(fd, ctx, e->exec_id | e->flags, flags & BAN, NULL);
+	hang = igt_hang_ctx(fd, (igt_hang_opt_t){
+									.ctx = ctx,
+									.ring = e->exec_id | e->flags,
+									.flags = flags & BAN});
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -543,7 +546,7 @@ static void test_close_pending_fork(const struct intel_execution_engine *e,
 
 	assert_reset_status(fd, fd, 0, RS_NO_ERROR);
 
-	hang = igt_hang_ctx(fd, 0, e->exec_id | e->flags, 0, NULL);
+	hang = igt_hang_ctx(fd, (igt_hang_opt_t){.ring = e->exec_id | e->flags});
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index 99388599..f03f2c6f 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -359,7 +359,7 @@ static void test_evict_hang(int fd)
 	execbuf.buffers_ptr = to_user_pointer(&object);
 	execbuf.buffer_count = 1;
 
-	hang = igt_hang_ctx(fd, 0, 0, 0, (uint64_t *)&expected);
+	hang = igt_hang_ctx(fd, (igt_hang_opt_t){.offset = (uint64_t *)&expected});
 	object.offset = expected;
 	object.flags = EXEC_OBJECT_PINNED;
 
-- 
2.14.2



More information about the Intel-gfx mailing list