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: [CI 26/26] drm/i915: Export our request as a dma-buf fence on the reservation object
Date: Thu,  4 Aug 2016 08:33:15 +0100	[thread overview]
Message-ID: <1470295995-9669-26-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1470295995-9669-1-git-send-email-chris@chris-wilson.co.uk>

If the GEM objects being rendered with in this request have been
exported via dma-buf to a third party, hook ourselves into the dma-buf
reservation object so that the third party can serialise with our
rendering via the dma-buf fences.

Testcase: igt/prime_busy
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c     | 58 ++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 31 ++++++++++++++--
 2 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 3a00ab3ad06e..c60a8d5bbad0 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -23,9 +23,13 @@
  * Authors:
  *	Dave Airlie <airlied@redhat.com>
  */
+
+#include <linux/dma-buf.h>
+#include <linux/reservation.h>
+
 #include <drm/drmP.h>
+
 #include "i915_drv.h"
-#include <linux/dma-buf.h>
 
 static struct drm_i915_gem_object *dma_buf_to_obj(struct dma_buf *buf)
 {
@@ -218,25 +222,73 @@ static const struct dma_buf_ops i915_dmabuf_ops =  {
 	.end_cpu_access = i915_gem_end_cpu_access,
 };
 
+static void export_fences(struct drm_i915_gem_object *obj,
+			  struct dma_buf *dma_buf)
+{
+	struct reservation_object *resv = dma_buf->resv;
+	struct drm_i915_gem_request *req;
+	unsigned long active;
+	int idx;
+
+	active = __I915_BO_ACTIVE(obj);
+	if (!active)
+		return;
+
+	/* Serialise with execbuf to prevent concurrent fence-loops */
+	mutex_lock(&obj->base.dev->struct_mutex);
+
+	/* Mark the object for future fences before racily adding old fences */
+	obj->base.dma_buf = dma_buf;
+
+	ww_mutex_lock(&resv->lock, NULL);
+
+	for_each_active(active, idx) {
+		req = i915_gem_active_get(&obj->last_read[idx],
+					  &obj->base.dev->struct_mutex);
+		if (!req)
+			continue;
+
+		if (reservation_object_reserve_shared(resv) == 0)
+			reservation_object_add_shared_fence(resv, &req->fence);
+
+		i915_gem_request_put(req);
+	}
+
+	req = i915_gem_active_get(&obj->last_write,
+				  &obj->base.dev->struct_mutex);
+	if (req) {
+		reservation_object_add_excl_fence(resv, &req->fence);
+		i915_gem_request_put(req);
+	}
+
+	ww_mutex_unlock(&resv->lock);
+	mutex_unlock(&obj->base.dev->struct_mutex);
+}
+
 struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
 				      struct drm_gem_object *gem_obj, int flags)
 {
 	struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
 	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
+	struct dma_buf *dma_buf;
 
 	exp_info.ops = &i915_dmabuf_ops;
 	exp_info.size = gem_obj->size;
 	exp_info.flags = flags;
 	exp_info.priv = gem_obj;
 
-
 	if (obj->ops->dmabuf_export) {
 		int ret = obj->ops->dmabuf_export(obj);
 		if (ret)
 			return ERR_PTR(ret);
 	}
 
-	return dma_buf_export(&exp_info);
+	dma_buf = dma_buf_export(&exp_info);
+	if (IS_ERR(dma_buf))
+		return dma_buf;
+
+	export_fences(obj, dma_buf);
+	return dma_buf;
 }
 
 static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index a1da3028a949..71834741bd87 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -26,14 +26,18 @@
  *
  */
 
+#include <linux/dma_remapping.h>
+#include <linux/reservation.h>
+#include <linux/uaccess.h>
+
 #include <drm/drmP.h>
 #include <drm/i915_drm.h>
+
 #include "i915_drv.h"
+#include "i915_gem_dmabuf.h"
 #include "i915_trace.h"
 #include "intel_drv.h"
 #include "intel_frontbuffer.h"
-#include <linux/dma_remapping.h>
-#include <linux/uaccess.h>
 
 #define  __EXEC_OBJECT_HAS_PIN		(1<<31)
 #define  __EXEC_OBJECT_HAS_FENCE	(1<<30)
@@ -1205,6 +1209,28 @@ void i915_vma_move_to_active(struct i915_vma *vma,
 	list_move_tail(&vma->vm_link, &vma->vm->active_list);
 }
 
