All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
@ 2018-07-13  9:46 ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13  9:46 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

From: Antonio Argenziano <antonio.argenziano@intel.com>

An hanging batch is nothing more than a spinning batch that never gets
stopped, so re-use the routines implemented in dummyload.c.

v2:
	- Let caller decide spin loop size
	- Now builds with meson.
v3:
	- Only use loose loops for hangs (Chris)
v4:
	- No requires
v5:
	- Free the spinner

Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_ring.c        |   1 +
 lib/igt_aux.h              | 105 ------------------------------
 lib/igt_core.h             |   4 ++
 lib/igt_dummyload.h        |   3 +-
 lib/igt_gt.c               |  72 ++++-----------------
 lib/igt_gt.h               |   9 +--
 lib/igt_kmod.c             |   3 +-
 lib/igt_kmod.h             |   2 +-
 lib/igt_list.h             | 128 +++++++++++++++++++++++++++++++++++++
 tests/drv_hangman.c        |   9 ++-
 tests/gem_concurrent_all.c |  23 ++-----
 tests/gem_exec_schedule.c  |   4 +-
 tests/gem_mmap_gtt.c       |   2 +-
 tests/gem_reset_stats.c    |   4 +-
 tests/gem_shrink.c         |   2 +-
 tests/gem_softpin.c        |   7 +-
 16 files changed, 175 insertions(+), 203 deletions(-)
 create mode 100644 lib/igt_list.h

diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
index 0708c8a2e..fdb9fc1b1 100644
--- a/lib/i915/gem_ring.c
+++ b/lib/i915/gem_ring.c
@@ -25,6 +25,7 @@
 
 #include <signal.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
 
 #include "intel_reg.h"
 #include "drmtest.h"
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 9a962881b..639a90778 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -31,7 +31,6 @@
 #include <intel_bufmgr.h>
 #include <inttypes.h>
 #include <stdbool.h>
-#include <stddef.h>
 #include <sys/time.h>
 
 #include <i915/gem_submission.h>
@@ -39,12 +38,6 @@
 extern drm_intel_bo **trash_bos;
 extern int num_trash_bos;
 
-/* signal interrupt helpers */
-
-#define MSEC_PER_SEC (1000)
-#define USEC_PER_SEC (1000*MSEC_PER_SEC)
-#define NSEC_PER_SEC (1000*USEC_PER_SEC)
-
 /* signal interrupt helpers */
 #define gettid() syscall(__NR_gettid)
 #define sigev_notify_thread_id _sigev_un._tid
@@ -295,104 +288,6 @@ void igt_set_module_param_int(const char *name, int val);
 int igt_terminate_process(int sig, const char *comm);
 void igt_lsof(const char *dpath);
 
-/*
- * This list data structure is a verbatim copy from wayland-util.h from the
- * Wayland project; except that wl_ prefix has been removed.
- */
-
-struct igt_list {
-	struct igt_list *prev;
-	struct igt_list *next;
-};
-
-#define __IGT_INIT_LIST(name) { &(name), &(name) }
-#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
-
-static inline void igt_list_init(struct igt_list *list)
-{
-	list->prev = list;
-	list->next = list;
-}
-
-static inline void __igt_list_add(struct igt_list *list,
-				  struct igt_list *prev,
-				  struct igt_list *next)
-{
-	next->prev = list;
-	list->next = next;
-	list->prev = prev;
-	prev->next = list;
-}
-
-static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
-{
-	__igt_list_add(elm, list, list->next);
-}
-
-static inline void igt_list_add_tail(struct igt_list *elm,
-				     struct igt_list *list)
-{
-	__igt_list_add(elm, list->prev, list);
-}
-
-static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void igt_list_del(struct igt_list *elm)
-{
-	__igt_list_del(elm->prev, elm->next);
-}
-
-static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add(elm, list);
-}
-
-static inline void igt_list_move_tail(struct igt_list *elm,
-				      struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add_tail(elm, list);
-}
-
-static inline bool igt_list_empty(const struct igt_list *list)
-{
-	return list->next == list;
-}
-
-#define container_of(ptr, sample, member)				\
-	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
-
-#define igt_list_first_entry(head, pos, member) \
-	container_of((head)->next, (pos), member)
-#define igt_list_last_entry(head, pos, member) \
-	container_of((head)->prev, (pos), member)
-
-#define igt_list_next_entry(pos, member) \
-	container_of((pos)->member.next, (pos), member)
-#define igt_list_prev_entry(pos, member) \
-	container_of((pos)->member.prev, (pos), member)
-
-#define igt_list_for_each(pos, head, member)				\
-	for (pos = igt_list_first_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_next_entry(pos, member))
-
-#define igt_list_for_each_reverse(pos, head, member)			\
-	for (pos = igt_list_last_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_prev_entry(pos, member))
-
-#define igt_list_for_each_safe(pos, tmp, head, member)			\
-	for (pos = igt_list_first_entry(head, pos, member),		\
-	     tmp = igt_list_next_entry(pos, member);			\
-	     &pos->member != (head);					\
-	     pos = tmp, tmp = igt_list_next_entry(pos, member))
-
 #define igt_hweight(x) \
 	__builtin_choose_expr(sizeof(x) == 8, \
 			      __builtin_popcountll(x), \
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a73b06493..aaf1b6268 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1005,4 +1005,8 @@ void igt_kmsg(const char *format, ...);
 
 #define READ_ONCE(x) (*(volatile typeof(x) *)(&(x)))
 
+#define MSEC_PER_SEC (1000)
+#define USEC_PER_SEC (1000*MSEC_PER_SEC)
+#define NSEC_PER_SEC (1000*USEC_PER_SEC)
+
 #endif /* IGT_CORE_H */
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 38bc7682e..73bd035b4 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -28,7 +28,8 @@
 #include <stdint.h>
 #include <time.h>
 
-#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_list.h"
 #include "i915_drm.h"
 
 typedef struct igt_spin {
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 89b318ae6..a20619246 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -40,6 +40,7 @@
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
+#include "igt_dummyload.h"
 
 /**
  * SECTION:igt_gt
@@ -265,20 +266,11 @@ 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, uint32_t ctx, int ring, unsigned flags)
 {
-	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];
+	igt_spin_t *spin;
 	unsigned ban;
-	unsigned len;
-	int gen;
 
 	igt_require_hang_ring(fd, ring);
 
@@ -302,52 +294,12 @@ igt_hang_t igt_hang_ctx(int fd,
 	if ((flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, 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 = 0;
-	gen = intel_gen(intel_get_drm_devid(fd));
-	if (gen >= 8) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1;
-		b[len++] = 0;
-		b[len++] = 0;
-	} else if (gen >= 6) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8;
-		b[len++] = 0;
-	} else {
-		b[len++] = MI_BATCH_BUFFER_START | 2 << 6;
-		b[len] = 0;
-		if (gen < 4) {
-			b[len] |= 1;
-			reloc.delta = 1;
-		}
-		len++;
-	}
-	b[len++] = MI_BATCH_BUFFER_END;
-	b[len] = 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 = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
-	gem_execbuf(fd, &execbuf);
-
-	if (offset)
-		*offset = exec.offset;
+	spin = __igt_spin_batch_new(fd,
+				    .ctx = ctx,
+				    .engine = ring,
+				    .flags = IGT_SPIN_NO_PREEMPTION);
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ spin, ctx, ban, flags };
 }
 
 /**
@@ -364,7 +316,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, 0, ring, 0);
 }
 
 /**
@@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
  */
 void igt_post_hang_ring(int fd, igt_hang_t arg)
 {
-	if (arg.handle == 0)
+	if (!arg.spin)
 		return;
 
-	gem_sync(fd, arg.handle);
-	gem_close(fd, arg.handle);
+	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
+	igt_spin_batch_free(fd, arg.spin);
 
 	context_set_ban(fd, arg.ctx, arg.ban);
 
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d44b7552f..54e95da98 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -25,6 +25,7 @@
 #define IGT_GT_H
 
 #include "igt_debugfs.h"
+#include "igt_dummyload.h"
 #include "igt_core.h"
 
 #include "i915_drm.h"
@@ -32,7 +33,7 @@
 void igt_require_hang_ring(int fd, int ring);
 
 typedef struct igt_hang {
-	unsigned handle;
+	igt_spin_t *spin;
 	unsigned ctx;
 	unsigned ban;
 	unsigned flags;
@@ -43,11 +44,7 @@ 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, uint32_t ctx, int ring, unsigned flags);
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
 
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index f3f34a62d..b2f4f884b 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -24,9 +24,10 @@
 #include <signal.h>
 #include <errno.h>
 
+#include "igt_aux.h"
 #include "igt_core.h"
-#include "igt_sysfs.h"
 #include "igt_kmod.h"
+#include "igt_sysfs.h"
 
 /**
  * SECTION:igt_kmod
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index fd307a456..87d36d400 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -26,7 +26,7 @@
 
 #include <libkmod.h>
 
-#include "igt_aux.h"
+#include "igt_list.h"
 
 bool igt_kmod_is_loaded(const char *mod_name);
 void igt_kmod_list_loaded(void);
diff --git a/lib/igt_list.h b/lib/igt_list.h
new file mode 100644
index 000000000..744f4ecf9
--- /dev/null
+++ b/lib/igt_list.h
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef IGT_LIST_H
+#define IGT_LIST_H
+
+#include <stddef.h>
+
+/*
+ * This list data structure is a verbatim copy from wayland-util.h from the
+ * Wayland project; except that wl_ prefix has been removed.
+ */
+
+struct igt_list {
+	struct igt_list *prev;
+	struct igt_list *next;
+};
+
+#define __IGT_INIT_LIST(name) { &(name), &(name) }
+#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
+
+static inline void igt_list_init(struct igt_list *list)
+{
+	list->prev = list;
+	list->next = list;
+}
+
+static inline void __igt_list_add(struct igt_list *list,
+				  struct igt_list *prev,
+				  struct igt_list *next)
+{
+	next->prev = list;
+	list->next = next;
+	list->prev = prev;
+	prev->next = list;
+}
+
+static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
+{
+	__igt_list_add(elm, list, list->next);
+}
+
+static inline void igt_list_add_tail(struct igt_list *elm,
+				     struct igt_list *list)
+{
+	__igt_list_add(elm, list->prev, list);
+}
+
+static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static inline void igt_list_del(struct igt_list *elm)
+{
+	__igt_list_del(elm->prev, elm->next);
+}
+
+static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add(elm, list);
+}
+
+static inline void igt_list_move_tail(struct igt_list *elm,
+				      struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add_tail(elm, list);
+}
+
+static inline bool igt_list_empty(const struct igt_list *list)
+{
+	return list->next == list;
+}
+
+#define container_of(ptr, sample, member)				\
+	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
+
+#define igt_list_first_entry(head, pos, member) \
+	container_of((head)->next, (pos), member)
+#define igt_list_last_entry(head, pos, member) \
+	container_of((head)->prev, (pos), member)
+
+#define igt_list_next_entry(pos, member) \
+	container_of((pos)->member.next, (pos), member)
+#define igt_list_prev_entry(pos, member) \
+	container_of((pos)->member.prev, (pos), member)
+
+#define igt_list_for_each(pos, head, member)				\
+	for (pos = igt_list_first_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_next_entry(pos, member))
+
+#define igt_list_for_each_reverse(pos, head, member)			\
+	for (pos = igt_list_last_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_prev_entry(pos, member))
+
+#define igt_list_for_each_safe(pos, tmp, head, member)			\
+	for (pos = igt_list_first_entry(head, pos, member),		\
+	     tmp = igt_list_next_entry(pos, member);			\
+	     &pos->member != (head);					\
+	     pos = tmp, tmp = igt_list_next_entry(pos, member))
+
+#endif /* IGT_LIST_H */
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index 1736d2a64..6ddae4912 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -199,9 +199,12 @@ static void test_error_state_capture(unsigned ring_id,
 
 	clear_error_state();
 
-	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE, &offset);
-	batch = gem_mmap__cpu(device, hang.handle, 0, 4096, PROT_READ);
-	gem_set_domain(device, hang.handle, I915_GEM_DOMAIN_CPU, 0);
+	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE);
+	offset = hang.spin->obj[1].offset;
+
+	batch = gem_mmap__cpu(device, hang.spin->handle, 0, 4096, PROT_READ);
+	gem_set_domain(device, hang.spin->handle, I915_GEM_DOMAIN_CPU, 0);
+
 	igt_post_hang_ring(device, hang);
 
 	check_error_state(ring_name, offset, batch);
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 3a1097ba5..4ac08c1b1 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -946,30 +946,19 @@ static igt_hang_t rcs_hang(void)
 
 static igt_hang_t all_hang(void)
 {
-	uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 obj;
-	igt_hang_t hang;
+	igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
 	unsigned engine;
 
-	memset(&obj, 0, sizeof(obj));
-	obj.handle = gem_create(fd, 4096);
-	gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe));
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj);
-	execbuf.buffer_count = 1;
-
 	for_each_physical_engine(fd, engine) {
-		hang = igt_hang_ring(fd, engine);
+		struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf;
 
-		execbuf.flags = engine;
-		__gem_execbuf(fd, &execbuf);
+		if (engine == I915_EXEC_RENDER)
+			continue;
 
-		gem_close(fd, hang.handle);
+		eb.flags = engine;
+		__gem_execbuf(fd, &eb);
 	}
 
