From patchwork Fri Mar 12 06:11:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11561 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 8CBB0BD1F1 for ; Fri, 12 Mar 2021 06:11:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9067F68C74; Fri, 12 Mar 2021 07:11:37 +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="mv+N/Ik7"; 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 40302602ED for ; Fri, 12 Mar 2021 07:11:36 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BCA8E8F9; Fri, 12 Mar 2021 07:11:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529495; bh=WSRrLaQBYWjP+vcKGc7yio/nTR2LbBqY95CXK5wPI2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mv+N/Ik7Ius9KMOGxrQ+jvq87tKAOX6Ho7Yd2GbFLOEXM8aFWwgy9ouvTJU/jMZPr BgYO+p5P1QbZkZ34j32/p54hGEI/SSPqrOYVRM3N0dbh7DpZ3BgfFHBUC/iimTQ+kr 87WufnbY8Jn0OO+mzPTzR/NsneANcfAjUaR04LbQ= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:24 +0000 Message-Id: <20210312061131.854849-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/8] libcamera: request: Provide a sequence number 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 sequence number on Requests which are added by the pipeline handler. Each pipeline handler keeps a requestSequence and increments everytime a request is queued. The sequence number is associated with the Request and can be utilised for assisting with debugging, and printing the queueing sequence of in flight requests. Signed-off-by: Kieran Bingham --- include/libcamera/internal/pipeline_handler.h | 4 +++- include/libcamera/request.h | 2 ++ src/libcamera/pipeline_handler.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 6aca0b46f43d..0655a665a85f 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -38,7 +38,7 @@ class CameraData { public: explicit CameraData(PipelineHandler *pipe) - : pipe_(pipe) + : pipe_(pipe), requestSequence_(0) { } virtual ~CameraData() = default; @@ -48,6 +48,8 @@ public: ControlInfoMap controlInfo_; ControlList properties_; + uint64_t requestSequence_; + private: LIBCAMERA_DISABLE_COPY(CameraData) }; diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 6e5aad5f6b75..6f2f881e840a 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -50,6 +50,7 @@ public: int addBuffer(const Stream *stream, FrameBuffer *buffer); FrameBuffer *findBuffer(const Stream *stream) const; + uint64_t sequence() const { return sequence_; } uint64_t cookie() const { return cookie_; } Status status() const { return status_; } @@ -71,6 +72,7 @@ private: BufferMap bufferMap_; std::unordered_set pending_; + uint64_t sequence_; const uint64_t cookie_; Status status_; bool cancelled_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index d22991d318c9..e3d4975d9ffd 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -382,6 +382,8 @@ int PipelineHandler::queueRequest(Request *request) CameraData *data = cameraData(camera); data->queuedRequests_.push_back(request); + request->sequence_ = data->requestSequence_++; + int ret = queueRequestDevice(camera, request); if (ret) data->queuedRequests_.remove(request); From patchwork Fri Mar 12 06:11:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11562 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 C9451BD1F1 for ; Fri, 12 Mar 2021 06:11:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D875F68C7D; Fri, 12 Mar 2021 07:11:39 +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="Ab7X32Wt"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9627D602ED for ; Fri, 12 Mar 2021 07:11:36 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 24C90A27; Fri, 12 Mar 2021 07:11:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529496; bh=mio3TBRsq6S1QTk5nncX/izBn0dtYPYRAfyfChvig+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ab7X32Wt8gyxiNjYs80uR9YqC5EY9h0u49gTGAYg+d5NnIMIImS9/AYldjexE/81a qZqL1NiFrnDIopmujSp331pg8o/jgJHNegbdgwMVP+t4y+oWM7c8WXkeLt/i2CbqKb YjrFzMQ5XPcnvVHDEVVI1F1+Wq+iJEnFsyEqI7E8= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:25 +0000 Message-Id: <20210312061131.854849-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/8] libcamera: request: Add a toString() 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 toString helper to assist in printing Request state for debug and logging contexts. Signed-off-by: Kieran Bingham --- include/libcamera/request.h | 2 ++ src/libcamera/request.cpp | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 6f2f881e840a..59d7f4bac0d2 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -56,6 +56,8 @@ public: bool hasPendingBuffers() const { return !pending_.empty(); } + const std::string toString() const; + private: LIBCAMERA_DISABLE_COPY(Request) diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 24c3694de5fc..12c2e7d425f9 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -268,7 +268,7 @@ void Request::complete() status_ = cancelled_ ? RequestCancelled : RequestComplete; LOG(Request, Debug) - << "Request has completed - cookie: " << cookie_ + << toString() << " has completed - cookie: " << cookie_ << (cancelled_ ? " [Cancelled]" : ""); LIBCAMERA_TRACEPOINT(request_complete, this); @@ -302,4 +302,22 @@ bool Request::completeBuffer(FrameBuffer *buffer) return !hasPendingBuffers(); } +const std::string Request::toString() const +{ + std::stringstream ss; + + static const char *statuses[] = { + "Pending", + "Complete", + "Cancelled", + }; + + ss << "Request (" << sequence_ << ") " << statuses[status_]; + + if (hasPendingBuffers()) + ss << " [Pending:" << pending_.size() << "]"; + + return ss.str(); +} + } /* namespace libcamera */ From patchwork Fri Mar 12 06:11:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11563 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 54F37BD1F1 for ; Fri, 12 Mar 2021 06:11:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A02A668C77; Fri, 12 Mar 2021 07:11:40 +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="HHetBgmJ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E8B7E602ED for ; Fri, 12 Mar 2021 07:11:36 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80695A2A; Fri, 12 Mar 2021 07:11:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529496; bh=yytt+4azPIqoYR4s4qT2V1wzg8BBRWKQN5WkdQJsu3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HHetBgmJ/ch0tMsopHdgynsZ/CCd16GhlhQ0jQGBt7VqXjD0RsJJeEoX5dwFFRVdk a9ehQaWcCgFdqLLXDkXpv/hO7i4eMgQhpdCgFHBSYhvyEv/m4YHZu4cJYfDjGTSXRO YTY/1Mk+7I1z6ytybeZsLG8DwMmRtomPgrCEeENM= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:26 +0000 Message-Id: <20210312061131.854849-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] libcamera: pipeline: ipu3: Reset sequence counts to zero on stop 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" Reset the request sequence counter back to zero when a camera has stopped, giving each camera run an independent sequence stream. Signed-off-by: Kieran Bingham --- RFC: This again would be perhaps better handled by the base class to ensure all pipeline handlers handle this in a consistent manner. src/libcamera/pipeline/ipu3/ipu3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index a61e2b51ef9e..3d3bd4a43c23 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -780,6 +780,8 @@ void PipelineHandlerIPU3::stop(Camera *camera) LOG(IPU3, Fatal) << "There are still requests to complete."; freeBuffers(camera); + + data->requestSequence_ = 0; } int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) From patchwork Fri Mar 12 06:11:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11564 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 6C55BBD1F1 for ; Fri, 12 Mar 2021 06:11:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2D05F68C69; Fri, 12 Mar 2021 07:11:43 +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="MjuasMTL"; 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 65F2B68C71 for ; Fri, 12 Mar 2021 07:11:37 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF232ACB; Fri, 12 Mar 2021 07:11:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529497; bh=GN4ZSNV/Ucmhqppk28VewwPpJ1HdcIXmRI2HpNpYuWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MjuasMTLU/JOaLXJeR8j9JdaSAouieH2HLLirkPRutqdnZ3hYrxjc0aQuh58gMBrd 7OhlXhDU1MvYGXiLbOIBhD5hObtMZoE6h8wcrAhJ/dGTbSR4FpClEpGOaWwvMFP3C3 T5hUb6ODr8J+z1w5S3kydoUodWou6jDG8X9VbQCk= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:27 +0000 Message-Id: <20210312061131.854849-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/8] libcamera: pipeline: ipu3: frames: Use the request sequence 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" For all frame indexes, use the same sequence number as generated by the Request object. This allows clear matching of what operations occured to which request. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/frames.cpp | 4 +--- src/libcamera/pipeline/ipu3/frames.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 151ebfe7ca5f..4198e2019f3f 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -18,7 +18,6 @@ namespace libcamera { LOG_DECLARE_CATEGORY(IPU3) IPU3Frames::IPU3Frames() - : nextId_(0) { } @@ -31,7 +30,6 @@ void IPU3Frames::init(const std::vector> ¶mBuff for (const std::unique_ptr &buffer : statBuffers) availableStatBuffers_.push(buffer.get()); - nextId_ = 0; frameInfo_.clear(); } @@ -43,7 +41,7 @@ void IPU3Frames::clear() IPU3Frames::Info *IPU3Frames::create(Request *request) { - unsigned int id = nextId_++; + unsigned int id = request->sequence(); if (availableParamBuffers_.empty()) { LOG(IPU3, Error) << "Parameters buffer underrun"; diff --git a/src/libcamera/pipeline/ipu3/frames.h b/src/libcamera/pipeline/ipu3/frames.h index 106e5c15cc7a..4acdf48eca9d 100644 --- a/src/libcamera/pipeline/ipu3/frames.h +++ b/src/libcamera/pipeline/ipu3/frames.h @@ -53,7 +53,6 @@ private: std::queue availableParamBuffers_; std::queue availableStatBuffers_; - unsigned int nextId_; std::map> frameInfo_; }; From patchwork Fri Mar 12 06:11:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11565 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 E2D2CBD1F1 for ; Fri, 12 Mar 2021 06:11:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B019602ED; Fri, 12 Mar 2021 07:11:43 +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="ddyoaOsa"; 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 D753168C75 for ; Fri, 12 Mar 2021 07:11:37 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4642BB60; Fri, 12 Mar 2021 07:11:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529497; bh=mjb9EEd8Zf5PA1G9OwUMexHAJ/QoKzQTvOaU/OXhVFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ddyoaOsaj3vEl8xj/FtzrGI2Lk7IKsPcdFZB+3ClUx053NEUErDeLo2tNcDVqoycP 4Mh0CoihcY2LFS0+BApfAHLaZfQzdA/sBDJlnONxz4PyIR01k8axlV8EyE6fiyg3Tl sK5omrcXtVKqvqNOsUjjF5KGAaa4rb/CSVEVmpGM= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:28 +0000 Message-Id: <20210312061131.854849-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/8] libcamera: pipeline: ipu3: frames: Add FrameInfo state tracing 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 toString() function on the IPU3Frames::Info structure so that it can be reported during debug logs. Provide a public helper on the IPU3Frames class to report the state of all Info structures it holds. This method can be used when debugging the contexts that are associated with requests. Signed-off-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/frames.cpp | 23 +++++++++++++++++++++++ src/libcamera/pipeline/ipu3/frames.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 4198e2019f3f..b8b471c3c561 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -131,4 +131,27 @@ IPU3Frames::Info *IPU3Frames::find(FrameBuffer *buffer) return nullptr; } +const std::string IPU3Frames::Info::toString() const +{ + std::stringstream ss; + + ss << request->toString() + << (metadataProcessed ? "" : "[!metadata]") + << (paramDequeued ? "" : "[!param]"); + + return ss.str(); +} + +void IPU3Frames::dump() const +{ + LOG(IPU3, Error) << "Frames:"; + + for (auto const &itInfo : frameInfo_) { + Info *info = itInfo.second.get(); + + LOG(IPU3, Error) + << " - " << info->toString(); + } +} + } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/ipu3/frames.h b/src/libcamera/pipeline/ipu3/frames.h index 4acdf48eca9d..c769ae864d32 100644 --- a/src/libcamera/pipeline/ipu3/frames.h +++ b/src/libcamera/pipeline/ipu3/frames.h @@ -34,6 +34,8 @@ public: bool paramDequeued; bool metadataProcessed; + + const std::string toString() const; }; IPU3Frames(); @@ -49,6 +51,8 @@ public: Info *find(unsigned int id); Info *find(FrameBuffer *buffer); + void dump() const; + private: std::queue availableParamBuffers_; std::queue availableStatBuffers_; From patchwork Fri Mar 12 06:11:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11566 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 63DDCBD1F1 for ; Fri, 12 Mar 2021 06:11:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 11BA868C75; Fri, 12 Mar 2021 07:11:44 +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="uJ9B4kQd"; 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 3F89268C76 for ; Fri, 12 Mar 2021 07:11:38 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C581588F; Fri, 12 Mar 2021 07:11:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529498; bh=BmNdLAWejPuHrU3gWw6s6ZHjwSS7pi1sF0vPBIL1VBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJ9B4kQdE4xbASQ4TWx1is0C8HBbJo0KZKbps0J9XXEh9Kjb6MLzi+ipQlr9qkefk lfD8wNfiTY8gT5EjRsuHCP/g+Fko7r5RshJVk8/vDNeF5V8y/GsUf7axNoie3E35Zc 6WVRrqkp+mB6PK0oW27zZ5QLZWMxSRUYuB4kbSH4= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:29 +0000 Message-Id: <20210312061131.854849-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] libcamera: pipeline: ipu3: frames: Group FrameBuffer operations 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" Ensure that checks on resource availability are handled first, and then operate on the queues only after the resources are confirmed as available. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/frames.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index b8b471c3c561..7a7c5643df43 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -47,12 +47,13 @@ IPU3Frames::Info *IPU3Frames::create(Request *request) LOG(IPU3, Error) << "Parameters buffer underrun"; return nullptr; } - FrameBuffer *paramBuffer = availableParamBuffers_.front(); if (availableStatBuffers_.empty()) { LOG(IPU3, Error) << "Statistics buffer underrun"; return nullptr; } + + FrameBuffer *paramBuffer = availableParamBuffers_.front(); FrameBuffer *statBuffer = availableStatBuffers_.front(); availableParamBuffers_.pop(); From patchwork Fri Mar 12 06:11:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11567 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 C0A4EBD1F1 for ; Fri, 12 Mar 2021 06:11:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 661FC68C81; Fri, 12 Mar 2021 07:11:44 +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="eF1m73f2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A907368C67 for ; Fri, 12 Mar 2021 07:11:38 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DFB58F9; Fri, 12 Mar 2021 07:11:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529498; bh=NkTIBejSuTKX8bN2tl3f+W+sLauNdmU90qI2WGQbWy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eF1m73f2PhDaZ/dwwLJzn4fWqpLJYtgJjAW1jD8m/hUD9JJ830+08PHZAXeuZetd5 uolP9I+d45XPqS2G2iik7NBCqm2LYwXhYkt4/QTdAN1jaVymswqTEiGpi7YdwuANil CZZ0jkCeFw426ZbFx/a8Xvgt7o9AtF+lYpiO04wE= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:30 +0000 Message-Id: <20210312061131.854849-8-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/8] libcamera: pipeline: ipu3: frames: Associate buffers with the reqeust 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" Ensure that the buffers are associated with the request even if they are used internally to be able to correctly map back to the resources they are being used to fulfil. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/frames.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 7a7c5643df43..2a0590258d03 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -56,6 +56,9 @@ IPU3Frames::Info *IPU3Frames::create(Request *request) FrameBuffer *paramBuffer = availableParamBuffers_.front(); FrameBuffer *statBuffer = availableStatBuffers_.front(); + paramBuffer->setRequest(request); + statBuffer->setRequest(request); + availableParamBuffers_.pop(); availableStatBuffers_.pop(); From patchwork Fri Mar 12 06:11:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11568 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 30C57BD1F1 for ; Fri, 12 Mar 2021 06:11:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE4F168C84; Fri, 12 Mar 2021 07:11:44 +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="h0290R9X"; 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 01B0468C6B for ; Fri, 12 Mar 2021 07:11:39 +0100 (CET) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C912F95; Fri, 12 Mar 2021 07:11:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615529498; bh=CXpckEd6t9K6vgSZfAjDek218hD66ksQ8YyosdKLQ20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h0290R9XE7bqzekZ+WghhU1f7gnFJ2Iqx5hpFGterajV/L/9nSJO/0v0Imo0KTVX3 h3wXH5U76ZV7XPDdNfrILkfVO6vcccdeUuR4fPu5ccHAH738HnRpfuG/mBD9D+H+5d ysLIZrTTvvpgMbgCyUzlk1Z+BhHWoTamCxIq3BmE= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Mar 2021 06:11:31 +0000 Message-Id: <20210312061131.854849-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> References: <20210312061131.854849-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] [RFC-Only] libcamera: request: A request canary 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" Request objects are created and owned by the application, but are of course utilised widely throughout the internals of libcamera. If the application free's the requests while they are still active within libcamera a use after free will occur. While this can be trapped by tools such as valgrind, given the importance of this object and the relationship of external ownership, it may have some value to provide Debug build (disabled at Release build) assertions on the condition of these objects. Make sure the request fails an assertion immediately if used after free. Signed-off-by: Kieran Bingham --- RFC only, as I was going to dispose of this patch. We added it while debugging the IPU3 stability, and it may prove useful to catch errors if requests are used after they are released. However this may be redundant as pipeline handlers should guarantee that requests are fully completed when they stop(). Of course the IPU3 wasn't meeting that requirement, and we do not have a specific assertion that validates that requirement on all pipeline handlers. So perhaps this canary might serve as a beneficial guard? If not, at least posting it will mean it can be used in the future if it comes up again, or the concept could be applied to other objects if appropriate. include/libcamera/request.h | 2 ++ src/libcamera/request.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index 59d7f4bac0d2..fc56d63c8c67 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -78,6 +78,8 @@ private: const uint64_t cookie_; Status status_; bool cancelled_; + + int canary_; }; } /* namespace libcamera */ diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 12c2e7d425f9..83169a11e1e5 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -18,6 +18,8 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/tracepoints.h" +#define REQUEST_CANARY 0x1F2E3D4C + /** * \file request.h * \brief Describes a frame capture request to be processed by a camera @@ -89,6 +91,8 @@ Request::Request(Camera *camera, uint64_t cookie) LIBCAMERA_TRACEPOINT(request_construct, this); + canary_ = REQUEST_CANARY; + LOG(Request, Debug) << "Created request - cookie: " << cookie_; } @@ -99,6 +103,8 @@ Request::~Request() delete metadata_; delete controls_; delete validator_; + + canary_ = 0; } /** @@ -113,6 +119,8 @@ Request::~Request() */ void Request::reuse(ReuseFlag flags) { + ASSERT(canary_ == REQUEST_CANARY); + LIBCAMERA_TRACEPOINT(request_reuse, this); pending_.clear(); @@ -176,6 +184,8 @@ void Request::reuse(ReuseFlag flags) */ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) { + ASSERT(canary_ == REQUEST_CANARY); + if (!stream) { LOG(Request, Error) << "Invalid stream reference"; return -EINVAL; @@ -211,6 +221,8 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer) */ FrameBuffer *Request::findBuffer(const Stream *stream) const { + ASSERT(canary_ == REQUEST_CANARY); + const auto it = bufferMap_.find(stream); if (it == bufferMap_.end()) return nullptr; @@ -262,6 +274,7 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const */ void Request::complete() { + ASSERT(canary_ == REQUEST_CANARY); ASSERT(status_ == RequestPending); ASSERT(!hasPendingBuffers()); @@ -289,6 +302,8 @@ void Request::complete() */ bool Request::completeBuffer(FrameBuffer *buffer) { + ASSERT(canary_ == REQUEST_CANARY); + LIBCAMERA_TRACEPOINT(request_complete_buffer, this, buffer); int ret = pending_.erase(buffer);