[PATCH 3/3] tweaks

Matthew Auld matthew.auld at intel.com
Thu Dec 1 19:57:21 UTC 2022


---
 drivers/gpu/drm/i915/gt/selftest_migrate.c | 93 +++++++---------------
 1 file changed, 28 insertions(+), 65 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_migrate.c b/drivers/gpu/drm/i915/gt/selftest_migrate.c
index 1da51add2c02..306cd47d1f7d 100644
--- a/drivers/gpu/drm/i915/gt/selftest_migrate.c
+++ b/drivers/gpu/drm/i915/gt/selftest_migrate.c
@@ -530,14 +530,17 @@ static int live_migrate_clear(void *arg)
 	return 0;
 }
 
-static int spinner_kill(void *arg)
+struct spinner_timer {
+	struct timer_list timer;
+	struct igt_spinner spin;
+};
+
+static void spinner_kill(struct timer_list *timer)
 {
-	struct igt_spinner *spin = arg;
+	struct spinner_timer *st = from_timer(st, timer, timer);
 
-	msleep(2000); /* Should be plenty */
-	igt_spinner_end(spin);
+	igt_spinner_end(&st->spin);
 	pr_info("%s\n", __func__);
-	return 0;
 }
 
 static int live_emit_pte_full_ring(void *arg)
@@ -547,13 +550,11 @@ static int live_emit_pte_full_ring(void *arg)
 	struct drm_i915_private *i915 = migrate->context->engine->i915;
 	struct drm_i915_gem_object *obj;
 	struct intel_context *ce;
-	struct i915_request *rq, *prev;
-	struct igt_spinner spin;
-	struct task_struct *tsk = NULL;
+	struct i915_request *rq;
+	struct spinner_timer st;
 	struct sgt_dma it;
-	int len, sz, err;
-	int status;
-	u32 *cs;
+	int len, err;
+
 
 	/*
 	 * Simple regression test to check that we don't trample the
@@ -561,7 +562,7 @@ static int live_emit_pte_full_ring(void *arg)
 	 * nearly full.
 	 */
 
-	if (igt_spinner_init(&spin, to_gt(i915)))
+	if (igt_spinner_init(&st.spin, to_gt(i915)))
 		return -ENOMEM;
 
 	obj = i915_gem_object_create_internal(i915, 2 * PAGE_SIZE);
@@ -586,18 +587,24 @@ static int live_emit_pte_full_ring(void *arg)
 	if (err)
 		goto out_put;
 
-	rq = igt_spinner_create_request(&spin, ce, MI_ARB_CHECK);
+	rq = igt_spinner_create_request(&st.spin, ce, MI_ARB_CHECK);
 	if (IS_ERR(rq)) {
 		err = PTR_ERR(rq);
 		goto out_unpin;
 	}
 
 	i915_request_add(rq);
-	if (!igt_wait_for_spinner(&spin, rq)) {
+	if (!igt_wait_for_spinner(&st.spin, rq)) {
 		err = -EIO;
 		goto out_unpin;
 	}
 
+	rq = i915_request_create(ce);
+	if (IS_ERR(rq)) {
+		err = PTR_ERR(rq);
+		goto out_unpin;
+	}
+
 	/*
 	 * Fill the rest of the ring leaving I915_EMIT_PTE_NUM_DWORDS +
 	 * ring->reserved_space at the end. To actually emit the PTEs we require
@@ -606,55 +613,17 @@ static int live_emit_pte_full_ring(void *arg)
 	 * ring space in emit_pte(), otherwise we trample on the reserved_space
 	 * resulting in crashes when later submitting the rq.
 	 */
+	rq->ring->space = rq->reserved_space + I915_EMIT_PTE_NUM_DWORDS * sizeof(u32);
 
-	prev = NULL;
-	do {
-		if (prev)
-			i915_request_add(rq);
-
-		rq = i915_request_create(ce);
-		if (IS_ERR(rq)) {
-			err = PTR_ERR(rq);
-			goto out_unpin;
-		}
-
-		sz = (rq->ring->space - rq->reserved_space) / sizeof(u32) -
-			I915_EMIT_PTE_NUM_DWORDS;
-		sz = min_t(u32, sz, (SZ_1K - rq->reserved_space) / sizeof(u32) -
-			   I915_EMIT_PTE_NUM_DWORDS);
-		cs = intel_ring_begin(rq, sz);
-		if (IS_ERR(cs)) {
-			err = PTR_ERR(cs);
-			goto out_rq;
-		}
-
-		memset32(cs, MI_NOOP, sz);
-		cs += sz;
-		intel_ring_advance(rq, cs);
-
-		pr_info("%s emit=%u sz=%d\n", __func__, rq->ring->emit, sz);
-
-		prev = rq;
-	} while (rq->ring->space > (rq->reserved_space +
-				    I915_EMIT_PTE_NUM_DWORDS * sizeof(u32)));
-
-	it = sg_sgt(obj->mm.pages->sgl);
-
-	tsk = kthread_run(spinner_kill, &spin, "igt-kill-spinner");
-	if (IS_ERR(tsk)) {
-		err = PTR_ERR(tsk);
-		goto out_rq;
-	}
-
-	get_task_struct(tsk);
-
-	msleep(10); /* start all threads before we kthread_stop() */
+	timer_setup_on_stack(&st.timer, spinner_kill, 0);
+	mod_timer(&st.timer, jiffies + 3 * HZ);
 
 	/*
 	 * This should wait for the spinner to be killed, otherwise we should go
 	 * down in flames when doing i915_request_add().
 	 */
 	pr_info("%s emite_pte ring space=%u\n", __func__, rq->ring->space);
+	it = sg_sgt(obj->mm.pages->sgl);
 	len = emit_pte(rq, &it, obj->cache_level, false, 0, CHUNK_SZ);
 	if (!len) {
 		err = -EINVAL;
@@ -667,14 +636,8 @@ static int live_emit_pte_full_ring(void *arg)
 
 out_rq:
 	i915_request_add(rq); /* GEM_BUG_ON(rq->reserved_space > ring->space)? */
-
-	if (!IS_ERR_OR_NULL(tsk)) {
-		status = kthread_stop(tsk);
-		if (status && !err)
-			err = status;
-
-		put_task_struct(tsk);
-	}
+	del_timer_sync(&st.timer);
+	destroy_timer_on_stack(&st.timer);
 out_unpin:
 	intel_context_unpin(ce);
 out_put:
@@ -682,7 +645,7 @@ static int live_emit_pte_full_ring(void *arg)
 out_obj:
 	i915_gem_object_put(obj);
 out_spinner:
-	igt_spinner_fini(&spin);
+	igt_spinner_fini(&st.spin);
 	return err;
 }
 
-- 
2.38.1



More information about the Intel-gfx-trybot mailing list