All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] reservation: don't wait when timeout=0
@ 2017-11-21 14:08 Rob Clark
  2017-11-21 14:27   ` Christian König
  2017-11-21 14:38 ` Chris Wilson
  0 siblings, 2 replies; 11+ messages in thread
From: Rob Clark @ 2017-11-21 14:08 UTC (permalink / raw)
  To: dri-devel
  Cc: Rob Clark, Sumit Semwal, linux-media, linaro-mm-sig, linux-kernel

If we are testing if a reservation object's fences have been
signaled with timeout=0 (non-blocking), we need to pass 0 for
timeout to dma_fence_wait_timeout().

Plus bonus spelling correction.

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 drivers/dma-buf/reservation.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index dec3a815455d..71f51140a9ad 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
  *
  * RETURNS
  * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
- * greater than zer on success.
+ * greater than zero on success.
  */
 long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 					 bool wait_all, bool intr,
@@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 			goto retry;
 		}
 
-		ret = dma_fence_wait_timeout(fence, intr, ret);
+		/*
+		 * Note that dma_fence_wait_timeout() will return 1 if
+		 * the fence is already signaled, so in the wait_all
+		 * case when we go through the retry loop again, ret
+		 * will be greater than 0 and we don't want this to
+		 * cause _wait_timeout() to block
+		 */
+		ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
 		dma_fence_put(fence);
 		if (ret > 0 && wait_all && (i + 1 < shared_count))
 			goto retry;
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 14:08 [PATCH] reservation: don't wait when timeout=0 Rob Clark
@ 2017-11-21 14:27   ` Christian König
  2017-11-21 14:38 ` Chris Wilson
  1 sibling, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 14:27 UTC (permalink / raw)
  To: Rob Clark, dri-devel; +Cc: linaro-mm-sig, linux-kernel, linux-media

Am 21.11.2017 um 15:08 schrieb Rob Clark:
> If we are testing if a reservation object's fences have been
> signaled with timeout=0 (non-blocking), we need to pass 0 for
> timeout to dma_fence_wait_timeout().
>
> Plus bonus spelling correction.
>
> Signed-off-by: Rob Clark <robdclark@gmail.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/dma-buf/reservation.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> index dec3a815455d..71f51140a9ad 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>    *
>    * RETURNS
>    * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
> - * greater than zer on success.
> + * greater than zero on success.
>    */
>   long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>   					 bool wait_all, bool intr,
> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>   			goto retry;
>   		}
>   
> -		ret = dma_fence_wait_timeout(fence, intr, ret);
> +		/*
> +		 * Note that dma_fence_wait_timeout() will return 1 if
> +		 * the fence is already signaled, so in the wait_all
> +		 * case when we go through the retry loop again, ret
> +		 * will be greater than 0 and we don't want this to
> +		 * cause _wait_timeout() to block
> +		 */
> +		ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>   		dma_fence_put(fence);
>   		if (ret > 0 && wait_all && (i + 1 < shared_count))
>   			goto retry;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
@ 2017-11-21 14:27   ` Christian König
  0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 14:27 UTC (permalink / raw)
  To: Rob Clark, dri-devel; +Cc: linaro-mm-sig, linux-kernel, linux-media

Am 21.11.2017 um 15:08 schrieb Rob Clark:
> If we are testing if a reservation object's fences have been
> signaled with timeout=0 (non-blocking), we need to pass 0 for
> timeout to dma_fence_wait_timeout().
>
> Plus bonus spelling correction.
>
> Signed-off-by: Rob Clark <robdclark@gmail.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/dma-buf/reservation.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> index dec3a815455d..71f51140a9ad 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>    *
>    * RETURNS
>    * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
> - * greater than zer on success.
> + * greater than zero on success.
>    */
>   long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>   					 bool wait_all, bool intr,
> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>   			goto retry;
>   		}
>   
> -		ret = dma_fence_wait_timeout(fence, intr, ret);
> +		/*
> +		 * Note that dma_fence_wait_timeout() will return 1 if
> +		 * the fence is already signaled, so in the wait_all
> +		 * case when we go through the retry loop again, ret
> +		 * will be greater than 0 and we don't want this to
> +		 * cause _wait_timeout() to block
> +		 */
> +		ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>   		dma_fence_put(fence);
>   		if (ret > 0 && wait_all && (i + 1 < shared_count))
>   			goto retry;


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 14:08 [PATCH] reservation: don't wait when timeout=0 Rob Clark
  2017-11-21 14:27   ` Christian König
