2017-07-06 Hans Verkuil <hverkuil@xxxxxxxxx>: > On 06/16/17 09:39, Gustavo Padovan wrote: > > From: Gustavo Padovan <gustavo.padovan@xxxxxxxxxxxxx> > > > > If V4L2_BUF_FLAG_OUT_FENCE flag is present on the QBUF call we create > > an out_fence for the buffer and return it to userspace on the fence_fd > > field. It only works with ordered queues. > > > > The fence is signaled on buffer_done(), when the job on the buffer is > > finished. > > > > v2: check if the queue is ordered. > > > > Signed-off-by: Gustavo Padovan <gustavo.padovan@xxxxxxxxxxxxx> > > --- > > drivers/media/v4l2-core/videobuf2-core.c | 6 ++++++ > > drivers/media/v4l2-core/videobuf2-v4l2.c | 22 +++++++++++++++++++++- > > 2 files changed, 27 insertions(+), 1 deletion(-) > > > > <snip> > > > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c > > index e6ad77f..e2733dd 100644 > > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c > > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c > > @@ -204,9 +204,14 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) > > b->timestamp = ns_to_timeval(vb->timestamp); > > b->timecode = vbuf->timecode; > > b->sequence = vbuf->sequence; > > - b->fence_fd = -1; > > + b->fence_fd = vb->out_fence_fd; > > I forgot to ask: can a buffer have both an in and an out fence? If so, then we > have a problem here since we can report only one fence fd. > > If it is not allowed, then we need a check for that somewhere. It is perfect fine to have both, I just wasn't expecting to get them out from the kernel at the same time. In-fence is set by userspace in the fence_fd field and then sent to the kernel, the field is then reused to send the out-fence created in the kernel to userspace. That is how GPU drivers do it. Gustavo