From patchwork Wed Oct 16 17:03:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 21646 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 93CBEC32FA for ; Wed, 16 Oct 2024 17:04:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 12B1365388; Wed, 16 Oct 2024 19:04:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mpfIL3z/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 264C96537F for ; Wed, 16 Oct 2024 19:04:00 +0200 (CEST) Received: from ideasonboard.com (unknown [5.179.178.254]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 65798A57; Wed, 16 Oct 2024 19:02:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729098137; bh=ApN1YnTciaugYHGpzFbsef+SuUqa2tEbXHZztJC5rFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mpfIL3z/fbNf92KTTYy8R0RfuaZe2UgU8bz4p+cGllmo0p9W00TwHp2Q1iC9QFN2z R9UsJuRS+x+KhqspqLNsBysG9K+WaEoN0tEkHp2bt+Mgt/LCOd2cefMX6jtFOyTkjT DUjM77ET0qZBNPo+75EnqdcFXlwsM48xpOxe5I4k= From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Paul Elder Subject: [PATCH 2/4] libipa: FCQueue: Make sure FrameContext#0 is initialized Date: Wed, 16 Oct 2024 19:03:43 +0200 Message-ID: <20241016170348.715993-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016170348.715993-1-jacopo.mondi@ideasonboard.com> References: <20241016170348.715993-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 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" Some IPA modules, like the RkISP1 one, call FCQueue::get(0) at IPA::start() time, before any frame context has been allocated with FCQueue::alloc() called at queueRequest() time. The FCQueue implementation aims to detect when a FrameContext is get() before it is alloc()-ated, Warns about it, and initializes the FrameContext before returning it. In case of frame#0, a get() preceding an alloc() call is not detected as the "frame == frameContext.frame" test returns success, as FrameContexts are zeroed by default. As a result, the first returned FrameContext is not initialized. Explicitly test for frame#0 to make sure the FrameContext is initialized if get(0) is called before alloc(0). To avoid re-initializing a frame context, in case alloc() has been called correctly before get(), introduce an "initialised" state variable that tracks the FrameContext initialisation state. Signed-off-by: Jacopo Mondi Reviewed-by: Daniel Scally Reviewed-by: Stefan Klug --- src/ipa/libipa/fc_queue.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/fc_queue.h b/src/ipa/libipa/fc_queue.h index b1e8bc1485d4..bfcce5a81356 100644 --- a/src/ipa/libipa/fc_queue.h +++ b/src/ipa/libipa/fc_queue.h @@ -26,11 +26,13 @@ protected: virtual void init(const uint32_t frameNum) { frame = frameNum; + initialised = true; } private: template friend class FCQueue; uint32_t frame; + bool initialised = false; }; template @@ -44,8 +46,10 @@ public: void clear() { - for (FrameContext &ctx : contexts_) + for (FrameContext &ctx : contexts_) { + ctx.initialised = false; ctx.frame = 0; + } } FrameContext &alloc(const uint32_t frame) @@ -89,6 +93,21 @@ public: << " has been overwritten by " << frameContext.frame; + if (frame == 0 && !frameContext.initialised) { + /* + * If the IPA calls get() at start() time it will get an + * un-intialized FrameContext as the below "frame == + * frameContext.frame" check will return success because + * FrameContexts are zeroed at creation time. + * + * Make sure the FrameContext gets initialised if get() + * is called before alloc() by the IPA for frame#0. + */ + frameContext.init(frame); + + return frameContext; + } + if (frame == frameContext.frame) return frameContext;