From patchwork Fri Jun 3 13:22:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16139 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 BC8FEC326D for ; Fri, 3 Jun 2022 13:23:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E05860105; Fri, 3 Jun 2022 15:23:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654262588; bh=+VLfXU/12xLb9bTzefRzNmnud605OTY0ljKOxSSuNbE=; 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=EfET7njHoLNEipLZ/47AGQICu9Wi6QTh974sxt3enJ68K4DM+R5gKxUHALZ+N1VWa EW3A7/v+a8cq7kRhb4H91/RLOEWsKDfaXK/ZKNgZPa5Sog0esUgYC5ht8U9BNlYNmY aeFiBsdFTWy+G1AHFJgnh+fpOYUc9aQsKPW6Fu0kctiaoQbvHLMDDEE0I6oiT3tkWD avoc0TwSsnKCDlLqGRuTp1hKBQ+GErkWtNGZYx1aPiAPwjDoqCEhztKZ4UT2jD/sVz NKH14rjnCZr9ZzauS1Z8QZiq6ZsClYTlcgrBOJ3OQWl3mPeZUK0sTxV/oL9qPdpaNu aa2diHnn+2P4Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FC8A6040E for ; Fri, 3 Jun 2022 15:23:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ozbrhxRg"; dkim-atps=neutral Received: from perceval.ideasonboard.com (static-127-186-62-95.ipcom.comunitel.net [95.62.186.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 08FDD10DD; Fri, 3 Jun 2022 15:23:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1654262586; bh=+VLfXU/12xLb9bTzefRzNmnud605OTY0ljKOxSSuNbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ozbrhxRgsnWfGRr0JDxUsuSXgj5u8afCxPAJQIcVNxRH0JWCXWUNA344UbVLsCvOv CG/2Dzz5P9KbeRwcK8JrAJbizhrH9VWroAEdIXsTMbihQuLAb3psSrzVDPCB3FBqrL 4YIRmM2SDKyoCapFlimyzq379asW4b2ZNc8ZCeqI= To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jun 2022 15:22:57 +0200 Message-Id: <20220603132259.188845-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220603132259.188845-1-umang.jain@ideasonboard.com> References: <20220603132259.188845-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/4] 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 | 95 +++++++++++++++++++++++++++++++++--- src/ipa/ipu3/ipa_context.h | 9 ++++ src/ipa/ipu3/ipu3.cpp | 4 +- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index 9f95a61c..2438d68d 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -222,13 +222,33 @@ IPAFrameContext::IPAFrameContext(uint32_t id, const ControlList &reqControls) * \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. + * to be processed by the IPA at a given point. An 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 + */ + +/** + * \var FCQueue::isFull_ + * \brief Flag set when the FCQueue is full */ /** * \brief FCQueue constructor */ FCQueue::FCQueue() + : head_(nullptr), tail_(nullptr), isFull_(false) { clear(); } @@ -238,21 +258,75 @@ FCQueue::FCQueue() * \param[in] frame Frame number for which the IPAFrameContext needs to * retrieved * - * \return Pointer to the IPAFrameContext + * This function returns the IPAFrameContext for the desired frame. If the + * frame context does not exist in the queue, the next available slot in the + * queue is returned. It is the responsibility of the caller to fill the correct + * IPAFrameContext parameters of newly returned IPAFrameContext. + * + * \return Pointer to the IPAFrameContext or nullptr if frame context couldn't + * be created */ 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 { + if (isFull_) { + LOG(IPAIPU3, Warning) + << "Cannot create frame context for frame " << frame + << " since FCQueue is full"; + + return nullptr; + } + + /* + * 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; + + /* Check if the queue is full to avoid over-queueing later */ + if (tail_->frame - head_->frame >= kMaxFrameContexts - 1) + isFull_ = true; - if (frame != frameContext.frame) { + 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); + + if (isFull_) + isFull_ = false; } +/** + * \fn FCQueue::isFull() + * \brief Checks whether the frame context queue is full + */ + /** * \brief Clear the FCQueue by resetting all the entries in the ring-buffer */ @@ -260,6 +334,13 @@ void FCQueue::clear() { IPAFrameContext initFrameContext; this->fill(initFrameContext); + + isFull_ = false; + + /* 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 56d281f6..475855da 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -93,9 +93,18 @@ class FCQueue : public std::array { public: FCQueue(); + FCQueue &operator[](const FCQueue &) = delete; void clear(); + void completeFrame(uint32_t frame); IPAFrameContext *get(uint32_t frame); + bool isFull() { return isFull_; } + +private: + IPAFrameContext *head_; + IPAFrameContext *tail_; + + bool isFull_; }; struct IPAContext { diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 0843d882..1d6ee515 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 }; } /**