From: Gustavo Padovan <gustavo@padovan.org>
To: Brian Starkey <brian.starkey@arm.com>
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>,
Alexandre Courbot <acourbot@chromium.org>,
Sakari Ailus <sakari.ailus@iki.fi>,
linux-kernel@vger.kernel.org,
Gustavo Padovan <gustavo.padovan@collabora.com>
Subject: Re: [RFC v4 16/17] [media] vb2: add out-fence support to QBUF
Date: Thu, 2 Nov 2017 22:03:13 -0200 [thread overview]
Message-ID: <20171103000313.GJ4111@jade> (raw)
In-Reply-To: <20171027100139.GF40170@e107564-lin.cambridge.arm.com>
Hi Brian,
2017-10-27 Brian Starkey <brian.starkey@arm.com>:
> Hi Gustavo,
>
> On Fri, Oct 20, 2017 at 07:50:11PM -0200, 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 to userspace on the V4L2_EVENT_OUT_FENCE when
> > the buffer is queued to the driver, or right away if the queue is ordered
> > both in VB2 and in the driver.
> >
> > The fence is signaled on buffer_done(), when the job on the buffer is
> > finished.
> >
> > 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/v4l2-event.c | 2 ++
> > drivers/media/v4l2-core/videobuf2-core.c | 25 +++++++++++++++
> > drivers/media/v4l2-core/videobuf2-v4l2.c | 55 ++++++++++++++++++++++++++++++++
> > 3 files changed, 82 insertions(+)
> >
> > diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c
> > index 6274e3e174e0..275da224ace4 100644
> > --- a/drivers/media/v4l2-core/v4l2-event.c
> > +++ b/drivers/media/v4l2-core/v4l2-event.c
> > @@ -385,6 +385,8 @@ int v4l2_subscribe_event_v4l2(struct v4l2_fh *fh,
> > switch (sub->type) {
> > case V4L2_EVENT_CTRL:
> > return v4l2_ctrl_subscribe_event(fh, sub);
> > + case V4L2_EVENT_OUT_FENCE:
> > + return v4l2_event_subscribe(fh, sub, VIDEO_MAX_FRAME, NULL);
> > }
> > return -EINVAL;
> > }
> > diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> > index c7ba67bda5ac..21e2052776c1 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,24 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
> > case VB2_BUF_STATE_QUEUED:
> > return;
> > case VB2_BUF_STATE_REQUEUEING:
> > + /*
> > + * Explicit synchronization requires ordered queues for now,
> > + * so WARN_ON if we are requeuing on an ordered queue.
> > + */
> > + if (vb->out_fence)
> > + WARN_ON_ONCE(q->ordered_in_driver);
> > +
> > if (q->start_streaming_called)
> > __enqueue_in_driver(vb);
> > return;
> > default:
> > + if (state == VB2_BUF_STATE_ERROR)
> > + dma_fence_set_error(vb->out_fence, -ENOENT);
> > + 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;
> > @@ -1235,6 +1250,9 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
> > trace_vb2_buf_queue(q, vb);
> >
> > call_void_vb_qop(vb, buf_queue, vb);
> > +
> > + if (!(q->is_output || q->ordered_in_vb2))
> > + call_void_bufop(q, send_out_fence, vb);
> > }
> >
> > static int __buf_prepare(struct vb2_buffer *vb, const void *pb)
> > @@ -1451,6 +1469,7 @@ static struct dma_fence *__set_in_fence(struct vb2_queue *q,
> > }
> >
> > q->last_fence = dma_fence_get(fence);
> > + call_void_bufop(q, send_out_fence, vb);
> > }
> >
> > return fence;
> > @@ -1840,6 +1859,11 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
> > }
> >
> > /*
> > + * Renew out-fence context.
> > + */
>
> Why is that? I don't think I understand the nuances of fence contexts.
Because inside each context we should maintain ordering of the fences.
If we cancel the stream and restart it with we need a new context. Look
at ordering between two different streams doesn't make sense.
>
> > + q->out_fence_context = dma_fence_context_alloc(1);
> > +
> > + /*
> > * Remove all buffers from videobuf's list...
> > */
> > INIT_LIST_HEAD(&q->queued_list);
> > @@ -2171,6 +2195,7 @@ int vb2_core_queue_init(struct vb2_queue *q)
> > spin_lock_init(&q->done_lock);
> > mutex_init(&q->mmap_lock);
> > init_waitqueue_head(&q->done_wq);
> > + q->out_fence_context = dma_fence_context_alloc(1);
> >
> > if (q->buf_struct_size == 0)
> > q->buf_struct_size = sizeof(struct vb2_buffer);
> > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
> > index 4c09ea007d90..9fb01ddefdc9 100644
> > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> > @@ -32,6 +32,11 @@
> >
> > #include <media/videobuf2-v4l2.h>
> >
> > +struct out_fence_data {
> > + int fence_fd;
> > + struct file *file;
> > +};
> > +
> > static int debug;
> > module_param(debug, int, 0644);
> >
> > @@ -138,6 +143,38 @@ static void __copy_timestamp(struct vb2_buffer *vb, const void *pb)
> > }
> > };
> >
> > +static void __fd_install_at_dequeue_cb(void *data)
> > +{
> > + struct out_fence_data *of = data;
> > +
> > + fd_install(of->fence_fd, of->file);
> > + kfree(of);
>
> Is it possible for the user to never dequeue the event? In that case
> the fd and sync_file would leak I guess.
Yes. It is totally possible. That fell through...
>
> > +}
> > +
> > +static void __send_out_fence(struct vb2_buffer *vb)
> > +{
> > + struct video_device *vdev = to_video_device(vb->vb2_queue->dev);
> > + struct v4l2_fh *fh = vdev->queue->owner;
> > + struct v4l2_event event;
> > + struct out_fence_data *of;
> > +
> > + if (vb->out_fence_fd < 0)
> > + return;
> > +
> > + memset(&event, 0, sizeof(event));
> > + event.type = V4L2_EVENT_OUT_FENCE;
> > + event.u.out_fence.index = vb->index;
> > + event.u.out_fence.out_fence_fd = vb->out_fence_fd;
> > +
> > + of = kmalloc(sizeof(*of), GFP_KERNEL);
> > + of->fence_fd = vb->out_fence_fd;
> > + of->file = vb->sync_file->file;
> > +
> > + v4l2_event_queue_fh_with_cb(fh, &event, __fd_install_at_dequeue_cb, of);
> > +
> > + vb->sync_file = NULL;
>
> See the comment above about never dequeuing the event - maybe you need
> to keep hold of the sync file to be able to clean it up in-case the
> user never dequeues. If not, then you could set vb->out_fence_fd = -1
> here too.
That is a good suggestion.
> I've been looking at your v4l2-fences branch on kernel.org, which
> looks quite different. Is this the newer version?
Yes. I wrote this in a hurry to send it to the mailing list before
the Media Summit, so I probably forgot to push and left a few issues
around.
Regards,
Gustavo
next prev parent reply other threads:[~2017-11-03 0:03 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-20 21:49 [RFC v4 00/17] V4L2 Explicit Synchronization support Gustavo Padovan
2017-10-20 21:49 ` [RFC v4 01/17] [media] v4l: create v4l2_event_subscribe_v4l2() Gustavo Padovan
2017-10-24 12:51 ` Hans Verkuil
2017-10-20 21:49 ` [RFC v4 02/17] [media] v4l: use v4l2_subscribe_event_v4l2() on vtables Gustavo Padovan
2017-10-20 21:49 ` [RFC v4 03/17] [media] v4l: use v4l2_subscribe_event_v4l2() on drivers Gustavo Padovan
2017-10-20 21:49 ` [RFC v4 04/17] WIP: [media] v4l2: add v4l2_event_queue_fh_with_cb() Gustavo Padovan
2017-11-03 7:31 ` Hans Verkuil
2017-10-20 21:50 ` [RFC v4 05/17] [media] v4l: add V4L2_EVENT_OUT_FENCE event Gustavo Padovan
2017-10-24 13:09 ` Hans Verkuil
2017-10-20 21:50 ` [RFC v4 06/17] [media] vb2: add .send_out_fence() to notify userspace of out_fence_fd Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 07/17] [media] vivid: assign the specific device to the vb2_queue->dev Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 08/17] [media] vb2: add 'ordered_in_driver' property to queues Gustavo Padovan
2017-10-24 13:11 ` Hans Verkuil
2017-10-20 21:50 ` [RFC v4 09/17] [media] vb2: add 'ordered_in_vb2' " Gustavo Padovan
2017-11-03 7:23 ` Hans Verkuil
2017-10-20 21:50 ` [RFC v4 10/17] [media] vivid: mark vivid queues as ordered_in_driver Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 11/17] [media] vb2: check earlier if stream can be started Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 12/17] [media] vb2: add explicit fence user API Gustavo Padovan
2017-11-03 7:47 ` Hans Verkuil
2017-10-20 21:50 ` [RFC v4 13/17] [media] vb2: add in-fence support to QBUF Gustavo Padovan
2017-10-25 14:49 ` Brian Starkey
2017-11-10 12:38 ` Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 14/17] [media] vb2: add videobuf2 dma-buf fence helpers Gustavo Padovan
2017-10-20 21:50 ` [RFC v4 15/17] [media] vb2: add infrastructure to support out-fences Gustavo Padovan
2017-10-27 9:41 ` Brian Starkey
2017-10-20 21:50 ` [RFC v4 16/17] [media] vb2: add out-fence support to QBUF Gustavo Padovan
2017-10-27 10:01 ` Brian Starkey
2017-11-03 0:03 ` Gustavo Padovan [this message]
2017-10-20 21:50 ` [RFC v4 17/17] [media] v4l: Document explicit synchronization behaviour Gustavo Padovan
2017-10-27 10:08 ` Brian Starkey
2017-11-03 7:53 ` Hans Verkuil
2017-11-03 13:32 ` 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=20171103000313.GJ4111@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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.