@ 2017-11-21 14:38 ` Chris Wilson
  2017-11-21 14:59     ` Rob Clark
  1 sibling, 1 reply; 11+ messages in thread
From: Chris Wilson @ 2017-11-21 14:38 UTC (permalink / raw)
  To: Rob Clark, dri-devel; +Cc: linaro-mm-sig, linux-kernel, linux-media

Quoting Rob Clark (2017-11-21 14:08:46)
> If we are testing if a reservation object's fences have been
> signaled with timeout=0 (non-blocking), we need to pass 0 for
> timeout to dma_fence_wait_timeout().
> 
> Plus bonus spelling correction.
> 
> Signed-off-by: Rob Clark <robdclark@gmail.com>
> ---
>  drivers/dma-buf/reservation.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> index dec3a815455d..71f51140a9ad 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>   *
>   * RETURNS
>   * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
> - * greater than zer on success.
> + * greater than zero on success.
>   */
>  long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>                                          bool wait_all, bool intr,
> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>                         goto retry;
>                 }
>  
> -               ret = dma_fence_wait_timeout(fence, intr, ret);
> +               /*
> +                * Note that dma_fence_wait_timeout() will return 1 if
> +                * the fence is already signaled, so in the wait_all
> +                * case when we go through the retry loop again, ret
> +                * will be greater than 0 and we don't want this to
> +                * cause _wait_timeout() to block
> +                */
> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);

One should ask if we should just fix the interface to stop returning
incorrect results (stop "correcting" a completion with 0 jiffies remaining
as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
-Chris

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 14:38 ` Chris Wilson
@ 2017-11-21 14:59     ` Rob Clark
  0 siblings, 0 replies; 11+ messages in thread
From: Rob Clark @ 2017-11-21 14:59 UTC (permalink / raw)
  To: Chris Wilson
  Cc: dri-devel, linaro-mm-sig, Linux Kernel Mailing List, linux-media

On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> Quoting Rob Clark (2017-11-21 14:08:46)
>> If we are testing if a reservation object's fences have been
>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>> timeout to dma_fence_wait_timeout().
>>
>> Plus bonus spelling correction.
>>
>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>> ---
>>  drivers/dma-buf/reservation.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>> index dec3a815455d..71f51140a9ad 100644
>> --- a/drivers/dma-buf/reservation.c
>> +++ b/drivers/dma-buf/reservation.c
>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>   *
>>   * RETURNS
>>   * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>> - * greater than zer on success.
>> + * greater than zero on success.
>>   */
>>  long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>                                          bool wait_all, bool intr,
>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>                         goto retry;
>>                 }
>>
>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>> +               /*
>> +                * Note that dma_fence_wait_timeout() will return 1 if
>> +                * the fence is already signaled, so in the wait_all
>> +                * case when we go through the retry loop again, ret
>> +                * will be greater than 0 and we don't want this to
>> +                * cause _wait_timeout() to block
>> +                */
>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>
> One should ask if we should just fix the interface to stop returning
> incorrect results (stop "correcting" a completion with 0 jiffies remaining
> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).

perhaps -EBUSY, if we go that route (although maybe it should be a
follow-on patch, this one is suitable for backport to stable/lts if
one should so choose..)

I think current approach was chosen to match schedule_timeout() and
other such functions that take a timeout in jiffies.  Not making a
judgement on whether that is a good or bad reason..

