Received: by 10.213.65.68 with SMTP id h4csp1081990imn; Wed, 14 Mar 2018 09:04:46 -0700 (PDT) X-Google-Smtp-Source: AG47ELtjQktLkfPW4AGJN0RP9lyZhWn0bZ7qvEf5WHd/RNiMD34EiAr6xr8wyHkGy9as+mdQI276 X-Received: by 10.98.91.66 with SMTP id p63mr4727547pfb.163.1521043486160; Wed, 14 Mar 2018 09:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521043486; cv=none; d=google.com; s=arc-20160816; b=fIRtUPAwcDrfFXeWJG/IOfkombnhEGrt08DXzom8lN0D9hQNam5f92EOARK9ZjhOoM Z6ySBT1UKICQ4YmJ7jBpPhva+7R2frMfcYysjb6Qp2kko6vgRR1WzeSecDKnpCCYDobs DNsjsY20FGaQXcTW8GZsPjm5sy3x8nJ8pvjVnF4OAmPAF66V5xFXaZiKJfw7SnRRpEMF 5Z6Uwc5IrkdkzsmXvU7sONyRFGzlLenQs0DDvRW2D2V7Xj9v8ekH4DZz6IrddRVgvCHh gtX2sSCVionzoamDzVLsCruNIdxYoUMnzDwxA3yFQCZHpMsrouWXDeHNXxih5ClZd74V IYUA== 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:references:cc:to:from:subject:arc-authentication-results; bh=f1paTul0fpRTC4Uitlwvm0BYZGcWrLnnbzRVBzyKnns=; b=VwkPinZRczFDNYjn7AFIFAa3b9GJ+Shr8dc/J3AzeRrp2MvbnGFyYLOt+n9g2UyXQQ dVrEwe4A/hyWvzTwgquHuQHwamgv4p2sELcSgmk/beOXYEU/raHty2BUTLdzf11OIrEN 7IUbuaC6D6CcZ72D+2Ahxg3zuQ6HXPG2IGZ2IS6T3ow+xWajHsDH8Yux8FLRFTDHZhzE 4IvDCq+0plsFsu+ZuB+hTbDW3Kw3DHPbuyXzK+lGnUWItEJ9A/e3rNoKaZSQ7PEiI8Hw EcSH/SRu6Gg1hv0yFSYVPRP31lO/A3+FzKHTIRakCL05cMFUjdd/yfhlj++ERiowIArL CxdA== 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 99-v6si2215495plc.601.2018.03.14.09.04.11; Wed, 14 Mar 2018 09:04:46 -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 S1752561AbeCNQBr (ORCPT + 99 others); Wed, 14 Mar 2018 12:01:47 -0400 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:39527 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752038AbeCNQBq (ORCPT ); Wed, 14 Mar 2018 12:01:46 -0400 Received: from [10.11.18.221] ([65.153.83.185]) by smtp-cloud8.xs4all.net with ESMTPA id w8qQerW1maXTbw8qUeeDAC; Wed, 14 Mar 2018 17:01:44 +0100 Subject: Re: [PATCH v8 13/13] [media] v4l: Document explicit synchronization behavior From: Hans Verkuil 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> Message-ID: Date: Wed, 14 Mar 2018 09:01:37 -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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfO/THOT01gkqkR8p3zua/Sm5n1eroPcHFN8qf2dEkIuaFn1EZqAfPN+yDSAW6wKOI97u01RwVq/WSiFVqf5r5LYVzVrkRERaeUoK0DbonCUCi7b2tJU/ IM1IFmLJ+IGAg9h52g5/l4iFbgAMs2h6OmUurDYWg+fun98XUf13KZQvH1jsM9shKXPxjglOyVbjAsVdu0UOSt7gERnn/2Fk8yBQosoDUCrDNsB5tY2K3CMt vAwA//WYFxDC0Yx+tE7xscihtPYYrGdZz8rPboyZqfn/YMw5Kmu6zX5VwJw0BNxLs778MzSqrP61kNswgJtLzIcljcxHl+F1HROvTUcsftFhHbjl82rcpEST i9I0cQlcLcBXWBHEaguwPi1+QwgV/1PuScK6boEbwwOcDFT/picSG5sARMee37M40AnPfp+A+V6byEOdIzq6DTndCj7qh/kyMa50taiQehkRJ80LTeVo0R+C 26jFBwYNk7E0XgYI Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/13/2018 08:33 PM, Hans Verkuil wrote: > 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'. Ignore this comment. > > The fence_fd field will be ignored if the >> +``V4L2_BUF_FLAG_IN_FENCE`` is not set. Looking at the code, I don't think this is correct. You get an error if IN_FENCE is not set but fence_fd is. Removing this sentence would fix this and the previous sentence would make a lot more sense. >> + >> +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 What is missing in the documentation is what happens when you mix in-fence buffers and buffers without an in-fence. Regards, Hans