From: Gustavo Padovan <gustavo@padovan.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
dri-devel@lists.freedesktop.org,
"Daniel Stone" <daniels@collabora.com>,
"Arve Hjønnevåg" <arve@android.com>,
"Riley Andrews" <riandrews@android.com>,
"Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Rob Clark" <robdclark@gmail.com>,
"Greg Hackmann" <ghackmann@google.com>,
"John Harrison" <John.C.Harrison@Intel.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Gustavo Padovan" <gustavo.padovan@collabora.co.uk>
Subject: [RFC v2 3/8] dma-buf/sync_file: add sync_file_fences_get()
Date: Mon, 25 Apr 2016 19:33:23 -0300 [thread overview]
Message-ID: <1461623608-29538-4-git-send-email-gustavo@padovan.org> (raw)
In-Reply-To: <1461623608-29538-1-git-send-email-gustavo@padovan.org>
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Creates a function that given an sync file descriptor returns a
fence_collection containing all fences in the sync_file.
If there is only one fence in the sync_file this fence itself is returned,
however if there is more than one, a fence_collection fence is returned.
v2: Comments by Daniel Vetter
- Adapt to new version of fence_collection_init()
- Hold a reference for the fence we return
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
drivers/dma-buf/sync_file.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/sync_file.h | 3 +++
2 files changed, 63 insertions(+)
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 40ee098..5dd76c0 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -23,6 +23,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/anon_inodes.h>
+#include <linux/fence-collection.h>
#include <linux/sync_file.h>
#include <uapi/linux/sync_file.h>
@@ -147,6 +148,62 @@ void sync_file_install(struct sync_file *sync_file, int fd)
}
EXPORT_SYMBOL(sync_file_install);
+/**
+ * sync_file_fences_get - get the fence(s) related to the sync_file fd
+ * @fd: sync_file fd to get the fence(s) from
+ *
+ * Ensures @fd references a valid sync_file and returns a fence that
+ * represents all fence in the sync_file.
+ *
+ * If there is only one fence in the sync_file, this fence is returned.
+ * If there is more than one, a fence_collection containing all fences
+ * is created and its base fence object is returned.
+ * On both cases a reference to the returned fence is held. On error
+ * NULL is returned.
+ */
+struct fence *sync_file_fences_get(int fd)
+{
+ struct sync_file *sync_file;
+ struct fence_collection *collection;
+ struct fence_collection_cb *cb;
+ int i;
+
+ sync_file = sync_file_fdget(fd);
+ if (!sync_file)
+ return NULL;
+
+ if (sync_file->num_fences == 1) {
+ struct fence *fence = sync_file->cbs[0].fence;
+
+ fence_get(fence);
+ sync_file_put(sync_file);
+ return fence;
+ }
+
+ cb = kcalloc(sync_file->num_fences, sizeof(*cb), GFP_KERNEL);
+ if (!cb) {
+ sync_file_put(sync_file);
+ return NULL;
+ }
+
+ for (i = 0 ; i < sync_file->num_fences ; i++)
+ cb[i].fence = sync_file->cbs[i].fence;
+
+ collection = fence_collection_create(sync_file->num_fences, cb);
+ if (!collection) {
+ kfree(cb);
+ sync_file_put(sync_file);
+ return NULL;
+ }
+
+ sync_file->collection = collection;
+ fence_get(&collection->base);
+ sync_file_put(sync_file);
+
+ return &collection->base;
+}
+EXPORT_SYMBOL(sync_file_fences_get);
+
static void sync_file_add_pt(struct sync_file *sync_file, int *i,
struct fence *fence)
{
@@ -234,6 +291,9 @@ static void sync_file_free(struct kref *kref)
kref);
int i;
+ if (sync_file->collection)
+ fence_put(&sync_file->collection->base);
+
for (i = 0; i < sync_file->num_fences; ++i) {
fence_remove_callback(sync_file->cbs[i].fence,
&sync_file->cbs[i].cb);
diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
index 900fa0c..3eb3aad 100644
--- a/include/linux/sync_file.h
+++ b/include/linux/sync_file.h
@@ -35,6 +35,7 @@ struct sync_file_cb {
* @num_fences: number of sync_pts in the fence
* @wq: wait queue for fence signaling
* @status: 0: signaled, >0:active, <0: error
+ * @collection: collection with the fences in the sync_file
* @cbs: sync_pts callback information
*/
struct sync_file {
@@ -49,6 +50,7 @@ struct sync_file {
wait_queue_head_t wq;
atomic_t status;
+ struct fence_collection *collection;
struct sync_file_cb cbs[];
};
@@ -59,4 +61,5 @@ void sync_file_install(struct sync_file *sync_file, int fd);
struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
struct sync_file *b);
+struct fence *sync_file_fences_get(int fd);
#endif /* _LINUX_SYNC_H */
--
2.5.5
next prev parent reply other threads:[~2016-04-25 22:33 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-25 22:33 [RFC v2 0/8] drm: explicit fencing support Gustavo Padovan
2016-04-25 22:33 ` [RFC v2 1/8] dma-buf/fence: add fence_collection fences Gustavo Padovan
2016-04-26 14:41 ` Daniel Vetter
2016-04-26 15:02 ` Gustavo Padovan
2016-04-27 6:36 ` Daniel Vetter
2016-04-26 15:09 ` Chris Wilson
2016-04-28 14:47 ` Gustavo Padovan
2016-04-25 22:33 ` [RFC v2 2/8] Documentation: add fence-collection to kernel DocBook Gustavo Padovan
2016-04-25 22:33 ` Gustavo Padovan [this message]
2016-04-25 22:33 ` [RFC v2 4/8] drm/fence: allow fence waiting to be interrupted by userspace Gustavo Padovan
2016-04-25 22:33 ` [RFC v2 5/8] drm/fence: add in-fences support Gustavo Padovan
2016-04-26 10:10 ` Ville Syrjälä
2016-04-26 14:14 ` Gustavo Padovan
2016-04-26 14:36 ` Daniel Vetter
2016-04-26 16:26 ` Ville Syrjälä
2016-04-26 17:20 ` Daniel Vetter
2016-04-26 17:40 ` Ville Syrjälä
2016-04-26 18:23 ` Daniel Vetter
2016-04-26 18:55 ` Ville Syrjälä
2016-04-26 20:05 ` Daniel Vetter
2016-04-26 20:48 ` Greg Hackmann
2016-04-27 6:39 ` Daniel Vetter
2016-04-28 21:28 ` Rob Clark
2016-04-29 7:48 ` Daniel Stone
2016-04-29 22:23 ` Rob Clark
2016-04-29 21:14 ` Greg Hackmann
2016-04-27 6:57 ` Daniel Stone
2016-04-28 14:36 ` Gustavo Padovan
2016-04-28 14:38 ` Daniel Vetter
2016-04-28 16:56 ` Ville Syrjälä
2016-04-28 17:43 ` Daniel Vetter
2016-04-28 17:51 ` Ville Syrjälä
2016-04-28 17:55 ` Gustavo Padovan
2016-04-28 18:02 ` Daniel Vetter
2016-04-28 18:17 ` Ville Syrjälä
2016-04-28 20:40 ` Daniel Vetter
2016-04-26 16:25 ` Ville Syrjälä
2016-04-25 22:33 ` [RFC v2 6/8] drm/fence: add fence to drm_pending_event Gustavo Padovan
2016-04-25 22:33 ` [RFC v2 7/8] drm/fence: add fence timeline to drm_crtc Gustavo Padovan
2016-04-26 10:12 ` Ville Syrjälä
2016-04-26 14:23 ` Gustavo Padovan
2016-04-26 16:34 ` Ville Syrjälä
2016-04-27 8:23 ` Daniel Stone
2016-04-25 22:33 ` [RFC v2 8/8] drm/fence: add out-fences support Gustavo Padovan
2016-04-26 14:53 ` Daniel Vetter
2016-04-28 15:23 ` Gustavo Padovan
[not found] ` <CAHbf0-HVNM=akFaE54U6B=51eegwumFmH=dUv+HHbnGOgGD=nw@mail.gmail.com>
2016-04-26 6:30 ` [RFC v2 0/8] drm: explicit fencing support Daniel Vetter
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=1461623608-29538-4-git-send-email-gustavo@padovan.org \
--to=gustavo@padovan.org \
--cc=John.C.Harrison@Intel.com \
--cc=arve@android.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniels@collabora.com \
--cc=devel@driverdev.osuosl.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ghackmann@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavo.padovan@collabora.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=riandrews@android.com \
--cc=robdclark@gmail.com \
--cc=sumit.semwal@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).