[PATCH 5/8] sync_file: add support for a semaphore object
Chris Wilson
chris at chris-wilson.co.uk
Tue Apr 4 11:52:32 UTC 2017
On Tue, Apr 04, 2017 at 02:27:30PM +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>
> ---
> drivers/dma-buf/sync_file.c | 36 +++++++++++++++++++++++++++++++++++-
> include/linux/sync_file.h | 2 ++
> include/uapi/linux/sync_file.h | 14 ++++++++++++++
> 3 files changed, 51 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> index 6376f6f..a82f6d8 100644
> --- a/drivers/dma-buf/sync_file.c
> +++ b/drivers/dma-buf/sync_file.c
> @@ -44,7 +44,7 @@ int sync_file_validate_type_flags(uint32_t type, uint32_t flags)
> {
> if (flags)
> return -EINVAL;
> - if (type != SYNC_FILE_TYPE_FENCE)
> + if (type != SYNC_FILE_TYPE_FENCE && type != SYNC_FILE_TYPE_SEMAPHORE)
> return -EINVAL;
> return 0;
> }
> @@ -200,6 +200,38 @@ sync_file_get_fence_locked(struct sync_file *sync_file)
> sync_file_held(sync_file));
> }
>
> +/**
> + * 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);
This is racy with sync_file_poll. And sync_file_poll now needs rcu
protection (as does all access to sync_file->fence), I need to check
whether the previous patches are complete. Also needs to handle, or
forbid, the caller passing in the same fence.
> + }
> +
> + RCU_INIT_POINTER(sync_file->fence, fence);
> +
> + mutex_unlock(&sync_file->lock);
> + return ret_fence;
> +}
> +EXPORT_SYMBOL(sync_file_replace_fence);
> +
> static int sync_file_set_fence(struct sync_file *sync_file,
> struct dma_fence **fences, int num_fences)
> {
> @@ -278,6 +310,8 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
>
> if (a->type != b->type)
> return NULL;
> + if (a->type != SYNC_FILE_TYPE_FENCE)
> + return NULL;
No rules for containerisation? Being able to pass in an array of current
semaphore in-fences through a single fd? It will have a bigger window
for change than doing everything inside the kernel, but since the kernel
cannot take a simultaneous snaphot of all in-semaphores either (could
use ww_mutex?) it seems harsh to exclude current ABI interop.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
More information about the dri-devel
mailing list