From: Daniel Vetter <daniel@ffwll.ch>
To: Gustavo Padovan <gustavo@padovan.org>
Cc: dri-devel@lists.freedesktop.org, 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: Re: [PATCH 1/3] dma-buf/sync_file: only enable fence signalling during wait
Date: Fri, 10 Jun 2016 00:12:54 +0200 [thread overview]
Message-ID: <20160609221254.GW3363@phenom.ffwll.local> (raw)
In-Reply-To: <1465484730-8128-1-git-send-email-gustavo@padovan.org>
On Thu, Jun 09, 2016 at 12:05:28PM -0300, Gustavo Padovan wrote:
> 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.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
> drivers/dma-buf/sync_file.c | 36 +++++++++++++++++++++++-------------
> include/linux/fence.h | 12 ++++++++++++
> 2 files changed, 35 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> index 00e9186..59f3445 100644
> --- a/drivers/dma-buf/sync_file.c
> +++ b/drivers/dma-buf/sync_file.c
> @@ -91,9 +91,7 @@ struct sync_file *sync_file_create(struct fence *fence)
>
> sync_file->cbs[0].fence = fence;
> sync_file->cbs[0].sync_file = sync_file;
> - if (fence_add_callback(fence, &sync_file->cbs[0].cb,
> - fence_check_cb_func))
> - atomic_dec(&sync_file->status);
> + INIT_LIST_HEAD(&sync_file->cbs[0].cb.node);
>
> sync_file_debug_add(sync_file);
> return sync_file;
> @@ -130,8 +128,7 @@ static void sync_file_add_pt(struct sync_file *sync_file, int *i,
> sync_file->cbs[*i].fence = fence;
> sync_file->cbs[*i].sync_file = sync_file;
>
> - if (!fence_add_callback(fence, &sync_file->cbs[*i].cb,
> - fence_check_cb_func)) {
> + if (!fence_is_signaled(fence)) {
> fence_get(fence);
> (*i)++;
> }
> @@ -212,11 +209,8 @@ static void sync_file_free(struct kref *kref)
> kref);
> int i;
>
> - for (i = 0; i < sync_file->num_fences; ++i) {
> - fence_remove_callback(sync_file->cbs[i].fence,
> - &sync_file->cbs[i].cb);
> + for (i = 0; i < sync_file->num_fences; ++i)
> fence_put(sync_file->cbs[i].fence);
> - }
>
> sync_file_debug_remove(sync_file);
> kfree(sync_file);
> @@ -233,17 +227,33 @@ static int sync_file_release(struct inode *inode, struct file *file)
> static unsigned int sync_file_poll(struct file *file, poll_table *wait)
> {
> struct sync_file *sync_file = file->private_data;
> - int status;
> + int status, i;
>
> poll_wait(file, &sync_file->wq, wait);
>
> + for (i = 0 ; i < sync_file->num_fences ; i++) {
> + if (fence_is_enabled(sync_file->cbs[i].fence))
If some other sync_file (or anyone else really) added enabling, then
you'll miss adding a callback. I don't think this check here works. You
probably also need more testcases in the debugfs-based tests if this falls
through the cracks ;-)
-Daniel
> + continue;
> +
> + if (fence_add_callback(sync_file->cbs[i].fence,
> + &sync_file->cbs[i].cb,
> + fence_check_cb_func))
> + atomic_dec(&sync_file->status);
> + }
> +
> status = atomic_read(&sync_file->status);
>
> - if (!status)
> - return POLLIN;
> + if (status > 0)
> + return 0;
> +
> + for (i = 0 ; i < sync_file->num_fences ; i++)
> + fence_remove_callback(sync_file->cbs[i].fence,
> + &sync_file->cbs[i].cb);
> +
> 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/fence.h b/include/linux/fence.h
> index 523ea3f..95a70b2 100644
> --- a/include/linux/fence.h
> +++ b/include/linux/fence.h
> @@ -283,6 +283,18 @@ fence_is_signaled(struct fence *fence)
> }
>
> /**
> + * fence_is_enabled - return an indication if signalling is enabled
> + * @fence: [in] the fence to check
> + *
> + * Returns true if signalling was already enabled, false if not.
> + */
> +static inline bool
> +fence_is_enabled(struct fence *fence)
> +{
> + return test_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags);
> +}
> +
> +/**
> * fence_is_later - return if f1 is chronologically later than f2
> * @f1: [in] the first fence from the same context
> * @f2: [in] the second fence from the same context
> --
> 2.5.5
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
prev parent reply other threads:[~2016-06-09 22:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-09 15:05 Gustavo Padovan
2016-06-09 15:05 ` [PATCH 2/3] dma-buf/sync_file: add sync_file_get_fence() Gustavo Padovan
2016-06-10 12:23 ` Chris Wilson
2016-06-13 21:21 ` Gustavo Padovan
2016-06-09 15:05 ` [PATCH 3/3] Documentation: add doc for sync_file_get_fence() Gustavo Padovan
2016-06-09 22:12 ` Daniel Vetter [this message]
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=20160609221254.GW3363@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--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=gustavo@padovan.org \
--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®