From patchwork Fri Jan 7 12:55:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15259 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E89A5C3259 for ; Fri, 7 Jan 2022 12:55:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E24F860921; Fri, 7 Jan 2022 13:55:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gQ90xyeF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB993608E6 for ; Fri, 7 Jan 2022 13:55:10 +0100 (CET) Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7CF46A4D; Fri, 7 Jan 2022 13:55:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1641560110; bh=Pn75HRmzKvRVkRnUb+Q6QwDpslmAnlakg162AnOULQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gQ90xyeFH0qttco3vzGp3AMyJ9uxX17hBhszJfSR1fKDhRN5td0ghAuvJ2jXgwdJG WQw+oTmz4qQKtaWDoQxM47qmLEEiLlpmJ+Pj7Vf/8jzCERT7JhK/zK8n3JZj6IHVFM 2tgR6QhT6euuoYnND/Izy53mE+eD43sO7ZaFFQ8k= From: Kieran Bingham To: libcamera devel Date: Fri, 7 Jan 2022 12:55:05 +0000 Message-Id: <20220107125506.1477795-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220107125506.1477795-1-kieran.bingham@ideasonboard.com> References: <20220107125506.1477795-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: pipeline_handler: Prepare requests X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide a call allowing requests to be prepared and associated with the pipeline handler after being constructed by the camera. This provides an opportunity for the Pipeline Handler to connect any signals it may be interested in receiveing for the request such as getting notifications when the request is ready for processing when using a fence. While here, update the existing usage of the d pointer in Camera::createRequest() to match the style of other functions. Signed-off-by: Kieran Bingham Tested-by: David Plowman --- include/libcamera/internal/pipeline_handler.h | 1 + src/libcamera/camera.cpp | 14 ++++++++++--- src/libcamera/pipeline_handler.cpp | 20 ++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index e5b8ffb4db3d..ef7e1390560f 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -59,6 +59,7 @@ public: void stop(Camera *camera); bool hasPendingRequests(const Camera *camera) const; + void prepareRequest(Request *request); void queueRequest(Request *request); bool completeBuffer(Request *request, FrameBuffer *buffer); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 86d84ac0a77d..1a00b34d9d9d 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -1074,12 +1074,20 @@ int Camera::configure(CameraConfiguration *config) */ std::unique_ptr Camera::createRequest(uint64_t cookie) { - int ret = _d()->isAccessAllowed(Private::CameraConfigured, - Private::CameraRunning); + Private *const d = _d(); + + int ret = d->isAccessAllowed(Private::CameraConfigured, + Private::CameraRunning); if (ret < 0) return nullptr; - return std::make_unique(this, cookie); + std::unique_ptr request = std::make_unique(this, cookie); + + /* Associate the request with the pipeline handler */ + if (request) + d->pipe_->prepareRequest(request.get()); + + return request; } /** diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 03e4b9e66aa6..18b59ef27fb6 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -337,6 +337,23 @@ bool PipelineHandler::hasPendingRequests(const Camera *camera) const return !camera->_d()->queuedRequests_.empty(); } +/** + * \fn PipelineHandler::prepareRequest() + * \brief Prepare a request for use by the Pipeline Handler + * \param[in] request The request to prepare + */ +void PipelineHandler::prepareRequest(Request *request) +{ + /* + * Connect the request prepared signal to the pipeline handler + * to manage fence based preparations allowing the request + * to inform us when it is ready to be processed by hardware. + */ + request->_d()->prepared.connect(this, [this]() { + doQueueRequests(); + }); +} + /** * \fn PipelineHandler::queueRequest() * \brief Queue a request @@ -366,9 +383,6 @@ void PipelineHandler::queueRequest(Request *request) waitingRequests_.push(request); - request->_d()->prepared.connect(this, [this]() { - doQueueRequests(); - }); request->_d()->prepare(300ms); } From patchwork Fri Jan 7 12:55:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15260 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BFF20C325A for ; Fri, 7 Jan 2022 12:55:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 483BC608E6; Fri, 7 Jan 2022 13:55:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="J/p3E8y6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16F926091E for ; Fri, 7 Jan 2022 13:55:11 +0100 (CET) Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B56FD11BB; Fri, 7 Jan 2022 13:55:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1641560110; bh=i20JeXHm30wC0P+xND/ZuoxhTyzcltGmvvWoMiRwLxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J/p3E8y6Pk7yfOlYdvKjyzNI33SimLOOO8MqSRmallVNcVHdDs7wauRO73aOk8c9m m1LPggT/9pOZ4VnrRCCLOut5+bfFhmCGNW9rM84XTtGlgG5r+JQU/5oTA2brc3E8NO jGjGUOrnW3eDg8sD1QgghDcdf30Wne+QgZiVTy6g= From: Kieran Bingham To: libcamera devel Date: Fri, 7 Jan 2022 12:55:06 +0000 Message-Id: <20220107125506.1477795-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220107125506.1477795-1-kieran.bingham@ideasonboard.com> References: <20220107125506.1477795-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: base: signal: Prevent excessive slot usage X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Slots are not expected to be connected to lots of signals. Our normal use case is a one to one mapping with a signal expected to call one slot. While we support multiple slots, excessive use is likely the result of a bug indicating a failure to disconnect slots or repeated connection of a slot which can lead to memory leaks and poor performance when deleting the Object. Assert that a maximum of 8 slots are connected which will catch any bug and still allow some multiple slot usage. If this limit is ever met it can be extended and considered at that time. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi Tested-by: David Plowman --- Note that this patch causes the CTS tests to fail as they hit this assertion. It is not yet investigated if we really need more slots or if the assertion has already caught a slot-leak, but posting for early review anyway. src/libcamera/base/signal.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/base/signal.cpp b/src/libcamera/base/signal.cpp index 9df45d079a42..7e6a23cc909d 100644 --- a/src/libcamera/base/signal.cpp +++ b/src/libcamera/base/signal.cpp @@ -7,6 +7,7 @@ #include +#include #include /** @@ -35,6 +36,13 @@ void SignalBase::connect(BoundMethodBase *slot) if (object) object->connect(this); slots_.push_back(slot); + + /* + * Slots are not expected to be used to connect many items. If we exceed + * a reasonable amount, presume that there is a bug and fail fast on + * debug builds. + */ + ASSERT(slots_.size() < 8); } void SignalBase::disconnect(Object *object)