-	hang.handle = obj.handle;
 	return hang;
 }
 
diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c
index 35a44ab10..43ea97e61 100644
--- a/tests/gem_exec_schedule.c
+++ b/tests/gem_exec_schedule.c
@@ -423,7 +423,7 @@ static void preempt(int fd, unsigned ring, unsigned flags)
 	gem_context_set_priority(fd, ctx[HI], MAX_PRIO);
 
 	if (flags & HANG_LP)
-		hang = igt_hang_ctx(fd, ctx[LO], ring, 0, NULL);
+		hang = igt_hang_ctx(fd, ctx[LO], ring, 0);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
 		if (flags & NEW_CTX) {
@@ -730,7 +730,7 @@ static void preemptive_hang(int fd, unsigned ring)
 		gem_context_destroy(fd, ctx[LO]);
 	}
 
-	hang = igt_hang_ctx(fd, ctx[HI], ring, 0, NULL);
+	hang = igt_hang_ctx(fd, ctx[HI], ring, 0);
 	igt_post_hang_ring(fd, hang);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index fd60b8ff8..c8a0bedec 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -399,7 +399,7 @@ test_hang(int fd)
 
 		last_pattern = next_pattern;
 		next_pattern = (next_pattern + 1) % ARRAY_SIZE(patterns);
-	} while (gem_bo_busy(fd, hang.handle));
+	} while (gem_bo_busy(fd, hang.spin->handle));
 
 	igt_post_hang_ring(fd, hang);
 
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 74ba2656a..ac9af23f2 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -164,7 +164,7 @@ 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, ctx, e->exec_id | e->flags, flags & BAN);
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -546,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, 0, e->exec_id | e->flags, 0);
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 929e0426a..c8e05814e 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -208,7 +208,7 @@ static void hang(int fd, uint64_t alloc)
 		gem_execbuf(fd, &execbuf);
 	}
 
-	gem_close(fd, igt_hang_ring(fd, 0).handle);
+	gem_close(fd, igt_hang_ring(fd, 0).spin->handle);
 	for (int i = 0; i <= count; i++)
 		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
 	munmap(obj, obj_size);
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index 23f936237..336008b8e 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -359,11 +359,12 @@ 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);
-	object.offset = expected;
-	object.flags = EXEC_OBJECT_PINNED;
+	hang = igt_hang_ctx(fd, 0, 0, 0);
+	expected = hang.spin->obj[1].offset;
 
 	/* Replace the hung batch with ourselves, forcing an eviction */
+	object.offset = expected;
+	object.flags = EXEC_OBJECT_PINNED;
 	gem_execbuf(fd, &execbuf);
 	igt_assert_eq_u64(object.offset, expected);
 
-- 
2.18.0

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
@ 2018-07-13  9:46 ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13  9:46 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

From: Antonio Argenziano <antonio.argenziano@intel.com>

An hanging batch is nothing more than a spinning batch that never gets
stopped, so re-use the routines implemented in dummyload.c.

v2:
	- Let caller decide spin loop size
	- Now builds with meson.
v3:
	- Only use loose loops for hangs (Chris)
v4:
	- No requires
v5:
	- Free the spinner

Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_ring.c        |   1 +
 lib/igt_aux.h              | 105 ------------------------------
 lib/igt_core.h             |   4 ++
 lib/igt_dummyload.h        |   3 +-
 lib/igt_gt.c               |  72 ++++-----------------
 lib/igt_gt.h               |   9 +--
 lib/igt_kmod.c             |   3 +-
 lib/igt_kmod.h             |   2 +-
 lib/igt_list.h             | 128 +++++++++++++++++++++++++++++++++++++
 tests/drv_hangman.c        |   9 ++-
 tests/gem_concurrent_all.c |  23 ++-----
 tests/gem_exec_schedule.c  |   4 +-
 tests/gem_mmap_gtt.c       |   2 +-
 tests/gem_reset_stats.c    |   4 +-
 tests/gem_shrink.c         |   2 +-
 tests/gem_softpin.c        |   7 +-
 16 files changed, 175 insertions(+), 203 deletions(-)
 create mode 100644 lib/igt_list.h

diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
index 0708c8a2e..fdb9fc1b1 100644
--- a/lib/i915/gem_ring.c
+++ b/lib/i915/gem_ring.c
@@ -25,6 +25,7 @@
 
 #include <signal.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
 
 #include "intel_reg.h"
 #include "drmtest.h"
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 9a962881b..639a90778 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -31,7 +31,6 @@
 #include <intel_bufmgr.h>
 #include <inttypes.h>
 #include <stdbool.h>
-#include <stddef.h>
 #include <sys/time.h>
 
 #include <i915/gem_submission.h>
@@ -39,12 +38,6 @@
 extern drm_intel_bo **trash_bos;
 extern int num_trash_bos;
 
-/* signal interrupt helpers */
-
-#define MSEC_PER_SEC (1000)
-#define USEC_PER_SEC (1000*MSEC_PER_SEC)
-#define NSEC_PER_SEC (1000*USEC_PER_SEC)
-
 /* signal interrupt helpers */
 #define gettid() syscall(__NR_gettid)
 #define sigev_notify_thread_id _sigev_un._tid
@@ -295,104 +288,6 @@ void igt_set_module_param_int(const char *name, int val);
 int igt_terminate_process(int sig, const char *comm);
 void igt_lsof(const char *dpath);
 
