[{"id":26102,"web_url":"https://patchwork.libcamera.org/comment/26102/","msgid":"<20221216152536.vdbuznkyjh6elv2t@uno.localdomain>","date":"2022-12-16T15:25:36","subject":"Re: [libcamera-devel] [PATCH v9 07/18] libcamera: pipeline: rkisp1:\n\tDon't rely on bufferCount","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Paul\n\nOn Fri, Dec 16, 2022 at 09:29:28PM +0900, Paul Elder via libcamera-devel wrote:\n> From: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n>\n> Currently the rkisp1 pipeline handler relies on bufferCount to decide on\n> the number of parameter and statistics buffers to allocate internally\n> and for the number of V4L2 buffer slots to reserve. Instead, the number\n> of internal buffers should be the minimum required by the pipeline to\n> keep the requests flowing, in order to avoid wasting memory, while the\n> number of V4L2 buffer slots should be greater than the expected number\n> of requests queued by the application, in order to avoid thrashing\n> dmabuf mappings, which would degrade performance.\n>\n> Stop relying on bufferCount for these numbers and instead set them to\n> appropriate, and independent, constants.\n>\n> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n>\n> ---\n> Changes in v9:\n> - rebased\n>\n> Changes in v8:\n> - New\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 19 ++++++++++++-------\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |  3 +--\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.h   |  2 ++\n>  3 files changed, 15 insertions(+), 9 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 8fe37c4f..5028ef1a 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -199,6 +199,16 @@ private:\n>  \tCamera *activeCamera_;\n>\n>  \tconst MediaPad *ispSink_;\n> +\n> +\t/*\n> +\t * This many internal buffers (or rather parameter and statistics buffer\n> +\t * pairs) ensures that the pipeline runs smoothly, without frame drops.\n> +\t * This number considers:\n> +\t * - three buffers queued to the driver, which is also the minimum\n> +\t *   required to start streaming\n> +\t * - one buffer being processed on the IPA\n> +\t */\n> +\tstatic constexpr unsigned int kRkISP1InternalBufferCount = 4;\n\nI indeed see\ndrivers/media/platform/rockchip/rkisp1/rkisp1-capture.c:#define RKISP1_MIN_BUFFERS_NEEDED 3\n\nThis seems quite right\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n\n>  };\n>\n>  RkISP1Frames::RkISP1Frames(PipelineHandler *pipe)\n> @@ -835,17 +845,12 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n>  \tunsigned int ipaBufferId = 1;\n>  \tint ret;\n>\n> -\tunsigned int maxCount = std::max({\n> -\t\tdata->mainPathStream_.configuration().bufferCount,\n> -\t\tdata->selfPathStream_.configuration().bufferCount,\n> -\t});\n> -\n>  \tif (!isRaw_) {\n> -\t\tret = param_->allocateBuffers(maxCount, &paramBuffers_);\n> +\t\tret = param_->allocateBuffers(kRkISP1InternalBufferCount, &paramBuffers_);\n>  \t\tif (ret < 0)\n>  \t\t\tgoto error;\n>\n> -\t\tret = stat_->allocateBuffers(maxCount, &statBuffers_);\n> +\t\tret = stat_->allocateBuffers(kRkISP1InternalBufferCount, &statBuffers_);\n>  \t\tif (ret < 0)\n>  \t\t\tgoto error;\n>  \t}\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> index 5079b268..a168e0ad 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> @@ -370,8 +370,7 @@ int RkISP1Path::start()\n>  \tif (running_)\n>  \t\treturn -EBUSY;\n>\n> -\t/* \\todo Make buffer count user configurable. */\n> -\tret = video_->importBuffers(RKISP1_BUFFER_COUNT);\n> +\tret = video_->importBuffers(kRkISP1BufferSlotCount);\n>  \tif (ret)\n>  \t\treturn ret;\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> index bdf3f95b..5b53783c 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> @@ -76,6 +76,8 @@ private:\n>  \tstd::unique_ptr<V4L2Subdevice> resizer_;\n>  \tstd::unique_ptr<V4L2VideoDevice> video_;\n>  \tMediaLink *link_;\n> +\n> +\tstatic constexpr unsigned int kRkISP1BufferSlotCount = 16;\n>  };\n>\n>  class RkISP1MainPath : public RkISP1Path\n> --\n> 2.35.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9AD5DC31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Dec 2022 15:25:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1385863360;\n\tFri, 16 Dec 2022 16:25:41 +0100 (CET)","from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::221])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 38BBB603D0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Dec 2022 16:25:39 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id DD53524000B;\n\tFri, 16 Dec 2022 15:25:37 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1671204341;\n\tbh=+DGPws6qkCR8w1RgJrBh4dfBO078YyBXyn6qSJTRoJA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=GMCRMfib50fnZGwcszmmmJMf1eQC1ciQgnl2GlzWhhhl9Y9EGnCKEjnIB4ajQSM7T\n\tItUF6m5ET9MoKFIHo38gHCzbUTABf/z4u6qtqUbyCHaDpJVtdCo3FT/7oJzV37VIVP\n\tsmyMb/r8WzHfuN3+bQlkoS0Gg95pK4cmi33z2fltsnGxXOKB4toRJxWmMEYnkUruvp\n\tVqQL0Pi2rKZRM18VqmvxPvtc1lfn8NIEhX4wV6pf9Hg8G6o9zY36uniCh9ixvvcU4P\n\tWsIaM8psdiG0Ro0N6mRgIyIUnAPhiGl7ETR1by6Tb8BHtG7avBXTER0ZhELMd8CR08\n\tBQP9nhKuCs92A==","Date":"Fri, 16 Dec 2022 16:25:36 +0100","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20221216152536.vdbuznkyjh6elv2t@uno.localdomain>","References":"<20221216122939.256534-1-paul.elder@ideasonboard.com>\n\t<20221216122939.256534-8-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20221216122939.256534-8-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v9 07/18] libcamera: pipeline: rkisp1:\n\tDon't rely on bufferCount","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]