Received: by 10.192.165.148 with SMTP id m20csp2967672imm; Mon, 7 May 2018 04:31:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqeUq4TxoesFIHjMeBW870XhCNhrV53vt6y55/+fe2zzNfLOvkFCFPMU0i5vUVynA2k+Cwz X-Received: by 2002:a17:902:3225:: with SMTP id y34-v6mr38625568plb.180.1525692687638; Mon, 07 May 2018 04:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525692687; cv=none; d=google.com; s=arc-20160816; b=oN2i14A4uKIFJ1bpiWnJ0Wa6SDDmn0rvvE1x2nBxoHC1KydZxNUv2aFUqNfApMn4EZ zo4oHFMioJ6TibRnuzZGDCXWMwyChewCZf5ZCVJCc3FlOOO29KZCn4St/v9KgmzAnDc1 0JKsZoGfB2962EKJJl+lZ6vLKMUcFhE71NORdJU2joNAfxWQbwSLjBWhP7L/TdgeaytZ W+DcKMfoQF3FS1GlZQoVJq7y1P3CREgY04FS3eZakhnlq9+CcoCV16BAvL2luu5jO7L0 D++081ZpWtPqM6MvgyjbXZ8st3U2o6nlBLecwCHQLV14YQoxNwIg4Co0USAF5mzJL2G+ Knnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=eadkBvcbFRrZ6cRPUieyHFi8Pul9sGowyKcNdLMXzQw=; b=HboISTiH5OMdtWbBnQ36PBaZYkCjMiMYM+NesPBwz+KpqEEIkBq0s1kHexcT0BamZC RnNd3xJ7uQfjmQNDwq9nBCL3Te2BzKc8SY5m5qLHxDA6+LKujbCsDrOALeTRwAdYNCHr 9bC/BKy3Pcxv0iqmO/JWiL3+1uJGW95wHrqqQCbd4IzaBQc3TJGWRPn4gsvuxFtvZgw3 VGre96lNhHpRZr3ogpzYWOLmzqxQVHtZp3ce9jF57LIuHfBOCCyDb3FNVp5z82mNt196 sGNP/aSehnpvpFdesAJu/hFxWnDpkH7F/ILeRrQGydv+KETT288mUF+5fXP9F8v12Q8P 4mtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b124-v6si9487994pgc.49.2018.05.07.04.31.12; Mon, 07 May 2018 04:31:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752126AbeEGLbC (ORCPT + 99 others); Mon, 7 May 2018 07:31:02 -0400 Received: from lb2-smtp-cloud9.xs4all.net ([194.109.24.26]:56769 "EHLO lb2-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751938AbeEGLa7 (ORCPT ); Mon, 7 May 2018 07:30:59 -0400 Received: from [IPv6:2001:983:e9a7:1:2913:d371:8c33:6f] ([IPv6:2001:983:e9a7:1:2913:d371:8c33:6f]) by smtp-cloud9.xs4all.net with ESMTPA id FeM4fczhjHgC9FeM5fG3wY; Mon, 07 May 2018 13:30:57 +0200 Subject: Re: [PATCH v9 10/15] vb2: add explicit fence user API To: Ezequiel Garcia , linux-media@vger.kernel.org Cc: kernel@collabora.com, Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan References: <20180504200612.8763-1-ezequiel@collabora.com> <20180504200612.8763-11-ezequiel@collabora.com> From: Hans Verkuil Message-ID: <1f3e8527-d18b-9d60-31c4-11b3bd6a28b5@xs4all.nl> Date: Mon, 7 May 2018 13:30:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180504200612.8763-11-ezequiel@collabora.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfPLi+1Kou097S1uEbgWQGrZpOZvMfvJ81Y2VISvfeZncopcAsdBSNQMitNb2+cYErdPxbAR8kzfraiIAU6fkYjJTXHyO/9mReYyXq2DyBzmGFR61yXQu FdEU5vGJ95ie1f/Qm4rG+aooRhHFNAmd7vsOiUB/J+2GAga3guZrxX8onPIwRHjiPbsk5lAx9+OOvqJDMvW5T6cB3aLi0x/nFDBdlgQFuZVkGEDeGrqE/CRs NBjpfEz5QYHzIK4NW0fZmVQtOW+WJXnjRW56cgKnjbGC46R1VyKGJngHyW6nm8Ly4AzSt3vx5ZGAI2BZxnGkHsqF90yNsEvIHJbPVh6LPImfmF4VQBsEQ7pb ZfNVSFxcwOuBrrZz8l1Nu/DMnYGbwHu4GpS2VJUvfqpmWFEghmW4MLSw0ZyvD6JLInT6aDDGnamgmt8sXqSytQkbwaMy8QF1HQUFiVrOvtlpPcDR05h7WG3o anC/IXnTac2sOLWC3tSsobYeA1W4V9LkP9r6uhKys7JCsIvV0zilLkZ5Ru47whmRlrrneKZ4kbstXN50NUgOl7aagEKwOF9T/l9BSvXH47F3QWcafTYnSetn YLBdyrj7tcdFqK3ssBl20DnV Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/05/18 22:06, Ezequiel Garcia wrote: > From: Gustavo Padovan > > Turn the reserved2 field into fence_fd that we will use to send > an in-fence to the kernel or 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 an in-fence to the kernel to be waited on, and > V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. > > v7: minor fixes on the Documentation (Hans Verkuil) > > v6: big improvement on doc (Hans Verkuil) > > v5: - keep using reserved2 field for cpia2 > - set fence_fd to 0 for now, for compat with userspace(Mauro) > > 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 > --- > Documentation/media/uapi/v4l/buffer.rst | 45 +++++++++++++++++++++++-- > drivers/media/common/videobuf2/videobuf2-v4l2.c | 2 +- > drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +-- > include/uapi/linux/videodev2.h | 8 ++++- > 4 files changed, 52 insertions(+), 7 deletions(-) > > diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst > index e2c85ddc990b..be9719cf5745 100644 > --- a/Documentation/media/uapi/v4l/buffer.rst > +++ b/Documentation/media/uapi/v4l/buffer.rst > @@ -301,10 +301,22 @@ struct v4l2_buffer > elements in the ``planes`` array. The driver will fill in the > actual number of valid elements in that array. > * - __u32 Type is now __s32. > - - ``reserved2`` > + - ``fence_fd`` > - > - - A place holder for future extensions. Drivers and applications > - must set this to 0. > + - Used to communicate a fence file descriptors from userspace to kernel descriptors -> descriptor > + and vice-versa. On :ref:`VIDIOC_QBUF ` when sending > + an in-fence for V4L2 to wait on, the ``V4L2_BUF_FLAG_IN_FENCE`` flag must > + be used and this field set to the fence file descriptor of the in-fence. > + If the in-fence is not valid ` VIDIOC_QBUF`` returns an error. > + > + To get an out-fence back from V4L2 the ``V4L2_BUF_FLAG_OUT_FENCE`` > + must be set, the kernel will return the out-fence file descriptor in > + this field. If it fails to create the out-fence ``VIDIOC_QBUF` returns > + an error. > + > + For all other ioctls V4L2 sets this field to -1 if > + ``V4L2_BUF_FLAG_IN_FENCE`` and/or ``V4L2_BUF_FLAG_OUT_FENCE`` are set, > + otherwise this field is set to 0 for backward compatibility. > * - __u32 > - ``reserved`` > - > @@ -648,6 +660,33 @@ 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 the fence passed in the ``fence_fd`` field. The > + buffer won't be queued to the driver until the fence signals. The order > + in which buffers are queued is guaranteed to be preserved, so any > + buffers queued after this buffer will also be blocked until this fence > + signals. This flag must be set before calling ``VIDIOC_QBUF``. For > + other ioctls the driver just reports the value of the flag. > + > + If the fence signals the flag is cleared and not reported anymore. > + If the fence is not valid ``VIDIOC_QBUF`` returns an error. > + > + > + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: > + > + - ``V4L2_BUF_FLAG_OUT_FENCE`` > + - 0x00400000 > + - Request for a fence to be attached to the buffer. The driver will fill > + in the out-fence fd in the ``fence_fd`` field when :ref:`VIDIOC_QBUF > + ` returns. This flag must be set before calling > + ``VIDIOC_QBUF``. For other ioctls the driver just reports the value of > + the flag. What happens once the out fence signals? Is this flag cleared? I think that would make sense. > + > + If the creation of the out-fence fails ``VIDIOC_QBUF`` returns an > + error. > > I would like to see a mention here that it is valid to set both FENCE flags. > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > index 64503615d00b..b1c0fa2b0b88 100644 > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > +++ b/drivers/media/common/videobuf2/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 = 0; > b->reserved = 0; > > if (q->is_multiplanar) { > diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > index 4312935f1dfc..93c752459aec 100644 > --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c > @@ -388,7 +388,7 @@ struct v4l2_buffer32 { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + __s32 fence_fd; > __u32 reserved; > }; > > @@ -606,7 +606,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, > assign_in_user(&up->timestamp.tv_usec, &kp->timestamp.tv_usec) || > copy_in_user(&up->timecode, &kp->timecode, sizeof(kp->timecode)) || > assign_in_user(&up->sequence, &kp->sequence) || > - assign_in_user(&up->reserved2, &kp->reserved2) || > + assign_in_user(&up->fence_fd, &kp->fence_fd) || > assign_in_user(&up->reserved, &kp->reserved) || > get_user(length, &kp->length) || > put_user(length, &up->length)) > diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h > index a8842a5ca636..1f18dc68ecab 100644 > --- a/include/uapi/linux/videodev2.h > +++ b/include/uapi/linux/videodev2.h > @@ -934,7 +934,10 @@ struct v4l2_buffer { > __s32 fd; > } m; > __u32 length; > - __u32 reserved2; > + union { > + __s32 fence_fd; > + __u32 reserved2; > + }; > __u32 reserved; > }; > > @@ -971,6 +974,9 @@ struct v4l2_buffer { > #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 > /* mem2mem encoder/decoder */ > #define V4L2_BUF_FLAG_LAST 0x00100000 > +/* Explicit synchronization */ > +#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 > Regards, Hans