[PATCH 5/8] sync_file: add support for a semaphore object

Chris Wilson chris at chris-wilson.co.uk
Tue Apr 11 07:50:57 UTC 2017


On Tue, Apr 11, 2017 at 01:22:17PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This object can be used to implement the Vulkan semaphores.
> 
> The object behaviour differs from fence, in that you can
> replace the underlying fence, and you cannot merge semaphores.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
> +/**
> + * sync_file_replace_fence - replace the fence related to the sync_file
> + * @sync_file:	 sync file to replace fence in
> + * @fence: fence to replace with (or NULL for no fence).
> + * Returns previous fence.
> + */
> +struct dma_fence *sync_file_replace_fence(struct sync_file *sync_file,
> +					  struct dma_fence *fence)
> +{
> +	struct dma_fence *ret_fence = NULL;
> +
> +	if (sync_file->type != SYNC_FILE_TYPE_SEMAPHORE)
> +		return NULL;
> +
> +	if (fence)
> +		dma_fence_get(fence);
> +
> +	mutex_lock(&sync_file->lock);
> +
> +	ret_fence = sync_file_get_fence_locked(sync_file);
> +	if (ret_fence) {
> +		if (test_bit(POLL_ENABLED, &ret_fence->flags))
> +			dma_fence_remove_callback(ret_fence, &sync_file->cb);
> +	}

Fails when sync_file_replace_fence is passed sync_file->fence.

if (test_and_clear_bit(POLL_ENABLED, &ret_fence->flags)) {
	dma_fence_remove_callback(ret_fence, &sync_file->cb);
	wake_up(&sync_file->wq); /* only needs the first to redo the add */
}

will get the waiter to reset the callback on a new fence, or the old
fence replacing itself. Otherwise the waiter will never be woken over
the change in fence, not even when the old or new fence is signaled.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the amd-gfx mailing list