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 03/19] drm/i915/fence: Separate timeout mechanism for awaiting on dma-fences
Date: Tue,  2 Jan 2018 15:12:19 +0000	[thread overview]
Message-ID: <20180102151235.3949-3-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20180102151235.3949-1-chris@chris-wilson.co.uk>

As the timeout mechanism has grown more and more complicated, using
multiple deferred tasks and more than doubling the size of our struct,
split the two implementations to streamline the simpler no-timeout
callback variant.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_sw_fence.c | 61 +++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_sw_fence.c b/drivers/gpu/drm/i915/i915_sw_fence.c
index 5fcb428b2dfe..1de5173e53a2 100644
--- a/drivers/gpu/drm/i915/i915_sw_fence.c
+++ b/drivers/gpu/drm/i915/i915_sw_fence.c
@@ -365,18 +365,31 @@ int i915_sw_fence_await_sw_fence_gfp(struct i915_sw_fence *fence,
 struct i915_sw_dma_fence_cb {
 	struct dma_fence_cb base;
 	struct i915_sw_fence *fence;
+};
+
+struct i915_sw_dma_fence_cb_timer {
+	struct i915_sw_dma_fence_cb base;
 	struct dma_fence *dma;
 	struct timer_list timer;
 	struct irq_work work;
 	struct rcu_head rcu;
 };
 
+static void dma_i915_sw_fence_wake(struct dma_fence *dma,
+				   struct dma_fence_cb *data)
+{
+	struct i915_sw_dma_fence_cb *cb = container_of(data, typeof(*cb), base);
+
+	i915_sw_fence_complete(cb->fence);
+	kfree(cb);
+}
+
 static void timer_i915_sw_fence_wake(struct timer_list *t)
 {
-	struct i915_sw_dma_fence_cb *cb = from_timer(cb, t, timer);
+	struct i915_sw_dma_fence_cb_timer *cb = from_timer(cb, t, timer);
 	struct i915_sw_fence *fence;
 
-	fence = xchg(&cb->fence, NULL);
+	fence = xchg(&cb->base.fence, NULL);
 	if (!fence)
 		return;
 
@@ -388,27 +401,24 @@ static void timer_i915_sw_fence_wake(struct timer_list *t)
 	i915_sw_fence_complete(fence);
 }
 
-static void dma_i915_sw_fence_wake(struct dma_fence *dma,
-				   struct dma_fence_cb *data)
+static void dma_i915_sw_fence_wake_timer(struct dma_fence *dma,
+					 struct dma_fence_cb *data)
 {
-	struct i915_sw_dma_fence_cb *cb = container_of(data, typeof(*cb), base);
+	struct i915_sw_dma_fence_cb_timer *cb =
+		container_of(data, typeof(*cb), base.base);
 	struct i915_sw_fence *fence;
 
-	fence = xchg(&cb->fence, NULL);
+	fence = xchg(&cb->base.fence, NULL);
 	if (fence)
 		i915_sw_fence_complete(fence);
 
-	if (cb->dma){
-		irq_work_queue(&cb->work);
-		return;
-	}
-
-	kfree(cb);
+	irq_work_queue(&cb->work);
 }
 
 static void irq_i915_sw_fence_work(struct irq_work *wrk)
 {
-	struct i915_sw_dma_fence_cb *cb = container_of(wrk, typeof(*cb), work);
+	struct i915_sw_dma_fence_cb_timer *cb =
+		container_of(wrk, typeof(*cb), work);
 
 	del_timer_sync(&cb->timer);
 	dma_fence_put(cb->dma);
@@ -422,6 +432,7 @@ int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
 				  gfp_t gfp)
 {
 	struct i915_sw_dma_fence_cb *cb;
+	dma_fence_func_t func;
 	int ret;
 
 	debug_fence_assert(fence);
@@ -430,7 +441,10 @@ int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
 	if (dma_fence_is_signaled(dma))
 		return 0;
 
-	cb = kmalloc(sizeof(*cb), gfp);
+	cb = kmalloc(timeout ?
+		     sizeof(struct i915_sw_dma_fence_cb_timer) :
+		     sizeof(struct i915_sw_dma_fence_cb),
+		     gfp);
 	if (!cb) {
 		if (!gfpflags_allow_blocking(gfp))
 			return -ENOMEM;
@@ -441,21 +455,26 @@ int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
 	cb->fence = fence;
 	i915_sw_fence_await(fence);
 
-	cb->dma = NULL;
+	func = dma_i915_sw_fence_wake;
 	if (timeout) {
-		cb->dma = dma_fence_get(dma);
-		init_irq_work(&cb->work, irq_i915_sw_fence_work);
+		struct i915_sw_dma_fence_cb_timer *timer =
+			container_of(cb, typeof(*timer), base);
 
-		timer_setup(&cb->timer,
+		timer->dma = dma_fence_get(dma);
+		init_irq_work(&timer->work, irq_i915_sw_fence_work);
+
+		timer_setup(&timer->timer,
 			    timer_i915_sw_fence_wake, TIMER_IRQSAFE);
-		mod_timer(&cb->timer, round_jiffies_up(jiffies + timeout));
+		mod_timer(&timer->timer, round_jiffies_up(jiffies + timeout));
+
+		func = dma_i915_sw_fence_wake_timer;
 	}
 
-	ret = dma_fence_add_callback(dma, &cb->base, dma_i915_sw_fence_wake);
+	ret = dma_fence_add_callback(dma, &cb->base, func);
 	if (ret == 0) {
 		ret = 1;
 	} else {
-		dma_i915_sw_fence_wake(dma, &cb->base);
+		func(dma, &cb->base);
 		if (ret == -ENOENT) /* fence already signaled */
 			ret = 0;
 	}
-- 
2.15.1

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

  parent reply	other threads:[~2018-01-02 15:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-02 15:12 [PATCH 01/19] drm/i915: Delete defunct i915_gem_request_assign() Chris Wilson
2018-01-02 15:12 ` [PATCH 02/19] drm/i915: Only defer freeing of fence callback when also using the timer Chris Wilson
2018-01-02 15:12 ` Chris Wilson [this message]
2018-01-02 15:12 ` [PATCH 04/19] drm/i915: Use our singlethreaded wq for freeing objects Chris Wilson
2018-01-02 15:12 ` [PATCH 05/19] drm/i915: Only attempt to scan the requested number of shrinker slabs Chris Wilson
2018-01-02 15:12 ` [PATCH 06/19] drm/i915: Move i915_gem_retire_work_handler Chris Wilson
2018-01-02 15:12 ` [PATCH 07/19] drm/i915: Shrink the GEM kmem_caches upon idling Chris Wilson
2018-01-02 15:12 ` [PATCH 08/19] drm/i915: Shrink the request kmem_cache on allocation error Chris Wilson
2018-01-02 15:12 ` [PATCH 09/19] drm/i915: Assert all signalers we depended on did indeed signal Chris Wilson
2018-01-03 11:40   ` Michał Winiarski
2018-01-03 12:24     ` Chris Wilson
2018-01-02 15:12 ` [PATCH 10/19] drm/i915/execlists: Assert there are no simple cycles in the dependencies Chris Wilson
2018-01-03 11:13   ` Michał Winiarski
2018-01-02 15:12 ` [PATCH 11/19] drm/i915/execlists: Reduce list_for_each_safe+list_safe_reset_next Chris Wilson
2018-01-03 11:12   ` Michał Winiarski
2018-01-02 15:12 ` [PATCH 12/19] drm/i915: Drop request reference for the signaler thread Chris Wilson
2018-01-02 15:12 ` [PATCH 13/19] drm/i915: Reduce spinlock hold time during notify_ring() interrupt Chris Wilson
2018-01-02 15:12 ` [PATCH 14/19] drm/i915: Reconstruct active state on starting busy-stats Chris Wilson
2018-01-08 14:18   ` Tvrtko Ursulin
2018-01-08 14:29     ` Chris Wilson
2018-01-08 14:44       ` Tvrtko Ursulin
2018-01-08 14:52         ` Chris Wilson
2018-01-02 15:12 ` [PATCH 15/19] drm/i915: Hold rpm wakeref for modifying the global seqno Chris Wilson
2018-01-03 10:58   ` Michał Winiarski
2018-01-02 15:12 ` [PATCH 16/19] drm/i915/execlists: Clear context-switch interrupt earlier in the reset Chris Wilson
2018-01-03 10:23   ` Michał Winiarski
2018-01-02 15:12 ` [PATCH 17/19] drm/i915/execlists: Record elsp offset during engine setup Chris Wilson
2018-01-03 10:00   ` Michał Winiarski
2018-01-02 15:12 ` [PATCH 18/19] drm/i915/execlists: Tidy enabling execlists Chris Wilson
2018-01-03  9:55   ` Michał Winiarski
2018-01-03 11:12     ` Chris Wilson
2018-01-02 15:12 ` [PATCH 19/19] drm/i915/execlists: Repeat CSB mmio until it returns a sensible result Chris Wilson
2018-01-02 15:37 ` ✓ Fi.CI.BAT: success for series starting with [01/19] drm/i915: Delete defunct i915_gem_request_assign() Patchwork
2018-01-02 16:24 ` ✓ Fi.CI.IGT: " Patchwork
2018-01-02 19:01 ` [PATCH 01/19] " Rodrigo Vivi

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=20180102151235.3949-3-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.