From: Gustavo Padovan <gustavo@padovan.org>
To: Alexandre Courbot <acourbot@chromium.org>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>,
Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
Shuah Khan <shuahkh@osg.samsung.com>,
Pawel Osciak <pawel@osciak.com>,
Sakari Ailus <sakari.ailus@iki.fi>,
Brian Starkey <brian.starkey@arm.com>,
Thierry Escande <thierry.escande@collabora.com>,
linux-kernel@vger.kernel.org,
Gustavo Padovan <gustavo.padovan@collabora.com>
Subject: Re: [RFC v5 10/11] [media] vb2: add out-fence support to QBUF
Date: Fri, 17 Nov 2017 09:48:35 -0200 [thread overview]
Message-ID: <20171117114835.GD19033@jade> (raw)
In-Reply-To: <4c1a4932-87af-4593-94f5-94739cc61084@chromium.org>
2017-11-17 Alexandre Courbot <acourbot@chromium.org>:
> On Thursday, November 16, 2017 2:10:56 AM JST, Gustavo Padovan wrote:
> > From: Gustavo Padovan <gustavo.padovan@collabora.com>
> >
> > If V4L2_BUF_FLAG_OUT_FENCE flag is present on the QBUF call we create
> > an out_fence and send its fd to userspace on the fence_fd field as a
> > return arg for the QBUF call.
> >
> > The fence is signaled on buffer_done(), when the job on the buffer is
> > finished.
> >
> > With out-fences we do not allow drivers to requeue buffers through vb2,
> > instead we flag an error on the buffer, signals it fence with error and
>
> s/it/its
>
> > return it to userspace.
> >
> > v6
> > - get rid of the V4L2_EVENT_OUT_FENCE event. We always keep the
> > ordering in vb2 for queueing in the driver, so the event is not
> > necessary anymore and the out_fence_fd is sent back to userspace
> > on QBUF call return arg
> > - do not allow requeueing with out-fences, instead mark the buffer
> > with an error and wake up to userspace.
> > - send the out_fence_fd back to userspace on the fence_fd field
> >
> > v5:
> > - delay fd_install to DQ_EVENT (Hans)
> > - if queue is fully ordered send OUT_FENCE event right away
> > (Brian)
> > - rename 'q->ordered' to 'q->ordered_in_driver'
> > - merge change to implement OUT_FENCE event here
> >
> > v4:
> > - return the out_fence_fd in the BUF_QUEUED event(Hans)
> >
> > v3: - add WARN_ON_ONCE(q->ordered) on requeueing (Hans)
> > - set the OUT_FENCE flag if there is a fence pending (Hans)
> > - call fd_install() after vb2_core_qbuf() (Hans)
> > - clean up fence if vb2_core_qbuf() fails (Hans)
> > - add list to store sync_file and fence for the next queued buffer
> >
> > v2: check if the queue is ordered.
> >
> > Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
> > ---
> > drivers/media/v4l2-core/videobuf2-core.c | 42
> > +++++++++++++++++++++++++++++---
> > drivers/media/v4l2-core/videobuf2-v4l2.c | 21 +++++++++++++++-
> > 2 files changed, 58 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/media/v4l2-core/videobuf2-core.c
> > b/drivers/media/v4l2-core/videobuf2-core.c
> > index 8b4f0e9bcb36..2eb5ffa8e028 100644
> > --- a/drivers/media/v4l2-core/videobuf2-core.c
> > +++ b/drivers/media/v4l2-core/videobuf2-core.c
> > @@ -354,6 +354,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q,
> > enum vb2_memory memory,
> > vb->planes[plane].length = plane_sizes[plane];
> > vb->planes[plane].min_length = plane_sizes[plane];
> > }
> > + vb->out_fence_fd = -1;
> > q->bufs[vb->index] = vb;
> > /* Allocate video buffer memory for the MMAP type */
> > @@ -934,10 +935,26 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum
> > vb2_buffer_state state)
> > case VB2_BUF_STATE_QUEUED:
> > return;
> > case VB2_BUF_STATE_REQUEUEING:
> > - if (q->start_streaming_called)
> > - __enqueue_in_driver(vb);
> > - return;
> > +
> > + if (!vb->out_fence) {
> > + if (q->start_streaming_called)
> > + __enqueue_in_driver(vb);
> > + return;
> > + }
> > +
> > + /* Do not allow requeuing with explicit synchronization,
> > + * report it as an error to userspace */
> > + state = VB2_BUF_STATE_ERROR;
> > +
> > + /* fall through */
> > default:
> > + if (state == VB2_BUF_STATE_ERROR)
> > + dma_fence_set_error(vb->out_fence, -EFAULT);
> > + dma_fence_signal(vb->out_fence);
> > + dma_fence_put(vb->out_fence);
> > + vb->out_fence = NULL;
> > + vb->out_fence_fd = -1;
> > +
> > /* Inform any processes that may be waiting for buffers */
> > wake_up(&q->done_wq);
> > break;
> > @@ -1325,12 +1342,18 @@ EXPORT_SYMBOL_GPL(vb2_core_prepare_buf);
> > int vb2_setup_out_fence(struct vb2_queue *q, unsigned int index)
> > {
> > struct vb2_buffer *vb;
> > + u64 context;
> > vb = q->bufs[index];
> > vb->out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
> > - vb->out_fence = vb2_fence_alloc(q->out_fence_context);
> > + if (q->ordered_in_driver)
> > + context = q->out_fence_context;
> > + else
> > + context = dma_fence_context_alloc(1);
> > +
> > + vb->out_fence = vb2_fence_alloc(context);
> > if (!vb->out_fence) {
> > put_unused_fd(vb->out_fence_fd);
> > return -ENOMEM;
> > @@ -1594,6 +1617,9 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned
> > int index, void *pb,
> > if (pb)
> > call_void_bufop(q, fill_user_buffer, vb, pb);
> > + fd_install(vb->out_fence_fd, vb->sync_file->file);
>
> What happens if the buffer does not have an output fence? Shouldn't this be
> protected by a check on whether the buffer has been queued with
> V4L2_BUF_FLAG_OUT_FENCE?
Ouch, I think we would have a nice crash. We should protect it, yes.
Gustavo
next prev parent reply other threads:[~2017-11-17 11:48 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 17:10 [RFC v5 00/11] V4L2 Explicit Synchronization Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 01/11] [media] v4l: add V4L2_CAP_ORDERED to the uapi Gustavo Padovan
2017-11-17 11:57 ` Mauro Carvalho Chehab
2017-11-17 12:23 ` Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 02/11] [media] vivid: add the V4L2_CAP_ORDERED capability Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 03/11] [media] vb2: add 'ordered_in_driver' property to queues Gustavo Padovan
2017-11-17 5:56 ` Alexandre Courbot
2017-11-17 11:23 ` Gustavo Padovan
2017-11-17 12:15 ` Mauro Carvalho Chehab
2017-11-17 12:27 ` Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 04/11] [media] vivid: mark vivid queues as ordered_in_driver Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 05/11] [media] vb2: check earlier if stream can be started Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 06/11] [media] vb2: add explicit fence user API Gustavo Padovan
2017-11-17 12:25 ` Mauro Carvalho Chehab
2017-11-17 13:29 ` Hans Verkuil
2017-11-17 13:53 ` Mauro Carvalho Chehab
2017-11-17 14:31 ` Hans Verkuil
2017-11-15 17:10 ` [RFC v5 07/11] [media] vb2: add in-fence support to QBUF Gustavo Padovan
2017-11-17 6:49 ` Alexandre Courbot
2017-11-17 13:00 ` Mauro Carvalho Chehab
2017-11-17 13:08 ` Gustavo Padovan
2017-11-17 13:19 ` Mauro Carvalho Chehab
2017-11-20 11:41 ` Brian Starkey
2017-11-17 13:01 ` Gustavo Padovan
2017-11-20 2:53 ` Alexandre Courbot
2017-11-17 12:53 ` Mauro Carvalho Chehab
2017-11-17 13:12 ` Gustavo Padovan
2017-11-17 13:47 ` Mauro Carvalho Chehab
2017-11-17 17:20 ` Gustavo Padovan
2017-11-17 14:15 ` Hans Verkuil
2017-11-17 17:40 ` Gustavo Padovan
2017-11-17 17:50 ` Gustavo Padovan
2017-11-18 9:30 ` Hans Verkuil
2017-11-15 17:10 ` [RFC v5 08/11] [media] vb2: add videobuf2 dma-buf fence helpers Gustavo Padovan
2017-11-17 7:02 ` Alexandre Courbot
2017-11-17 7:11 ` Alexandre Courbot
2017-11-17 11:27 ` Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 09/11] [media] vb2: add infrastructure to support out-fences Gustavo Padovan
2017-11-17 7:19 ` Alexandre Courbot
2017-11-17 7:29 ` Alexandre Courbot
2017-11-17 11:30 ` Gustavo Padovan
2017-11-15 17:10 ` [RFC v5 10/11] [media] vb2: add out-fence support to QBUF Gustavo Padovan
2017-11-17 7:38 ` Alexandre Courbot
2017-11-17 11:48 ` Gustavo Padovan [this message]
2017-11-17 13:34 ` Hans Verkuil
2017-11-15 17:10 ` [RFC v5 11/11] [media] v4l: Document explicit synchronization behavior Gustavo Padovan
2017-11-20 10:19 ` [RFC v5 00/11] V4L2 Explicit Synchronization Smitha T Murthy
2017-11-30 18:53 ` Gustavo Padovan
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=20171117114835.GD19033@jade \
--to=gustavo@padovan.org \
--cc=acourbot@chromium.org \
--cc=brian.starkey@arm.com \
--cc=gustavo.padovan@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@osg.samsung.com \
--cc=pawel@osciak.com \
--cc=sakari.ailus@iki.fi \
--cc=shuahkh@osg.samsung.com \
--cc=thierry.escande@collabora.com \
/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).