Commit e2416553 authored by Gustavo Padovan's avatar Gustavo Padovan Committed by Sumit Semwal

dma-buf/sync_file: only enable fence signalling on poll()

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()

v4: use user bit from fence flags (comment from Chris Wilson)

v5: use ternary if on poll return (comment from Chris Wilson)
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarSumit Semwal <sumit.semwal@linaro.org>
  [sumits: remove unused var status]
Link: http://patchwork.freedesktop.org/patch/msgid/1470404378-27961-1-git-send-email-gustavo@padovan.org
parent 395dec6f
...@@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence) ...@@ -86,8 +86,6 @@ struct sync_file *sync_file_create(struct fence *fence)
fence->ops->get_timeline_name(fence), fence->context, fence->ops->get_timeline_name(fence), fence->context,
fence->seqno); fence->seqno);
fence_add_callback(fence, &sync_file->cb, fence_check_cb_func);
return sync_file; return sync_file;
} }
EXPORT_SYMBOL(sync_file_create); EXPORT_SYMBOL(sync_file_create);
...@@ -274,9 +272,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a, ...@@ -274,9 +272,6 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
goto err; goto err;
} }
fence_add_callback(sync_file->fence, &sync_file->cb,
fence_check_cb_func);
strlcpy(sync_file->name, name, sizeof(sync_file->name)); strlcpy(sync_file->name, name, sizeof(sync_file->name));
return sync_file; return sync_file;
...@@ -291,7 +286,8 @@ static void sync_file_free(struct kref *kref) ...@@ -291,7 +286,8 @@ static void sync_file_free(struct kref *kref)
struct sync_file *sync_file = container_of(kref, struct sync_file, struct sync_file *sync_file = container_of(kref, struct sync_file,
kref); kref);
fence_remove_callback(sync_file->fence, &sync_file->cb); if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
fence_remove_callback(sync_file->fence, &sync_file->cb);
fence_put(sync_file->fence); fence_put(sync_file->fence);
kfree(sync_file); kfree(sync_file);
} }
...@@ -307,17 +303,16 @@ static int sync_file_release(struct inode *inode, struct file *file) ...@@ -307,17 +303,16 @@ static int sync_file_release(struct inode *inode, struct file *file)
static unsigned int sync_file_poll(struct file *file, poll_table *wait) static unsigned int sync_file_poll(struct file *file, poll_table *wait)
{ {
struct sync_file *sync_file = file->private_data; struct sync_file *sync_file = file->private_data;
int status;
poll_wait(file, &sync_file->wq, wait); poll_wait(file, &sync_file->wq, wait);
status = fence_is_signaled(sync_file->fence); if (!test_and_set_bit(POLL_ENABLED, &sync_file->fence->flags)) {
if (fence_add_callback(sync_file->fence, &sync_file->cb,
fence_check_cb_func) < 0)
wake_up_all(&sync_file->wq);
}
if (status) return fence_is_signaled(sync_file->fence) ? POLLIN : 0;
return POLLIN;
if (status < 0)
return POLLERR;
return 0;
} }
static long sync_file_ioctl_merge(struct sync_file *sync_file, static long sync_file_ioctl_merge(struct sync_file *sync_file,
......
...@@ -45,6 +45,8 @@ struct sync_file { ...@@ -45,6 +45,8 @@ struct sync_file {
struct fence_cb cb; struct fence_cb cb;
}; };
#define POLL_ENABLED FENCE_FLAG_USER_BITS
struct sync_file *sync_file_create(struct fence *fence); struct sync_file *sync_file_create(struct fence *fence);
struct fence *sync_file_get_fence(int fd); struct fence *sync_file_get_fence(int fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment