[{"id":33486,"web_url":"https://patchwork.libcamera.org/comment/33486/","msgid":"<20250226003709.GL18866@pendragon.ideasonboard.com>","date":"2025-02-26T00:37:09","subject":"Re: [PATCH v3 5/6] libcamera: software_isp: Dispatch messages on\n\tstop","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Tue, Feb 25, 2025 at 04:06:11PM +0100, Milan Zamazal wrote:\n> There may be pending messages in SoftwareIsp message queue when\n> SoftwareIsp stops.  The call to IPAProxySoft::stop() will dispatch them\n> before SoftwareIsp::stop() finishes.  But this is dependent on\n> IPAProxySoft::stop() implementation, let's break this dependency and\n> dispatch messages to SoftwareIsp explicitly in SoftwareIsp::stop().\n> \n> This also allows dropping `running_' flag.  Since the SoftwareIsp\n> messages get processed and invoke IPA calls before the IPA proxy is set\n> to ProxyStopping state and the SoftwareIsp worker thread is no longer\n> running, it's guaranteed that no new messages come to SoftwareIsp and\n> attempt to call the stopped IPA proxy.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  .../internal/software_isp/software_isp.h      |  1 -\n>  src/libcamera/software_isp/software_isp.cpp   | 24 ++++++++-----------\n>  2 files changed, 10 insertions(+), 15 deletions(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index 400a4dc5..133b545c 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -101,7 +101,6 @@ private:\n>  \tDmaBufAllocator dmaHeap_;\n>  \n>  \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n> -\tbool running_;\n>  \tstd::deque<FrameBuffer *> queuedInputBuffers_;\n>  \tstd::deque<FrameBuffer *> queuedOutputBuffers_;\n>  };\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index beac66fc..193713b9 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -14,6 +14,7 @@\n>  #include <unistd.h>\n>  \n>  #include <libcamera/base/log.h>\n> +#include <libcamera/base/thread.h>\n>  \n>  #include <libcamera/controls.h>\n>  #include <libcamera/formats.h>\n> @@ -323,7 +324,6 @@ int SoftwareIsp::start()\n>  \tint ret = ipa_->start();\n>  \tif (ret)\n>  \t\treturn ret;\n> -\trunning_ = true;\n>  \n>  \tispWorkerThread_.start();\n>  \treturn 0;\n> @@ -340,7 +340,8 @@ void SoftwareIsp::stop()\n>  \tispWorkerThread_.exit();\n>  \tispWorkerThread_.wait();\n>  \n> -\trunning_ = false;\n> +\tThread::current()->dispatchMessages(Message::Type::InvokeMessage, this);\n> +\n>  \tipa_->stop();\n>  \n>  \tfor (auto buffer : queuedOutputBuffers_) {\n> @@ -383,26 +384,21 @@ void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls)\n>  \n>  void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)\n>  {\n> -\tif (running_)\n> -\t\tispStatsReady.emit(frame, bufferId);\n> +\tispStatsReady.emit(frame, bufferId);\n>  }\n>  \n>  void SoftwareIsp::inputReady(FrameBuffer *input)\n>  {\n> -\tif (running_) {\n> -\t\tASSERT(queuedInputBuffers_.front() == input);\n> -\t\tqueuedInputBuffers_.pop_front();\n> -\t\tinputBufferReady.emit(input);\n> -\t}\n> +\tASSERT(queuedInputBuffers_.front() == input);\n> +\tqueuedInputBuffers_.pop_front();\n> +\tinputBufferReady.emit(input);\n>  }\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>  {\n> -\tif (running_) {\n> -\t\tASSERT(queuedOutputBuffers_.front() == output);\n> -\t\tqueuedOutputBuffers_.pop_front();\n> -\t\toutputBufferReady.emit(output);\n> -\t}\n> +\tASSERT(queuedOutputBuffers_.front() == output);\n> +\tqueuedOutputBuffers_.pop_front();\n> +\toutputBufferReady.emit(output);\n>  }\n>  \n>  } /* namespace libcamera */","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 A9B7DBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Feb 2025 00:37:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B9A9468736;\n\tWed, 26 Feb 2025 01:37:31 +0100 (CET)","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 7E3B361852\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Feb 2025 01:37:29 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB42A6A6;\n\tWed, 26 Feb 2025 01:36:01 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"OuG3X/aA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740530161;\n\tbh=19vXz2X1IGFwjhqEWB0Np6Yfyqyli4dmzlXzYBm89uw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OuG3X/aAvan6nVC9z+UwCwZyXiZN4cP0CGgOKIVXHEEyfAyMT8JJ/3QhZf7S2hHk3\n\tFR8wS1YdXdFcUZ34l4LuYG7yNwZAb2/hey0cNAhM+6b57CSwhFb1KRt4TGg9UuoGDt\n\tACxd+uuwJP6EsSA+TWiSMhN51Bk4/CCopjsUb064=","Date":"Wed, 26 Feb 2025 02:37:09 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v3 5/6] libcamera: software_isp: Dispatch messages on\n\tstop","Message-ID":"<20250226003709.GL18866@pendragon.ideasonboard.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-6-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250225150614.20195-6-mzamazal@redhat.com>","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":33521,"web_url":"https://patchwork.libcamera.org/comment/33521/","msgid":"<174087035408.3864332.5896186043936173703@ping.linuxembedded.co.uk>","date":"2025-03-01T23:05:54","subject":"Re: [PATCH v3 5/6] libcamera: software_isp: Dispatch messages on\n\tstop","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-02-25 15:06:11)\n> There may be pending messages in SoftwareIsp message queue when\n> SoftwareIsp stops.  The call to IPAProxySoft::stop() will dispatch them\n> before SoftwareIsp::stop() finishes.  But this is dependent on\n> IPAProxySoft::stop() implementation, let's break this dependency and\n> dispatch messages to SoftwareIsp explicitly in SoftwareIsp::stop().\n> \n> This also allows dropping `running_' flag.  Since the SoftwareIsp\n> messages get processed and invoke IPA calls before the IPA proxy is set\n> to ProxyStopping state and the SoftwareIsp worker thread is no longer\n> running, it's guaranteed that no new messages come to SoftwareIsp and\n> attempt to call the stopped IPA proxy.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  .../internal/software_isp/software_isp.h      |  1 -\n>  src/libcamera/software_isp/software_isp.cpp   | 24 ++++++++-----------\n>  2 files changed, 10 insertions(+), 15 deletions(-)\n> \n> diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\n> index 400a4dc5..133b545c 100644\n> --- a/include/libcamera/internal/software_isp/software_isp.h\n> +++ b/include/libcamera/internal/software_isp/software_isp.h\n> @@ -101,7 +101,6 @@ private:\n>         DmaBufAllocator dmaHeap_;\n>  \n>         std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n> -       bool running_;\n>         std::deque<FrameBuffer *> queuedInputBuffers_;\n>         std::deque<FrameBuffer *> queuedOutputBuffers_;\n>  };\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index beac66fc..193713b9 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -14,6 +14,7 @@\n>  #include <unistd.h>\n>  \n>  #include <libcamera/base/log.h>\n> +#include <libcamera/base/thread.h>\n>  \n>  #include <libcamera/controls.h>\n>  #include <libcamera/formats.h>\n> @@ -323,7 +324,6 @@ int SoftwareIsp::start()\n>         int ret = ipa_->start();\n>         if (ret)\n>                 return ret;\n> -       running_ = true;\n>  \n>         ispWorkerThread_.start();\n>         return 0;\n> @@ -340,7 +340,8 @@ void SoftwareIsp::stop()\n>         ispWorkerThread_.exit();\n>         ispWorkerThread_.wait();\n>  \n> -       running_ = false;\n> +       Thread::current()->dispatchMessages(Message::Type::InvokeMessage, this);\n> +\n>         ipa_->stop();\n>  \n>         for (auto buffer : queuedOutputBuffers_) {\n> @@ -383,26 +384,21 @@ void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls)\n>  \n>  void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId)\n>  {\n> -       if (running_)\n> -               ispStatsReady.emit(frame, bufferId);\n> +       ispStatsReady.emit(frame, bufferId);\n>  }\n>  \n>  void SoftwareIsp::inputReady(FrameBuffer *input)\n>  {\n> -       if (running_) {\n> -               ASSERT(queuedInputBuffers_.front() == input);\n> -               queuedInputBuffers_.pop_front();\n> -               inputBufferReady.emit(input);\n> -       }\n> +       ASSERT(queuedInputBuffers_.front() == input);\n> +       queuedInputBuffers_.pop_front();\n> +       inputBufferReady.emit(input);\n>  }\n>  \n>  void SoftwareIsp::outputReady(FrameBuffer *output)\n>  {\n> -       if (running_) {\n> -               ASSERT(queuedOutputBuffers_.front() == output);\n> -               queuedOutputBuffers_.pop_front();\n> -               outputBufferReady.emit(output);\n> -       }\n> +       ASSERT(queuedOutputBuffers_.front() == output);\n> +       queuedOutputBuffers_.pop_front();\n> +       outputBufferReady.emit(output);\n>  }\n>  \n>  } /* namespace libcamera */\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 6ADC5C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  1 Mar 2025 23:05:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1FD5F68822;\n\tSun,  2 Mar 2025 00:05:58 +0100 (CET)","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 07647687FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  2 Mar 2025 00:05:57 +0100 (CET)","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 D0302666;\n\tSun,  2 Mar 2025 00:04:26 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ti7VQH2+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740870266;\n\tbh=B5a+36tQ9Qm9udHw2aMv8RXMlH/idVx8qlSUbNOiU0Y=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ti7VQH2+VvX56IkxyF1cch4sNgattqH4hai0S+C36EnGToCAsdZaRUp92xjnKXJap\n\tQRXGp4pfosd89na+ZpPx+iFiz6FoUkq4VI8IGTuDZw/EALjNrWpil+5SSAIKL1wKSF\n\t05eaHmSO6adkucu+sqjlXO3b7R1KspFIP659nuIU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250225150614.20195-6-mzamazal@redhat.com>","References":"<20250225150614.20195-1-mzamazal@redhat.com>\n\t<20250225150614.20195-6-mzamazal@redhat.com>","Subject":"Re: [PATCH v3 5/6] libcamera: software_isp: Dispatch messages on\n\tstop","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Sat, 01 Mar 2025 23:05:54 +0000","Message-ID":"<174087035408.3864332.5896186043936173703@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>"}}]