Message ID | 20171115171057.17340-7-gustavo@padovan.org (mailing list archive) |
---|---|
State | RFC, archived |
Headers |
Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from <linux-media-owner@vger.kernel.org>) id 1eF1EB-0006o7-DF; Wed, 15 Nov 2017 17:11:55 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933140AbdKORLv (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Wed, 15 Nov 2017 12:11:51 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:43060 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933271AbdKORL3 (ORCPT <rfc822;linux-media@vger.kernel.org>); Wed, 15 Nov 2017 12:11:29 -0500 Received: by mail-qt0-f195.google.com with SMTP id r58so12053413qtc.0; Wed, 15 Nov 2017 09:11:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fAfyVfPk52cTtN7VIsvspylP+y2nS8Ye+m0YHMf7/Jw=; b=iifbBJKk8Dx7lOUN3WXS/bJ/28A9K89Hd+LRoxTmYG6qD4BiKxsSBycWorUiPnqjXC 86kjxRDAEuVuxGDLdjgJhH8d+JpMRKlz8Eh/OXz6k1RYcc1vULUdbRVOcfqdUh+UqUwd nepnuqvsZZjH4RNPctCHSdWOodUnBBKKuCcYbmoGYae/3osywURC8Y2Iilfl4CdVMaTy lU9hhgoLNUO6RTAGlGRkSlMBgS5bGyhY3e1Rt8pOB38md62ew2otX/9+l8IYvY+GZU33 y52Xuk0fRzRR5fSg5XPmsw/q2J6z3xHHJu4J0MqAFiQuHzJjC3WfL1izoBxbdiwrrlAU nC3Q== X-Gm-Message-State: AJaThX6lRoziDVGJ8Vs/pQbvTJp+VUcD+yDsTlZZYqT/rExJHWw0KKGJ VCwzPaSMrDqV9PcoU9hjg18VRUb7 X-Google-Smtp-Source: AGs4zMbMm/5bxqiSTMf2do6OZc70QyX02aHmsemetlTwBox9U0oOSss0Uje+Al4bzqMIhuSDLTW6bA== X-Received: by 10.55.147.67 with SMTP id v64mr12622103qkd.10.1510765887660; Wed, 15 Nov 2017 09:11:27 -0800 (PST) Received: from localhost.localdomain ([179.110.36.75]) by smtp.gmail.com with ESMTPSA id p85sm15211633qkp.94.2017.11.15.09.11.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Nov 2017 09:11:27 -0800 (PST) From: Gustavo Padovan <gustavo@padovan.org> To: linux-media@vger.kernel.org Cc: 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>, Brian Starkey <brian.starkey@arm.com>, Thierry Escande <thierry.escande@collabora.com>, linux-kernel@vger.kernel.org, Gustavo Padovan <gustavo.padovan@collabora.com> Subject: [RFC v5 06/11] [media] vb2: add explicit fence user API Date: Wed, 15 Nov 2017 15:10:52 -0200 Message-Id: <20171115171057.17340-7-gustavo@padovan.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171115171057.17340-1-gustavo@padovan.org> References: <20171115171057.17340-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org |
Commit Message
Gustavo F. Padovan
Nov. 15, 2017, 5:10 p.m. UTC
From: Gustavo Padovan <gustavo.padovan@collabora.com> Turn the reserved2 field into fence_fd that we will use to send an in-fence to the kernel and return an out-fence from the kernel to userspace. Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used when sending a fence to the kernel to be waited on, and V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. v4: - make it a union with reserved2 and fence_fd (Hans Verkuil) v3: - make the out_fence refer to the current buffer (Hans Verkuil) v2: add documentation Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> --- Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- include/uapi/linux/videodev2.h | 7 ++++++- 5 files changed, 25 insertions(+), 5 deletions(-)
Comments
Em Wed, 15 Nov 2017 15:10:52 -0200 Gustavo Padovan <gustavo@padovan.org> escreveu: > From: Gustavo Padovan <gustavo.padovan@collabora.com> > > Turn the reserved2 field into fence_fd that we will use to send > an in-fence to the kernel and return an out-fence from the kernel to > userspace. > > Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used > when sending a fence to the kernel to be waited on, and > V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. > > v4: > - make it a union with reserved2 and fence_fd (Hans Verkuil) > > v3: > - make the out_fence refer to the current buffer (Hans Verkuil) > > v2: add documentation > > Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> > --- > Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ > drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- > drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- > drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- > include/uapi/linux/videodev2.h | 7 ++++++- > 5 files changed, 25 insertions(+), 5 deletions(-) > > diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst > index ae6ee73f151c..eeefbd2547e7 100644 > --- a/Documentation/media/uapi/v4l/buffer.rst > +++ b/Documentation/media/uapi/v4l/buffer.rst > @@ -648,6 +648,21 @@ Buffer Flags > - Start Of Exposure. The buffer timestamp has been taken when the > exposure of the frame has begun. This is only valid for the > ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. > + * .. _`V4L2-BUF-FLAG-IN-FENCE`: > + > + - ``V4L2_BUF_FLAG_IN_FENCE`` > + - 0x00200000 > + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer > + won't be queued to the driver until the fence signals. > + > + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: > + > + - ``V4L2_BUF_FLAG_OUT_FENCE`` > + - 0x00400000 > + - Request a fence to be attached to the buffer. The ``fence_fd`` > + field on > + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence > + fd to userspace. > > > > diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c > index 3dedd83f0b19..6cde686bf44c 100644 > --- a/drivers/media/usb/cpia2/cpia2_v4l.c > +++ b/drivers/media/usb/cpia2/cpia2_v4l.c > @@ -948,7 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) > buf->sequence = cam->buffers[buf->index].seq; > buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; > buf->length = cam->frame_size; > - buf->reserved2 = 0; > + buf->fence_fd = -1; > buf->reserved = 0; > memset(&buf->timecode, 0, sizeof(buf->timecode)); > > diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > index 821f2aa299ae..3a31d318df2a 100644 > --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > @@ -370,7 +370,7 @@ struct v4l2_buffer32 { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + __s32 fence_fd; > __u32 reserved; > }; > > @@ -533,7 +533,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user > put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || > copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || > put_user(kp->sequence, &up->sequence) || > - put_user(kp->reserved2, &up->reserved2) || > + put_user(kp->fence_fd, &up->fence_fd) || > put_user(kp->reserved, &up->reserved) || > put_user(kp->length, &up->length)) > return -EFAULT; > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c > index 0c0669976bdc..110fb45fef6f 100644 > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c > @@ -203,7 +203,7 @@ 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->reserved2 = 0; > + b->fence_fd = -1; > b->reserved = 0; > > if (q->is_multiplanar) { > diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h > index cd6fc1387f47..311c3a331eda 100644 > --- a/include/uapi/linux/videodev2.h > +++ b/include/uapi/linux/videodev2.h > @@ -925,7 +925,10 @@ struct v4l2_buffer { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + union { > + __s32 fence_fd; You forgot to document the fence_fd at the uAPI book. In particular, it should be noticed there that a non-positive value means no fence. (as userspace should be setting reserved2 to zero, I'm assuming that we'll likely not accept 0 here). You should likely also remove the description from reserved2 at Documentation/media/uapi/v4l/buffer.rst. > + __u32 reserved2; > + }; > __u32 reserved; > }; > > @@ -962,6 +965,8 @@ struct v4l2_buffer { > #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 > /* mem2mem encoder/decoder */ > #define V4L2_BUF_FLAG_LAST 0x00100000 > +#define V4L2_BUF_FLAG_IN_FENCE 0x00200000 > +#define V4L2_BUF_FLAG_OUT_FENCE 0x00400000 > > /** > * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
On 15/11/17 18:10, Gustavo Padovan wrote: > From: Gustavo Padovan <gustavo.padovan@collabora.com> > > Turn the reserved2 field into fence_fd that we will use to send > an in-fence to the kernel and return an out-fence from the kernel to > userspace. > > Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used > when sending a fence to the kernel to be waited on, and > V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. > > v4: > - make it a union with reserved2 and fence_fd (Hans Verkuil) > > v3: > - make the out_fence refer to the current buffer (Hans Verkuil) > > v2: add documentation > > Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> > --- > Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ > drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- > drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- > drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- > include/uapi/linux/videodev2.h | 7 ++++++- > 5 files changed, 25 insertions(+), 5 deletions(-) > > diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst > index ae6ee73f151c..eeefbd2547e7 100644 > --- a/Documentation/media/uapi/v4l/buffer.rst > +++ b/Documentation/media/uapi/v4l/buffer.rst > @@ -648,6 +648,21 @@ Buffer Flags > - Start Of Exposure. The buffer timestamp has been taken when the > exposure of the frame has begun. This is only valid for the > ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. > + * .. _`V4L2-BUF-FLAG-IN-FENCE`: > + > + - ``V4L2_BUF_FLAG_IN_FENCE`` > + - 0x00200000 > + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer > + won't be queued to the driver until the fence signals. > + > + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: > + > + - ``V4L2_BUF_FLAG_OUT_FENCE`` > + - 0x00400000 > + - Request a fence to be attached to the buffer. The ``fence_fd`` > + field on > + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence > + fd to userspace. How would userspace know if fences are not supported? E.g. any driver that does not use vb2 will have no support for it. While the driver could clear the flag on return, the problem is that it is a bit late for applications to discover lack of fence support. Perhaps we do need a capability flag for this? I wonder what others think. Regards, Hans > > > > diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c > index 3dedd83f0b19..6cde686bf44c 100644 > --- a/drivers/media/usb/cpia2/cpia2_v4l.c > +++ b/drivers/media/usb/cpia2/cpia2_v4l.c > @@ -948,7 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) > buf->sequence = cam->buffers[buf->index].seq; > buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; > buf->length = cam->frame_size; > - buf->reserved2 = 0; > + buf->fence_fd = -1; > buf->reserved = 0; > memset(&buf->timecode, 0, sizeof(buf->timecode)); > > diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > index 821f2aa299ae..3a31d318df2a 100644 > --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > @@ -370,7 +370,7 @@ struct v4l2_buffer32 { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + __s32 fence_fd; > __u32 reserved; > }; > > @@ -533,7 +533,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user > put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || > copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || > put_user(kp->sequence, &up->sequence) || > - put_user(kp->reserved2, &up->reserved2) || > + put_user(kp->fence_fd, &up->fence_fd) || > put_user(kp->reserved, &up->reserved) || > put_user(kp->length, &up->length)) > return -EFAULT; > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c > index 0c0669976bdc..110fb45fef6f 100644 > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c > @@ -203,7 +203,7 @@ 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->reserved2 = 0; > + b->fence_fd = -1; > b->reserved = 0; > > if (q->is_multiplanar) { > diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h > index cd6fc1387f47..311c3a331eda 100644 > --- a/include/uapi/linux/videodev2.h > +++ b/include/uapi/linux/videodev2.h > @@ -925,7 +925,10 @@ struct v4l2_buffer { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + union { > + __s32 fence_fd; > + __u32 reserved2; > + }; > __u32 reserved; > }; > > @@ -962,6 +965,8 @@ struct v4l2_buffer { > #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 > /* mem2mem encoder/decoder */ > #define V4L2_BUF_FLAG_LAST 0x00100000 > +#define V4L2_BUF_FLAG_IN_FENCE 0x00200000 > +#define V4L2_BUF_FLAG_OUT_FENCE 0x00400000 > > /** > * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor >
Em Fri, 17 Nov 2017 14:29:23 +0100 Hans Verkuil <hverkuil@xs4all.nl> escreveu: > On 15/11/17 18:10, Gustavo Padovan wrote: > > From: Gustavo Padovan <gustavo.padovan@collabora.com> > > > > Turn the reserved2 field into fence_fd that we will use to send > > an in-fence to the kernel and return an out-fence from the kernel to > > userspace. > > > > Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used > > when sending a fence to the kernel to be waited on, and > > V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. > > > > v4: > > - make it a union with reserved2 and fence_fd (Hans Verkuil) > > > > v3: > > - make the out_fence refer to the current buffer (Hans Verkuil) > > > > v2: add documentation > > > > Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> > > --- > > Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ > > drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- > > drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- > > drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- > > include/uapi/linux/videodev2.h | 7 ++++++- > > 5 files changed, 25 insertions(+), 5 deletions(-) > > > > diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst > > index ae6ee73f151c..eeefbd2547e7 100644 > > --- a/Documentation/media/uapi/v4l/buffer.rst > > +++ b/Documentation/media/uapi/v4l/buffer.rst > > @@ -648,6 +648,21 @@ Buffer Flags > > - Start Of Exposure. The buffer timestamp has been taken when the > > exposure of the frame has begun. This is only valid for the > > ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. > > + * .. _`V4L2-BUF-FLAG-IN-FENCE`: > > + > > + - ``V4L2_BUF_FLAG_IN_FENCE`` > > + - 0x00200000 > > + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer > > + won't be queued to the driver until the fence signals. > > + > > + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: > > + > > + - ``V4L2_BUF_FLAG_OUT_FENCE`` > > + - 0x00400000 > > + - Request a fence to be attached to the buffer. The ``fence_fd`` > > + field on > > + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence > > + fd to userspace. > > How would userspace know if fences are not supported? E.g. any driver that does > not use vb2 will have no support for it. > > While the driver could clear the flag on return, the problem is that it is a bit > late for applications to discover lack of fence support. > > Perhaps we do need a capability flag for this? I wonder what others think. We're almost running out of flags at v4l2 caps (and at struct v4l2_buffer). So, I would prefer to not add more flags on those structs if there is another way. As the fences out of order flags should go to ENUM_FMT (and, currently there's just one flag defined there), I wander if it would make sense to also add CAN_IN_FENCES/CAN_OUT_FENCES flags there, as maybe we would want to disable/enable fences based on the format. > > Regards, > > Hans > > > > > > > > > diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c > > index 3dedd83f0b19..6cde686bf44c 100644 > > --- a/drivers/media/usb/cpia2/cpia2_v4l.c > > +++ b/drivers/media/usb/cpia2/cpia2_v4l.c > > @@ -948,7 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) > > buf->sequence = cam->buffers[buf->index].seq; > > buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; > > buf->length = cam->frame_size; > > - buf->reserved2 = 0; > > + buf->fence_fd = -1; > > buf->reserved = 0; > > memset(&buf->timecode, 0, sizeof(buf->timecode)); > > > > diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > > index 821f2aa299ae..3a31d318df2a 100644 > > --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > > +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > > @@ -370,7 +370,7 @@ struct v4l2_buffer32 { > > __s32 fd; > > } m; > > __u32 length; > > - __u32 reserved2; > > + __s32 fence_fd; > > __u32 reserved; > > }; > > > > @@ -533,7 +533,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user > > put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || > > copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || > > put_user(kp->sequence, &up->sequence) || > > - put_user(kp->reserved2, &up->reserved2) || > > + put_user(kp->fence_fd, &up->fence_fd) || > > put_user(kp->reserved, &up->reserved) || > > put_user(kp->length, &up->length)) > > return -EFAULT; > > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c > > index 0c0669976bdc..110fb45fef6f 100644 > > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c > > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c > > @@ -203,7 +203,7 @@ 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->reserved2 = 0; > > + b->fence_fd = -1; > > b->reserved = 0; > > > > if (q->is_multiplanar) { > > diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h > > index cd6fc1387f47..311c3a331eda 100644 > > --- a/include/uapi/linux/videodev2.h > > +++ b/include/uapi/linux/videodev2.h > > @@ -925,7 +925,10 @@ struct v4l2_buffer { > > __s32 fd; > > } m; > > __u32 length; > > - __u32 reserved2; > > + union { > > + __s32 fence_fd; > > + __u32 reserved2; > > + }; > > __u32 reserved; > > }; > > > > @@ -962,6 +965,8 @@ struct v4l2_buffer { > > #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 > > /* mem2mem encoder/decoder */ > > #define V4L2_BUF_FLAG_LAST 0x00100000 > > +#define V4L2_BUF_FLAG_IN_FENCE 0x00200000 > > +#define V4L2_BUF_FLAG_OUT_FENCE 0x00400000 > > > > /** > > * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor > > >
On 17/11/17 14:53, Mauro Carvalho Chehab wrote: > Em Fri, 17 Nov 2017 14:29:23 +0100 > Hans Verkuil <hverkuil@xs4all.nl> escreveu: > >> On 15/11/17 18:10, Gustavo Padovan wrote: >>> From: Gustavo Padovan <gustavo.padovan@collabora.com> >>> >>> Turn the reserved2 field into fence_fd that we will use to send >>> an in-fence to the kernel and return an out-fence from the kernel to >>> userspace. >>> >>> Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used >>> when sending a fence to the kernel to be waited on, and >>> V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. >>> >>> v4: >>> - make it a union with reserved2 and fence_fd (Hans Verkuil) >>> >>> v3: >>> - make the out_fence refer to the current buffer (Hans Verkuil) >>> >>> v2: add documentation >>> >>> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> >>> --- >>> Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ >>> drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- >>> drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- >>> drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- >>> include/uapi/linux/videodev2.h | 7 ++++++- >>> 5 files changed, 25 insertions(+), 5 deletions(-) >>> >>> diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst >>> index ae6ee73f151c..eeefbd2547e7 100644 >>> --- a/Documentation/media/uapi/v4l/buffer.rst >>> +++ b/Documentation/media/uapi/v4l/buffer.rst >>> @@ -648,6 +648,21 @@ Buffer Flags >>> - Start Of Exposure. The buffer timestamp has been taken when the >>> exposure of the frame has begun. This is only valid for the >>> ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. >>> + * .. _`V4L2-BUF-FLAG-IN-FENCE`: >>> + >>> + - ``V4L2_BUF_FLAG_IN_FENCE`` >>> + - 0x00200000 >>> + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer >>> + won't be queued to the driver until the fence signals. >>> + >>> + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: >>> + >>> + - ``V4L2_BUF_FLAG_OUT_FENCE`` >>> + - 0x00400000 >>> + - Request a fence to be attached to the buffer. The ``fence_fd`` >>> + field on >>> + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence >>> + fd to userspace. >> >> How would userspace know if fences are not supported? E.g. any driver that does >> not use vb2 will have no support for it. >> >> While the driver could clear the flag on return, the problem is that it is a bit >> late for applications to discover lack of fence support. >> >> Perhaps we do need a capability flag for this? I wonder what others think. > > We're almost running out of flags at v4l2 caps (and at struct v4l2_buffer). struct v4l2_capability has more than enough room to add a new device_caps2 field. So I see no problem there, and it is very useful for applications to know what features are supported up front and not when you start to use them. Think about it: you're setting up complete fence support in your application, only to discover when you queue the first buffer that there is no fence support! That doesn't work. The reserved[] array wasn't added for nothing to v4l2_capability. struct v4l2_buffer is indeed very full. But I posted an RFC on October 26 introducing a struct v4l2_ext_buffer, designed from scratch. We can switch to a u64 flags there. See here: https://www.mail-archive.com/linux-media@vger.kernel.org/msg121215.html I am waiting for fences and the request API to go in before continuing with that RFC series, unless we think it is better to only support fences/request API with this redesign. Let me know and I can pick up development of that RFC. > > So, I would prefer to not add more flags on those structs if there is > another way. > > As the fences out of order flags should go to ENUM_FMT (and, currently > there's just one flag defined there), I wander if it would make sense > to also add CAN_IN_FENCES/CAN_OUT_FENCES flags there, as maybe we > would want to disable/enable fences based on the format. I don't see a reason for that. There is no relationship between formats and fences. Fences apply to buffers, not formats. Whereas the 'ordered' value can be specific to a format. Regards, Hans
diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index ae6ee73f151c..eeefbd2547e7 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -648,6 +648,21 @@ Buffer Flags - Start Of Exposure. The buffer timestamp has been taken when the exposure of the frame has begun. This is only valid for the ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. + * .. _`V4L2-BUF-FLAG-IN-FENCE`: + + - ``V4L2_BUF_FLAG_IN_FENCE`` + - 0x00200000 + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer + won't be queued to the driver until the fence signals. + + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: + + - ``V4L2_BUF_FLAG_OUT_FENCE`` + - 0x00400000 + - Request a fence to be attached to the buffer. The ``fence_fd`` + field on + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence + fd to userspace. diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c index 3dedd83f0b19..6cde686bf44c 100644 --- a/drivers/media/usb/cpia2/cpia2_v4l.c +++ b/drivers/media/usb/cpia2/cpia2_v4l.c @@ -948,7 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) buf->sequence = cam->buffers[buf->index].seq; buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; buf->length = cam->frame_size; - buf->reserved2 = 0; + buf->fence_fd = -1; buf->reserved = 0; memset(&buf->timecode, 0, sizeof(buf->timecode)); diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 821f2aa299ae..3a31d318df2a 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -370,7 +370,7 @@ struct v4l2_buffer32 { __s32 fd; } m; __u32 length; - __u32 reserved2; + __s32 fence_fd; __u32 reserved; }; @@ -533,7 +533,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || put_user(kp->sequence, &up->sequence) || - put_user(kp->reserved2, &up->reserved2) || + put_user(kp->fence_fd, &up->fence_fd) || put_user(kp->reserved, &up->reserved) || put_user(kp->length, &up->length)) return -EFAULT; diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index 0c0669976bdc..110fb45fef6f 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -203,7 +203,7 @@ 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->reserved2 = 0; + b->fence_fd = -1; b->reserved = 0; if (q->is_multiplanar) { diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index cd6fc1387f47..311c3a331eda 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -925,7 +925,10 @@ struct v4l2_buffer { __s32 fd; } m; __u32 length; - __u32 reserved2; + union { + __s32 fence_fd; + __u32 reserved2; + }; __u32 reserved; }; @@ -962,6 +965,8 @@ struct v4l2_buffer { #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 /* mem2mem encoder/decoder */ #define V4L2_BUF_FLAG_LAST 0x00100000 +#define V4L2_BUF_FLAG_IN_FENCE 0x00200000 +#define V4L2_BUF_FLAG_OUT_FENCE 0x00400000 /** * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor