[RFC,i-g-t,3/5] lib/igt_hang_ctx: Use dummyload batch to hang ctx.
diff mbox

Message ID 20171206230346.30767-3-antonio.argenziano@intel.com
State New
Headers show

Commit Message

Antonio Argenziano Dec. 6, 2017, 11:03 p.m. UTC
To hang a context we were effectively reimplementing a spinning batch
and never stopping it. This patch reuses the recursive batch from
igt_dummyload to hang a context.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
---
 lib/igt_dummyload.c |  4 +++-
 lib/igt_dummyload.h |  2 ++
 lib/igt_gt.c        | 38 ++++----------------------------------
 lib/igt_gt.h        |  1 +
 4 files changed, 10 insertions(+), 35 deletions(-)

Comments

Chris Wilson Dec. 7, 2017, 11:05 a.m. UTC | #1
Quoting Antonio Argenziano (2017-12-06 23:03:44)
> To hang a context we were effectively reimplementing a spinning batch
> and never stopping it. This patch reuses the recursive batch from
> igt_dummyload to hang a context.
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> ---
>  #define SCRATCH 0
> @@ -168,6 +168,8 @@ static void emit_recursive_batch(igt_spin_t *spin,
>                 execbuf.flags = engines[i];
>                 gem_execbuf(fd, &execbuf);
>         }
> +
> +       spin->spinning_offset = obj->offset;

s/spinning_offset/gtt_offset;

spin->gtt_offset = obj[BATCH].offset;

which should fix up the CI failures.
-Chris
Antonio Argenziano Dec. 7, 2017, 10:03 p.m. UTC | #2
On 07/12/17 03:05, Chris Wilson wrote:
> Quoting Antonio Argenziano (2017-12-06 23:03:44)
>> To hang a context we were effectively reimplementing a spinning batch
>> and never stopping it. This patch reuses the recursive batch from
>> igt_dummyload to hang a context.
>>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
>> ---
>>   #define SCRATCH 0
>> @@ -168,6 +168,8 @@ static void emit_recursive_batch(igt_spin_t *spin,
>>                  execbuf.flags = engines[i];
>>                  gem_execbuf(fd, &execbuf);
>>          }
>> +
>> +       spin->spinning_offset = obj->offset;
> 
> s/spinning_offset/gtt_offset;
> > spin->gtt_offset = obj[BATCH].offset;

Ops, thanks for catching this.

-Antonio

> 
> which should fix up the CI failures.
> -Chris
>

Patch
diff mbox

diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index fee311f7..0bb02e5b 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -69,7 +69,7 @@  fill_reloc(struct drm_i915_gem_relocation_entry *reloc,
 	reloc->write_domain = write_domains;
 }
 
-static void emit_recursive_batch(igt_spin_t *spin,
+void emit_recursive_batch(igt_spin_t *spin,
 				 int fd, igt_spin_opt_t opts)
 {
 #define SCRATCH 0
@@ -168,6 +168,8 @@  static void emit_recursive_batch(igt_spin_t *spin,
 		execbuf.flags = engines[i];
 		gem_execbuf(fd, &execbuf);
 	}
+
+	spin->spinning_offset = obj->offset;
 }
 
 igt_spin_t *
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 76ccd37a..2f3f2ebf 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -35,6 +35,7 @@  typedef struct igt_spin {
 	timer_t timer;
 	struct igt_list link;
 	uint32_t *batch;
+	uint64_t spinning_offset;
 } igt_spin_t;
 
 typedef struct igt_spin_opt {
@@ -43,6 +44,7 @@  typedef struct igt_spin_opt {
 	uint32_t dep;
 } igt_spin_opt_t;
 
+void emit_recursive_batch(igt_spin_t *spin, int fd, igt_spin_opt_t opts);
 igt_spin_t *__igt_spin_batch_new(int fd, igt_spin_opt_t opts);
 igt_spin_t *igt_spin_batch_new(int fd, igt_spin_opt_t opts);
 void igt_spin_batch_set_timeout(igt_spin_t *spin, int64_t ns);
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index c9a2b508..9ec3b0f6 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -266,13 +266,9 @@  static bool has_ctx_exec(int fd, unsigned ring, uint32_t ctx)
  */
 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;
-	struct drm_i915_gem_exec_object2 exec;
 	struct drm_i915_gem_context_param param;
-	uint32_t b[16];
 	unsigned ban;
-	unsigned len;
+	igt_spin_t spin;
 
 	igt_require_hang_ring(fd, opts.ring);
 
@@ -297,38 +293,12 @@  igt_hang_t igt_hang_ctx(int fd, igt_hang_opt_t opts)
 	if ((opts.flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, opts.ctx, 0);
 
-	memset(&reloc, 0, sizeof(reloc));
-	memset(&exec, 0, sizeof(exec));
-	memset(&execbuf, 0, sizeof(execbuf));
-
-	exec.handle = gem_create(fd, 4096);
-	exec.relocation_count = 1;
-	exec.relocs_ptr = to_user_pointer(&reloc);
-
-	memset(b, 0xc5, sizeof(b));
-
-	len = 2;
-	if (intel_gen(intel_get_drm_devid(fd)) >= 8)
-		len++;
-	b[0] = MI_BATCH_BUFFER_START | (len - 2);
-	b[len] = MI_BATCH_BUFFER_END;
-	b[len+1] = MI_NOOP;
-	gem_write(fd, exec.handle, 0, b, sizeof(b));
-
-	reloc.offset = sizeof(uint32_t);
-	reloc.target_handle = exec.handle;
-	reloc.read_domains = I915_GEM_DOMAIN_COMMAND;
-
-	execbuf.buffers_ptr = to_user_pointer(&exec);
-	execbuf.buffer_count = 1;
-	execbuf.flags = opts.ring;
-	i915_execbuffer2_set_context_id(execbuf, opts.ctx);
-	gem_execbuf(fd, &execbuf);
+	emit_recursive_batch(&spin, fd, (igt_spin_opt_t){opts.ctx, opts.ring, 0});
 
 	if (opts.offset)
-		*opts.offset = exec.offset;
+		*opts.offset = spin.spinning_offset;
 
-	return (igt_hang_t){ exec.handle, opts.ctx, ban, opts.flags };
+	return (igt_hang_t){ spin.handle, opts.ctx, ban, opts.flags };
 }
 
 /**
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index 55de04d5..3f3e2d96 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -26,6 +26,7 @@ 
 
 #include "igt_debugfs.h"
 #include "igt_core.h"
+#include "igt_dummyload.h"
 
 void igt_require_hang_ring(int fd, int ring);