All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Wait for completion of pending flips when starved of fences
@ 2014-01-19 21:20 Chris Wilson
  2014-01-19 21:55 ` Daniel Vetter
  0 siblings, 1 reply; 14+ messages in thread
From: Chris Wilson @ 2014-01-19 21:20 UTC (permalink / raw)
  To: intel-gfx

On older generations (gen2, gen3) the GPU requires fences for many
operations, such as blits. The display hardware also requires fences for
scanouts and this leads to a situation where an arbitrary number of
fences may be pinned by old scanouts following a pageflip but before we
have executed the unpin workqueue. This is unpredictable by userspace
and leads to random EDEADLK when submitting an otherwise benign
execbuffer. However, we can detect when we have an outstanding flip and
so cause userspace to wait upon their completion before finally
declaring that the system is starved of fences. This is really no worse
than forcing the GPU to stall waiting for older execbuffer to retire and
release their fences before we can reallocate them for the next
execbuffer.

Reported-and-tested-by: dimon@gmx.net
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=73696
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c |   23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 41d5a99..686620c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3214,7 +3214,7 @@ i915_find_fence_reg(struct drm_device *dev)
 	}
 
 	if (avail == NULL)
-		return NULL;
+		goto deadlock;
 
 	/* None available, try to steal one or wait for a user to finish */
 	list_for_each_entry(reg, &dev_priv->mm.fence_list, lru_list) {
@@ -3224,7 +3224,22 @@ i915_find_fence_reg(struct drm_device *dev)
 		return reg;
 	}
 
-	return NULL;
+deadlock:
+	{ /* Wait for completion of pending flips which consume fences */
+		struct intel_crtc *crtc;
+
+		list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
+			if (atomic_read(&crtc->unpin_work_count) == 0)
+				continue;
+
+			if (crtc->unpin_work)
+				intel_wait_for_vblank(dev, crtc->pipe);
+
+			return ERR_PTR(-EAGAIN);
+		}
+	}
+
+	return ERR_PTR(-EDEADLK);
 }
 
 /**
@@ -3269,8 +3284,8 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj)
 		}
 	} else if (enable) {
 		reg = i915_find_fence_reg(dev);
-		if (reg == NULL)
-			return -EDEADLK;
+		if (IS_ERR(reg))
+			return PTR_ERR(reg);
 
 		if (reg->obj) {
 			struct drm_i915_gem_object *old = reg->obj;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-01-21 12:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-19 21:20 [PATCH] drm/i915: Wait for completion of pending flips when starved of fences Chris Wilson
2014-01-19 21:55 ` Daniel Vetter
2014-01-20  9:49   ` Chris Wilson
2014-01-20 10:17     ` [PATCH 1/2] " Chris Wilson
2014-01-20 10:17       ` [PATCH 2/2] drm/i915: Repeat evictions whilst pageflip completions are outstanding Chris Wilson
2014-01-21 11:03         ` Bloomfield, Jon
2014-01-21 12:19           ` Daniel Vetter
2014-01-20 20:30       ` [PATCH 1/2] drm/i915: Wait for completion of pending flips when starved of fences Chris Wilson
2014-01-21  9:32         ` Daniel Vetter
2014-01-21  9:37           ` Chris Wilson
2014-01-21 11:03       ` Bloomfield, Jon
2014-01-20 10:37     ` [PATCH] " Daniel Vetter
2014-01-20 10:44       ` Chris Wilson
2014-01-20 16:17         ` Daniel Vetter

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.