-/*
- * This list data structure is a verbatim copy from wayland-util.h from the
- * Wayland project; except that wl_ prefix has been removed.
- */
-
-struct igt_list {
-	struct igt_list *prev;
-	struct igt_list *next;
-};
-
-#define __IGT_INIT_LIST(name) { &(name), &(name) }
-#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
-
-static inline void igt_list_init(struct igt_list *list)
-{
-	list->prev = list;
-	list->next = list;
-}
-
-static inline void __igt_list_add(struct igt_list *list,
-				  struct igt_list *prev,
-				  struct igt_list *next)
-{
-	next->prev = list;
-	list->next = next;
-	list->prev = prev;
-	prev->next = list;
-}
-
-static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
-{
-	__igt_list_add(elm, list, list->next);
-}
-
-static inline void igt_list_add_tail(struct igt_list *elm,
-				     struct igt_list *list)
-{
-	__igt_list_add(elm, list->prev, list);
-}
-
-static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void igt_list_del(struct igt_list *elm)
-{
-	__igt_list_del(elm->prev, elm->next);
-}
-
-static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add(elm, list);
-}
-
-static inline void igt_list_move_tail(struct igt_list *elm,
-				      struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add_tail(elm, list);
-}
-
-static inline bool igt_list_empty(const struct igt_list *list)
-{
-	return list->next == list;
-}
-
-#define container_of(ptr, sample, member)				\
-	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
-
-#define igt_list_first_entry(head, pos, member) \
-	container_of((head)->next, (pos), member)
-#define igt_list_last_entry(head, pos, member) \
-	container_of((head)->prev, (pos), member)
-
-#define igt_list_next_entry(pos, member) \
-	container_of((pos)->member.next, (pos), member)
-#define igt_list_prev_entry(pos, member) \
-	container_of((pos)->member.prev, (pos), member)
-
-#define igt_list_for_each(pos, head, member)				\
-	for (pos = igt_list_first_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_next_entry(pos, member))
-
-#define igt_list_for_each_reverse(pos, head, member)			\
-	for (pos = igt_list_last_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_prev_entry(pos, member))
-
-#define igt_list_for_each_safe(pos, tmp, head, member)			\
-	for (pos = igt_list_first_entry(head, pos, member),		\
-	     tmp = igt_list_next_entry(pos, member);			\
-	     &pos->member != (head);					\
-	     pos = tmp, tmp = igt_list_next_entry(pos, member))
-
 #define igt_hweight(x) \
 	__builtin_choose_expr(sizeof(x) == 8, \
 			      __builtin_popcountll(x), \
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a73b06493..aaf1b6268 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1005,4 +1005,8 @@ void igt_kmsg(const char *format, ...);
 
 #define READ_ONCE(x) (*(volatile typeof(x) *)(&(x)))
 
+#define MSEC_PER_SEC (1000)
+#define USEC_PER_SEC (1000*MSEC_PER_SEC)
+#define NSEC_PER_SEC (1000*USEC_PER_SEC)
+
 #endif /* IGT_CORE_H */
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 38bc7682e..73bd035b4 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -28,7 +28,8 @@
 #include <stdint.h>
 #include <time.h>
 
-#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_list.h"
 #include "i915_drm.h"
 
 typedef struct igt_spin {
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 89b318ae6..a20619246 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -40,6 +40,7 @@
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
+#include "igt_dummyload.h"
 
 /**
  * SECTION:igt_gt
@@ -265,20 +266,11 @@ 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, uint32_t ctx, int ring, unsigned flags)
 {
-	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];
+	igt_spin_t *spin;
 	unsigned ban;
-	unsigned len;
-	int gen;
 
 	igt_require_hang_ring(fd, ring);
 
@@ -302,52 +294,12 @@ igt_hang_t igt_hang_ctx(int fd,
 	if ((flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, 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 = 0;
-	gen = intel_gen(intel_get_drm_devid(fd));
-	if (gen >= 8) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1;
-		b[len++] = 0;
-		b[len++] = 0;
-	} else if (gen >= 6) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8;
-		b[len++] = 0;
-	} else {
-		b[len++] = MI_BATCH_BUFFER_START | 2 << 6;
-		b[len] = 0;
-		if (gen < 4) {
-			b[len] |= 1;
-			reloc.delta = 1;
-		}
-		len++;
-	}
-	b[len++] = MI_BATCH_BUFFER_END;
-	b[len] = 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 = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
-	gem_execbuf(fd, &execbuf);
-
-	if (offset)
-		*offset = exec.offset;
+	spin = __igt_spin_batch_new(fd,
+				    .ctx = ctx,
+				    .engine = ring,
+				    .flags = IGT_SPIN_NO_PREEMPTION);
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ spin, ctx, ban, flags };
 }
 
 /**
@@ -364,7 +316,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, 0, ring, 0);
 }
 
 /**
@@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
  */
 void igt_post_hang_ring(int fd, igt_hang_t arg)
 {
-	if (arg.handle == 0)
+	if (!arg.spin)
 		return;
 
-	gem_sync(fd, arg.handle);
-	gem_close(fd, arg.handle);
+	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
+	igt_spin_batch_free(fd, arg.spin);
 
 	context_set_ban(fd, arg.ctx, arg.ban);
 
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d44b7552f..54e95da98 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -25,6 +25,7 @@
 #define IGT_GT_H
 
 #include "igt_debugfs.h"
+#include "igt_dummyload.h"
 #include "igt_core.h"
 
 #include "i915_drm.h"
@@ -32,7 +33,7 @@
 void igt_require_hang_ring(int fd, int ring);
 
 typedef struct igt_hang {
-	unsigned handle;
+	igt_spin_t *spin;
 	unsigned ctx;
 	unsigned ban;
 	unsigned flags;
@@ -43,11 +44,7 @@ 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, uint32_t ctx, int ring, unsigned flags);
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
 
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index f3f34a62d..b2f4f884b 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -24,9 +24,10 @@
 #include <signal.h>
 #include <errno.h>
 
+#include "igt_aux.h"
 #include "igt_core.h"
-#include "igt_sysfs.h"
 #include "igt_kmod.h"
+#include "igt_sysfs.h"
 
 /**
  * SECTION:igt_kmod
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index fd307a456..87d36d400 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -26,7 +26,7 @@
 
 #include <libkmod.h>
 
-#include "igt_aux.h"
+#include "igt_list.h"
 
 bool igt_kmod_is_loaded(const char *mod_name);
 void igt_kmod_list_loaded(void);
diff --git a/lib/igt_list.h b/lib/igt_list.h
new file mode 100644
index 000000000..744f4ecf9
--- /dev/null
+++ b/lib/igt_list.h
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef IGT_LIST_H
+#define IGT_LIST_H
+
+#include <stddef.h>
+
+/*
+ * This list data structure is a verbatim copy from wayland-util.h from the
+ * Wayland project; except that wl_ prefix has been removed.
+ */
+
+struct igt_list {
+	struct igt_list *prev;
+	struct igt_list *next;
+};
+
+#define __IGT_INIT_LIST(name) { &(name), &(name) }
+#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
+
+static inline void igt_list_init(struct igt_list *list)
+{
+	list->prev = list;
+	list->next = list;
+}
+
+static inline void __igt_list_add(struct igt_list *list,
+				  struct igt_list *prev,
+				  struct igt_list *next)
+{
+	next->prev = list;
+	list->next = next;
+	list->prev = prev;
+	prev->next = list;
+}
+
+static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
+{
+	__igt_list_add(elm, list, list->next);
+}
+
+static inline void igt_list_add_tail(struct igt_list *elm,
+				     struct igt_list *list)
+{
+	__igt_list_add(elm, list->prev, list);
+}
+
+static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static inline void igt_list_del(struct igt_list *elm)
+{
+	__igt_list_del(elm->prev, elm->next);
+}
+
+static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add(elm, list);
+}
+
+static inline void igt_list_move_tail(struct igt_list *elm,
+				      struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add_tail(elm, list);
+}
+
+static inline bool igt_list_empty(const struct igt_list *list)
+{
+	return list->next == list;
+}
+
+#define container_of(ptr, sample, member)				\
+	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
+
+#define igt_list_first_entry(head, pos, member) \
+	container_of((head)->next, (pos), member)
+#define igt_list_last_entry(head, pos, member) \
+	container_of((head)->prev, (pos), member)
+
+#define igt_list_next_entry(pos, member) \
+	container_of((pos)->member.next, (pos), member)
+#define igt_list_prev_entry(pos, member) \
+	container_of((pos)->member.prev, (pos), member)
+
+#define igt_list_for_each(pos, head, member)				\
+	for (pos = igt_list_first_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_next_entry(pos, member))
+
+#define igt_list_for_each_reverse(pos, head, member)			\
+	for (pos = igt_list_last_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_prev_entry(pos, member))
+
+#define igt_list_for_each_safe(pos, tmp, head, member)			\
+	for (pos = igt_list_first_entry(head, pos, member),		\
+	     tmp = igt_list_next_entry(pos, member);			\
+	     &pos->member != (head);					\
+	     pos = tmp, tmp = igt_list_next_entry(pos, member))
+
+#endif /* IGT_LIST_H */
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index 1736d2a64..6ddae4912 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -199,9 +199,12 @@ static void test_error_state_capture(unsigned ring_id,
 
 	clear_error_state();
 
-	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE, &offset);
-	batch = gem_mmap__cpu(device, hang.handle, 0, 4096, PROT_READ);
-	gem_set_domain(device, hang.handle, I915_GEM_DOMAIN_CPU, 0);
+	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE);
+	offset = hang.spin->obj[1].offset;
+
+	batch = gem_mmap__cpu(device, hang.spin->handle, 0, 4096, PROT_READ);
+	gem_set_domain(device, hang.spin->handle, I915_GEM_DOMAIN_CPU, 0);
+
 	igt_post_hang_ring(device, hang);
 
 	check_error_state(ring_name, offset, batch);
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 3a1097ba5..4ac08c1b1 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -946,30 +946,19 @@ static igt_hang_t rcs_hang(void)
 
 static igt_hang_t all_hang(void)
 {
-	uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 obj;
-	igt_hang_t hang;
+	igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
 	unsigned engine;
 
-	memset(&obj, 0, sizeof(obj));
-	obj.handle = gem_create(fd, 4096);
-	gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe));
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj);
-	execbuf.buffer_count = 1;
-
 	for_each_physical_engine(fd, engine) {
-		hang = igt_hang_ring(fd, engine);
+		struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf;
 
-		execbuf.flags = engine;
-		__gem_execbuf(fd, &execbuf);
+		if (engine == I915_EXEC_RENDER)
+			continue;
 
-		gem_close(fd, hang.handle);
+		eb.flags = engine;
+		__gem_execbuf(fd, &eb);
 	}
 
-	hang.handle = obj.handle;
 	return hang;
 }
 
diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c
index 35a44ab10..43ea97e61 100644
--- a/tests/gem_exec_schedule.c
+++ b/tests/gem_exec_schedule.c
@@ -423,7 +423,7 @@ static void preempt(int fd, unsigned ring, unsigned flags)
 	gem_context_set_priority(fd, ctx[HI], MAX_PRIO);
 
 	if (flags & HANG_LP)
-		hang = igt_hang_ctx(fd, ctx[LO], ring, 0, NULL);
+		hang = igt_hang_ctx(fd, ctx[LO], ring, 0);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
 		if (flags & NEW_CTX) {
@@ -730,7 +730,7 @@ static void preemptive_hang(int fd, unsigned ring)
 		gem_context_destroy(fd, ctx[LO]);
 	}
 
-	hang = igt_hang_ctx(fd, ctx[HI], ring, 0, NULL);
+	hang = igt_hang_ctx(fd, ctx[HI], ring, 0);
 	igt_post_hang_ring(fd, hang);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index fd60b8ff8..c8a0bedec 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -399,7 +399,7 @@ test_hang(int fd)
 
 		last_pattern = next_pattern;
 		next_pattern = (next_pattern + 1) % ARRAY_SIZE(patterns);
-	} while (gem_bo_busy(fd, hang.handle));
+	} while (gem_bo_busy(fd, hang.spin->handle));
 
 	igt_post_hang_ring(fd, hang);
 
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 74ba2656a..ac9af23f2 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -164,7 +164,7 @@ 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, ctx, e->exec_id | e->flags, flags & BAN);
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -546,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, 0, e->exec_id | e->flags, 0);
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 929e0426a..c8e05814e 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -208,7 +208,7 @@ static void hang(int fd, uint64_t alloc)
 		gem_execbuf(fd, &execbuf);
 	}
 
-	gem_close(fd, igt_hang_ring(fd, 0).handle);
+	gem_close(fd, igt_hang_ring(fd, 0).spin->handle);
 	for (int i = 0; i <= count; i++)
 		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
 	munmap(obj, obj_size);
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index 23f936237..336008b8e 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -359,11 +359,12 @@ 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);
-	object.offset = expected;
-	object.flags = EXEC_OBJECT_PINNED;
+	hang = igt_hang_ctx(fd, 0, 0, 0);
+	expected = hang.spin->obj[1].offset;
 
 	/* Replace the hung batch with ourselves, forcing an eviction */
