From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 5/8] sync_file: add support for a semaphore object
Date: Tue, 4 Apr 2017 14:27:30 +1000 [thread overview]
Message-ID: <20170404042733.17203-6-airlied@gmail.com> (raw)
In-Reply-To: <20170404042733.17203-1-airlied@gmail.com>
From: Dave Airlie <airlied@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@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);
+ }
+
+ 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;
if (!rcu_access_pointer(a->fence) ||
!rcu_access_pointer(b->fence))
diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
index 4bf661b..245c7da 100644
--- a/include/linux/sync_file.h
+++ b/include/linux/sync_file.h
@@ -62,4 +62,6 @@ struct sync_file *sync_file_alloc(uint32_t type, uint32_t flags);
struct sync_file *sync_file_create(struct dma_fence *fence, uint32_t type, uint32_t flags);
struct dma_fence *sync_file_get_fence(int fd);
struct sync_file *sync_file_fdget(int fd);
+struct dma_fence *sync_file_replace_fence(struct sync_file *sync_file,
+ struct dma_fence *fence);
#endif /* _LINUX_SYNC_H */
diff --git a/include/uapi/linux/sync_file.h b/include/uapi/linux/sync_file.h
index f439cda..5f266e0 100644
--- a/include/uapi/linux/sync_file.h
+++ b/include/uapi/linux/sync_file.h
@@ -80,6 +80,20 @@ struct sync_file_info {
#define SYNC_FILE_TYPE_FENCE 0
/**
+ * DOC: SYNC_FILE_TYPE_SEMAPHORE - semaphore sync file object
+ *
+ * This is a sync file that operates like a Vulkan semaphore.
+ * The object should just be imported/exported but not use the
+ * sync file ioctls (except info).
+ * This object can have it's backing fence replaced multiple times.
+ * Each signal operation assigns a backing fence.
+ * Each wait operation waits on the current fence, and removes it.
+ * These operations should happen via driver command submission interfaces.
+ * This is useful for shared vulkan semaphores.
+ */
+#define SYNC_FILE_TYPE_SEMAPHORE 1
+
+/**
* struct sync_file_type - data returned from sync file type ioctl
* @type: sync_file type
* @flags: sync_file creation flags
--
2.9.3
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-04-04 4:27 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-04 4:27 [RFC] DRM synchronisation objects Dave Airlie
2017-04-04 4:27 ` [PATCH 1/8] sync_file: add type/flags to sync file object creation Dave Airlie
2017-04-04 7:08 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 2/8] sync_file: export some interfaces needed by drm sync objects Dave Airlie
2017-04-04 7:10 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 3/8] drm: introduce sync objects as sync file objects with no fd Dave Airlie
2017-04-04 7:42 ` Daniel Vetter
[not found] ` <CAPM=9tyj6k4hqJWrwDW8Ch+TZCOoXRuAK2g71ciUm5vxpwmkuw@mail.gmail.com>
[not found] ` <CAKMK7uFoFvsREVtSxsoOeM6OPDM-iGOATtcAK6p65LzG39D6oQ@mail.gmail.com>
2017-04-11 6:00 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 4/8] sync_file: add a mutex to protect fence and callback members. (v4) Dave Airlie
2017-04-04 7:52 ` Daniel Vetter
2017-04-04 8:07 ` Christian König
2017-04-11 2:57 ` Dave Airlie
2017-04-04 4:27 ` Dave Airlie [this message]
2017-04-04 7:59 ` [PATCH 5/8] sync_file: add support for a semaphore object Daniel Vetter
2017-04-04 11:52 ` Chris Wilson
2017-04-04 11:59 ` Chris Wilson
2017-04-04 4:27 ` [PATCH 6/8] drm/syncobj: add semaphore support helpers Dave Airlie
2017-04-04 8:07 ` Daniel Vetter
2017-04-04 4:27 ` [PATCH 7/8] amdgpu/cs: split out fence dependency checking Dave Airlie
2017-04-04 7:37 ` Christian König
2017-04-04 4:27 ` [PATCH 8/8] amdgpu: use sync file for shared semaphores (v2) Dave Airlie
2017-04-04 7:40 ` Christian König
2017-04-04 8:10 ` Daniel Vetter
2017-04-04 11:05 ` Christian König
2017-04-11 3:18 ` Dave Airlie
2017-04-11 6:55 ` Christian König
2017-04-04 4:35 ` [RFC] DRM synchronisation objects Dave Airlie
2017-04-04 8:02 ` Christian König
2017-04-04 8:11 ` Daniel Vetter
-- strict thread matches above, loose matches on Subject: below --
2017-04-11 3:22 [repost] drm sync objects cleaned up Dave Airlie
2017-04-11 3:22 ` [PATCH 5/8] sync_file: add support for a semaphore object Dave Airlie
[not found] ` <20170411032220.21101-6-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-11 7:50 ` Chris Wilson
2017-04-12 2:36 ` Dave Airlie
[not found] ` <CAPM=9tzgNoSXPoZfJbRcoRmGZL9gENo+TTZCbauMjB7mwayZxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-12 10:31 ` Chris Wilson
[not found] ` <20170412103116.GL4250-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-04-12 19:05 ` Dave Airlie
[not found] ` <CAPM=9tyiKAH-T2rxwcqxc=LWZ8o_5TyxV3GVhy_JKZv3PZQsCw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-12 20:01 ` Chris Wilson
[not found] ` <20170412200132.GJ12532-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-04-12 20:39 ` Chris Wilson
2017-04-12 20:51 ` Dave Airlie
[not found] ` <CAPM=9tyk2NvVTfzEmm+psYv2BfL3xNKhEq_CE7gGeHmS3R9BMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-12 21:13 ` Chris Wilson
2017-04-12 21:41 ` Dave Airlie
[not found] ` <CAPM=9tzx8TjPUQ0qH0j=b=U_RyGerCjCNb+2feTuuONB9iRkqA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-12 22:34 ` Chris Wilson
[not found] ` <20170412223438.GQ12532-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org>
2017-04-12 22:42 ` Dave Airlie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170404042733.17203-6-airlied@gmail.com \
--to=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.