BR,
-R

> -Chris

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
@ 2017-11-21 14:59     ` Rob Clark
  0 siblings, 0 replies; 11+ messages in thread
From: Rob Clark @ 2017-11-21 14:59 UTC (permalink / raw)
  To: Chris Wilson
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> Quoting Rob Clark (2017-11-21 14:08:46)
>> If we are testing if a reservation object's fences have been
>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>> timeout to dma_fence_wait_timeout().
>>
>> Plus bonus spelling correction.
>>
>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>> ---
>>  drivers/dma-buf/reservation.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>> index dec3a815455d..71f51140a9ad 100644
>> --- a/drivers/dma-buf/reservation.c
>> +++ b/drivers/dma-buf/reservation.c
>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>   *
>>   * RETURNS
>>   * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>> - * greater than zer on success.
>> + * greater than zero on success.
>>   */
>>  long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>                                          bool wait_all, bool intr,
>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>                         goto retry;
>>                 }
>>
>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>> +               /*
>> +                * Note that dma_fence_wait_timeout() will return 1 if
>> +                * the fence is already signaled, so in the wait_all
>> +                * case when we go through the retry loop again, ret
>> +                * will be greater than 0 and we don't want this to
>> +                * cause _wait_timeout() to block
>> +                */
>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>
> One should ask if we should just fix the interface to stop returning
> incorrect results (stop "correcting" a completion with 0 jiffies remaining
> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).

perhaps -EBUSY, if we go that route (although maybe it should be a
follow-on patch, this one is suitable for backport to stable/lts if
one should so choose..)

I think current approach was chosen to match schedule_timeout() and
other such functions that take a timeout in jiffies.  Not making a
judgement on whether that is a good or bad reason..

BR,
-R

> -Chris
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 14:59     ` Rob Clark
@ 2017-11-21 15:49       ` Christian König
  -1 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 15:49 UTC (permalink / raw)
  To: Rob Clark, Chris Wilson
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

Am 21.11.2017 um 15:59 schrieb Rob Clark:
> On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> Quoting Rob Clark (2017-11-21 14:08:46)
>>> If we are testing if a reservation object's fences have been
>>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>>> timeout to dma_fence_wait_timeout().
>>>
>>> Plus bonus spelling correction.
>>>
>>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>>> ---
>>>   drivers/dma-buf/reservation.c | 11 +++++++++--
>>>   1 file changed, 9 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>>> index dec3a815455d..71f51140a9ad 100644
>>> --- a/drivers/dma-buf/reservation.c
>>> +++ b/drivers/dma-buf/reservation.c
>>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>>    *
>>>    * RETURNS
>>>    * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>>> - * greater than zer on success.
>>> + * greater than zero on success.
>>>    */
>>>   long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>                                           bool wait_all, bool intr,
>>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>                          goto retry;
>>>                  }
>>>
>>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>>> +               /*
>>> +                * Note that dma_fence_wait_timeout() will return 1 if
>>> +                * the fence is already signaled, so in the wait_all
>>> +                * case when we go through the retry loop again, ret
>>> +                * will be greater than 0 and we don't want this to
>>> +                * cause _wait_timeout() to block
>>> +                */
>>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>> One should ask if we should just fix the interface to stop returning
>> incorrect results (stop "correcting" a completion with 0 jiffies remaining
>> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
> perhaps -EBUSY, if we go that route (although maybe it should be a
> follow-on patch, this one is suitable for backport to stable/lts if
> one should so choose..)
>
> I think current approach was chosen to match schedule_timeout() and
> other such functions that take a timeout in jiffies.  Not making a
> judgement on whether that is a good or bad reason..

We intentionally switched away from that to be in sync with the 
wait_event_* interface.

Returning 1 when a function with a zero timeout succeeds is actually 
quite common in the kernel.

Regards,
Christian.

> BR,
> -R
>
>> -Chris
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
@ 2017-11-21 15:49       ` Christian König
  0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 15:49 UTC (permalink / raw)
  To: Rob Clark, Chris Wilson
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