+	object.offset = expected;
+	object.flags = EXEC_OBJECT_PINNED;
 	gem_execbuf(fd, &execbuf);
 	igt_assert_eq_u64(object.offset, expected);
 
-- 
2.18.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] ✗ Fi.CI.BAT: failure for lib/gt: Make use of dummyload library to create recursive batch
  2018-07-13  9:46 ` [igt-dev] " Chris Wilson
  (?)
@ 2018-07-13 10:02 ` Patchwork
  -1 siblings, 0 replies; 11+ messages in thread
From: Patchwork @ 2018-07-13 10:02 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

== Series Details ==

Series: lib/gt: Make use of dummyload library to create recursive batch
URL   : https://patchwork.freedesktop.org/series/46462/
State : failure

== Summary ==

IGT patchset build failed on latest successful build
a742ebd9b4908c7eaca8a3d54f86b3d14583b5b5 igt/gem_unfence_active_buffers: Check GEM before use

ninja: Entering directory `build'
[1/531] Generating version.h with a custom command.
[2/528] Linking static target lib/libigt-igt_kms_c.a.
[3/528] Linking static target lib/libigt-igt_fb_c.a.
[4/528] Linking static target lib/libigt-igt_core_c.a.
[5/528] Compiling C object 'lib/igt-igt_chamelium_c@sta/igt_chamelium.c.o'.
FAILED: lib/igt-igt_chamelium_c@sta/igt_chamelium.c.o 
ccache cc  -Ilib/igt-igt_chamelium_c@sta -Ilib -I../lib -I. -I../ -I../include/drm-uapi -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/opt/igt/include -I/opt/igt/include/libdrm -I/usr/include/x86_64-linux-gnu -I/usr/include -I/home/cidrm/kernel_headers/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -D_GNU_SOURCE -include config.h -Wno-unused-parameter -Wno-sign-compare -Wno-missing-field-initializers -Wno-clobbered -Wno-type-limits -Wimplicit-fallthrough=0 -fPIC -pthread '-DIGT_DATADIR="/opt/igt/share/igt-gpu-tools"' '-DIGT_SRCDIR="/home/cidrm/igt-gpu-tools/tests"' '-DIGT_LOG_DOMAIN="igt_chamelium"' -MD -MQ 'lib/igt-igt_chamelium_c@sta/igt_chamelium.c.o' -MF 'lib/igt-igt_chamelium_c@sta/igt_chamelium.c.o.d' -o 'lib/igt-igt_chamelium_c@sta/igt_chamelium.c.o' -c ../lib/igt_chamelium.c
../lib/igt_chamelium.c:84:18: error: field ‘link’ has incomplete type
  struct igt_list link;
                  ^~~~
../lib/igt_chamelium.c: In function ‘chamelium_new_edid’:
../lib/igt_chamelium.c:508:2: warning: implicit declaration of function ‘igt_list_init’; did you mean ‘g_test_init’? [-Wimplicit-function-declaration]
  igt_list_init(&allocated_edid->link);
  ^~~~~~~~~~~~~
  g_test_init
../lib/igt_chamelium.c:511:3: warning: implicit declaration of function ‘igt_list_add’; did you mean ‘g_test_add’? [-Wimplicit-function-declaration]
   igt_list_add(&chamelium->edids->link, &allocated_edid->link);
   ^~~~~~~~~~~~
   g_test_add
../lib/igt_chamelium.c: In function ‘chamelium_deinit’:
../lib/igt_chamelium.c:1623:2: warning: implicit declaration of function ‘igt_list_for_each_safe’; did you mean ‘g_list_foreach’? [-Wimplicit-function-declaration]
  igt_list_for_each_safe(pos, tmp, &chamelium->edids->link, link) {
  ^~~~~~~~~~~~~~~~~~~~~~
  g_list_foreach
../lib/igt_chamelium.c:1623:66: error: expected ‘;’ before ‘{’ token
  igt_list_for_each_safe(pos, tmp, &chamelium->edids->link, link) {
                                                                  ^
At top level:
../lib/igt_chamelium.c:518:13: warning: ‘chamelium_destroy_edid’ defined but not used [-Wunused-function]
 static void chamelium_destroy_edid(struct chamelium *chamelium, int edid_id)
             ^~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
  2018-07-13  9:46 ` [igt-dev] " Chris Wilson
