[{"id":34802,"web_url":"https://patchwork.libcamera.org/comment/34802/","msgid":"<175188753935.2340557.8896280344292999751@ping.linuxembedded.co.uk>","date":"2025-07-07T11:25:39","subject":"Re: [PATCH v2 5/5] libcamera: pipeline: rkisp1: Don't rely on\n\tbufferCount","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-07-07 08:53:39)\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> Instead, the number of internal buffers should be the minimum required\n> by the pipeline to keep the requests flowing, in order to avoid wasting\n> memory.\n> \n> Stop relying on bufferCount for these numbers and instead set them to\n> kPipelineDepth, as this already limits the number of buffers queued\n> to the driver.\n> \n> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 15 +++++++--------\n>  1 file changed, 7 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index bdaeb935ee06..8591e4868e6f 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -157,6 +157,10 @@ private:\n>  \n>  namespace {\n>  \n> +/*\n> + * This many internal buffers (or rather parameter and statistics buffer\n> + * pairs) ensures that the pipeline runs smoothly, without frame drops.\n> + */\n>  const unsigned int kPipelineDepth = 4;\n>  \n>  } // namespace\n> @@ -990,24 +994,19 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n>         unsigned int ipaBufferId = 1;\n>         int ret;\n>  \n> -       unsigned int maxCount = std::max({\n> -               data->mainPathStream_.configuration().bufferCount,\n> -               data->selfPathStream_.configuration().bufferCount,\n> -       });\n> -\n>         if (!isRaw_) {\n> -               ret = param_->allocateBuffers(maxCount, &paramBuffers_);\n> +               ret = param_->allocateBuffers(kPipelineDepth, &paramBuffers_);\n>                 if (ret < 0)\n>                         goto error;\n>  \n> -               ret = stat_->allocateBuffers(maxCount, &statBuffers_);\n> +               ret = stat_->allocateBuffers(kPipelineDepth, &statBuffers_);\n>                 if (ret < 0)\n>                         goto error;\n>         }\n>  \n>         /* If the dewarper is being used, allocate internal buffers for ISP. */\n>         if (useDewarper_) {\n> -               ret = mainPath_.exportBuffers(maxCount, &mainPathBuffers_);\n> +               ret = mainPath_.exportBuffers(kPipelineDepth, &mainPathBuffers_);\n>                 if (ret < 0)\n>                         goto error;\n>  \n> -- \n> 2.48.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 24B5CC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Jul 2025 11:25:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3BE8E68EAA;\n\tMon,  7 Jul 2025 13:25:43 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 92DC468E92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Jul 2025 13:25:41 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9FFFE524;\n\tMon,  7 Jul 2025 13:25:14 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wRGyUDHS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1751887514;\n\tbh=vFWvCbtseEn2sJlhQqid/N20jtUen978C45xiAWgbzk=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=wRGyUDHShf6Vdm0nb4mLLLTWj7jMj8An9GpWB3cmWUpYOMmesWgZcDW+Ok5JDlH0H\n\tHzOGHiYYzQtCCwZeb13BHxyeFLjEVU1wdJcnU21zw2J4bEisgMV56niD5ClQdOL7Pu\n\t9VMGiopfMxOv+wBJHADg26XO4pfJFpGI9gAjI8Bc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250707075400.9079-6-stefan.klug@ideasonboard.com>","References":"<20250707075400.9079-1-stefan.klug@ideasonboard.com>\n\t<20250707075400.9079-6-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 5/5] libcamera: pipeline: rkisp1: Don't rely on\n\tbufferCount","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>, =?utf-8?q?N=C3=ADcolas?=\n\tF. R. A. Prado <nfraprado@collabora.com>, Paul Elder\n\t<paul.elder@ideasonboard.com>, Sven =?utf-8?q?P=C3=BCschel?=\n\t<s.pueschel@pengutronix.de>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 07 Jul 2025 12:25:39 +0100","Message-ID":"<175188753935.2340557.8896280344292999751@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34818,"web_url":"https://patchwork.libcamera.org/comment/34818/","msgid":"<nxlhxn7xzmjw3ur56priv3pmudtkjjhbruculxhbvqvwvy4wqf@wsgs7qs7zpsa>","date":"2025-07-08T05:23:55","subject":"Re: [PATCH v2 5/5] libcamera: pipeline: rkisp1: Don't rely on\n\tbufferCount","submitter":{"id":232,"url":"https://patchwork.libcamera.org/api/people/232/","name":"Umang Jain","email":"uajain@igalia.com"},"content":"On Mon, Jul 07, 2025 at 09:53:39AM +0200, Stefan Klug 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> Instead, the number of internal buffers should be the minimum required\n> by the pipeline to keep the requests flowing, in order to avoid wasting\n> memory.\n> \n\nThe commit message should be adapted to reflect the usage of\nmaxQueuedRequestsDevice_.\n\n```\nThe RkISP1 pipeline handler currently relies on CameraConfiguration::bufferCount\nto allocate internal buffers for parameters and statistics buffers.\n\nHowever, only maxQueuedRequestsDevice_ requests can be queued to the\nunderlying hardware to saturate the pipeline, hence allocate buffers\npairs upto maxQueuedRequestsDevice_, for parameters and statistics.\n```\n\n> Stop relying on bufferCount for these numbers and instead set them to\n> kPipelineDepth, as this already limits the number of buffers queued\n> to the driver.\n> \n> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 15 +++++++--------\n>  1 file changed, 7 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index bdaeb935ee06..8591e4868e6f 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -157,6 +157,10 @@ private:\n>  \n>  namespace {\n>  \n> +/*\n> + * This many internal buffers (or rather parameter and statistics buffer\n> + * pairs) ensures that the pipeline runs smoothly, without frame drops.\n> + */\n\nnit: With the kPipelineDepth naming changed, this comment would rather be\nobvious to understand, hence can be considered to drop.\n\nReviewed-by: Umang Jain <uajain@igalia.com>\n\n>  const unsigned int kPipelineDepth = 4;\n>  \n>  } // namespace\n> @@ -990,24 +994,19 @@ 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(kPipelineDepth, &paramBuffers_);\n>  \t\tif (ret < 0)\n>  \t\t\tgoto error;\n>  \n> -\t\tret = stat_->allocateBuffers(maxCount, &statBuffers_);\n> +\t\tret = stat_->allocateBuffers(kPipelineDepth, &statBuffers_);\n>  \t\tif (ret < 0)\n>  \t\t\tgoto error;\n>  \t}\n>  \n>  \t/* If the dewarper is being used, allocate internal buffers for ISP. */\n>  \tif (useDewarper_) {\n> -\t\tret = mainPath_.exportBuffers(maxCount, &mainPathBuffers_);\n> +\t\tret = mainPath_.exportBuffers(kPipelineDepth, &mainPathBuffers_);\n>  \t\tif (ret < 0)\n>  \t\t\tgoto error;\n>  \n> -- \n> 2.48.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 3E950C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Jul 2025 05:23:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4A7C368ECF;\n\tTue,  8 Jul 2025 07:23:57 +0200 (CEST)","from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5CC976186C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jul 2025 07:23:55 +0200 (CEST)","from [49.36.71.127] (helo=uajain)\n\tby fanzine2.igalia.com with esmtpsa \n\t(Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)\n\t(Exim) id 1uZ0o5-00DrRJ-Go; Tue, 08 Jul 2025 07:23:54 +0200"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=igalia.com header.i=@igalia.com\n\theader.b=\"hhWt9Q/H\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n\ts=20170329;\n\th=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version\n\t:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=qkJHMH4UeJCCyQ4utGWQW3fzxR6poT3UgqRQdv7lGvQ=;\n\tb=hhWt9Q/HLjVyLqPH0C4fU2izWw\n\tXkAt0J1TFTMl+aBqFz93BLbZXrs0USuvdBGRpnvfLNdeLqwWYkQ/RK/gHlDsxdkioqKuXqOrS0wRH\n\txVOwhiaT5EVjhrIGBwcXk0LVc+e33ZoeLtenT8erWmtyK/Sjago2TiTSSS/k0oQXrNR7mA/dPFlNj\n\tJRis5PClOG2tUZ7+ZN8JclS9SVf0eG70VO6VUqMjdDdCrBcztjUnuSJw+XC7ehbsrfQAWbji3YRyq\n\tQ43Fq1xJ3lc9t/RA6vQgtojXgyyytP/6f1ToCxc1RcnuO9CyY+5j+ruQ+gKAUsRCXyDHxIBHprSyH\n\tNqx/znJw==;","Date":"Tue, 8 Jul 2025 10:53:55 +0530","From":"Umang Jain <uajain@igalia.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, =?utf-8?b?TsOtY29sYXMgRi4gUi4g?=\n\t=?utf-8?q?A=2E?= Prado <nfraprado@collabora.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>, Sven =?utf-8?q?P=C3=BCschel?=\n\t<s.pueschel@pengutronix.de>","Subject":"Re: [PATCH v2 5/5] libcamera: pipeline: rkisp1: Don't rely on\n\tbufferCount","Message-ID":"<nxlhxn7xzmjw3ur56priv3pmudtkjjhbruculxhbvqvwvy4wqf@wsgs7qs7zpsa>","References":"<20250707075400.9079-1-stefan.klug@ideasonboard.com>\n\t<20250707075400.9079-6-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250707075400.9079-6-stefan.klug@ideasonboard.com>","User-Agent":"NeoMutt/20250510-dirty","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]