dma-buf: return index of the first signaled fence (v2)
authormonk.liu <monk.liu@amd.com>
Fri, 4 Nov 2016 20:16:09 +0000 (16:16 -0400)
committerSumit Semwal <sumit.semwal@linaro.org>
Tue, 8 Nov 2016 18:42:00 +0000 (00:12 +0530)
Return the index of the first signaled fence.  This information
is useful in some APIs like Vulkan.

v2: rebase on drm-next (fence -> dma_fence)

Signed-off-by: monk.liu <monk.liu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
 [sumits: fix warnings]
Link: http://patchwork.freedesktop.org/patch/msgid/1478290570-30982-1-git-send-email-alexander.deucher@amd.com
drivers/dma-buf/dma-fence.c
include/linux/dma-fence.h

index 3a7bf009c21cd45ff402059a3b340855de33e354..cda40cbd8c43f293e5f0a8140fd036ceab0c1327 100644 (file)
@@ -403,14 +403,18 @@ out:
 EXPORT_SYMBOL(dma_fence_default_wait);
 
 static bool
-dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count)
+dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count,
+                           uint32_t *idx)
 {
        int i;
 
        for (i = 0; i < count; ++i) {
                struct dma_fence *fence = fences[i];
-               if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
+               if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+                       if (idx)
+                               *idx = i;
                        return true;
+               }
        }
        return false;
 }
@@ -422,6 +426,8 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count)
  * @count:     [in]    number of fences to wait on
  * @intr:      [in]    if true, do an interruptible wait
  * @timeout:   [in]    timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT
+ * @idx:       [out]   the first signaled fence index, meaningful only on
+ *                     positive return
  *
  * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if
  * interrupted, 0 if the wait timed out, or the remaining timeout in jiffies
@@ -433,7 +439,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count)
  */
 signed long
 dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
-                          bool intr, signed long timeout)
+                          bool intr, signed long timeout, uint32_t *idx)
 {
        struct default_wait_cb *cb;
        signed long ret = timeout;
@@ -444,8 +450,11 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 
        if (timeout == 0) {
                for (i = 0; i < count; ++i)
-                       if (dma_fence_is_signaled(fences[i]))
+                       if (dma_fence_is_signaled(fences[i])) {
+                               if (idx)
+                                       *idx = i;
                                return 1;
+                       }
 
                return 0;
        }
@@ -468,6 +477,8 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
                if (dma_fence_add_callback(fence, &cb[i].base,
                                           dma_fence_default_wait_cb)) {
                        /* This fence is already signaled */
+                       if (idx)
+                               *idx = i;
                        goto fence_rm_cb;
                }
        }
@@ -478,7 +489,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
                else
                        set_current_state(TASK_UNINTERRUPTIBLE);
 
-               if (dma_fence_test_signaled_any(fences, count))
+               if (dma_fence_test_signaled_any(fences, count, idx))
                        break;
 
                ret = schedule_timeout(ret);
index ba60c043a5d3bffda6a69c53690f726e9f29eaf3..fcf4b1971eba178277612e7770988cb66a3b2e83 100644 (file)
@@ -382,7 +382,8 @@ signed long dma_fence_wait_timeout(struct dma_fence *,
                                   bool intr, signed long timeout);
 signed long dma_fence_wait_any_timeout(struct dma_fence **fences,
                                       uint32_t count,
-                                      bool intr, signed long timeout);
+                                      bool intr, signed long timeout,
+                                      uint32_t *idx);
 
 /**
  * dma_fence_wait - sleep until the fence gets signaled