@ 2018-07-13 10:06   ` Chris Wilson
  -1 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13 10:06 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

From: Antonio Argenziano <antonio.argenziano@intel.com>

An hanging batch is nothing more than a spinning batch that never gets
stopped, so re-use the routines implemented in dummyload.c.

v2: Let caller decide spin loop size
v3: Only use loose loops for hangs (Chris)
v4: No requires
v5: Free the spinner
v6: Chamelium exists.

Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_ring.c        |   1 +
 lib/igt_aux.h              | 105 ------------------------------
 lib/igt_chamelium.c        |   3 +-
 lib/igt_core.h             |   4 ++
 lib/igt_dummyload.h        |   3 +-
 lib/igt_gt.c               |  72 ++++-----------------
 lib/igt_gt.h               |   9 +--
 lib/igt_kmod.c             |   3 +-
 lib/igt_kmod.h             |   2 +-
 lib/igt_list.h             | 128 +++++++++++++++++++++++++++++++++++++
 tests/drv_hangman.c        |   9 ++-
 tests/gem_concurrent_all.c |  23 ++-----
 tests/gem_exec_schedule.c  |   4 +-
 tests/gem_mmap_gtt.c       |   2 +-
 tests/gem_reset_stats.c    |   4 +-
 tests/gem_shrink.c         |   2 +-
 tests/gem_softpin.c        |   7 +-
 17 files changed, 177 insertions(+), 204 deletions(-)
 create mode 100644 lib/igt_list.h

diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
index 0708c8a2e..fdb9fc1b1 100644
--- a/lib/i915/gem_ring.c
+++ b/lib/i915/gem_ring.c
@@ -25,6 +25,7 @@
 
 #include <signal.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
 
 #include "intel_reg.h"
 #include "drmtest.h"
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 9a962881b..639a90778 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -31,7 +31,6 @@
 #include <intel_bufmgr.h>
 #include <inttypes.h>
 #include <stdbool.h>
-#include <stddef.h>
 #include <sys/time.h>
 
 #include <i915/gem_submission.h>
@@ -39,12 +38,6 @@
 extern drm_intel_bo **trash_bos;
 extern int num_trash_bos;
 
-/* signal interrupt helpers */
-
-#define MSEC_PER_SEC (1000)
-#define USEC_PER_SEC (1000*MSEC_PER_SEC)
-#define NSEC_PER_SEC (1000*USEC_PER_SEC)
-
 /* signal interrupt helpers */
 #define gettid() syscall(__NR_gettid)
 #define sigev_notify_thread_id _sigev_un._tid
@@ -295,104 +288,6 @@ void igt_set_module_param_int(const char *name, int val);
 int igt_terminate_process(int sig, const char *comm);
 void igt_lsof(const char *dpath);
 
-/*
- * This list data structure is a verbatim copy from wayland-util.h from the
- * Wayland project; except that wl_ prefix has been removed.
- */
-
-struct igt_list {
-	struct igt_list *prev;
-	struct igt_list *next;
-};
-
-#define __IGT_INIT_LIST(name) { &(name), &(name) }
-#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
-
-static inline void igt_list_init(struct igt_list *list)
-{
-	list->prev = list;
-	list->next = list;
-}
-
-static inline void __igt_list_add(struct igt_list *list,
-				  struct igt_list *prev,
-				  struct igt_list *next)
-{
-	next->prev = list;
-	list->next = next;
-	list->prev = prev;
-	prev->next = list;
-}
-
-static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
-{
-	__igt_list_add(elm, list, list->next);
-}
-
-static inline void igt_list_add_tail(struct igt_list *elm,
-				     struct igt_list *list)
-{
-	__igt_list_add(elm, list->prev, list);
-}
-
-static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void igt_list_del(struct igt_list *elm)
-{
-	__igt_list_del(elm->prev, elm->next);
-}
-
-static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add(elm, list);
-}
-
-static inline void igt_list_move_tail(struct igt_list *elm,
-				      struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add_tail(elm, list);
-}
-
-static inline bool igt_list_empty(const struct igt_list *list)
-{
-	return list->next == list;
-}
-
-#define container_of(ptr, sample, member)				\
-	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
-
-#define igt_list_first_entry(head, pos, member) \
-	container_of((head)->next, (pos), member)
-#define igt_list_last_entry(head, pos, member) \
-	container_of((head)->prev, (pos), member)
-
-#define igt_list_next_entry(pos, member) \
-	container_of((pos)->member.next, (pos), member)
-#define igt_list_prev_entry(pos, member) \
-	container_of((pos)->member.prev, (pos), member)
-
-#define igt_list_for_each(pos, head, member)				\
-	for (pos = igt_list_first_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_next_entry(pos, member))
-
-#define igt_list_for_each_reverse(pos, head, member)			\
-	for (pos = igt_list_last_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_prev_entry(pos, member))
-
-#define igt_list_for_each_safe(pos, tmp, head, member)			\
-	for (pos = igt_list_first_entry(head, pos, member),		\
-	     tmp = igt_list_next_entry(pos, member);			\
-	     &pos->member != (head);					\
-	     pos = tmp, tmp = igt_list_next_entry(pos, member))
-
 #define igt_hweight(x) \
 	__builtin_choose_expr(sizeof(x) == 8, \
 			      __builtin_popcountll(x), \
diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index b25855a41..b8418e13e 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -38,8 +38,9 @@
 #include "igt_chamelium.h"
 #include "igt_core.h"
 #include "igt_aux.h"
-#include "igt_kms.h"
 #include "igt_frame.h"
+#include "igt_list.h"
+#include "igt_kms.h"
 #include "igt_rc.h"
 
 /**
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a73b06493..aaf1b6268 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1005,4 +1005,8 @@ void igt_kmsg(const char *format, ...);
 
 #define READ_ONCE(x) (*(volatile typeof(x) *)(&(x)))
 
+#define MSEC_PER_SEC (1000)
+#define USEC_PER_SEC (1000*MSEC_PER_SEC)
+#define NSEC_PER_SEC (1000*USEC_PER_SEC)
+
 #endif /* IGT_CORE_H */
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 38bc7682e..73bd035b4 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -28,7 +28,8 @@
 #include <stdint.h>
 #include <time.h>
 
-#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_list.h"
 #include "i915_drm.h"
 
 typedef struct igt_spin {
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 89b318ae6..a20619246 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -40,6 +40,7 @@
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
+#include "igt_dummyload.h"
 
 /**
  * SECTION:igt_gt
@@ -265,20 +266,11 @@ 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, uint32_t ctx, int ring, unsigned flags)
 {
-	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];
+	igt_spin_t *spin;
 	unsigned ban;
-	unsigned len;
-	int gen;
 
 	igt_require_hang_ring(fd, ring);
 
@@ -302,52 +294,12 @@ igt_hang_t igt_hang_ctx(int fd,
 	if ((flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, 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 = 0;
-	gen = intel_gen(intel_get_drm_devid(fd));
-	if (gen >= 8) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1;
-		b[len++] = 0;
-		b[len++] = 0;
-	} else if (gen >= 6) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8;
-		b[len++] = 0;
-	} else {
-		b[len++] = MI_BATCH_BUFFER_START | 2 << 6;
-		b[len] = 0;
-		if (gen < 4) {
-			b[len] |= 1;
-			reloc.delta = 1;
-		}
-		len++;
-	}
-	b[len++] = MI_BATCH_BUFFER_END;
-	b[len] = 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 = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
-	gem_execbuf(fd, &execbuf);
-
-	if (offset)
-		*offset = exec.offset;
+	spin = __igt_spin_batch_new(fd,
+				    .ctx = ctx,
+				    .engine = ring,
+				    .flags = IGT_SPIN_NO_PREEMPTION);
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ spin, ctx, ban, flags };
 }
 
 /**
@@ -364,7 +316,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, 0, ring, 0);
 }
 
 /**
@@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
  */
 void igt_post_hang_ring(int fd, igt_hang_t arg)
 {
-	if (arg.handle == 0)
+	if (!arg.spin)
 		return;
 
-	gem_sync(fd, arg.handle);
-	gem_close(fd, arg.handle);
+	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
+	igt_spin_batch_free(fd, arg.spin);
 
 	context_set_ban(fd, arg.ctx, arg.ban);
 
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d44b7552f..54e95da98 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -25,6 +25,7 @@
 #define IGT_GT_H
 
 #include "igt_debugfs.h"
+#include "igt_dummyload.h"
 #include "igt_core.h"
 
 #include "i915_drm.h"
@@ -32,7 +33,7 @@
 void igt_require_hang_ring(int fd, int ring);
 
 typedef struct igt_hang {
-	unsigned handle;
+	igt_spin_t *spin;
 	unsigned ctx;
 	unsigned ban;
 	unsigned flags;
@@ -43,11 +44,7 @@ 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, uint32_t ctx, int ring, unsigned flags);
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
 
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index f3f34a62d..b2f4f884b 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -24,9 +24,10 @@
 #include <signal.h>
 #include <errno.h>
 
+#include "igt_aux.h"
 #include "igt_core.h"
-#include "igt_sysfs.h"
 #include "igt_kmod.h"
+#include "igt_sysfs.h"
 
 /**
  * SECTION:igt_kmod
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index fd307a456..87d36d400 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -26,7 +26,7 @@
 
 #include <libkmod.h>
 
-#include "igt_aux.h"
+#include "igt_list.h"
 
 bool igt_kmod_is_loaded(const char *mod_name);
 void igt_kmod_list_loaded(void);
diff --git a/lib/igt_list.h b/lib/igt_list.h
new file mode 100644
index 000000000..744f4ecf9
--- /dev/null
+++ b/lib/igt_list.h
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef IGT_LIST_H
+#define IGT_LIST_H
+
+#include <stddef.h>
+
+/*
+ * This list data structure is a verbatim copy from wayland-util.h from the
+ * Wayland project; except that wl_ prefix has been removed.
+ */
+
+struct igt_list {
+	struct igt_list *prev;
+	struct igt_list *next;
+};
+
+#define __IGT_INIT_LIST(name) { &(name), &(name) }
+#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
+
+static inline void igt_list_init(struct igt_list *list)
+{
+	list->prev = list;
+	list->next = list;
+}
+
+static inline void __igt_list_add(struct igt_list *list,
+				  struct igt_list *prev,
+				  struct igt_list *next)
+{
+	next->prev = list;
+	list->next = next;
+	list->prev = prev;
+	prev->next = list;
+}
+
+static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
+{
+	__igt_list_add(elm, list, list->next);
+}
+
+static inline void igt_list_add_tail(struct igt_list *elm,
+				     struct igt_list *list)
+{
+	__igt_list_add(elm, list->prev, list);
+}
+
+static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static inline void igt_list_del(struct igt_list *elm)
+{
+	__igt_list_del(elm->prev, elm->next);
+}
+
+static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add(elm, list);
+}
+
+static inline void igt_list_move_tail(struct igt_list *elm,
+				      struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add_tail(elm, list);
+}
+
+static inline bool igt_list_empty(const struct igt_list *list)
+{
+	return list->next == list;
+}
+
+#define container_of(ptr, sample, member)				\
+	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
+
+#define igt_list_first_entry(head, pos, member) \
+	container_of((head)->next, (pos), member)
+#define igt_list_last_entry(head, pos, member) \
+	container_of((head)->prev, (pos), member)
+
+#define igt_list_next_entry(pos, member) \
+	container_of((pos)->member.next, (pos), member)
+#define igt_list_prev_entry(pos, member) \
+	container_of((pos)->member.prev, (pos), member)
+
+#define igt_list_for_each(pos, head, member)				\
+	for (pos = igt_list_first_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_next_entry(pos, member))
+
+#define igt_list_for_each_reverse(pos, head, member)			\
+	for (pos = igt_list_last_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_prev_entry(pos, member))
+
+#define igt_list_for_each_safe(pos, tmp, head, member)			\
+	for (pos = igt_list_first_entry(head, pos, member),		\
+	     tmp = igt_list_next_entry(pos, member);			\
+	     &pos->member != (head);					\
+	     pos = tmp, tmp = igt_list_next_entry(pos, member))
+
+#endif /* IGT_LIST_H */
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index 1736d2a64..6ddae4912 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -199,9 +199,12 @@ static void test_error_state_capture(unsigned ring_id,
 
 	clear_error_state();
 
-	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE, &offset);
-	batch = gem_mmap__cpu(device, hang.handle, 0, 4096, PROT_READ);
-	gem_set_domain(device, hang.handle, I915_GEM_DOMAIN_CPU, 0);
+	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE);
+	offset = hang.spin->obj[1].offset;
+
+	batch = gem_mmap__cpu(device, hang.spin->handle, 0, 4096, PROT_READ);
+	gem_set_domain(device, hang.spin->handle, I915_GEM_DOMAIN_CPU, 0);
+
 	igt_post_hang_ring(device, hang);
 
 	check_error_state(ring_name, offset, batch);
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 3a1097ba5..4ac08c1b1 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -946,30 +946,19 @@ static igt_hang_t rcs_hang(void)
 
 static igt_hang_t all_hang(void)
 {
-	uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 obj;
-	igt_hang_t hang;
+	igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
 	unsigned engine;
 
-	memset(&obj, 0, sizeof(obj));
-	obj.handle = gem_create(fd, 4096);
-	gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe));
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj);
-	execbuf.buffer_count = 1;
-
 	for_each_physical_engine(fd, engine) {
-		hang = igt_hang_ring(fd, engine);
+		struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf;
 
-		execbuf.flags = engine;
-		__gem_execbuf(fd, &execbuf);
+		if (engine == I915_EXEC_RENDER)
+			continue;
 
-		gem_close(fd, hang.handle);
+		eb.flags = engine;
+		__gem_execbuf(fd, &eb);
 	}
 
-	hang.handle = obj.handle;
 	return hang;
 }
 
diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c
index 35a44ab10..43ea97e61 100644
--- a/tests/gem_exec_schedule.c
+++ b/tests/gem_exec_schedule.c
@@ -423,7 +423,7 @@ static void preempt(int fd, unsigned ring, unsigned flags)
 	gem_context_set_priority(fd, ctx[HI], MAX_PRIO);
 
 	if (flags & HANG_LP)
-		hang = igt_hang_ctx(fd, ctx[LO], ring, 0, NULL);
+		hang = igt_hang_ctx(fd, ctx[LO], ring, 0);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
 		if (flags & NEW_CTX) {
@@ -730,7 +730,7 @@ static void preemptive_hang(int fd, unsigned ring)
 		gem_context_destroy(fd, ctx[LO]);
 	}
 
-	hang = igt_hang_ctx(fd, ctx[HI], ring, 0, NULL);
+	hang = igt_hang_ctx(fd, ctx[HI], ring, 0);
 	igt_post_hang_ring(fd, hang);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index fd60b8ff8..c8a0bedec 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -399,7 +399,7 @@ test_hang(int fd)
 
 		last_pattern = next_pattern;
 		next_pattern = (next_pattern + 1) % ARRAY_SIZE(patterns);
-	} while (gem_bo_busy(fd, hang.handle));
+	} while (gem_bo_busy(fd, hang.spin->handle));
 
 	igt_post_hang_ring(fd, hang);
 
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 74ba2656a..ac9af23f2 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -164,7 +164,7 @@ 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, ctx, e->exec_id | e->flags, flags & BAN);
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -546,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, 0, e->exec_id | e->flags, 0);
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 929e0426a..c8e05814e 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -208,7 +208,7 @@ static void hang(int fd, uint64_t alloc)
 		gem_execbuf(fd, &execbuf);
 	}
 
-	gem_close(fd, igt_hang_ring(fd, 0).handle);
+	gem_close(fd, igt_hang_ring(fd, 0).spin->handle);
 	for (int i = 0; i <= count; i++)
 		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
 	munmap(obj, obj_size);
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index 23f936237..336008b8e 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -359,11 +359,12 @@ 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);
-	object.offset = expected;
-	object.flags = EXEC_OBJECT_PINNED;
+	hang = igt_hang_ctx(fd, 0, 0, 0);
+	expected = hang.spin->obj[1].offset;
 
 	/* Replace the hung batch with ourselves, forcing an eviction */
+	object.offset = expected;
+	object.flags = EXEC_OBJECT_PINNED;
 	gem_execbuf(fd, &execbuf);
 	igt_assert_eq_u64(object.offset, expected);
 
-- 
2.18.0

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Intel-gfx] [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
@ 2018-07-13 10:06   ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13 10:06 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

From: Antonio Argenziano <antonio.argenziano@intel.com>

An hanging batch is nothing more than a spinning batch that never gets
stopped, so re-use the routines implemented in dummyload.c.

v2: Let caller decide spin loop size
v3: Only use loose loops for hangs (Chris)
v4: No requires
v5: Free the spinner
v6: Chamelium exists.

Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_ring.c        |   1 +
 lib/igt_aux.h              | 105 ------------------------------
 lib/igt_chamelium.c        |   3 +-
 lib/igt_core.h             |   4 ++
 lib/igt_dummyload.h        |   3 +-
 lib/igt_gt.c               |  72 ++++-----------------
 lib/igt_gt.h               |   9 +--
 lib/igt_kmod.c             |   3 +-
 lib/igt_kmod.h             |   2 +-
 lib/igt_list.h             | 128 +++++++++++++++++++++++++++++++++++++
 tests/drv_hangman.c        |   9 ++-
 tests/gem_concurrent_all.c |  23 ++-----
 tests/gem_exec_schedule.c  |   4 +-
 tests/gem_mmap_gtt.c       |   2 +-
 tests/gem_reset_stats.c    |   4 +-
 tests/gem_shrink.c         |   2 +-
 tests/gem_softpin.c        |   7 +-
 17 files changed, 177 insertions(+), 204 deletions(-)
 create mode 100644 lib/igt_list.h

diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c
index 0708c8a2e..fdb9fc1b1 100644
--- a/lib/i915/gem_ring.c
+++ b/lib/i915/gem_ring.c
@@ -25,6 +25,7 @@
 
 #include <signal.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
 
 #include "intel_reg.h"
 #include "drmtest.h"
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 9a962881b..639a90778 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -31,7 +31,6 @@
 #include <intel_bufmgr.h>
 #include <inttypes.h>
 #include <stdbool.h>
-#include <stddef.h>
 #include <sys/time.h>
 
 #include <i915/gem_submission.h>
@@ -39,12 +38,6 @@
 extern drm_intel_bo **trash_bos;
 extern int num_trash_bos;
 
-/* signal interrupt helpers */
-
-#define MSEC_PER_SEC (1000)
-#define USEC_PER_SEC (1000*MSEC_PER_SEC)
-#define NSEC_PER_SEC (1000*USEC_PER_SEC)
-
 /* signal interrupt helpers */
 #define gettid() syscall(__NR_gettid)
 #define sigev_notify_thread_id _sigev_un._tid
@@ -295,104 +288,6 @@ void igt_set_module_param_int(const char *name, int val);
 int igt_terminate_process(int sig, const char *comm);
 void igt_lsof(const char *dpath);
 
-/*
- * This list data structure is a verbatim copy from wayland-util.h from the
- * Wayland project; except that wl_ prefix has been removed.
- */
-
-struct igt_list {
-	struct igt_list *prev;
-	struct igt_list *next;
-};
-
-#define __IGT_INIT_LIST(name) { &(name), &(name) }
-#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
-
-static inline void igt_list_init(struct igt_list *list)
-{
-	list->prev = list;
-	list->next = list;
-}
-
-static inline void __igt_list_add(struct igt_list *list,
-				  struct igt_list *prev,
-				  struct igt_list *next)
-{
-	next->prev = list;
-	list->next = next;
-	list->prev = prev;
-	prev->next = list;
-}
-
-static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
-{
-	__igt_list_add(elm, list, list->next);
-}
-
-static inline void igt_list_add_tail(struct igt_list *elm,
-				     struct igt_list *list)
-{
-	__igt_list_add(elm, list->prev, list);
-}
-
-static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-static inline void igt_list_del(struct igt_list *elm)
-{
-	__igt_list_del(elm->prev, elm->next);
-}
-
-static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add(elm, list);
-}
-
-static inline void igt_list_move_tail(struct igt_list *elm,
-				      struct igt_list *list)
-{
-	igt_list_del(elm);
-	igt_list_add_tail(elm, list);
-}
-
-static inline bool igt_list_empty(const struct igt_list *list)
-{
-	return list->next == list;
-}
-
-#define container_of(ptr, sample, member)				\
-	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
-
-#define igt_list_first_entry(head, pos, member) \
-	container_of((head)->next, (pos), member)
-#define igt_list_last_entry(head, pos, member) \
-	container_of((head)->prev, (pos), member)
-
-#define igt_list_next_entry(pos, member) \
-	container_of((pos)->member.next, (pos), member)
-#define igt_list_prev_entry(pos, member) \
-	container_of((pos)->member.prev, (pos), member)
-
-#define igt_list_for_each(pos, head, member)				\
-	for (pos = igt_list_first_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_next_entry(pos, member))
-
-#define igt_list_for_each_reverse(pos, head, member)			\
-	for (pos = igt_list_last_entry(head, pos, member);		\
-	     &pos->member != (head);					\
-	     pos = igt_list_prev_entry(pos, member))
-
-#define igt_list_for_each_safe(pos, tmp, head, member)			\
-	for (pos = igt_list_first_entry(head, pos, member),		\
-	     tmp = igt_list_next_entry(pos, member);			\
-	     &pos->member != (head);					\
-	     pos = tmp, tmp = igt_list_next_entry(pos, member))
-
 #define igt_hweight(x) \
 	__builtin_choose_expr(sizeof(x) == 8, \
 			      __builtin_popcountll(x), \
diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index b25855a41..b8418e13e 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -38,8 +38,9 @@
 #include "igt_chamelium.h"
 #include "igt_core.h"
 #include "igt_aux.h"
-#include "igt_kms.h"
 #include "igt_frame.h"
+#include "igt_list.h"
+#include "igt_kms.h"
 #include "igt_rc.h"
 
 /**
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a73b06493..aaf1b6268 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1005,4 +1005,8 @@ void igt_kmsg(const char *format, ...);
 
 #define READ_ONCE(x) (*(volatile typeof(x) *)(&(x)))
 
+#define MSEC_PER_SEC (1000)
+#define USEC_PER_SEC (1000*MSEC_PER_SEC)
+#define NSEC_PER_SEC (1000*USEC_PER_SEC)
+
 #endif /* IGT_CORE_H */
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 38bc7682e..73bd035b4 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -28,7 +28,8 @@
 #include <stdint.h>
 #include <time.h>
 
-#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_list.h"
 #include "i915_drm.h"
 
 typedef struct igt_spin {
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 89b318ae6..a20619246 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -40,6 +40,7 @@
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
+#include "igt_dummyload.h"
 
 /**
  * SECTION:igt_gt
@@ -265,20 +266,11 @@ 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, uint32_t ctx, int ring, unsigned flags)
 {
-	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];
+	igt_spin_t *spin;
 	unsigned ban;
-	unsigned len;
-	int gen;
 
 	igt_require_hang_ring(fd, ring);
 
@@ -302,52 +294,12 @@ igt_hang_t igt_hang_ctx(int fd,
 	if ((flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, 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 = 0;
-	gen = intel_gen(intel_get_drm_devid(fd));
-	if (gen >= 8) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1;
-		b[len++] = 0;
-		b[len++] = 0;
-	} else if (gen >= 6) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8;
-		b[len++] = 0;
-	} else {
-		b[len++] = MI_BATCH_BUFFER_START | 2 << 6;
-		b[len] = 0;
-		if (gen < 4) {
-			b[len] |= 1;
-			reloc.delta = 1;
-		}
-		len++;
-	}
-	b[len++] = MI_BATCH_BUFFER_END;
-	b[len] = 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 = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
-	gem_execbuf(fd, &execbuf);
-
-	if (offset)
-		*offset = exec.offset;
+	spin = __igt_spin_batch_new(fd,
+				    .ctx = ctx,
+				    .engine = ring,
+				    .flags = IGT_SPIN_NO_PREEMPTION);
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ spin, ctx, ban, flags };
 }
 
 /**
@@ -364,7 +316,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, 0, ring, 0);
 }
 
 /**
@@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
  */
 void igt_post_hang_ring(int fd, igt_hang_t arg)
 {
-	if (arg.handle == 0)
+	if (!arg.spin)
 		return;
 
-	gem_sync(fd, arg.handle);
-	gem_close(fd, arg.handle);
+	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
+	igt_spin_batch_free(fd, arg.spin);
 
 	context_set_ban(fd, arg.ctx, arg.ban);
 
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d44b7552f..54e95da98 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -25,6 +25,7 @@
 #define IGT_GT_H
 
 #include "igt_debugfs.h"
+#include "igt_dummyload.h"
 #include "igt_core.h"
 
 #include "i915_drm.h"
@@ -32,7 +33,7 @@
 void igt_require_hang_ring(int fd, int ring);
 
 typedef struct igt_hang {
-	unsigned handle;
+	igt_spin_t *spin;
 	unsigned ctx;
 	unsigned ban;
 	unsigned flags;
@@ -43,11 +44,7 @@ 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, uint32_t ctx, int ring, unsigned flags);
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
 
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index f3f34a62d..b2f4f884b 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -24,9 +24,10 @@
 #include <signal.h>
 #include <errno.h>
 
+#include "igt_aux.h"
 #include "igt_core.h"
-#include "igt_sysfs.h"
 #include "igt_kmod.h"
+#include "igt_sysfs.h"
 
 /**
  * SECTION:igt_kmod
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index fd307a456..87d36d400 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -26,7 +26,7 @@
 
 #include <libkmod.h>
 
-#include "igt_aux.h"
+#include "igt_list.h"
 
 bool igt_kmod_is_loaded(const char *mod_name);
 void igt_kmod_list_loaded(void);
diff --git a/lib/igt_list.h b/lib/igt_list.h
new file mode 100644
index 000000000..744f4ecf9
--- /dev/null
+++ b/lib/igt_list.h
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef IGT_LIST_H
+#define IGT_LIST_H
+
+#include <stddef.h>
+
+/*
+ * This list data structure is a verbatim copy from wayland-util.h from the
+ * Wayland project; except that wl_ prefix has been removed.
+ */
+
+struct igt_list {
+	struct igt_list *prev;
+	struct igt_list *next;
+};
+
+#define __IGT_INIT_LIST(name) { &(name), &(name) }
+#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name)
+
+static inline void igt_list_init(struct igt_list *list)
+{
+	list->prev = list;
+	list->next = list;
+}
+
+static inline void __igt_list_add(struct igt_list *list,
+				  struct igt_list *prev,
+				  struct igt_list *next)
+{
+	next->prev = list;
+	list->next = next;
+	list->prev = prev;
+	prev->next = list;
+}
+
+static inline void igt_list_add(struct igt_list *elm, struct igt_list *list)
+{
+	__igt_list_add(elm, list, list->next);
+}
+
+static inline void igt_list_add_tail(struct igt_list *elm,
+				     struct igt_list *list)
+{
+	__igt_list_add(elm, list->prev, list);
+}
+
+static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+static inline void igt_list_del(struct igt_list *elm)
+{
+	__igt_list_del(elm->prev, elm->next);
+}
+
+static inline void igt_list_move(struct igt_list *elm, struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add(elm, list);
+}
+
+static inline void igt_list_move_tail(struct igt_list *elm,
+				      struct igt_list *list)
+{
+	igt_list_del(elm);
+	igt_list_add_tail(elm, list);
+}
+
+static inline bool igt_list_empty(const struct igt_list *list)
+{
+	return list->next == list;
+}
+
+#define container_of(ptr, sample, member)				\
+	(typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member))
+
+#define igt_list_first_entry(head, pos, member) \
+	container_of((head)->next, (pos), member)
+#define igt_list_last_entry(head, pos, member) \
+	container_of((head)->prev, (pos), member)
+
+#define igt_list_next_entry(pos, member) \
+	container_of((pos)->member.next, (pos), member)
+#define igt_list_prev_entry(pos, member) \
+	container_of((pos)->member.prev, (pos), member)
+
+#define igt_list_for_each(pos, head, member)				\
+	for (pos = igt_list_first_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_next_entry(pos, member))
+
+#define igt_list_for_each_reverse(pos, head, member)			\
+	for (pos = igt_list_last_entry(head, pos, member);		\
+	     &pos->member != (head);					\
+	     pos = igt_list_prev_entry(pos, member))
+
+#define igt_list_for_each_safe(pos, tmp, head, member)			\
+	for (pos = igt_list_first_entry(head, pos, member),		\
+	     tmp = igt_list_next_entry(pos, member);			\
+	     &pos->member != (head);					\
+	     pos = tmp, tmp = igt_list_next_entry(pos, member))
+
+#endif /* IGT_LIST_H */
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index 1736d2a64..6ddae4912 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -199,9 +199,12 @@ static void test_error_state_capture(unsigned ring_id,
 
 	clear_error_state();
 
-	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE, &offset);
-	batch = gem_mmap__cpu(device, hang.handle, 0, 4096, PROT_READ);
-	gem_set_domain(device, hang.handle, I915_GEM_DOMAIN_CPU, 0);
+	hang = igt_hang_ctx(device, 0, ring_id, HANG_ALLOW_CAPTURE);
+	offset = hang.spin->obj[1].offset;
+
+	batch = gem_mmap__cpu(device, hang.spin->handle, 0, 4096, PROT_READ);
+	gem_set_domain(device, hang.spin->handle, I915_GEM_DOMAIN_CPU, 0);
+
 	igt_post_hang_ring(device, hang);
 
 	check_error_state(ring_name, offset, batch);
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 3a1097ba5..4ac08c1b1 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -946,30 +946,19 @@ static igt_hang_t rcs_hang(void)
 
 static igt_hang_t all_hang(void)
 {
-	uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 obj;
-	igt_hang_t hang;
+	igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
 	unsigned engine;
 
-	memset(&obj, 0, sizeof(obj));
-	obj.handle = gem_create(fd, 4096);
-	gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe));
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj);
-	execbuf.buffer_count = 1;
-
 	for_each_physical_engine(fd, engine) {
-		hang = igt_hang_ring(fd, engine);
+		struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf;
 
-		execbuf.flags = engine;
-		__gem_execbuf(fd, &execbuf);
+		if (engine == I915_EXEC_RENDER)
+			continue;
 
-		gem_close(fd, hang.handle);
+		eb.flags = engine;
+		__gem_execbuf(fd, &eb);
 	}
 
-	hang.handle = obj.handle;
 	return hang;
 }
 
diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c
index 35a44ab10..43ea97e61 100644
--- a/tests/gem_exec_schedule.c
+++ b/tests/gem_exec_schedule.c
@@ -423,7 +423,7 @@ static void preempt(int fd, unsigned ring, unsigned flags)
 	gem_context_set_priority(fd, ctx[HI], MAX_PRIO);
 
 	if (flags & HANG_LP)
-		hang = igt_hang_ctx(fd, ctx[LO], ring, 0, NULL);
+		hang = igt_hang_ctx(fd, ctx[LO], ring, 0);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
 		if (flags & NEW_CTX) {
@@ -730,7 +730,7 @@ static void preemptive_hang(int fd, unsigned ring)
 		gem_context_destroy(fd, ctx[LO]);
 	}
 
-	hang = igt_hang_ctx(fd, ctx[HI], ring, 0, NULL);
+	hang = igt_hang_ctx(fd, ctx[HI], ring, 0);
 	igt_post_hang_ring(fd, hang);
 
 	for (int n = 0; n < ARRAY_SIZE(spin); n++) {
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index fd60b8ff8..c8a0bedec 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -399,7 +399,7 @@ test_hang(int fd)
 
 		last_pattern = next_pattern;
 		next_pattern = (next_pattern + 1) % ARRAY_SIZE(patterns);
-	} while (gem_bo_busy(fd, hang.handle));
+	} while (gem_bo_busy(fd, hang.spin->handle));
 
 	igt_post_hang_ring(fd, hang);
 
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 74ba2656a..ac9af23f2 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -164,7 +164,7 @@ 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, ctx, e->exec_id | e->flags, flags & BAN);
 	if ((flags & ASYNC) == 0)
 		igt_post_hang_ring(fd, hang);
 }
@@ -546,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, 0, e->exec_id | e->flags, 0);
 	sleep(1);
 
 	/* Avoid helpers as we need to kill the child
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 929e0426a..c8e05814e 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -208,7 +208,7 @@ static void hang(int fd, uint64_t alloc)
 		gem_execbuf(fd, &execbuf);
 	}
 
-	gem_close(fd, igt_hang_ring(fd, 0).handle);
+	gem_close(fd, igt_hang_ring(fd, 0).spin->handle);
 	for (int i = 0; i <= count; i++)
 		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
 	munmap(obj, obj_size);
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index 23f936237..336008b8e 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -359,11 +359,12 @@ 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);
-	object.offset = expected;
-	object.flags = EXEC_OBJECT_PINNED;
+	hang = igt_hang_ctx(fd, 0, 0, 0);
+	expected = hang.spin->obj[1].offset;
 
 	/* Replace the hung batch with ourselves, forcing an eviction */
+	object.offset = expected;
+	object.flags = EXEC_OBJECT_PINNED;
 	gem_execbuf(fd, &execbuf);
 	igt_assert_eq_u64(object.offset, expected);
 
-- 
2.18.0

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [igt-dev] ✓ Fi.CI.BAT: success for lib/gt: Make use of dummyload library to create recursive batch (rev2)
  2018-07-13  9:46 ` [igt-dev] " Chris Wilson
                   ` (2 preceding siblings ...)
  (?)
@ 2018-07-13 12:14 ` Patchwork
  -1 siblings, 0 replies; 11+ messages in thread
