All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH] drm/i915/selftests: Wait for the dma-fence timeout
Date: Wed, 17 Jan 2018 12:15:46 +0000	[thread overview]
Message-ID: <20180117121546.6023-1-chris@chris-wilson.co.uk> (raw)

When testing that the timeout fired, we need to be sure we have waited
just long enough for the timeout to have occurred and for the softirq
(on another cpu) to have completed. Sleeping for an arbitrary amount is
prone to error, so wait for the timeout instead and complain if it was
too late.

References: https://bugs.freedesktop.org/show_bug.cgi?id=104670
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/selftests/i915_sw_fence.c | 30 +++++++++-----------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_sw_fence.c b/drivers/gpu/drm/i915/selftests/i915_sw_fence.c
index 4fb51deb81a1..f171db16a1c4 100644
--- a/drivers/gpu/drm/i915/selftests/i915_sw_fence.c
+++ b/drivers/gpu/drm/i915/selftests/i915_sw_fence.c
@@ -661,7 +661,7 @@ static int test_dma_fence(void *arg)
 {
 	struct i915_sw_fence *timeout = NULL, *not = NULL;
 	unsigned long delay = i915_selftest.timeout_jiffies;
-	unsigned long end, sleep;
+	unsigned long start, end;
 	struct dma_fence *dma;
 	int err;
 
@@ -688,36 +688,26 @@ static int test_dma_fence(void *arg)
 	}
 
 	/* We round the timeout for the fence up to the next second */
-	end = round_jiffies_up(jiffies + delay);
+	start = jiffies;
+	end = round_jiffies_up(start + delay);
 
-	sleep = jiffies_to_usecs(delay) / 3;
-	usleep_range(sleep, 2 * sleep);
-	if (time_after(jiffies, end)) {
-		pr_debug("Slept too long, delay=%lu, skipping!\n", delay);
-		goto skip;
+	if (wait_event_interruptible(timeout->wait,
+				     i915_sw_fence_done(timeout))) {
+		err = -EINTR;
+		goto err;
 	}
 
-	if (i915_sw_fence_done(timeout) || i915_sw_fence_done(not)) {
-		pr_err("Fences signaled too early\n");
+	if (time_after(jiffies, 2*end - start)) {
+		pr_err("Timeout (now %lu) later than expected (%lu)\n",
+		       jiffies, end);
 		goto err;
 	}
 
-	do {
-		sleep = jiffies_to_usecs(end - jiffies + 1);
-		usleep_range(sleep, 2 * sleep);
-	} while (!time_after(jiffies, end));
-
 	if (i915_sw_fence_done(not)) {
 		pr_err("No timeout fence signaled!\n");
 		goto err;
 	}
 
-	if (!i915_sw_fence_done(timeout)) {
-		pr_err("Timeout fence unsignaled!\n");
-		goto err;
-	}
-
-skip:
 	dma_fence_signal(dma);
 
 	if (!i915_sw_fence_done(timeout) || !i915_sw_fence_done(not)) {
-- 
2.15.1

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

             reply	other threads:[~2018-01-17 12:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 12:15 Chris Wilson [this message]
2018-01-17 12:27 ` [PATCH] drm/i915/selftests: Wait for the dma-fence timeout Tvrtko Ursulin
2018-01-17 12:44   ` Chris Wilson
2018-01-17 12:54     ` Tvrtko Ursulin
2018-01-17 13:11 ` [PATCH v2] " Chris Wilson
2018-01-17 13:36   ` Tvrtko Ursulin
2018-01-17 13:41     ` Chris Wilson
2018-01-17 13:15 ` [PATCH v3] " Chris Wilson
2018-01-17 13:25 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-01-17 13:29   ` Saarinen, Jani
2018-01-17 13:31     ` Chris Wilson
2018-01-17 13:45 ` ✓ Fi.CI.BAT: success for drm/i915/selftests: Wait for the dma-fence timeout (rev2) Patchwork
2018-01-17 13:57 ` [PATCH v4] drm/i915/selftests: Wait for the dma-fence timeout Chris Wilson
2018-01-17 14:25   ` Tvrtko Ursulin
2018-01-17 17:11     ` Chris Wilson
2018-01-17 14:02 ` ✓ Fi.CI.BAT: success for drm/i915/selftests: Wait for the dma-fence timeout (rev3) Patchwork
2018-01-17 14:20 ` ✓ Fi.CI.BAT: success for drm/i915/selftests: Wait for the dma-fence timeout (rev4) Patchwork
2018-01-17 16:45 ` ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180117121546.6023-1-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.