Patch Detail
Show a patch.
GET /api/1.1/patches/12863/?format=api
{ "id": 12863, "url": "https://patchwork.libcamera.org/api/1.1/patches/12863/?format=api", "web_url": "https://patchwork.libcamera.org/patch/12863/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210707144202.1327061-10-nfraprado@collabora.com>", "date": "2021-07-07T14:42:01", "name": "[libcamera-devel,v5,09/10] libcamera: pipeline: Don't rely on bufferCount", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7d9e5a8cc890282b5cf67e5e16c1d47b50bab2e8", "submitter": { "id": 84, "url": "https://patchwork.libcamera.org/api/1.1/people/84/?format=api", "name": "Nícolas F. R. A. Prado", "email": "nfraprado@collabora.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/12863/mbox/", "series": [ { "id": 2216, "url": "https://patchwork.libcamera.org/api/1.1/series/2216/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2216", "date": "2021-07-07T14:41:52", "name": "lc-compliance: Add test to queue more requests than hardware depth", "version": 5, "mbox": "https://patchwork.libcamera.org/series/2216/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/12863/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/12863/checks/", "tags": {}, "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 56EA4BD794\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 7 Jul 2021 14:42:39 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 23D9A68503;\n\tWed, 7 Jul 2021 16:42:39 +0200 (CEST)", "from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D5C9A68523\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 7 Jul 2021 16:42:37 +0200 (CEST)", "from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:6553:ad0c:9d2a:24db])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nfraprado)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id B93681F434E4;\n\tWed, 7 Jul 2021 15:42:35 +0100 (BST)" ], "From": "=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 7 Jul 2021 11:42:01 -0300", "Message-Id": "<20210707144202.1327061-10-nfraprado@collabora.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20210707144202.1327061-1-nfraprado@collabora.com>", "References": "<20210707144202.1327061-1-nfraprado@collabora.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 09/10] libcamera: pipeline: Don't rely\n\ton 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>", "Cc": "kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?=\n\t<andrealmeid@collabora.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Pipelines have relied on bufferCount to decide on the number of buffers\nto allocate internally through allocateBuffers() and on the number of\nV4L2 buffer slots to reserve through importBuffers(). Instead, the\nnumber of internal buffers should be the minimum required by the\nalgorithms to avoid wasting memory, and the number of V4L2 buffer slots\nshould overallocate to avoid thrashing dmabuf mappings.\n\nFor now, just set them to constants and stop relying on bufferCount, to\nallow for its removal.\n\nSigned-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n---\n src/libcamera/pipeline/ipu3/imgu.cpp | 12 ++++++------\n src/libcamera/pipeline/ipu3/imgu.h | 5 ++++-\n src/libcamera/pipeline/ipu3/ipu3.cpp | 9 +--------\n .../pipeline/raspberrypi/raspberrypi.cpp | 15 +++++----------\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 9 ++-------\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 2 +-\n src/libcamera/pipeline/rkisp1/rkisp1_path.h | 3 +++\n src/libcamera/pipeline/simple/converter.cpp | 4 ++--\n src/libcamera/pipeline/simple/converter.h | 3 +++\n src/libcamera/pipeline/simple/simple.cpp | 6 ++----\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 5 +++--\n src/libcamera/pipeline/vimc/vimc.cpp | 5 +++--\n 12 files changed, 35 insertions(+), 43 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\nindex e955bc3456ba..ac044638f9b0 100644\n--- a/src/libcamera/pipeline/ipu3/imgu.cpp\n+++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n@@ -593,22 +593,22 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad,\n /**\n * \\brief Allocate buffers for all the ImgU video devices\n */\n-int ImgUDevice::allocateBuffers(unsigned int bufferCount)\n+int ImgUDevice::allocateBuffers()\n {\n \t/* Share buffers between CIO2 output and ImgU input. */\n-\tint ret = input_->importBuffers(bufferCount);\n+\tint ret = input_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret) {\n \t\tLOG(IPU3, Error) << \"Failed to import ImgU input buffers\";\n \t\treturn ret;\n \t}\n \n-\tret = param_->allocateBuffers(bufferCount, ¶mBuffers_);\n+\tret = param_->allocateBuffers(INTERNAL_BUFFER_COUNT, ¶mBuffers_);\n \tif (ret < 0) {\n \t\tLOG(IPU3, Error) << \"Failed to allocate ImgU param buffers\";\n \t\tgoto error;\n \t}\n \n-\tret = stat_->allocateBuffers(bufferCount, &statBuffers_);\n+\tret = stat_->allocateBuffers(INTERNAL_BUFFER_COUNT, &statBuffers_);\n \tif (ret < 0) {\n \t\tLOG(IPU3, Error) << \"Failed to allocate ImgU stat buffers\";\n \t\tgoto error;\n@@ -619,13 +619,13 @@ int ImgUDevice::allocateBuffers(unsigned int bufferCount)\n \t * corresponding stream is active or inactive, as the driver needs\n \t * buffers to be requested on the V4L2 devices in order to operate.\n \t */\n-\tret = output_->importBuffers(bufferCount);\n+\tret = output_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0) {\n \t\tLOG(IPU3, Error) << \"Failed to import ImgU output buffers\";\n \t\tgoto error;\n \t}\n \n-\tret = viewfinder_->importBuffers(bufferCount);\n+\tret = viewfinder_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0) {\n \t\tLOG(IPU3, Error) << \"Failed to import ImgU viewfinder buffers\";\n \t\tgoto error;\ndiff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h\nindex 9d4915116087..4163a8dc0875 100644\n--- a/src/libcamera/pipeline/ipu3/imgu.h\n+++ b/src/libcamera/pipeline/ipu3/imgu.h\n@@ -61,7 +61,7 @@ public:\n \t\t\t\t\t outputFormat);\n \t}\n \n-\tint allocateBuffers(unsigned int bufferCount);\n+\tint allocateBuffers();\n \tvoid freeBuffers();\n \n \tint start();\n@@ -86,6 +86,9 @@ private:\n \tstatic constexpr unsigned int PAD_VF = 3;\n \tstatic constexpr unsigned int PAD_STAT = 4;\n \n+\tstatic constexpr unsigned int INTERNAL_BUFFER_COUNT = 4;\n+\tstatic constexpr unsigned int BUFFER_SLOT_COUNT = 5;\n+\n \tint linkSetup(const std::string &source, unsigned int sourcePad,\n \t\t const std::string &sink, unsigned int sinkPad,\n \t\t bool enable);\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex f3b456ba3afa..e80b0aaea8dc 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -681,16 +681,9 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)\n {\n \tIPU3CameraData *data = cameraData(camera);\n \tImgUDevice *imgu = data->imgu_;\n-\tunsigned int bufferCount;\n \tint ret;\n \n-\tbufferCount = std::max({\n-\t\tdata->outStream_.configuration().bufferCount,\n-\t\tdata->vfStream_.configuration().bufferCount,\n-\t\tdata->rawStream_.configuration().bufferCount,\n-\t});\n-\n-\tret = imgu->allocateBuffers(bufferCount);\n+\tret = imgu->allocateBuffers();\n \tif (ret < 0)\n \t\treturn ret;\n \ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 33d826433668..9ad837f23338 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1154,20 +1154,15 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n {\n \tRPiCameraData *data = cameraData(camera);\n \tint ret;\n+\tconstexpr unsigned int bufferCount = 4;\n \n \t/*\n-\t * Decide how many internal buffers to allocate. For now, simply look\n-\t * at how many external buffers will be provided. We'll need to improve\n-\t * this logic. However, we really must have all streams allocate the same\n-\t * number of buffers to simplify error handling in queueRequestDevice().\n+\t * Allocate internal buffers. We really must have all streams allocate\n+\t * the same number of buffers to simplify error handling in\n+\t * queueRequestDevice().\n \t */\n-\tunsigned int maxBuffers = 0;\n-\tfor (const Stream *s : camera->streams())\n-\t\tif (static_cast<const RPi::Stream *>(s)->isExternal())\n-\t\t\tmaxBuffers = std::max(maxBuffers, s->configuration().bufferCount);\n-\n \tfor (auto const stream : data->streams_) {\n-\t\tret = stream->prepareBuffers(maxBuffers);\n+\t\tret = stream->prepareBuffers(bufferCount);\n \t\tif (ret < 0)\n \t\t\treturn ret;\n \t}\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 768969f4194a..a36fc432cd0d 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -690,16 +690,11 @@ 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-\tret = param_->allocateBuffers(maxCount, ¶mBuffers_);\n+\tret = param_->allocateBuffers(INTERNAL_BUFFER_COUNT, ¶mBuffers_);\n \tif (ret < 0)\n \t\tgoto error;\n \n-\tret = stat_->allocateBuffers(maxCount, &statBuffers_);\n+\tret = stat_->allocateBuffers(INTERNAL_BUFFER_COUNT, &statBuffers_);\n \tif (ret < 0)\n \t\tgoto error;\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex 25f482eb8d8e..ec281fef316b 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -172,7 +172,7 @@ int RkISP1Path::start()\n \t\treturn -EBUSY;\n \n \t/* \\todo Make buffer count user configurable. */\n-\tret = video_->importBuffers(RKISP1_BUFFER_COUNT);\n+\tret = video_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret)\n \t\treturn ret;\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\nindex 91757600ccdc..a0c4ef066a71 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n@@ -27,6 +27,9 @@ class V4L2Subdevice;\n struct StreamConfiguration;\n struct V4L2SubdeviceFormat;\n \n+static constexpr unsigned int INTERNAL_BUFFER_COUNT = 4;\n+static constexpr unsigned int BUFFER_SLOT_COUNT = 5;\n+\n class RkISP1Path\n {\n public:\ndiff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\nindex 3baf78f9364c..e797a1e8f2e8 100644\n--- a/src/libcamera/pipeline/simple/converter.cpp\n+++ b/src/libcamera/pipeline/simple/converter.cpp\n@@ -103,11 +103,11 @@ int SimpleConverter::Stream::exportBuffers(unsigned int count,\n \n int SimpleConverter::Stream::start()\n {\n-\tint ret = m2m_->output()->importBuffers(inputBufferCount_);\n+\tint ret = m2m_->output()->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0)\n \t\treturn ret;\n \n-\tret = m2m_->capture()->importBuffers(outputBufferCount_);\n+\tret = m2m_->capture()->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0) {\n \t\tstop();\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h\nindex 276a2a291c21..dc252afd08e4 100644\n--- a/src/libcamera/pipeline/simple/converter.h\n+++ b/src/libcamera/pipeline/simple/converter.h\n@@ -29,6 +29,9 @@ class SizeRange;\n struct StreamConfiguration;\n class V4L2M2MDevice;\n \n+constexpr unsigned int INTERNAL_BUFFER_COUNT = 5;\n+constexpr unsigned int BUFFER_SLOT_COUNT = 5;\n+\n class SimpleConverter\n {\n public:\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 37e880db0782..e9c914b32d63 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -803,12 +803,10 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n \t\t * When using the converter allocate a fixed number of internal\n \t\t * buffers.\n \t\t */\n-\t\tret = video->allocateBuffers(kNumInternalBuffers,\n+\t\tret = video->allocateBuffers(INTERNAL_BUFFER_COUNT,\n \t\t\t\t\t &data->converterBuffers_);\n \t} else {\n-\t\t/* Otherwise, prepare for using buffers from the only stream. */\n-\t\tStream *stream = &data->streams_[0];\n-\t\tret = video->importBuffers(stream->configuration().bufferCount);\n+\t\tret = video->importBuffers(BUFFER_SLOT_COUNT);\n \t}\n \tif (ret < 0)\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex a1fa295a6456..f9fbcd721c4d 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -91,6 +91,8 @@ private:\n \t\treturn static_cast<UVCCameraData *>(\n \t\t\tPipelineHandler::cameraData(camera));\n \t}\n+\n+\tstatic constexpr unsigned int BUFFER_SLOT_COUNT = 5;\n };\n \n UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data)\n@@ -236,9 +238,8 @@ int PipelineHandlerUVC::exportFrameBuffers(Camera *camera,\n int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList *controls)\n {\n \tUVCCameraData *data = cameraData(camera);\n-\tunsigned int count = data->stream_.configuration().bufferCount;\n \n-\tint ret = data->video_->importBuffers(count);\n+\tint ret = data->video_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0)\n \t\treturn ret;\n \ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex d163e6b9767d..969f454e9951 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -102,6 +102,8 @@ private:\n \t\treturn static_cast<VimcCameraData *>(\n \t\t\tPipelineHandler::cameraData(camera));\n \t}\n+\n+\tstatic constexpr unsigned int BUFFER_SLOT_COUNT = 5;\n };\n \n namespace {\n@@ -312,9 +314,8 @@ int PipelineHandlerVimc::exportFrameBuffers(Camera *camera,\n int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlList *controls)\n {\n \tVimcCameraData *data = cameraData(camera);\n-\tunsigned int count = data->stream_.configuration().bufferCount;\n \n-\tint ret = data->video_->importBuffers(count);\n+\tint ret = data->video_->importBuffers(BUFFER_SLOT_COUNT);\n \tif (ret < 0)\n \t\treturn ret;\n \n", "prefixes": [ "libcamera-devel", "v5", "09/10" ] }