[{"id":14921,"web_url":"https://patchwork.libcamera.org/comment/14921/","msgid":"<20210203113653.zpy2urznxwxpj666@uno.localdomain>","date":"2021-02-03T11:36:53","subject":"Re: [libcamera-devel] [PATCH v4 3/3] cam: Only queue the exact\n\tnumber of requests asked for","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Tue, Feb 02, 2021 at 11:10:51PM +0100, Niklas Söderlund wrote:\n> The cam option --capture=N is suppose to only capture N requests. But if\n> the processing done for each request is large (such as writing it to a\n> slow disk) the current implementation could queue more then N requests\n> before the exit condition is detected and capturing stopped.\n>\n> Solve this by only queueing N requests while still waiting for N\n> requests to complete before exiting.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> ---\n>  src/cam/capture.cpp | 16 +++++++++++++---\n>  src/cam/capture.h   |  2 ++\n>  2 files changed, 15 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> index 113ea49d50046e5b..e498b562826b8794 100644\n> --- a/src/cam/capture.cpp\n> +++ b/src/cam/capture.cpp\n> @@ -18,7 +18,7 @@ using namespace libcamera;\n>  Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config,\n>  \t\t EventLoop *loop)\n>  \t: camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop),\n> -\t  captureCount_(0), captureLimit_(0)\n> +\t  queueCount_(0), captureCount_(0), captureLimit_(0)\n>  {\n>  }\n>\n> @@ -26,6 +26,7 @@ int Capture::run(const OptionsParser::Options &options)\n>  {\n>  \tint ret;\n>\n> +\tqueueCount_ = 0;\n>  \tcaptureCount_ = 0;\n>  \tcaptureLimit_ = options[OptCapture].toInteger();\n>\n> @@ -128,7 +129,7 @@ int Capture::capture(FrameBufferAllocator *allocator)\n>  \t}\n>\n>  \tfor (std::unique_ptr<Request> &request : requests_) {\n> -\t\tret = camera_->queueRequest(request.get());\n> +\t\tret = queueRequest(request.get());\n>  \t\tif (ret < 0) {\n>  \t\t\tstd::cerr << \"Can't queue request\" << std::endl;\n>  \t\t\tcamera_->stop();\n> @@ -152,6 +153,15 @@ int Capture::capture(FrameBufferAllocator *allocator)\n>  \treturn ret;\n>  }\n>\n> +int Capture::queueRequest(Request *request)\n> +{\n> +\tqueueCount_++;\n> +\tif (captureLimit_ && queueCount_ > captureLimit_)\n> +\t\treturn 0;\n> +\n> +\treturn camera_->queueRequest(request);\n> +}\n> +\n>  void Capture::requestComplete(Request *request)\n>  {\n>  \tif (request->status() == Request::RequestCancelled)\n> @@ -213,5 +223,5 @@ void Capture::processRequest(Request *request)\n>  \t}\n>\n>  \trequest->reuse(Request::ReuseBuffers);\n> -\tcamera_->queueRequest(request);\n> +\tqueueRequest(request);\n>  }\n> diff --git a/src/cam/capture.h b/src/cam/capture.h\n> index d21c95a26ce7d83a..c7c9dc00d30f06d6 100644\n> --- a/src/cam/capture.h\n> +++ b/src/cam/capture.h\n> @@ -32,6 +32,7 @@ public:\n>  private:\n>  \tint capture(libcamera::FrameBufferAllocator *allocator);\n>\n> +\tint queueRequest(libcamera::Request *request);\n>  \tvoid requestComplete(libcamera::Request *request);\n>  \tvoid processRequest(libcamera::Request *request);\n>\n> @@ -43,6 +44,7 @@ private:\n>  \tuint64_t last_;\n>\n>  \tEventLoop *loop_;\n> +\tunsigned int queueCount_;\n>  \tunsigned int captureCount_;\n>  \tunsigned int captureLimit_;\n>\n> --\n> 2.30.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 940E3BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Feb 2021 11:36:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6F9ED68442;\n\tWed,  3 Feb 2021 12:36:33 +0100 (CET)","from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE476683FE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Feb 2021 12:36:31 +0100 (CET)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 89C6D1C0011;\n\tWed,  3 Feb 2021 11:36:31 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Wed, 3 Feb 2021 12:36:53 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20210203113653.zpy2urznxwxpj666@uno.localdomain>","References":"<20210202221051.1740237-1-niklas.soderlund@ragnatech.se>\n\t<20210202221051.1740237-4-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210202221051.1740237-4-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 3/3] cam: Only queue the exact\n\tnumber of requests asked for","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":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14940,"web_url":"https://patchwork.libcamera.org/comment/14940/","msgid":"<YBtEj2MCH0B+DQcC@pendragon.ideasonboard.com>","date":"2021-02-04T00:49:19","subject":"Re: [libcamera-devel] [PATCH v4 3/3] cam: Only queue the exact\n\tnumber of requests asked for","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, Feb 02, 2021 at 11:10:51PM +0100, Niklas Söderlund wrote:\n> The cam option --capture=N is suppose to only capture N requests. But if\n> the processing done for each request is large (such as writing it to a\n> slow disk) the current implementation could queue more then N requests\n\ns/then/than/\n\n> before the exit condition is detected and capturing stopped.\n> \n> Solve this by only queueing N requests while still waiting for N\n> requests to complete before exiting.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/cam/capture.cpp | 16 +++++++++++++---\n>  src/cam/capture.h   |  2 ++\n>  2 files changed, 15 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> index 113ea49d50046e5b..e498b562826b8794 100644\n> --- a/src/cam/capture.cpp\n> +++ b/src/cam/capture.cpp\n> @@ -18,7 +18,7 @@ using namespace libcamera;\n>  Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config,\n>  \t\t EventLoop *loop)\n>  \t: camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop),\n> -\t  captureCount_(0), captureLimit_(0)\n> +\t  queueCount_(0), captureCount_(0), captureLimit_(0)\n>  {\n>  }\n>  \n> @@ -26,6 +26,7 @@ int Capture::run(const OptionsParser::Options &options)\n>  {\n>  \tint ret;\n>  \n> +\tqueueCount_ = 0;\n>  \tcaptureCount_ = 0;\n>  \tcaptureLimit_ = options[OptCapture].toInteger();\n>  \n> @@ -128,7 +129,7 @@ int Capture::capture(FrameBufferAllocator *allocator)\n>  \t}\n>  \n>  \tfor (std::unique_ptr<Request> &request : requests_) {\n> -\t\tret = camera_->queueRequest(request.get());\n> +\t\tret = queueRequest(request.get());\n>  \t\tif (ret < 0) {\n>  \t\t\tstd::cerr << \"Can't queue request\" << std::endl;\n>  \t\t\tcamera_->stop();\n> @@ -152,6 +153,15 @@ int Capture::capture(FrameBufferAllocator *allocator)\n>  \treturn ret;\n>  }\n>  \n> +int Capture::queueRequest(Request *request)\n> +{\n> +\tqueueCount_++;\n> +\tif (captureLimit_ && queueCount_ > captureLimit_)\n> +\t\treturn 0;\n\nI'd write this\n\n\tif (captureLimit_ && queueCount_ >= captureLimit_)\n\t\treturn 0;\n\n\tqueueCount_++;\n\nso that queueCount_ will never go above captureLimit_. The behaviour\nwill be the same, but it could be less confusing during debugging\nsessions when someone may wondering why the queueCount_ value seems to\nindicate that more requests are queued than the limit that has been set.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n> +\treturn camera_->queueRequest(request);\n> +}\n> +\n>  void Capture::requestComplete(Request *request)\n>  {\n>  \tif (request->status() == Request::RequestCancelled)\n> @@ -213,5 +223,5 @@ void Capture::processRequest(Request *request)\n>  \t}\n>  \n>  \trequest->reuse(Request::ReuseBuffers);\n> -\tcamera_->queueRequest(request);\n> +\tqueueRequest(request);\n>  }\n> diff --git a/src/cam/capture.h b/src/cam/capture.h\n> index d21c95a26ce7d83a..c7c9dc00d30f06d6 100644\n> --- a/src/cam/capture.h\n> +++ b/src/cam/capture.h\n> @@ -32,6 +32,7 @@ public:\n>  private:\n>  \tint capture(libcamera::FrameBufferAllocator *allocator);\n>  \n> +\tint queueRequest(libcamera::Request *request);\n>  \tvoid requestComplete(libcamera::Request *request);\n>  \tvoid processRequest(libcamera::Request *request);\n>  \n> @@ -43,6 +44,7 @@ private:\n>  \tuint64_t last_;\n>  \n>  \tEventLoop *loop_;\n> +\tunsigned int queueCount_;\n>  \tunsigned int captureCount_;\n>  \tunsigned int captureLimit_;\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 C8E49BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 00:49:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 431DE613E5;\n\tThu,  4 Feb 2021 01:49:43 +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 C700360302\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 01:49:41 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 455F351B;\n\tThu,  4 Feb 2021 01:49:41 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"C0/sUJKs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1612399781;\n\tbh=KgDLco93kugbFOmqdw/FP7yrWHkk9IABi+mspJ5hQuY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=C0/sUJKsmiCQOBnv3znEIEqnxsx5dWFLNoc32Efp/72yLtleKqunAY6DGUAXjdrFv\n\tHqa1nAzb33r+fzM2aa8vJMNN31Hy8jHnwzkOrwwMNu72DlPEWGZVh6GeFaHXZGsvfh\n\tYajcbjZ+1LXfQn1WOXqqAMHy/wbQawYb+7AYNIug=","Date":"Thu, 4 Feb 2021 02:49:19 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<YBtEj2MCH0B+DQcC@pendragon.ideasonboard.com>","References":"<20210202221051.1740237-1-niklas.soderlund@ragnatech.se>\n\t<20210202221051.1740237-4-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210202221051.1740237-4-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 3/3] cam: Only queue the exact\n\tnumber of requests asked for","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":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]