From patchwork Fri May 27 19:17:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16104 X-Patchwork-Delegate: umang.jain@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 5D1A9C3256 for ; Fri, 27 May 2022 19:17:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5143D633A5; Fri, 27 May 2022 21:17:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653679070; bh=6QaKR0Oc06NXJj9OaMhXbRJg5e5/1b7qBXL9P9S32Ik=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KWk4hbcUa4sVe4pVTfT9IRMPLvs2uitClSOnWEF3FvH3L7AilnxHUEd8ep6AqCpLT Pl1yF7ouoBXZHxpKwhpwT02759ejmCAlOxLLOHeX1dEKEHF0vPKnTD/GhjzWhrCvn6 cC1wvH+x/Nj6M4w1gR+F5zFhUgGk1208u6xq08S4Eu5/pUS1KNTlhzufRfyYI0dP0o h+YpP5nMyrW6anZUY3AM+UJvkN1axEYCbBF0Pc83Lfm5fjFZywOZXK+MJATagbRtIA BH2StG5p1NToxGRo1VzL3CUCM37MQUxcs6/31mWjXclewmwTjitZqKxr8+WVakd8Wy OKagTTwywW0SA== 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 2AD09633A2 for ; Fri, 27 May 2022 21:17:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WBSVcvyl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [90.164.63.43]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D023A32A; Fri, 27 May 2022 21:17:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653679067; bh=6QaKR0Oc06NXJj9OaMhXbRJg5e5/1b7qBXL9P9S32Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBSVcvyl2IG/0AKOfqr+GMdW1kfluDxXaCv+HdW5E/DCZOgBh2ibKD/QUtCOtSibs b5FfvxDuijW7HqSwbB+hqA4hjTKAnQRhMLAZ9EJtln8hmfuI5mqJXI2on+ujYcKh52 1DBYSrSVHG9A6JVEPTIWXjoNybRGhF4qQH9FPUO8= To: libcamera-devel@lists.libcamera.org Date: Fri, 27 May 2022 21:17:39 +0200 Message-Id: <20220527191740.242300-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220527191740.242300-1-umang.jain@ideasonboard.com> References: <20220527191740.242300-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 2/3] ipa: ipu3: ipa_context: Extend FCQueue::get() 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: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend the FCQueue::get() to return a IPAFrameContext for a non-existent frame. The .get() should be able to figure out if a existent frame context is asked for, or to create a new frame context based on the next available position. To keep track of next available position in the queue, use of head and tail pointer are used. We specifically want to have access to the queue through the .get() function hence operator[] is deleted for FCQueue as part of this patch as well. Signed-off-by: Umang Jain --- src/ipa/ipu3/ipa_context.cpp | 81 +++++++++++++++++++++++++++++++++--- src/ipa/ipu3/ipa_context.h | 5 +++ src/ipa/ipu3/ipu3.cpp | 4 +- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index e5010e3f..dcce6b48 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -217,32 +217,96 @@ IPAFrameContext::IPAFrameContext(uint32_t id, const ControlList &reqControls) * \brief Analogue gain multiplier */ +/** + * \class FCQueue + * \brief A FIFO circular queue holding IPAFrameContext(s) + * + * FCQueue holds all the IPAFrameContext(s) related to frames required + * to be processed by the IPA at a given point. A IPAFrameContext is created + * on the first call FCQueue::get(frame) for that frame. Subsequent calls to + * FCQueue::get() with the same frame number shall return the IPAFrameContext + * previously created until the frame is marked as complete through + * FCQueue::completeFrame(frame). + */ + +/** + * \var FCQueue::head + * \brief A pointer to the a IPAFrameContext next expected to complete + */ + +/** + * \var FCQueue::tail + * \brief A pointer to the latest IPAFrameContext created + */ + /** * \brief FCQueue constructor */ FCQueue::FCQueue() + : head(nullptr), tail(nullptr) { clear(); } /** - * Retrieve the IPAFrameContext for the frame + * \brief Retrieve the IPAFrameContext for the frame * \param[in] frame Frame number for which the IPAFrameContext needs to * retrieved * + * This functions returns the IPAFrameContext for the desired frame. If the + * frame context does not exists in the queue, the next available reference + * of the position in the queue, is returned. It is the responsibility of the + * caller to fill the correct IPAFrameContext parameters of newly returned + * IPAFrameContext. + * * \return Reference to the IPAFrameContext */ IPAFrameContext &FCQueue::get(uint32_t frame) { - IPAFrameContext &frameContext = this->at(frame % kMaxFrameContexts); + if (frame <= tail->frame) { + IPAFrameContext &frameContext = this->at(frame % kMaxFrameContexts); + if (frame != frameContext.frame) + LOG(IPAIPU3, Warning) + << "Got wrong frame context for frame " << frame; + return frameContext; + } else { + /* + * Frame context doesn't exist yet so get the next available + * position in the queue. + */ + tail = &this->at((tail->frame + 1) % kMaxFrameContexts); + tail->frame = frame; - if (frame != frameContext.frame) { + /* Avoid over-queuing of frame contexts */ + if (tail->frame > kMaxFrameContexts && + (tail->frame - head->frame) >= kMaxFrameContexts) { + LOG(IPAIPU3, Error) << "FCQueue is full!"; + + /* \todo: Determine return reference? or make it fatal? */ + } + + return *tail; + } +} + +/** + * \brief Notifies the FCQueue that a frame has been completed + * \param[in] frame The completed frame number + */ +void FCQueue::completeFrame(uint32_t frame) +{ + if (head->frame != frame) LOG(IPAIPU3, Warning) - << "Got wrong frame context for frame" << frame - << " or frame context doesn't exist yet"; + << "Frame " << frame << " completed out-of-sync?"; + + if (frame > tail->frame) { + LOG(IPAIPU3, Error) + << "Completing a frame " << frame + << " not present in the queue is disallowed"; + return; } - return frameContext; + head = &this->get(frame + 1); } /** @@ -252,6 +316,11 @@ void FCQueue::clear() { IPAFrameContext initFrameContext; this->fill(initFrameContext); + + /* Intialise 0th index to frame 0 */ + this->at(0).frame = 0; + tail = &this->at(0); + head = tail; } } /* namespace ipa::ipu3 */ diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index 61454b41..b36ec61d 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -93,9 +93,14 @@ class FCQueue : public std::array { public: FCQueue(); + FCQueue &operator[](const FCQueue &) = delete; void clear(); + void completeFrame(uint32_t frame); IPAFrameContext &get(uint32_t frame); + + IPAFrameContext *head; + IPAFrameContext *tail; }; struct IPAContext { diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index c48d2f62..e09c5d05 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -605,6 +605,8 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, */ metadataReady.emit(frame, ctrls); + + context_.frameContexts.completeFrame(frame); } /** @@ -618,7 +620,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls) { /* \todo Start processing for 'frame' based on 'controls'. */ - context_.frameContexts[frame % kMaxFrameContexts] = { frame, controls }; + context_.frameContexts.get(frame) = { frame, controls }; } /**