[{"id":4306,"web_url":"https://patchwork.libcamera.org/comment/4306/","msgid":"<20200326141957.GQ20581@pendragon.ideasonboard.com>","date":"2020-03-26T14:19:57","subject":"Re: [libcamera-devel] [PATCH 6/7] libcamera: ipu3: Do not\n\tunconditionally queue buffers to CIO2","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Tue, Mar 24, 2020 at 04:51:44PM +0100, Niklas Söderlund wrote:\n> Instead of unconditionally cycling buffers between the CIO2 and IMGU\n> pick a buffer when a request is queued to the pipeline. This is needed\n> if operations are to be applied to the buffer coming from CIO2 with\n> parameters coming from a Request.\n> \n> The approach to pick a CIO2 buffer when a request is queued is similar\n> to other pipelines, where parameters and statistic buffers are picked\n> this way.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n> * Changes since RFC\n> - Drop cio2ToRequest_ lookup map and use Request * in FrameBuffer.\n> - Removed duplicated LOG() from CIO2Device::allocateBuffers.\n> - Reassign instead of iterate to empty availableBuffers_.\n> - Fold CIO2Device::queueBuffer() into the only caller.\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 53 ++++++++++++++++++++++------\n>  1 file changed, 42 insertions(+), 11 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 1b44460e4d887d14..cc602834f24108a7 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -8,6 +8,7 @@\n>  #include <algorithm>\n>  #include <iomanip>\n>  #include <memory>\n> +#include <queue>\n>  #include <vector>\n>  \n>  #include <linux/media-bus-format.h>\n> @@ -118,6 +119,9 @@ public:\n>  \tint allocateBuffers();\n>  \tvoid freeBuffers();\n>  \n> +\tFrameBuffer *getBuffer();\n> +\tvoid putBuffer(FrameBuffer *buffer);\n> +\n>  \tint start();\n>  \tint stop();\n>  \n> @@ -129,6 +133,7 @@ public:\n>  \n>  private:\n>  \tstd::vector<std::unique_ptr<FrameBuffer>> buffers_;\n> +\tstd::queue<FrameBuffer *> availableBuffers_;\n>  };\n>  \n>  class IPU3Stream : public Stream\n> @@ -716,11 +721,21 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>  \n>  int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n>  {\n> +\tIPU3CameraData *data = cameraData(camera);\n> +\tFrameBuffer *buffer;\n>  \tint error = 0;\n>  \n> +\t/* Get a CIO2 buffer and track it it's used for this request. */\n\nSounds a bit weird. Maybe \"track that it's used\", or just \"and associate\nit with the request\" ? As you also queue the buffer, you may want to\nreflect that in the comment, \"..., associate it with the request and\nqueue it to the CIO2\" ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tbuffer = data->cio2_.getBuffer();\n> +\tif (!buffer)\n> +\t\treturn -EINVAL;\n> +\n> +\tbuffer->setRequest(request);\n> +\tdata->cio2_.output_->queueBuffer(buffer);\n> +\n>  \tfor (auto it : request->buffers()) {\n>  \t\tIPU3Stream *stream = static_cast<IPU3Stream *>(it.first);\n> -\t\tFrameBuffer *buffer = it.second;\n> +\t\tbuffer = it.second;\n>  \n>  \t\tint ret = stream->device_->dev->queueBuffer(buffer);\n>  \t\tif (ret < 0)\n> @@ -892,7 +907,7 @@ void IPU3CameraData::imguInputBufferReady(FrameBuffer *buffer)\n>  \tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n>  \t\treturn;\n>  \n> -\tcio2_.output_->queueBuffer(buffer);\n> +\tcio2_.putBuffer(buffer);\n>  }\n>  \n>  /**\n> @@ -1416,29 +1431,45 @@ int CIO2Device::allocateBuffers()\n>  {\n>  \tint ret = output_->allocateBuffers(CIO2_BUFFER_COUNT, &buffers_);\n>  \tif (ret < 0)\n> -\t\tLOG(IPU3, Error) << \"Failed to allocate CIO2 buffers\";\n> +\t\treturn ret;\n> +\n> +\tfor (std::unique_ptr<FrameBuffer> &buffer : buffers_)\n> +\t\tavailableBuffers_.push(buffer.get());\n>  \n>  \treturn ret;\n>  }\n>  \n>  void CIO2Device::freeBuffers()\n>  {\n> +\tavailableBuffers_ = {};\n> +\n>  \tbuffers_.clear();\n>  \n>  \tif (output_->releaseBuffers())\n>  \t\tLOG(IPU3, Error) << \"Failed to release CIO2 buffers\";\n>  }\n>  \n> +FrameBuffer *CIO2Device::getBuffer()\n> +{\n> +\tif (availableBuffers_.empty()) {\n> +\t\tLOG(IPU3, Error) << \"CIO2 buffer underrun\";\n> +\t\treturn nullptr;\n> +\t}\n> +\n> +\tFrameBuffer *buffer = availableBuffers_.front();\n> +\n> +\tavailableBuffers_.pop();\n> +\n> +\treturn buffer;\n> +}\n> +\n> +void CIO2Device::putBuffer(FrameBuffer *buffer)\n> +{\n> +\tavailableBuffers_.push(buffer);\n> +}\n> +\n>  int CIO2Device::start()\n>  {\n> -\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers_) {\n> -\t\tint ret = output_->queueBuffer(buffer.get());\n> -\t\tif (ret) {\n> -\t\t\tLOG(IPU3, Error) << \"Failed to queue CIO2 buffer\";\n> -\t\t\treturn ret;\n> -\t\t}\n> -\t}\n> -\n>  \treturn output_->streamOn();\n>  }\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E282F60410\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Mar 2020 15:20:01 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 50EA12DC;\n\tThu, 26 Mar 2020 15:20:01 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Wnx/hGBy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585232401;\n\tbh=cQ3ls+EpJXQEKmZVo987QeqhoXSsLCMBRVcZsVIbgmc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Wnx/hGByb/s4+KHiEtSfLrDXJVn11GYaSSPfrQOBb2TMxh0G+g/r+xAUzhJwE5ZMw\n\tURX0Yo0Du8v9U7LWxS+/gSq/8PNiasXm9nhOljYnFwzjC+usfnvG/iuEfI9DilgrxF\n\tAkc6x0adC1KGyEM5M2ensbKZZ2nZEE96jF7VVvrw=","Date":"Thu, 26 Mar 2020 16:19:57 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200326141957.GQ20581@pendragon.ideasonboard.com>","References":"<20200324155145.3896183-1-niklas.soderlund@ragnatech.se>\n\t<20200324155145.3896183-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200324155145.3896183-7-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 6/7] libcamera: ipu3: Do not\n\tunconditionally queue buffers to CIO2","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>","X-List-Received-Date":"Thu, 26 Mar 2020 14:20:02 -0000"}}]