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 <ch...@chris-wilson.co.uk>
Signed-off-by: Antonio Argenziano <antonio.argenzi...@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(-)

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);
 
-- 
2.14.2

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

Reply via email to