+static void eb_export_fence(struct drm_i915_gem_object *obj,
+			    struct drm_i915_gem_request *req,
+			    unsigned int flags)
+{
+	struct reservation_object *resv;
+
+	resv = i915_gem_object_get_dmabuf_resv(obj);
+	if (!resv)
+		return;
+
+	/* Ignore errors from failing to allocate the new fence, we can't
+	 * handle an error right now. Worst case should be missed
+	 * synchronisation leading to rendering corruption.
+	 */
+	ww_mutex_lock(&resv->lock, NULL);
+	if (flags & EXEC_OBJECT_WRITE)
+		reservation_object_add_excl_fence(resv, &req->fence);
+	else if (reservation_object_reserve_shared(resv) == 0)
+		reservation_object_add_shared_fence(resv, &req->fence);
+	ww_mutex_unlock(&resv->lock);
+}
+
 static void
 i915_gem_execbuffer_move_to_active(struct list_head *vmas,
 				   struct drm_i915_gem_request *req)
@@ -1224,6 +1250,7 @@ i915_gem_execbuffer_move_to_active(struct list_head *vmas,
 		obj->base.read_domains = obj->base.pending_read_domains;
 
 		i915_vma_move_to_active(vma, req, vma->exec_entry->flags);
+		eb_export_fence(obj, req, vma->exec_entry->flags);
 		trace_i915_gem_object_change_domain(obj, old_read, old_write);
 	}
 }
-- 
2.8.1

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

  parent reply	other threads:[~2016-08-04  7:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  7:32 [CI 01/26] drm/i915: Combine loops within i915_gem_evict_something Chris Wilson
2016-08-04  7:32 ` [CI 02/26] drm/i915: Remove surplus drm_device parameter to i915_gem_evict_something() Chris Wilson
2016-08-04  7:32 ` [CI 03/26] drm/i915: Double check the active status on the batch pool Chris Wilson
2016-08-04  7:32 ` [CI 04/26] drm/i915: Remove request retirement before each batch Chris Wilson
2016-08-04  7:32 ` [CI 05/26] drm/i915: Remove i915_gem_execbuffer_retire_commands() Chris Wilson
2016-08-04  7:32 ` [CI 06/26] drm/i915: Fix up vma alignment to be u64 Chris Wilson
2016-08-04  7:32 ` [CI 07/26] drm/i915: Pad GTT views of exec objects up to user specified size Chris Wilson
2016-08-04  7:32 ` [CI 08/26] drm/i915: Reduce WARN(i915_gem_valid_gtt_space) to a debug-only check Chris Wilson
2016-08-04  7:32 ` [CI 09/26] drm/i915: Split insertion/binding of an object into the VM Chris Wilson
2016-08-04  7:32 ` [CI 10/26] drm/i915: Convert 4096 alignment request to 0 for drm_mm allocations Chris Wilson
2016-08-04  7:33 ` [CI 11/26] drm/i915: Update the GGTT size/alignment query functions Chris Wilson
2016-08-04  7:33 ` [CI 12/26] drm/i915: Update i915_gem_get_ggtt_size/_alignment to use drm_i915_private Chris Wilson
2016-08-04  7:33 ` [CI 13/26] drm/i915: Record allocated vma size Chris Wilson
2016-08-04  7:33 ` [CI 14/26] drm/i915: Wrap vma->pin_count accessors with small inline helpers Chris Wilson
2016-08-04  7:33 ` [CI 15/26] drm/i915: Start passing around i915_vma from execbuffer Chris Wilson
2016-08-04  7:33 ` [CI 16/26] drm/i915: Combine all i915_vma bitfields into a single set of flags Chris Wilson
2016-08-04  7:33 ` [CI 17/26] drm/i915: Make i915_vma_pin() small and inline Chris Wilson
2016-08-04  7:33 ` [CI 18/26] drm/i915: Remove highly confusing i915_gem_obj_ggtt_pin() Chris Wilson
2016-08-04  7:33 ` [CI 19/26] drm/i915: Separate intel_frontbuffer into its own header Chris Wilson
2016-08-04  7:33 ` [CI 20/26] drm/i915: Make fb_tracking.lock a spinlock Chris Wilson
2016-08-04  7:33 ` [CI 21/26] drm/i915: Use atomics to manipulate obj->frontbuffer_bits Chris Wilson
2016-08-04  7:33 ` [CI 22/26] drm/i915: Use dev_priv consistently through the intel_frontbuffer interface Chris Wilson
2016-08-04  7:33 ` [CI 23/26] drm/i915: Move obj->active:5 to obj->flags Chris Wilson
2016-08-04  7:33 ` [CI 24/26] drm/i915: Move i915_gem_object_wait_rendering() Chris Wilson
2016-08-04  7:33 ` [CI 25/26] drm/i915: Enable lockless lookup of request tracking via RCU Chris Wilson
2016-08-04  7:33 ` Chris Wilson [this message]
2016-08-04  8:15 ` ✗ Ro.CI.BAT: failure for series starting with [CI,01/26] drm/i915: Combine loops within i915_gem_evict_something Patchwork
2016-08-04 15:32 [CI 01/26] " Chris Wilson
2016-08-04 15:32 ` [CI 26/26] drm/i915: Export our request as a dma-buf fence on the reservation object Chris Wilson

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=1470295995-9669-26-git-send-email-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.