drm/amdgpu: add amdgpu_sync_clone
authorFelix Kuehling <Felix.Kuehling@amd.com>
Wed, 7 Feb 2018 01:32:37 +0000 (20:32 -0500)
committerOded Gabbay <oded.gabbay@gmail.com>
Wed, 7 Feb 2018 01:32:37 +0000 (20:32 -0500)
Cloning a sync object is useful for waiting for a sync object
without locking the original structure indefinitely, blocking
other threads.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Acked-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h

index b8d3b87fd43e94b65d5b09a344043272c0b476bd..2d6f5ec77a687a0a905bd15e222b3215d2273c29 100644 (file)
@@ -322,6 +322,41 @@ struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit
        return NULL;
 }
 
+/**
+ * amdgpu_sync_clone - clone a sync object
+ *
+ * @source: sync object to clone
+ * @clone: pointer to destination sync object
+ *
+ * Adds references to all unsignaled fences in @source to @clone. Also
+ * removes signaled fences from @source while at it.
+ */
+int amdgpu_sync_clone(struct amdgpu_sync *source, struct amdgpu_sync *clone)
+{
+       struct amdgpu_sync_entry *e;
+       struct hlist_node *tmp;
+       struct dma_fence *f;
+       int i, r;
+
+       hash_for_each_safe(source->fences, i, tmp, e, node) {
+               f = e->fence;
+               if (!dma_fence_is_signaled(f)) {
+                       r = amdgpu_sync_fence(NULL, clone, f, e->explicit);
+                       if (r)
+                               return r;
+               } else {
+                       hash_del(&e->node);
+                       dma_fence_put(f);
+                       kmem_cache_free(amdgpu_sync_slab, e);
+               }
+       }
+
+       dma_fence_put(clone->last_vm_update);
+       clone->last_vm_update = dma_fence_get(source->last_vm_update);
+
+       return 0;
+}
+
 int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr)
 {
        struct amdgpu_sync_entry *e;
index 7aba38d5c9dff7c316338f0cf02ce5606dbd4850..10cf23a57f172756d7f3c9dc681bf4b8b421ac44 100644 (file)
@@ -50,6 +50,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev,
 struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
                                     struct amdgpu_ring *ring);
 struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync, bool *explicit);
+int amdgpu_sync_clone(struct amdgpu_sync *source, struct amdgpu_sync *clone);
 int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr);
 void amdgpu_sync_free(struct amdgpu_sync *sync);
 int amdgpu_sync_init(void);