[{"id":31808,"web_url":"https://patchwork.libcamera.org/comment/31808/","msgid":"<172928722560.532453.6700292534748122460@ping.linuxembedded.co.uk>","date":"2024-10-18T21:33:45","subject":"Re: [PATCH v4 3/3] libcamera: software_isp: Clean up pending\n\trequests on stop","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2024-10-18 10:27:16)\n> PipelineHandler::stop() calls stopDevice() method to perform pipeline\n> specific cleanup and then completes waiting requests.  If any queued\n> requests remain, an assertion error is raised.\n> \n> Software ISP stores request buffers in\n> SimpleCameraData::conversionQueue_ and queues them as V4L2 signals\n> bufferReady.  stopDevice() cleanup forgets to clean up the buffers and\n> their requests from conversionQueue_, possibly resulting in the\n> assertion error.  This patch fixes the omission.\n> \n> The problem wasn't very visible when\n> SimplePipelineHandler::kNumInternalBuffers (the number of buffers\n> allocated in V4L2) was equal to the number of buffers exported from\n> software ISP.  But when the number of the exported buffers was increased\n> by one in commit abe2ec64f9e4e97bbdfe3a50372611bd7b5315c2, the assertion\n> error started pop up in some environments.  Increasing the number of the\n> buffers much more, e.g. to 9, makes the problem very reproducible.\n> \n> Each pipeline uses its own mechanism to track the requests to clean up\n> and it can't be excluded that similar omissions are present in other\n> places.  But there is no obvious way to make a common cleanup for all\n> the pipelines (except for doing it instead of raising the assertion\n> error, which is probably undesirable, in order not to hide incomplete\n> pipeline specific cleanups).\n\nIndeed, that's why I added the assertion in the common place instead\nof a generic cleanup.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Bug: https://bugs.libcamera.org/show_bug.cgi?id=234\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/pipeline/simple/simple.cpp | 10 ++++++++++\n>  1 file changed, 10 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index a1339d87c..995223364 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -284,6 +284,7 @@ public:\n>         std::vector<std::unique_ptr<FrameBuffer>> conversionBuffers_;\n>         std::queue<std::pair<Request *, std::map<const Stream *, FrameBuffer *>>> conversionQueue_;\n>         bool useConversion_;\n> +       void clearIncompleteRequests();\n>  \n>         std::unique_ptr<Converter> converter_;\n>         std::unique_ptr<SoftwareIsp> swIsp_;\n> @@ -893,6 +894,14 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)\n>                 pipe->completeRequest(request);\n>  }\n>  \n> +void SimpleCameraData::clearIncompleteRequests()\n> +{\n> +       while (!conversionQueue_.empty()) {\n> +               pipe()->cancelRequest(conversionQueue_.front().first);\n> +               conversionQueue_.pop();\n> +       }\n> +}\n> +\n>  void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId)\n>  {\n>         swIsp_->processStats(frame, bufferId,\n> @@ -1402,6 +1411,7 @@ void SimplePipelineHandler::stopDevice(Camera *camera)\n>  \n>         video->bufferReady.disconnect(data, &SimpleCameraData::bufferReady);\n>  \n> +       data->clearIncompleteRequests();\n>         data->conversionBuffers_.clear();\n>  \n>         releasePipeline(data);\n> -- \n> 2.44.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 A01EBC32AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Oct 2024 21:33:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D7BE6538B;\n\tFri, 18 Oct 2024 23:33:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CAEF465380\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Oct 2024 23:33:48 +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 865297E2;\n\tFri, 18 Oct 2024 23:32:04 +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=\"KCnCOBay\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729287124;\n\tbh=hw/B/ZhuU+OOkWIfQ99mAeChqISYg482hkbCcM91vPs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KCnCOBay8/ddnqc9h9mtvKzg4Cv3XjyFlpf729kv6MCczDktIuJfnLVUfMPkwn9iL\n\t1ya1lpG1WNAcseXNTgd8mOchQeb9sApz2dhbjewhfHX3vtYhnGJb7GdZaMA0Is6M3E\n\t7psuR+Gha3A2FHsMrbO+9FCfG5597cSneJRpTPuk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241018092716.295624-4-mzamazal@redhat.com>","References":"<20241018092716.295624-1-mzamazal@redhat.com>\n\t<20241018092716.295624-4-mzamazal@redhat.com>","Subject":"Re: [PATCH v4 3/3] libcamera: software_isp: Clean up pending\n\trequests on stop","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, robert.mader@posteo.de,\n\tlaurent.pinchart@ideasonboard.com","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Fri, 18 Oct 2024 22:33:45 +0100","Message-ID":"<172928722560.532453.6700292534748122460@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]