drm/i915: Refactor export_fence() after i915_vma_move_to_active()
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 6 Jul 2018 10:39:42 +0000 (11:39 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 6 Jul 2018 17:22:34 +0000 (18:22 +0100)
Currently all callers are responsible for adding the vma to the active
timeline and then exporting its fence. Combine the two operations into
i915_vma_move_to_active() to move all the extra handling from the
callers to the single site.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180706103947.15919-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/i915/selftests/huge_pages.c
drivers/gpu/drm/i915/selftests/i915_gem_coherency.c
drivers/gpu/drm/i915/selftests/i915_gem_context.c
drivers/gpu/drm/i915/selftests/i915_gem_object.c
drivers/gpu/drm/i915/selftests/intel_workarounds.c

index c2dd9b4cdaceac299fc43c831caa512556b0519a..91f20445147f1c4dbd32c80dec816670627aaa52 100644 (file)
@@ -1166,15 +1166,9 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
 
        GEM_BUG_ON(!reservation_object_test_signaled_rcu(batch->resv, true));
        i915_vma_move_to_active(batch, rq, 0);
-       reservation_object_lock(batch->resv, NULL);
-       reservation_object_add_excl_fence(batch->resv, &rq->fence);
-       reservation_object_unlock(batch->resv);
        i915_vma_unpin(batch);
 
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
-       reservation_object_lock(vma->resv, NULL);
-       reservation_object_add_excl_fence(vma->resv, &rq->fence);
-       reservation_object_unlock(vma->resv);
 
        rq->batch = batch;
 
@@ -1771,25 +1765,6 @@ slow:
        return eb_relocate_slow(eb);
 }
 
-static void eb_export_fence(struct i915_vma *vma,
-                           struct i915_request *rq,
-                           unsigned int flags)
-{
-       struct reservation_object *resv = vma->resv;
-
-       /*
-        * 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.
-        */
-       reservation_object_lock(resv, NULL);
-       if (flags & EXEC_OBJECT_WRITE)
-               reservation_object_add_excl_fence(resv, &rq->fence);
-       else if (reservation_object_reserve_shared(resv) == 0)
-               reservation_object_add_shared_fence(resv, &rq->fence);
-       reservation_object_unlock(resv);
-}
-
 static int eb_move_to_gpu(struct i915_execbuffer *eb)
 {
        const unsigned int count = eb->buffer_count;
@@ -1844,7 +1819,6 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb)
                struct i915_vma *vma = eb->vma[i];
 
                i915_vma_move_to_active(vma, eb->request, flags);
-               eb_export_fence(vma, eb->request, flags);
 
                __eb_unreserve_vma(vma, flags);
                vma->exec_flags = NULL;
@@ -1884,6 +1858,25 @@ static bool i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
        return true;
 }
 
+static void export_fence(struct i915_vma *vma,
+                        struct i915_request *rq,
+                        unsigned int flags)
+{
+       struct reservation_object *resv = vma->resv;
+
+       /*
+        * 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.
+        */
+       reservation_object_lock(resv, NULL);
+       if (flags & EXEC_OBJECT_WRITE)
+               reservation_object_add_excl_fence(resv, &rq->fence);
+       else if (reservation_object_reserve_shared(resv) == 0)
+               reservation_object_add_shared_fence(resv, &rq->fence);
+       reservation_object_unlock(resv);
+}
+
 void i915_vma_move_to_active(struct i915_vma *vma,
                             struct i915_request *rq,
                             unsigned int flags)
@@ -1921,6 +1914,8 @@ void i915_vma_move_to_active(struct i915_vma *vma,
 
        if (flags & EXEC_OBJECT_NEEDS_FENCE)
                i915_gem_active_set(&vma->last_fence, rq);
+
+       export_fence(vma, rq, flags);
 }
 
 static int i915_reset_gen7_sol_offsets(struct i915_request *rq)
index ab662dabcff7a6fdfba578e6710c468faad334d5..84bed69f30cc2c6b43741dc7dae5413241e1d1f6 100644 (file)
@@ -998,10 +998,6 @@ static int gpu_write(struct i915_vma *vma,
 
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
 
-       reservation_object_lock(vma->resv, NULL);
-       reservation_object_add_excl_fence(vma->resv, &rq->fence);
-       reservation_object_unlock(vma->resv);
-
 err_request:
        i915_request_add(rq);
 
index 294c58aba2c152a8f106da91c55d5c11794b13d2..97a16311f083102a0f16ade83e992da17821720f 100644 (file)
@@ -225,10 +225,6 @@ static int gpu_set(struct drm_i915_gem_object *obj,
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
        i915_vma_unpin(vma);
 
-       reservation_object_lock(obj->resv, NULL);
-       reservation_object_add_excl_fence(obj->resv, &rq->fence);
-       reservation_object_unlock(obj->resv);
-
        i915_request_add(rq);
 
        return 0;
index 65100d3e31cffcb304ea412e6466f1b663529dc7..c642ab97698ee8d31c65085edb47d95336dbe0e9 100644 (file)
@@ -178,10 +178,6 @@ static int gpu_fill(struct drm_i915_gem_object *obj,
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
        i915_vma_unpin(vma);
 
-       reservation_object_lock(obj->resv, NULL);
-       reservation_object_add_excl_fence(obj->resv, &rq->fence);
-       reservation_object_unlock(obj->resv);
-
        i915_request_add(rq);
 
        return 0;
index 6fe71865b7109c59f5d87b638abde9d92ab91021..b2ccbc5e2bbedce312ee21fa83bd934c69cd9d8d 100644 (file)
@@ -466,10 +466,6 @@ static int make_obj_busy(struct drm_i915_gem_object *obj)
 
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
 
-       reservation_object_lock(vma->resv, NULL);
-       reservation_object_add_excl_fence(vma->resv, &rq->fence);
-       reservation_object_unlock(vma->resv);
-
        i915_request_add(rq);
 
        i915_gem_object_set_active_reference(obj);
index 3d86b90ab7221e55aab8a6544e13da937063bffc..4a9dc01a364a8a40728a77281b1df1991e4a818d 100644 (file)
@@ -68,9 +68,6 @@ read_nonprivs(struct i915_gem_context *ctx, struct intel_engine_cs *engine)
        intel_ring_advance(rq, cs);
 
        i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE);
-       reservation_object_lock(vma->resv, NULL);
-       reservation_object_add_excl_fence(vma->resv, &rq->fence);
-       reservation_object_unlock(vma->resv);
 
        i915_gem_object_get(result);
        i915_gem_object_set_active_reference(result);