From: Patchwork @ 2018-07-13 12:14 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

== Series Details ==

Series: lib/gt: Make use of dummyload library to create recursive batch (rev2)
URL   : https://patchwork.freedesktop.org/series/46462/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4479 -> IGTPW_1578 =

== Summary - SUCCESS ==

  No regressions found.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/46462/revisions/2/mbox/

== Known issues ==

  Here are the changes found in IGTPW_1578 that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
      fi-snb-2600:        PASS -> DMESG-WARN (fdo#102365)

    
    ==== Possible fixes ====

    igt@drv_module_reload@basic-reload:
      fi-ilk-650:         DMESG-WARN (fdo#106387) -> PASS +2

    igt@kms_chamelium@hdmi-hpd-fast:
      fi-kbl-7500u:       FAIL (fdo#103841, fdo#102672) -> SKIP

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
      fi-snb-2520m:       INCOMPLETE (fdo#103713) -> PASS

    
  fdo#102365 https://bugs.freedesktop.org/show_bug.cgi?id=102365
  fdo#102672 https://bugs.freedesktop.org/show_bug.cgi?id=102672
  fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
  fdo#103841 https://bugs.freedesktop.org/show_bug.cgi?id=103841
  fdo#106387 https://bugs.freedesktop.org/show_bug.cgi?id=106387


== Participating hosts (46 -> 41) ==

  Additional (1): fi-byt-j1900 
  Missing    (6): fi-ilk-m540 fi-bxt-dsi fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 


== Build changes ==

    * IGT: IGT_4553 -> IGTPW_1578

  CI_DRM_4479: c9c54a1c37adefd414d51ed919aab3f94794ee35 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1578: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1578/
  IGT_4553: 9d25d62bb6ff62694e5226b02d79075eab304402 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1578/issues.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/gt: Make use of dummyload library to create recursive batch (rev2)
  2018-07-13  9:46 ` [igt-dev] " Chris Wilson
                   ` (3 preceding siblings ...)
  (?)
@ 2018-07-13 15:32 ` Patchwork
  -1 siblings, 0 replies; 11+ messages in thread
From: Patchwork @ 2018-07-13 15:32 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

== Series Details ==

Series: lib/gt: Make use of dummyload library to create recursive batch (rev2)
URL   : https://patchwork.freedesktop.org/series/46462/
State : failure

== Summary ==

= CI Bug Log - changes from IGT_4553_full -> IGTPW_1578_full =

== Summary - FAILURE ==

  Serious unknown changes coming with IGTPW_1578_full absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_1578_full, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/46462/revisions/2/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in IGTPW_1578_full:

  === IGT changes ===

    ==== Possible regressions ====

    igt@kms_draw_crc@draw-method-xrgb8888-mmap-gtt-xtiled:
      shard-glk:          PASS -> FAIL +1

    
    ==== Warnings ====

    igt@gem_exec_schedule@deep-bsd2:
      shard-kbl:          PASS -> SKIP +2

    igt@gem_exec_schedule@deep-vebox:
      shard-kbl:          SKIP -> PASS +2

    igt@pm_rc6_residency@rc6-accuracy:
      shard-snb:          SKIP -> PASS

    
== Known issues ==

  Here are the changes found in IGTPW_1578_full that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@gem_exec_big:
      shard-hsw:          PASS -> INCOMPLETE (fdo#103540)

    igt@gem_ppgtt@blt-vs-render-ctxn:
      shard-kbl:          PASS -> INCOMPLETE (fdo#106023, fdo#103665)

    igt@gem_workarounds@suspend-resume:
      shard-glk:          PASS -> FAIL (fdo#103375)

    igt@kms_available_modes_crc@available_mode_test_crc:
      shard-snb:          PASS -> FAIL (fdo#106641)

    igt@kms_cursor_legacy@2x-nonblocking-modeset-vs-cursor-atomic:
      shard-glk:          PASS -> FAIL (fdo#105454, fdo#106509)

    igt@kms_flip@2x-plain-flip-ts-check-interruptible:
      shard-glk:          PASS -> FAIL (fdo#100368)

    igt@kms_flip_tiling@flip-to-x-tiled:
      shard-glk:          PASS -> FAIL (fdo#107161, fdo#103822)

    igt@kms_flip_tiling@flip-y-tiled:
      shard-glk:          NOTRUN -> FAIL (fdo#107161, fdo#103822)

    igt@kms_rotation_crc@sprite-rotation-180:
      shard-hsw:          PASS -> FAIL (fdo#103925)

    igt@kms_setmode@basic:
      shard-glk:          PASS -> FAIL (fdo#99912)

    igt@prime_busy@after-vebox:
      shard-snb:          SKIP -> INCOMPLETE (fdo#105411)

    
    ==== Possible fixes ====

    igt@kms_flip@plain-flip-ts-check-interruptible:
      shard-glk:          FAIL (fdo#100368) -> PASS

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      shard-kbl:          INCOMPLETE (fdo#103665) -> PASS

    
  fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
  fdo#103375 https://bugs.freedesktop.org/show_bug.cgi?id=103375
  fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
  fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
  fdo#103822 https://bugs.freedesktop.org/show_bug.cgi?id=103822
  fdo#103925 https://bugs.freedesktop.org/show_bug.cgi?id=103925
  fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
  fdo#105454 https://bugs.freedesktop.org/show_bug.cgi?id=105454
  fdo#106023 https://bugs.freedesktop.org/show_bug.cgi?id=106023
  fdo#106509 https://bugs.freedesktop.org/show_bug.cgi?id=106509
  fdo#106641 https://bugs.freedesktop.org/show_bug.cgi?id=106641
  fdo#107161 https://bugs.freedesktop.org/show_bug.cgi?id=107161
  fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912


== Participating hosts (5 -> 5) ==

  No changes in participating hosts


== Build changes ==

    * IGT: IGT_4553 -> IGTPW_1578
    * Linux: CI_DRM_4476 -> CI_DRM_4479

  CI_DRM_4476: b818fac0878147c6df45338cb515b9b7bd878b7f @ git://anongit.freedesktop.org/gfx-ci/linux
  CI_DRM_4479: c9c54a1c37adefd414d51ed919aab3f94794ee35 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1578: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1578/
  IGT_4553: 9d25d62bb6ff62694e5226b02d79075eab304402 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1578/shards.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
  2018-07-13 10:06   ` [Intel-gfx] " Chris Wilson
@ 2018-07-13 18:22     ` Antonio Argenziano
  -1 siblings, 0 replies; 11+ messages in thread
From: Antonio Argenziano @ 2018-07-13 18:22 UTC (permalink / raw)
  To: Chris Wilson, intel-gfx; +Cc: igt-dev



On 13/07/18 03:06, Chris Wilson wrote:
> From: Antonio Argenziano <antonio.argenziano@intel.com>
> 
> An hanging batch is nothing more than a spinning batch that never gets
> stopped, so re-use the routines implemented in dummyload.c.
> 
> v2: Let caller decide spin loop size
> v3: Only use loose loops for hangs (Chris)
> v4: No requires
> v5: Free the spinner
> v6: Chamelium exists.
> 
> Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---

>   /**
> @@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
>    */
>   void igt_post_hang_ring(int fd, igt_hang_t arg)
>   {
> -	if (arg.handle == 0)
> +	if (!arg.spin)
>   		return;
>   
> -	gem_sync(fd, arg.handle);
> -	gem_close(fd, arg.handle);
> +	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */

I was expecting a poll spinner + manual reset here.

> +	igt_spin_batch_free(fd, arg.spin);
>   
>   	context_set_ban(fd, arg.ctx, arg.ban);
>   
> diff --git a/lib/igt_gt.h b/lib/igt_gt.h

> +
> +#define igt_list_for_each_safe(pos, tmp, head, member)			\

(nitpick) extra tab.

> +	for (pos = igt_list_first_entry(head, pos, member),		\
> +	     tmp = igt_list_next_entry(pos, member);			\

I trust you and the compiler got all the places that needed changing.

Reviewed-by: Antonio Argenziano <antonio.argenziano@intel.com>

Thanks for picking-up this. At my speed it would have taken years :).
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
@ 2018-07-13 18:22     ` Antonio Argenziano
  0 siblings, 0 replies; 11+ messages in thread
From: Antonio Argenziano @ 2018-07-13 18:22 UTC (permalink / raw)
  To: Chris Wilson, intel-gfx; +Cc: igt-dev



On 13/07/18 03:06, Chris Wilson wrote:
> From: Antonio Argenziano <antonio.argenziano@intel.com>
> 
> An hanging batch is nothing more than a spinning batch that never gets
> stopped, so re-use the routines implemented in dummyload.c.
> 
> v2: Let caller decide spin loop size
> v3: Only use loose loops for hangs (Chris)
> v4: No requires
> v5: Free the spinner
> v6: Chamelium exists.
> 
> Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---

>   /**
> @@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
>    */
>   void igt_post_hang_ring(int fd, igt_hang_t arg)
>   {
> -	if (arg.handle == 0)
> +	if (!arg.spin)
>   		return;
>   
> -	gem_sync(fd, arg.handle);
> -	gem_close(fd, arg.handle);
> +	gem_sync(fd, arg.spin->handle); /* Wait until it hangs */

I was expecting a poll spinner + manual reset here.

> +	igt_spin_batch_free(fd, arg.spin);
>   
>   	context_set_ban(fd, arg.ctx, arg.ban);
>   
> diff --git a/lib/igt_gt.h b/lib/igt_gt.h

> +
> +#define igt_list_for_each_safe(pos, tmp, head, member)			\

(nitpick) extra tab.

> +	for (pos = igt_list_first_entry(head, pos, member),		\
> +	     tmp = igt_list_next_entry(pos, member);			\

I trust you and the compiler got all the places that needed changing.

Reviewed-by: Antonio Argenziano <antonio.argenziano@intel.com>

Thanks for picking-up this. At my speed it would have taken years :).
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
  2018-07-13 18:22     ` [igt-dev] " Antonio Argenziano
@ 2018-07-13 18:28       ` Chris Wilson
  -1 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13 18:28 UTC (permalink / raw)
  To: Antonio Argenziano, intel-gfx; +Cc: igt-dev

Quoting Antonio Argenziano (2018-07-13 19:22:41)
> 
> 
> On 13/07/18 03:06, Chris Wilson wrote:
> > From: Antonio Argenziano <antonio.argenziano@intel.com>
> > 
> > An hanging batch is nothing more than a spinning batch that never gets
> > stopped, so re-use the routines implemented in dummyload.c.
> > 
> > v2: Let caller decide spin loop size
> > v3: Only use loose loops for hangs (Chris)
> > v4: No requires
> > v5: Free the spinner
> > v6: Chamelium exists.
> > 
> > Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> 
> >   /**
> > @@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
> >    */
> >   void igt_post_hang_ring(int fd, igt_hang_t arg)
> >   {
> > -     if (arg.handle == 0)
> > +     if (!arg.spin)
> >               return;
> >   
> > -     gem_sync(fd, arg.handle);
> > -     gem_close(fd, arg.handle);
> > +     gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
> 
> I was expecting a poll spinner + manual reset here.

That would break some tests that are using this for hangcheck.
(Not break as such, just make them not work as intended.) More refinement
required, there's room for plenty here!

> 
> > +     igt_spin_batch_free(fd, arg.spin);
> >   
> >       context_set_ban(fd, arg.ctx, arg.ban);
> >   
> > diff --git a/lib/igt_gt.h b/lib/igt_gt.h
> 
> > +
> > +#define igt_list_for_each_safe(pos, tmp, head, member)                       \
> 
> (nitpick) extra tab.

So much for just moving it to a new header :)

> > +     for (pos = igt_list_first_entry(head, pos, member),             \
> > +          tmp = igt_list_next_entry(pos, member);                    \
> 
> I trust you and the compiler got all the places that needed changing.
> 
> Reviewed-by: Antonio Argenziano <antonio.argenziano@intel.com>
> 
> Thanks for picking-up this. At my speed it would have taken years :).

The task is only just begun.
-Sisyphus
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch
@ 2018-07-13 18:28       ` Chris Wilson
  0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-13 18:28 UTC (permalink / raw)
  To: Antonio Argenziano, intel-gfx; +Cc: igt-dev

Quoting Antonio Argenziano (2018-07-13 19:22:41)
> 
> 
> On 13/07/18 03:06, Chris Wilson wrote:
> > From: Antonio Argenziano <antonio.argenziano@intel.com>
> > 
> > An hanging batch is nothing more than a spinning batch that never gets
> > stopped, so re-use the routines implemented in dummyload.c.
> > 
> > v2: Let caller decide spin loop size
> > v3: Only use loose loops for hangs (Chris)
> > v4: No requires
> > v5: Free the spinner
> > v6: Chamelium exists.
> > 
> > Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> 
> >   /**
> > @@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring)
> >    */
> >   void igt_post_hang_ring(int fd, igt_hang_t arg)
> >   {
> > -     if (arg.handle == 0)
> > +     if (!arg.spin)
> >               return;
> >   
> > -     gem_sync(fd, arg.handle);
> > -     gem_close(fd, arg.handle);
> > +     gem_sync(fd, arg.spin->handle); /* Wait until it hangs */
> 
> I was expecting a poll spinner + manual reset here.

That would break some tests that are using this for hangcheck.
(Not break as such, just make them not work as intended.) More refinement
required, there's room for plenty here!

> 
> > +     igt_spin_batch_free(fd, arg.spin);
> >   
> >       context_set_ban(fd, arg.ctx, arg.ban);
> >   
> > diff --git a/lib/igt_gt.h b/lib/igt_gt.h
> 
> > +
> > +#define igt_list_for_each_safe(pos, tmp, head, member)                       \
> 
> (nitpick) extra tab.

So much for just moving it to a new header :)

> > +     for (pos = igt_list_first_entry(head, pos, member),             \
> > +          tmp = igt_list_next_entry(pos, member);                    \
> 
> I trust you and the compiler got all the places that needed changing.
> 
> Reviewed-by: Antonio Argenziano <antonio.argenziano@intel.com>
> 
> Thanks for picking-up this. At my speed it would have taken years :).

The task is only just begun.
-Sisyphus
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-07-13 18:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13  9:46 [PATCH i-g-t] lib/gt: Make use of dummyload library to create recursive batch Chris Wilson
2018-07-13  9:46 ` [igt-dev] " Chris Wilson
2018-07-13 10:02 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
2018-07-13 10:06 ` [PATCH i-g-t] " Chris Wilson
2018-07-13 10:06   ` [Intel-gfx] " Chris Wilson
2018-07-13 18:22   ` Antonio Argenziano
2018-07-13 18:22     ` [igt-dev] " Antonio Argenziano
2018-07-13 18:28     ` Chris Wilson
2018-07-13 18:28       ` [igt-dev] " Chris Wilson
2018-07-13 12:14 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/gt: Make use of dummyload library to create recursive batch (rev2) Patchwork
2018-07-13 15:32 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.