[{"id":34801,"web_url":"https://patchwork.libcamera.org/comment/34801/","msgid":"<175188735419.2340557.7707942098925167948@ping.linuxembedded.co.uk>","date":"2025-07-07T11:22:34","subject":"Re: [PATCH v2 4/5] pipeline: rkisp1: Properly handle the bufferCount\n\tset in the stream configuration","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:38)\n> The bufferCount is reset to a hardcoded value of 4 in\n> RkISP1Path::validate().  Keep the default value of 4 but do not reset\n> it, if it was changed.  This allows the user to set bufferCount to an\n> arbitrary number of buffers which then can be allocated for example by\n> the FrameBufferAllocator. Internally maxQueuedRequestsDevice_ is used as\n> buffer count which is the maximum number of buffers queued to the device\n> at once.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> \n> Changes in v1:\n> - Removed todo comment that was solved by this change\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 5 +++--\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 7 ++-----\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.h   | 4 +---\n>  3 files changed, 6 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index fff42359cbff..bdaeb935ee06 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -790,6 +790,7 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n>                         return nullptr;\n>  \n>                 cfg.colorSpace = colorSpace;\n> +               cfg.bufferCount = kPipelineDepth;\n>                 config->addConfiguration(cfg);\n>         }\n>  \n> @@ -1123,14 +1124,14 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL\n>         }\n>  \n>         if (data->mainPath_->isEnabled()) {\n> -               ret = mainPath_.start();\n> +               ret = mainPath_.start(maxQueuedRequestsDevice_);\n>                 if (ret)\n>                         return ret;\n>                 actions += [&]() { mainPath_.stop(); };\n>         }\n>  \n>         if (hasSelfPath_ && data->selfPath_->isEnabled()) {\n> -               ret = selfPath_.start();\n> +               ret = selfPath_.start(maxQueuedRequestsDevice_);\n>                 if (ret)\n>                         return ret;\n>         }\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> index 64018dc5b2f4..8ea5500d4080 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> @@ -249,7 +249,6 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,\n>         StreamConfiguration cfg(formats);\n>         cfg.pixelFormat = format;\n>         cfg.size = streamSize;\n> -       cfg.bufferCount = RKISP1_BUFFER_COUNT;\n>  \n>         return cfg;\n>  }\n> @@ -383,7 +382,6 @@ RkISP1Path::validate(const CameraSensor *sensor,\n>  \n>         cfg->size.boundTo(maxResolution);\n>         cfg->size.expandTo(minResolution);\n> -       cfg->bufferCount = RKISP1_BUFFER_COUNT;\n>  \n>         V4L2DeviceFormat format;\n>         format.fourcc = video_->toV4L2PixelFormat(cfg->pixelFormat);\n> @@ -480,15 +478,14 @@ int RkISP1Path::configure(const StreamConfiguration &config,\n>         return 0;\n>  }\n>  \n> -int RkISP1Path::start()\n> +int RkISP1Path::start(unsigned int bufferCount)\n>  {\n>         int ret;\n>  \n>         if (running_)\n>                 return -EBUSY;\n>  \n> -       /* \\todo Make buffer count user configurable. */\n> -       ret = video_->importBuffers(RKISP1_BUFFER_COUNT);\n> +       ret = video_->importBuffers(bufferCount);\n\nEeek. Sorry - this might be wrong here.\n\nWe're now letting applications allocate cfg.bufferCount size ... isn't\nthat what should be passed in here ?\n\nThis impacts the v4l2 buffer cache handling - where we track dma bufs to\nv4l2_buf objects.\n\nIt would still work - but I think we'll be cycling through permanantly\nhitting cache flush/misses now with this if the application sets\ncfg->bufferCount > kPipelineDepth.\n\n\nThe allocation that happens in this call is still small - and I still\nthink we should be 'importing' the maximum number V4L2 lets us in most\ncases - the existing v4l2 buffer cache we have would then manage these\naccordingly.\n\nI think for the time being - this series could instead pass in the\ncfg.Buffer count to the two paths... perhaps with a todo to suggest that\nit could easily just be the maximum allowed by v4l2 instead.\n\n--\nKieran\n\n\n>         if (ret)\n>                 return ret;\n>  \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> index 430181d371a7..0b60c499ac64 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> @@ -58,7 +58,7 @@ public:\n>                 return video_->exportBuffers(bufferCount, buffers);\n>         }\n>  \n> -       int start();\n> +       int start(unsigned int bufferCount);\n>         void stop();\n>  \n>         int queueBuffer(FrameBuffer *buffer) { return video_->queueBuffer(buffer); }\n> @@ -69,8 +69,6 @@ private:\n>         void populateFormats();\n>         Size filterSensorResolution(const CameraSensor *sensor);\n>  \n> -       static constexpr unsigned int RKISP1_BUFFER_COUNT = 4;\n> -\n>         const char *name_;\n>         bool running_;\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 3B75CC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Jul 2025 11:22:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43CA468EAA;\n\tMon,  7 Jul 2025 13:22:38 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 931B868E92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Jul 2025 13:22:36 +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 C56BA524;\n\tMon,  7 Jul 2025 13:22:09 +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=\"wBJnPYYV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1751887329;\n\tbh=cBCsZUTlLNsUokLpYw8zyuYaYHNhSxYfpeLakPTgXa0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=wBJnPYYV8uSBZZFtaUcQt+rppQuwwb15GbTorpOLO5ilRUrBj48j2pajFPEZMxh/i\n\tDTZX67NCg9vSSWsH97u4tFhL1R50o4kyncyviZmv0i+WYUwTJWKBXbX4y4VIMftWJR\n\tijgY/aPpidkIl+d9AR6AvZyn26Ecc76IiIXoRTPI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250707075400.9079-5-stefan.klug@ideasonboard.com>","References":"<20250707075400.9079-1-stefan.klug@ideasonboard.com>\n\t<20250707075400.9079-5-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 4/5] pipeline: rkisp1: Properly handle the bufferCount\n\tset in the stream configuration","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 07 Jul 2025 12:22:34 +0100","Message-ID":"<175188735419.2340557.7707942098925167948@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>"}}]