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 2/3] drm/i915: Wrap a timer into a i915_sw_fence
Date: Tue, 10 Oct 2017 16:50:19 +0100	[thread overview]
Message-ID: <20171010155020.8172-2-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20171010155020.8172-1-chris@chris-wilson.co.uk>

For some selftests, we want to issue requests but delay them going to
hardware. Furthermore, we don't want those requests to block
indefinitely (or else we may hang the driver and block testing) so we
want to employ a timeout. So naturally we want a fence that is
automatically signaled by a timer.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_sw_fence.c | 62 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_sw_fence.h |  4 +++
 2 files changed, 66 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_sw_fence.c b/drivers/gpu/drm/i915/i915_sw_fence.c
index 808ea4d5b962..308fbb201d4c 100644
--- a/drivers/gpu/drm/i915/i915_sw_fence.c
+++ b/drivers/gpu/drm/i915/i915_sw_fence.c
@@ -506,6 +506,68 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,
 	return ret;
 }
 
+struct timer_fence {
+	struct i915_sw_fence base;
+	struct timer_list timer;
+	struct kref ref;
+};
+
+static void timer_fence_wake(unsigned long data)
+{
+	struct timer_fence *tf = (struct timer_fence *)data;
+
+	i915_sw_fence_complete(&tf->base);
+}
+
+static int __i915_sw_fence_call
+timer_fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
+{
+	if (state == FENCE_FREE)
+		i915_sw_fence_timer_put(fence);
+
+	return NOTIFY_DONE;
+}
+
+struct i915_sw_fence *i915_sw_fence_create_timer(long timeout, gfp_t gfp)
+{
+	struct timer_fence *tf;
+
+	tf = kmalloc(sizeof(*tf), gfp);
+	if (!tf)
+		return ERR_PTR(-ENOMEM);
+
+	i915_sw_fence_init(&tf->base, timer_fence_notify);
+	kref_init(&tf->ref);
+
+	setup_timer(&tf->timer, timer_fence_wake, (unsigned long)tf);
+	mod_timer(&tf->timer, timeout);
+
+	kref_get(&tf->ref);
+	return &tf->base;
+}
+
+static void i915_sw_fence_timer_free(struct kref *ref)
+{
+	struct timer_fence *tf = container_of(ref, typeof(*tf), ref);
+
+	kfree(tf);
+}
+
+void i915_sw_fence_timer_flush(struct i915_sw_fence *fence)
+{
+	struct timer_fence *tf = container_of(fence, typeof(*tf), base);
+
+	if (del_timer_sync(&tf->timer))
+		i915_sw_fence_complete(&tf->base);
+}
+
+void i915_sw_fence_timer_put(struct i915_sw_fence *fence)
+{
+	struct timer_fence *tf = container_of(fence, typeof(*tf), base);
+
+	kref_put(&tf->ref, i915_sw_fence_timer_free);
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/i915_sw_fence.c"
 #endif
diff --git a/drivers/gpu/drm/i915/i915_sw_fence.h b/drivers/gpu/drm/i915/i915_sw_fence.h
index fe2ef4dadfc6..eccbee027cb8 100644
--- a/drivers/gpu/drm/i915/i915_sw_fence.h
+++ b/drivers/gpu/drm/i915/i915_sw_fence.h
@@ -61,6 +61,10 @@ void i915_sw_fence_fini(struct i915_sw_fence *fence);
 static inline void i915_sw_fence_fini(struct i915_sw_fence *fence) {}
 #endif
 
+struct i915_sw_fence *i915_sw_fence_create_timer(long timeout, gfp_t gfp);
+void i915_sw_fence_timer_flush(struct i915_sw_fence *fence);
+void i915_sw_fence_timer_put(struct i915_sw_fence *fence);
+
 void i915_sw_fence_commit(struct i915_sw_fence *fence);
 
 int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
-- 
2.15.0.rc0

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

  reply	other threads:[~2017-10-10 15:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 15:50 [PATCH 1/3] drm/i915: Fix eviction when the GGTT is idle but full Chris Wilson
2017-10-10 15:50 ` Chris Wilson [this message]
2017-10-10 15:50 ` [PATCH 3/3] drm/i915/selftests: Exercise adding requests to a full GGTT Chris Wilson
2017-10-10 17:17 ` ✗ Fi.CI.BAT: failure for series starting with [1/3] drm/i915: Fix eviction when the GGTT is idle but full 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=20171010155020.8172-2-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.