[PATCH] drm/syncobj: call drm_syncobj_fence_add_wait when, WAIT_AVAILABLE flag is set

Daniel Vetter daniel at ffwll.ch
Thu Jan 18 14:10:25 UTC 2024


On Fri, Jan 12, 2024 at 02:19:00PM -0800, Erik Kurzinger wrote:
> When waiting for a syncobj timeline point whose fence has not yet been
> submitted with the WAIT_FOR_SUBMIT flag, a callback is registered using
> drm_syncobj_fence_add_wait and the thread is put to sleep until the
> timeout expires. If the fence is submitted before then,
> drm_syncobj_add_point will wake up the sleeping thread immediately which
> will proceed to wait for the fence to be signaled.
> 
> However, if the WAIT_AVAILABLE flag is used instead,
> drm_syncobj_fence_add_wait won't get called, meaning the waiting thread
> will always sleep for the full timeout duration, even if the fence gets
> submitted earlier. If it turns out that the fence *has* been submitted
> by the time it eventually wakes up, it will still indicate to userspace
> that the wait completed successfully (it won't return -ETIME), but it
> will have taken much longer than it should have.
> 
> To fix this, we must call drm_syncobj_fence_add_wait if *either* the
> WAIT_FOR_SUBMIT flag or the WAIT_AVAILABLE flag is set. The only
> difference being that with WAIT_FOR_SUBMIT we will also wait for the
> fence to be signaled after it has been submitted while with
> WAIT_AVAILABLE we will return immediately.
> 
> IGT test patch: https://lists.freedesktop.org/archives/igt-dev/2024-January/067282.html
> 
> Fixes: 01d6c3578379 ("drm/syncobj: add support for timeline point wait v8")
> Signed-off-by: Erik Kurzinger <ekurzinger at nvidia.com>
> ---
>  drivers/gpu/drm/drm_syncobj.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index a8e6b61a188c..a1443c673f30 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1121,7 +1121,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
>  	 * fallthough and try a 0 timeout wait!
>  	 */
>  
> -	if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
> +	if (flags & (DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |

You also need to adjust the condition earlier in the function that guards
the lockdep_assert_none call.

I also noticed that unliked drm_syncobj_find_fence() we don't have the
might_sleep check in there, would be good to add that (in an additional
patch).

Also I think it'd be good to reject the
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE flag in drm_syncobj_find_fence()
since that's a clear misuses of that. Found that since I checked whether
there's more conditions that should be patched.

Cheers, Sima
> +		     DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE)) {
>  		for (i = 0; i < count; ++i)
>  			drm_syncobj_fence_add_wait(syncobjs[i], &entries[i]);
>  	}
> -- 
> 2.43.0
> 
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list