[PATCH 5/9] dma-buf/dma-fence: Allow wait_any_timeout without default_wait (v2)
Jason Ekstrand
jason at jlekstrand.net
Fri Aug 11 22:39:30 UTC 2017
dma_fence_wait_any_timeout only relies on two things to work correctly:
1) The callback list to get called upon fence signal
2) The SIGNALED flag to be set upon fence signal
The first if these is part of the core dma-fence API. The second is
only mostly part of the core dma-fence API with the one issue that the
flag may not be set and dma_fence_is_signaled may never return true if
fence->ops->enable_signaling() has not been called. It's easy enough to
work around that by always using dma_fence_is_signaled instead of
manually checking the bit and falling through to a zero-timeout wait if
none of the fences report that they are signaled.
v2:
- Use dma_fence_is_signaled in test_signaled_any
- Fall through to a zero-timeout wait
Cc: Christian König <christian.koenig at amd.com>
Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
drivers/dma-buf/dma-fence.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 9a30279..0cac367 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -437,8 +437,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count,
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 (dma_fence_is_signaled(fences[i])) {
if (idx)
*idx = i;
return true;
@@ -484,7 +483,13 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
return 1;
}
- return 0;
+ /* There's a very annoying laxness in the dma_fence API
+ * here, in that backends are not required to automatically
+ * report when a fence is signaled prior to
+ * fence->ops->enable_signaling() being called. So here if
+ * we fail to match signaled_count, we need to fallthough
+ * and try a 0 timeout wait!
+ */
}
cb = kcalloc(count, sizeof(struct default_wait_cb), GFP_KERNEL);
@@ -496,11 +501,6 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
for (i = 0; i < count; ++i) {
struct dma_fence *fence = fences[i];
- if (fence->ops->wait != dma_fence_default_wait) {
- ret = -EINVAL;
- goto fence_rm_cb;
- }
-
cb[i].task = current;
if (dma_fence_add_callback(fence, &cb[i].base,
dma_fence_default_wait_cb)) {
@@ -511,7 +511,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
}
}
- while (ret > 0) {
+ do {
if (intr)
set_current_state(TASK_INTERRUPTIBLE);
else
@@ -524,7 +524,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
if (ret > 0 && intr && signal_pending(current))
ret = -ERESTARTSYS;
- }
+ } while (ret > 0);
__set_current_state(TASK_RUNNING);
--
2.5.0.400.gff86faf
More information about the dri-devel
mailing list