[RFCv2 3/3] drm/i915: Add unit tests for the breadcrumb rbtree, completion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Second retroactive test, make sure that the waiters are removed from the
global wait-tree when their seqno completes.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/i915/intel_breadcrumbs.c | 79 ++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_breadcrumbs.c b/drivers/gpu/drm/i915/intel_breadcrumbs.c
index 3eda013903d3..fff1eddc5020 100644
--- a/drivers/gpu/drm/i915/intel_breadcrumbs.c
+++ b/drivers/gpu/drm/i915/intel_breadcrumbs.c
@@ -849,10 +849,89 @@ static int igt_random_insert_remove(void *ignore)
 	return err;
 }
 
+static void mock_seqno_advance(struct intel_engine_cs *engine, u32 seqno)
+{
+	intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno);
+}
+
+static int igt_insert_complete(void *ignore)
+{
+	struct intel_engine_cs *engine;
+	struct intel_wait *waiters;
+	const int count = 4096;
+	unsigned long *bitmap;
+	int err = -ENOMEM;
+	int n, m;
+
+	engine = mock_engine("mock");
+	if (!engine)
+		goto out;
+
+	waiters = kmalloc_array(count, sizeof(*waiters), GFP_KERNEL);
+	if (!waiters)
+		goto out_engines;
+
+	bitmap = kzalloc(DIV_ROUND_UP(count, BITS_PER_LONG) * sizeof(*bitmap),
+			 GFP_KERNEL);
+	if (!bitmap)
+		goto out_waiters;
+
+	for (n = 0; n < count; n++) {
+		intel_wait_init(&waiters[n], n + 0x1000);
+		intel_engine_add_wait(engine, &waiters[n]);
+		__set_bit(n, bitmap);
+	}
+	err = check_rbtree(engine, bitmap, waiters, count);
+	if (err)
+		goto err;
+
+	for (n = 0; n < count; n = m) {
+		int seqno = 2*n;
+
+		GEM_BUG_ON(find_first_bit(bitmap, count) != n);
+
+		if (intel_wait_complete(&waiters[n])) {
+			pr_err("waiter[%d, seqno=%d] completed too early\n",
+			       n, waiters[n].seqno);
+			err = -EINVAL;
+			goto err;
+		}
+
+		/* complete the following waiters */
+		mock_seqno_advance(engine, seqno + 0x1000);
+		for (m = n; m <= seqno; m++) {
+			if (m == count)
+				break;
+
+			GEM_BUG_ON(!test_bit(m, bitmap));
+			__clear_bit(m, bitmap);
+		}
+
+		intel_engine_remove_wait(engine, &waiters[n]);
+		err = check_rbtree(engine, bitmap, waiters, count);
+		if (err) {
+			pr_err("completion after seqno advance to %d failed\n",
+			       seqno);
+			goto err;
+		}
+	}
+
+	err = check_rbtree_empty(engine);
+err:
+	kfree(bitmap);
+out_waiters:
+	kfree(waiters);
+out_engines:
+	kfree(engine);
+out:
+	return err;
+}
+
 int intel_breadcrumbs_selftest(void)
 {
 	static const struct i915_subtest tests[] = {
 		SUBTEST(igt_random_insert_remove),
+		SUBTEST(igt_insert_complete),
 	};
 
 	return i915_subtests(tests, NULL);
-- 
2.10.2

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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux