Received: by 10.213.65.68 with SMTP id h4csp733360imn; Tue, 13 Mar 2018 20:34:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELvbGI7aRl+7TnWWrn2DhqdCceCwpg3O75rO8SjbstfuylEz4tzLUiQKSuPPGk9Y/a1MQrgI X-Received: by 10.99.124.92 with SMTP id l28mr2382304pgn.51.1520998472115; Tue, 13 Mar 2018 20:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520998472; cv=none; d=google.com; s=arc-20160816; b=uaCXWu931+Nltl2+4rcP4K8HMmUluYG2TzpREEm3zsZjpENcOfnPKXicFEFLsIxYnl hBF7ncXDE7XHI5e1ysecyoQS2k0lbshHBM/7y3HLjwK1AjGXIbL9V14Qi5HWak1XE+yA jhfi67bYpWwzwWUJiFXZ2zkDA5Rd+VOsaVBEg++dmNvPt8MqvWiyXiI+FX8YlZFGCQSe 4l+XyYb9DetWc7BL7wkSK2w3CdgzEZuUE28q9ej2c91ksr4dcpENa8oECcxkDHDpqdVj oWbk0EYQQspZXlcVg/CHmPz5tPqdtvTH2cturMYxmJgOa0e2R+7S+CnpYt/LoSNsgVN9 +Tsg== 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=kht8Y8LpDgwzpdLeBGJEOfbUVAiW38SHgAhA92fe5HM=; b=0/WZsDnJskKyXXFHAiCCaxBSp0febFD7XTrZdW6leQVSwzqM2fVOkB90gqtkCvTPsO +5Skr2U4XjfBtNTdAdoQVFhp2i1a9Z4AdLI9yZzkn8jQJIzk1jqIAAtA08t6rtNpEj72 ivTvzEPUVLPPOAmv9cHwxZ7VLn028qF0iFWE0nklUCmimcfzpPlsQk8Pb9WYVqmNBnJK IPatHaSHMjlANxsPCXTlLZmH402twac2DWEU7oHBbgmy55tGZI7DnlobfAAL7NtmjKTI q2t1/axE0MtAOcsnMmIbJ8g0a61kZx3EmLaCl3qdE1K56TMmWk9NLMS2zFazIryDBLgd 8i2g== 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 bc5-v6si1216125plb.506.2018.03.13.20.34.18; Tue, 13 Mar 2018 20:34:32 -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 S933324AbeCNDdN (ORCPT + 99 others); Tue, 13 Mar 2018 23:33:13 -0400 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:59362 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932937AbeCNDdM (ORCPT ); Tue, 13 Mar 2018 23:33:12 -0400 Received: from [10.20.15.13] ([96.65.213.252]) by smtp-cloud8.xs4all.net with ESMTPA id vxA0emglGaXTbvxA4ebbba; Wed, 14 Mar 2018 04:33:10 +0100 Subject: Re: [PATCH v8 13/13] [media] v4l: Document explicit synchronization behavior To: Gustavo Padovan , 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: <20180309174920.22373-1-gustavo@padovan.org> <20180309174920.22373-14-gustavo@padovan.org> From: Hans Verkuil Message-ID: Date: Tue, 13 Mar 2018 20:33:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20180309174920.22373-14-gustavo@padovan.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfEjceeUASca51Rri+VsEIxuvZQ/mEJ7GX2JRp0KAehXk1xvWzyXLr7lwuo3NZot+gfrZszEwThGheNWDcb8vaPKyASKPcnrQ7H1bL4EXGqDwhakO770a We79Tv12P+auSIGCSrNwWBSTRIv9hbVOQ88e1mpW2qqM3Hhj4FfDuuGoIGCGa4tXQsEESBvfXiQWPBUeCW4/xomjMdoVLUFYdppDcmfHPrhEBnFyFJ0pNYdJ CF5nidQq39VJyNDXK+KHQ1ZHa8ViSHgxHZd/vrzSY8E520T7Rjaxbj97o1/09Zc8Rq7+8QgYXGY0Mz39oTPxZ6knx86gSVTrE3Lc2Uwfd0BSLhtO/W1Cx4CR hbl3qKSCLzyLAAyeOII84TKsd9vTQm8LpmeDUTCHFl3nsB2T04nA5qZKtMjT+f1U/J3lHbi5+GDMWdmAR6WAyYHT96fKvjKbEtKz2gEidS1BcqqF2s1W9573 DnRCknypZWdn4KW2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/09/2018 09:49 AM, Gustavo Padovan wrote: > From: Gustavo Padovan > > Add section to VIDIOC_QBUF and VIDIOC_QUERY_BUF about it > > v6: - Close some gaps in the docs (Hans) > > v5: > - Remove V4L2_CAP_ORDERED > - Add doc about V4L2_FMT_FLAG_UNORDERED > > v4: > - Document ordering behavior for in-fences > - Document V4L2_CAP_ORDERED capability > - Remove doc about OUT_FENCE event > - Document immediate return of out-fence in QBUF > > v3: > - make the out_fence refer to the current buffer (Hans) > - Note what happens when the IN_FENCE is not set (Hans) > > v2: > - mention that fences are files (Hans) > - rework for the new API > > Signed-off-by: Gustavo Padovan > --- > Documentation/media/uapi/v4l/vidioc-qbuf.rst | 55 +++++++++++++++++++++++- > Documentation/media/uapi/v4l/vidioc-querybuf.rst | 12 ++++-- > 2 files changed, 63 insertions(+), 4 deletions(-) > > diff --git a/Documentation/media/uapi/v4l/vidioc-qbuf.rst b/Documentation/media/uapi/v4l/vidioc-qbuf.rst > index 9e448a4aa3aa..371d84966e34 100644 > --- a/Documentation/media/uapi/v4l/vidioc-qbuf.rst > +++ b/Documentation/media/uapi/v4l/vidioc-qbuf.rst > @@ -54,7 +54,7 @@ When the buffer is intended for output (``type`` is > or ``V4L2_BUF_TYPE_VBI_OUTPUT``) applications must also initialize the > ``bytesused``, ``field`` and ``timestamp`` fields, see :ref:`buffer` > for details. Applications must also set ``flags`` to 0. The > -``reserved2`` and ``reserved`` fields must be set to 0. When using the > +``reserved`` field must be set to 0. When using the > :ref:`multi-planar API `, the ``m.planes`` field must > contain a userspace pointer to a filled-in array of struct > :c:type:`v4l2_plane` and the ``length`` field must be set > @@ -118,6 +118,59 @@ immediately with an ``EAGAIN`` error code when no buffer is available. > The struct :c:type:`v4l2_buffer` structure is specified in > :ref:`buffer`. > > +Explicit Synchronization > +------------------------ > + > +Explicit Synchronization allows us to control the synchronization of > +shared buffers from userspace by passing fences to the kernel and/or > +receiving them from it. Fences passed to the kernel are named in-fences and > +the kernel should wait on them to signal before using the buffer. On the other > +side, the kernel can create out-fences for the buffers it queues to the > +drivers. Out-fences signal when the driver is finished with buffer, i.e., the > +buffer is ready. The fences are represented as a file and passed as a file > +descriptor to userspace. > + > +The in-fences are communicated to the kernel at the ``VIDIOC_QBUF`` ioctl > +using the ``V4L2_BUF_FLAG_IN_FENCE`` buffer flag and the `fence_fd` field. If > +an in-fence needs to be passed to the kernel, `fence_fd` should be set to the > +fence file descriptor number and the ``V4L2_BUF_FLAG_IN_FENCE`` should be set > +as well. Setting one but not the other will cause ``VIDIOC_QBUF`` to return > +with an error. This sentence is confusing since it is not clear what 'one' and 'the other' refer to. Be specific here. I think it should be 'Setting V4L2_BUF_FLAG_IN_FENCE but not fence_fd'. The fence_fd field will be ignored if the > +``V4L2_BUF_FLAG_IN_FENCE`` is not set. > + > +The videobuf2-core will guarantee that all buffers queued with an in-fence will > +be queued to the drivers in the same order. Fences may signal out of order, so > +this guarantee at videobuf2 is necessary to not change ordering. So when > +waiting on a fence to signal all buffers queued after will be also block until after -> afterwards will be also block -> will also be blocked > +that fence signal. signal -> signals > + > +If the in-fence signals with an error the buffer will be marked with > +``V4L2_BUF_FLAG_ERROR`` when returned to userspace at ``VIDIOC_DQBUF``. > +Even with the error the order of dequeueing the buffers are preserved. are -> is > + > +To get an out-fence back from V4L2 the ``V4L2_BUF_FLAG_OUT_FENCE`` flag should > +be set to ask for a fence to be attached to the buffer. The out-fence fd is > +sent to userspace as a ``VIDIOC_QBUF`` return argument on the `fence_fd` field. on -> in > + > +Note the the same `fence_fd` field is used for both sending the in-fence as > +input argument to receive the out-fence as a return argument. A buffer can input argument -> an input argument and > +have both in-fence ond out-fence. have both an in-fence and an out-fence. > + > +At streamoff the out-fences will either signal normally if the driver waits > +for the operations on the buffers to finish or signal with an error if the > +driver cancels the pending operations. Buffers with in-fences won't be queued > +to the driver if their fences signal. They will be cleaned up. > + > +The ``V4L2_FMT_FLAG_UNORDERED`` flag in ``VIDIOC_ENUM_FMT`` tells userspace > +that the when using this format the order in which buffers are dequeued can remove 'the' > +be different from the order in which they were queued. > + > +Ordering is important to fences because it can optimize the pipeline with > +other drivers like a DRM/KMS display driver. For example, if a capture from the > +camera is happening in an orderly manner one can send the capture buffer > +out-fence to the DRM/KMS driver and rest sure that the buffers will be shown on rest sure -> rest assured But I'd rephrase it as: be certain > +the screen at the correct order. If an ordered queue can not be set then such > +arrangements with other drivers may not be possible. > > Return Value > ============ > diff --git a/Documentation/media/uapi/v4l/vidioc-querybuf.rst b/Documentation/media/uapi/v4l/vidioc-querybuf.rst > index dd54747fabc9..9aa3358bee0b 100644 > --- a/Documentation/media/uapi/v4l/vidioc-querybuf.rst > +++ b/Documentation/media/uapi/v4l/vidioc-querybuf.rst > @@ -44,7 +44,7 @@ and the ``index`` field. Valid index numbers range from zero to the > number of buffers allocated with > :ref:`VIDIOC_REQBUFS` (struct > :c:type:`v4l2_requestbuffers` ``count``) minus > -one. The ``reserved`` and ``reserved2`` fields must be set to 0. When > +one. The ``reserved`` field must be set to 0. When > using the :ref:`multi-planar API `, the ``m.planes`` > field must contain a userspace pointer to an array of struct > :c:type:`v4l2_plane` and the ``length`` field has to be set > @@ -64,8 +64,14 @@ elements will be used instead and the ``length`` field of struct > array elements. The driver may or may not set the remaining fields and > flags, they are meaningless in this context. > > -The struct :c:type:`v4l2_buffer` structure is specified in > -:ref:`buffer`. > +When using in-fences, the ``V4L2_BUF_FLAG_IN_FENCE`` will be set if the > +in-fence didn't signal at the time of the > +:ref:`VIDIOC_QUERYBUF`. The ``V4L2_BUF_FLAG_OUT_FENCE`` will be set if > +the user asked for an out-fence for the buffer and the ``fence_fd`` > +field will be set to the out-fence fd. In case ``V4L2_BUF_FLAG_OUT_FENCE`` is > +not set ``fence_fd`` will be set to 0 for backward compatibility. > + > +The struct :c:type:`v4l2_buffer` structure is specified in :ref:`buffer`. > > > Return Value > Regards, Hans