From: Gustavo Padovan <gustavo@padovan.org>
To: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org,
Daniel Stone <daniels@collabora.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Rob Clark <robdclark@gmail.com>,
Greg Hackmann <ghackmann@google.com>,
John Harrison <John.C.Harrison@Intel.com>,
laurent.pinchart@ideasonboard.com, seanpaul@google.com,
marcheu@google.com, m.chehab@samsung.com,
Sumit Semwal <sumit.semwal@linaro.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Subject: [PATCH v4 5/5] dma-buf/sync_file: only enable fence signalling on poll()
Date: Tue, 12 Jul 2016 15:08:45 -0300 [thread overview]
Message-ID: <1468346925-12774-5-git-send-email-gustavo@padovan.org> (raw)
In-Reply-To: <1468346925-12774-1-git-send-email-gustavo@padovan.org>
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signalling doesn't need to be enabled at sync_file creation, it is only
required if userspace waiting the fence to signal through poll().
Thus we delay fence_add_callback() until poll is called. It only adds the
callback the first time poll() is called. This avoid re-adding the same
callback multiple times.
v2: rebase and update to work with new fence support for sync_file
v3: use atomic operation to set enabled and protect fence_add_callback()
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
drivers/dma-buf/sync_file.c | 22 +++++++++++++---------
include/linux/sync_file.h | 2 ++
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 61a687c..240ef22 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence)
fence->ops->get_timeline_name(fence), fence->context,
fence->seqno);
- fence_add_callback(fence, &sync_file->cb, fence_check_cb_func);
-
return sync_file;
}
EXPORT_SYMBOL(sync_file_create);
@@ -269,9 +267,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
goto err;
}
- fence_add_callback(sync_file->fence, &sync_file->cb,
- fence_check_cb_func);
-
strlcpy(sync_file->name, name, sizeof(sync_file->name));
return sync_file;
@@ -286,7 +281,8 @@ static void sync_file_free(struct kref *kref)
struct sync_file *sync_file = container_of(kref, struct sync_file,
kref);
- fence_remove_callback(sync_file->fence, &sync_file->cb);
+ if (atomic_read(&sync_file->enabled))
+ fence_remove_callback(sync_file->fence, &sync_file->cb);
fence_put(sync_file->fence);
kfree(sync_file);
}
@@ -306,13 +302,21 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait)
poll_wait(file, &sync_file->wq, wait);
+ if (!atomic_xchg(&sync_file->enabled, 1)) {
+ if (fence_add_callback(sync_file->fence, &sync_file->cb,
+ fence_check_cb_func) < 0)
+ wake_up_all(&sync_file->wq);
+ }
+
status = fence_is_signaled(sync_file->fence);
- if (status)
- return POLLIN;
+ if (!status)
+ return 0;
+
if (status < 0)
return POLLERR;
- return 0;
+
+ return POLLIN;
}
static long sync_file_ioctl_merge(struct sync_file *sync_file,
diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h
index f7de5a0..4ced13b 100644
--- a/include/linux/sync_file.h
+++ b/include/linux/sync_file.h
@@ -28,6 +28,7 @@
* @name: name of sync_file. Useful for debugging
* @sync_file_list: membership in global file list
* @wq: wait queue for fence signaling
+ * @enabled: wether fence signal is enabled or not
* @fence: fence with the fences in the sync_file
* @cb: fence callback information
*/
@@ -40,6 +41,7 @@ struct sync_file {
#endif
wait_queue_head_t wq;
+ atomic_t enabled;
struct fence *fence;
struct fence_cb cb;
--
2.5.5
next prev parent reply other threads:[~2016-07-12 18:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 18:08 [PATCH v4 1/5] dma-buf/fence-array: add fence_is_array() Gustavo Padovan
2016-07-12 18:08 ` [PATCH v4 2/5] dma-buf/sync_file: refactor fence storage in struct sync_file Gustavo Padovan
2016-07-19 12:15 ` Sumit Semwal
2016-07-19 12:21 ` Sumit Semwal
2016-07-28 11:00 ` Sumit Semwal
2016-07-28 14:26 ` Greg Kroah-Hartman
2016-07-12 18:08 ` [PATCH v4 3/5] dma-buf/sync_file: add sync_file_get_fence() Gustavo Padovan
2016-07-12 18:08 ` [PATCH v4 4/5] Documentation: add doc for sync_file_get_fence() Gustavo Padovan
2016-07-12 18:08 ` Gustavo Padovan [this message]
2016-07-14 13:21 ` [PATCH v4 5/5] dma-buf/sync_file: only enable fence signalling on poll() John Harrison
2016-08-03 11:43 ` Chris Wilson
2016-08-04 21:18 ` Gustavo Padovan
2016-08-04 21:32 ` Chris Wilson
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=1468346925-12774-5-git-send-email-gustavo@padovan.org \
--to=gustavo@padovan.org \
--cc=John.C.Harrison@Intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ghackmann@google.com \
--cc=gustavo.padovan@collabora.co.uk \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.chehab@samsung.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=marcheu@google.com \
--cc=robdclark@gmail.com \
--cc=seanpaul@google.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
all inboxes | Powered by JetHome®