Skip to contentSkip to conversation

dma-buf/fence: make timeout handling in fence_default_wait consistent

PATCH In review Christian König 2 participants 4 messages Oct 17, 2016 – Oct 18, 2016 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dma-buf/fence: make timeout handling in fence_default_wait consistent

From: Christian König <[email protected]>

Kernel functions taking a timeout usually return 1 on success even when they get a zero timeout.

---
 drivers/dma-buf/fence.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma-buf/fence.c +5 -3
index 4d51f9e..fb915ab 100644
@@ -335,18 +335,20 @@ fence_default_wait_cb(struct fence *fence, struct fence_cb *cb)
  * @timeout:	[in]	timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT
  *
  * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or the
- * remaining timeout in jiffies on success.
+ * remaining timeout in jiffies on success. If timeout is zero the value one is
+ * returned if the fence is already signaled for consistency with other
+ * functions taking a jiffies timeout.
  */
 signed long
 fence_default_wait(struct fence *fence, bool intr, signed long timeout)
 {
 	struct default_wait_cb cb;
 	unsigned long flags;
-	signed long ret = timeout;
+	signed long ret = timeout ? timeout : 1;
 	bool was_set;
 
 	if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
-		return timeout;
+		return ret;
 
 	spin_lock_irqsave(fence->lock, flags);
 
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/3 dma-buf/fence: revert "don't wait when specified timeout is zero"

From: Christian König <[email protected]>

This reverts commit 847b19a39e4c9b5e74c40f0842c48b41664cb43c.

When we don't call the wait function software signaling might never be activated. This can cause infinite polling loops with unreliable interrupt driven hardware.

---
 drivers/dma-buf/fence.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/dma-buf/fence.c +0 -3
index fb915ab..64478f9 100644
@@ -159,9 +159,6 @@ fence_wait_timeout(struct fence *fence, bool intr, signed long timeout)
 	if (WARN_ON(timeout < 0))
 		return -EINVAL;
 
-	if (timeout == 0)
-		return fence_is_signaled(fence);
-
 	trace_fence_wait_start(fence);
 	ret = fence->ops->wait(fence, intr, timeout);
 	trace_fence_wait_end(fence);
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 3/3 reservation: revert "wait only with non-zero timeout specified (v3)"

In reply to Christian König

From: Christian König <[email protected]>

This reverts commit fb8b7d2b9d80e1e71f379e57355936bd2b024be9.

Otherwise signaling might never be activated on the fences. This can result in infinite waiting with hardware which has unreliable interrupts.

---
 drivers/dma-buf/reservation.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/dma-buf/reservation.c +0 -3
index 9566a62..bb97b04 100644
@@ -381,9 +381,6 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 	unsigned seq, shared_count, i = 0;
 	long ret = timeout;
 
-	if (!timeout)
-		return reservation_object_test_signaled_rcu(obj, wait_all);
-
 retry:
 	fence = NULL;
 	shared_count = 0;
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
In reply to Christian König
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Kernel functions taking a timeout usually return 1 on success even when they get a zero timeout.

The series is Reviewed-by: Chunming Zhou <[email protected]>

Quoted 22 lines
---
  drivers/dma-buf/fence.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma-buf/fence.c +3 -1
index 4d51f9e..fb915ab 100644
@@ -335,18 +335,20 @@ fence_default_wait_cb(struct fence *fence, struct fence_cb *cb)
   * @timeout:	[in]	timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT
   *
   * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or the
- * remaining timeout in jiffies on success.
+ * remaining timeout in jiffies on success. If timeout is zero the value one is
+ * returned if the fence is already signaled for consistency with other
+ * functions taking a jiffies timeout.
   */
  signed long
  fence_default_wait(struct fence *fence, bool intr, signed long timeout)
  {
  	struct default_wait_cb cb;
  	unsigned long flags;

drivers/dma-buf/fence.c fence_default_wait_cb(struct fence *fence, struct fence_cb *cb) · line 354

Quoted 10 lines
drivers/dma-buf/fence.c +2 -2
-	signed long ret = timeout;
+	signed long ret = timeout ? timeout : 1;
  	bool was_set;
 
  	if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
-		return timeout;
+		return ret;
 
  	spin_lock_irqsave(fence->lock, flags);
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel