From patchwork Fri Mar 9 17:49:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10271443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11AAE603B5 for ; Fri, 9 Mar 2018 17:50:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2C74237F1 for ; Fri, 9 Mar 2018 17:50:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E73F2286F3; Fri, 9 Mar 2018 17:50:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 622F1237F1 for ; Fri, 9 Mar 2018 17:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932705AbeCIRu1 (ORCPT ); Fri, 9 Mar 2018 12:50:27 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:38052 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932689AbeCIRuZ (ORCPT ); Fri, 9 Mar 2018 12:50:25 -0500 Received: by mail-qk0-f195.google.com with SMTP id s198so4599980qke.5; Fri, 09 Mar 2018 09:50:24 -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=ud2i7/Q2DhutSvxpCkn0g09Q8OBJqb17vb7sBzDgWCQ=; b=iWxOPoX+0OX5GLTT2YxiBhpfuWRoqt0xx17D6R1ftBT8Iw/XVhD4AU1so+DzR8rwLC auq15eaClmkc+8aGE43yruo5mQUl2PIuhK6GOHp4nzZcsLjWM0lwLITCV7iFMW4ALy+Z s7iMhwMqFLLZo2ceVwFNLIAdmL6N6pwnkjw60BjWNonWDMxswQnq7HnI5gaStIvoeVOf pfUbQj0Ct0AyezuHNeOuexNXBnNei4l1E4kvlrhiY+D0Z/rtMCT0fOI8NT9/jEW7VVzk bH/ATgVFfXlhGkq9T9Wt8nqbkZLqqiNcadsBxRQNlJQejPXhlhCit2TdAvWwnvTohBGJ zsBA== X-Gm-Message-State: AElRT7GgpxQKSWiW1dFHXnxnEsahnXMxlLjRJ2vRx1QpTX8FoezE4Xl4 YoCJtqzp9S0OfVu2amKewfCicQRC X-Google-Smtp-Source: AG47ELuj3xAIKMREsi3mKyxwBidxa7fRQiKg6IbOYoWhjhqoQhE7Aqs444t9wtWxQtmo99DawWLf1A== X-Received: by 10.55.43.144 with SMTP id r16mr1799646qkr.117.1520617824069; Fri, 09 Mar 2018 09:50:24 -0800 (PST) Received: from localhost.localdomain ([2804:14c:138:2ada:4961:b672:c997:efad]) by smtp.gmail.com with ESMTPSA id g4sm873976qke.91.2018.03.09.09.50.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Mar 2018 09:50:23 -0800 (PST) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: kernel@collabora.com, Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [PATCH v8 13/13] [media] v4l: Document explicit synchronization behavior Date: Fri, 9 Mar 2018 14:49:20 -0300 Message-Id: <20180309174920.22373-14-gustavo@padovan.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180309174920.22373-1-gustavo@padovan.org> References: <20180309174920.22373-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 +that fence signal. + +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. + +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. + +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 +have both in-fence ond 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 +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 +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