Am 21.11.2017 um 15:59 schrieb Rob Clark:
> On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> Quoting Rob Clark (2017-11-21 14:08:46)
>>> If we are testing if a reservation object's fences have been
>>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>>> timeout to dma_fence_wait_timeout().
>>>
>>> Plus bonus spelling correction.
>>>
>>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>>> ---
>>>   drivers/dma-buf/reservation.c | 11 +++++++++--
>>>   1 file changed, 9 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>>> index dec3a815455d..71f51140a9ad 100644
>>> --- a/drivers/dma-buf/reservation.c
>>> +++ b/drivers/dma-buf/reservation.c
>>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>>    *
>>>    * RETURNS
>>>    * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>>> - * greater than zer on success.
>>> + * greater than zero on success.
>>>    */
>>>   long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>                                           bool wait_all, bool intr,
>>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>                          goto retry;
>>>                  }
>>>
>>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>>> +               /*
>>> +                * Note that dma_fence_wait_timeout() will return 1 if
>>> +                * the fence is already signaled, so in the wait_all
>>> +                * case when we go through the retry loop again, ret
>>> +                * will be greater than 0 and we don't want this to
>>> +                * cause _wait_timeout() to block
>>> +                */
>>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>> One should ask if we should just fix the interface to stop returning
>> incorrect results (stop "correcting" a completion with 0 jiffies remaining
>> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
> perhaps -EBUSY, if we go that route (although maybe it should be a
> follow-on patch, this one is suitable for backport to stable/lts if
> one should so choose..)
>
> I think current approach was chosen to match schedule_timeout() and
> other such functions that take a timeout in jiffies.  Not making a
> judgement on whether that is a good or bad reason..

We intentionally switched away from that to be in sync with the 
wait_event_* interface.

Returning 1 when a function with a zero timeout succeeds is actually 
quite common in the kernel.

Regards,
Christian.

> BR,
> -R
>
>> -Chris
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 15:49       ` Christian König
  (?)
@ 2017-11-21 15:58       ` Chris Wilson
  2017-11-21 16:11           ` Christian König
  -1 siblings, 1 reply; 11+ messages in thread
From: Chris Wilson @ 2017-11-21 15:58 UTC (permalink / raw)
  To: christian.koenig, Christian König, Rob Clark
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

Quoting Christian König (2017-11-21 15:49:55)
> Am 21.11.2017 um 15:59 schrieb Rob Clark:
> > On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >> Quoting Rob Clark (2017-11-21 14:08:46)
> >>> If we are testing if a reservation object's fences have been
> >>> signaled with timeout=0 (non-blocking), we need to pass 0 for
> >>> timeout to dma_fence_wait_timeout().
> >>>
> >>> Plus bonus spelling correction.
> >>>
> >>> Signed-off-by: Rob Clark <robdclark@gmail.com>
> >>> ---
> >>>   drivers/dma-buf/reservation.c | 11 +++++++++--
> >>>   1 file changed, 9 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> >>> index dec3a815455d..71f51140a9ad 100644
> >>> --- a/drivers/dma-buf/reservation.c
> >>> +++ b/drivers/dma-buf/reservation.c
> >>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
> >>>    *
> >>>    * RETURNS
> >>>    * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
> >>> - * greater than zer on success.
> >>> + * greater than zero on success.
> >>>    */
> >>>   long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
> >>>                                           bool wait_all, bool intr,
> >>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
> >>>                          goto retry;
> >>>                  }
> >>>
> >>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
> >>> +               /*
> >>> +                * Note that dma_fence_wait_timeout() will return 1 if
> >>> +                * the fence is already signaled, so in the wait_all
> >>> +                * case when we go through the retry loop again, ret
> >>> +                * will be greater than 0 and we don't want this to
> >>> +                * cause _wait_timeout() to block
> >>> +                */
> >>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
> >> One should ask if we should just fix the interface to stop returning
> >> incorrect results (stop "correcting" a completion with 0 jiffies remaining
> >> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
> > perhaps -EBUSY, if we go that route (although maybe it should be a
> > follow-on patch, this one is suitable for backport to stable/lts if
> > one should so choose..)
> >
> > I think current approach was chosen to match schedule_timeout() and
> > other such functions that take a timeout in jiffies.  Not making a
> > judgement on whether that is a good or bad reason..
> 
> We intentionally switched away from that to be in sync with the 
> wait_event_* interface.
> 
> Returning 1 when a function with a zero timeout succeeds is actually 
> quite common in the kernel.

We actually had this conversation last time, and outside of that it
isn't. Looking at all the convolution to first return 1, then undo the
damage in the caller, it looks pretty silly.
-Chris

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
  2017-11-21 15:58       ` Chris Wilson
@ 2017-11-21 16:11           ` Christian König
  0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 16:11 UTC (permalink / raw)
  To: Chris Wilson, christian.koenig, Rob Clark
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

Am 21.11.2017 um 16:58 schrieb Chris Wilson:
> Quoting Christian König (2017-11-21 15:49:55)
>> Am 21.11.2017 um 15:59 schrieb Rob Clark:
>>> On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>>>> Quoting Rob Clark (2017-11-21 14:08:46)
>>>>> If we are testing if a reservation object's fences have been
>>>>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>>>>> timeout to dma_fence_wait_timeout().
>>>>>
>>>>> Plus bonus spelling correction.
>>>>>
>>>>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>>>>> ---
>>>>>    drivers/dma-buf/reservation.c | 11 +++++++++--
>>>>>    1 file changed, 9 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>>>>> index dec3a815455d..71f51140a9ad 100644
>>>>> --- a/drivers/dma-buf/reservation.c
>>>>> +++ b/drivers/dma-buf/reservation.c
>>>>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>>>>     *
>>>>>     * RETURNS
>>>>>     * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>>>>> - * greater than zer on success.
>>>>> + * greater than zero on success.
>>>>>     */
>>>>>    long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>>>                                            bool wait_all, bool intr,
>>>>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>>>                           goto retry;
>>>>>                   }
>>>>>
>>>>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>>>>> +               /*
>>>>> +                * Note that dma_fence_wait_timeout() will return 1 if
>>>>> +                * the fence is already signaled, so in the wait_all
>>>>> +                * case when we go through the retry loop again, ret
>>>>> +                * will be greater than 0 and we don't want this to
>>>>> +                * cause _wait_timeout() to block
>>>>> +                */
>>>>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>>>> One should ask if we should just fix the interface to stop returning
>>>> incorrect results (stop "correcting" a completion with 0 jiffies remaining
>>>> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
>>> perhaps -EBUSY, if we go that route (although maybe it should be a
>>> follow-on patch, this one is suitable for backport to stable/lts if
>>> one should so choose..)
>>>
>>> I think current approach was chosen to match schedule_timeout() and
>>> other such functions that take a timeout in jiffies.  Not making a
>>> judgement on whether that is a good or bad reason..
>> We intentionally switched away from that to be in sync with the
>> wait_event_* interface.
>>
>> Returning 1 when a function with a zero timeout succeeds is actually
>> quite common in the kernel.
> We actually had this conversation last time, and outside of that it
> isn't. Looking at all the convolution to first return 1, then undo the
> damage in the caller, it looks pretty silly.

I don't find that very intuitive either, but you would also have to 
handle the error code in the calling function as well.

And it is what the whole kernel does all over the place with it's 
wait_event_* and scheduler timeouts as well.

Regards,
Christian.

> -Chris

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] reservation: don't wait when timeout=0
@ 2017-11-21 16:11           ` Christian König
  0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2017-11-21 16:11 UTC (permalink / raw)
  To: Chris Wilson, christian.koenig, Rob Clark
  Cc: linaro-mm-sig, Linux Kernel Mailing List, dri-devel, linux-media

Am 21.11.2017 um 16:58 schrieb Chris Wilson:
> Quoting Christian König (2017-11-21 15:49:55)
>> Am 21.11.2017 um 15:59 schrieb Rob Clark:
>>> On Tue, Nov 21, 2017 at 9:38 AM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>>>> Quoting Rob Clark (2017-11-21 14:08:46)
>>>>> If we are testing if a reservation object's fences have been
>>>>> signaled with timeout=0 (non-blocking), we need to pass 0 for
>>>>> timeout to dma_fence_wait_timeout().
>>>>>
>>>>> Plus bonus spelling correction.
>>>>>
>>>>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>>>>> ---
>>>>>    drivers/dma-buf/reservation.c | 11 +++++++++--
>>>>>    1 file changed, 9 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
>>>>> index dec3a815455d..71f51140a9ad 100644
>>>>> --- a/drivers/dma-buf/reservation.c
>>>>> +++ b/drivers/dma-buf/reservation.c
>>>>> @@ -420,7 +420,7 @@ EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu);
>>>>>     *
>>>>>     * RETURNS
>>>>>     * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
>>>>> - * greater than zer on success.
>>>>> + * greater than zero on success.
>>>>>     */
>>>>>    long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>>>                                            bool wait_all, bool intr,
>>>>> @@ -483,7 +483,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
>>>>>                           goto retry;
>>>>>                   }
>>>>>
>>>>> -               ret = dma_fence_wait_timeout(fence, intr, ret);
>>>>> +               /*
>>>>> +                * Note that dma_fence_wait_timeout() will return 1 if
>>>>> +                * the fence is already signaled, so in the wait_all
>>>>> +                * case when we go through the retry loop again, ret
>>>>> +                * will be greater than 0 and we don't want this to
>>>>> +                * cause _wait_timeout() to block
>>>>> +                */
>>>>> +               ret = dma_fence_wait_timeout(fence, intr, timeout ? ret : 0);
>>>> One should ask if we should just fix the interface to stop returning
>>>> incorrect results (stop "correcting" a completion with 0 jiffies remaining
>>>> as 1). A timeout can be distinguished by -ETIME (or your pick of errno).
>>> perhaps -EBUSY, if we go that route (although maybe it should be a
>>> follow-on patch, this one is suitable for backport to stable/lts if
>>> one should so choose..)
>>>
>>> I think current approach was chosen to match schedule_timeout() and
>>> other such functions that take a timeout in jiffies.  Not making a
>>> judgement on whether that is a good or bad reason..
>> We intentionally switched away from that to be in sync with the
>> wait_event_* interface.
>>
>> Returning 1 when a function with a zero timeout succeeds is actually
>> quite common in the kernel.
> We actually had this conversation last time, and outside of that it
> isn't. Looking at all the convolution to first return 1, then undo the
> damage in the caller, it looks pretty silly.

I don't find that very intuitive either, but you would also have to 
handle the error code in the calling function as well.

And it is what the whole kernel does all over the place with it's 
wait_event_* and scheduler timeouts as well.

Regards,
Christian.

> -Chris


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-21 16:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-21 14:08 [PATCH] reservation: don't wait when timeout=0 Rob Clark
2017-11-21 14:27 ` Christian König
2017-11-21 14:27   ` Christian König
2017-11-21 14:38 ` Chris Wilson
2017-11-21 14:59   ` Rob Clark
2017-11-21 14:59     ` Rob Clark
2017-11-21 15:49     ` Christian König
2017-11-21 15:49       ` Christian König
2017-11-21 15:58       ` Chris Wilson
2017-11-21 16:11         ` Christian König
2017-11-21 16:11           ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.