From patchwork Tue Feb 25 15:06:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22857 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 3EB50BDB1C for ; Tue, 25 Feb 2025 15:06:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 989C06871F; Tue, 25 Feb 2025 16:06:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="S3oHJSU/"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D73AD61855 for ; Tue, 25 Feb 2025 16:06:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740495988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kOI2yAMnOqdn+NRq9PiaAmANGbd3NScM+hL3TL2cZh0=; b=S3oHJSU/cSLcqK/jRp7U13OEChFWwWQFbBOuRIpPZH+f6vS49kQV8/iJtFGMGSO+XSPsFI 31ZSVOF9ekamz4vRlq6z9eySEG6zogh2KwNnJCYNnPpaFX64Rw1U2E0/oj445zcDu4PdqQ Id0apfWSfCfLekIYWjzP4u58ijvTGeo= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-OHhc8cz7MUqMsXUHmASi7A-1; Tue, 25 Feb 2025 10:06:27 -0500 X-MC-Unique: OHhc8cz7MUqMsXUHmASi7A-1 X-Mimecast-MFC-AGG-ID: OHhc8cz7MUqMsXUHmASi7A_1740495986 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 523D11975AFC; Tue, 25 Feb 2025 15:06:26 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46386180035F; Tue, 25 Feb 2025 15:06:24 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 1/6] libcamera: software_isp: Emit ispStatsReady only if IPA is running Date: Tue, 25 Feb 2025 16:06:07 +0100 Message-ID: <20250225150614.20195-2-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: k_qcu-bEqTxzXDjxLp1LhzDqfvZb0D3cr53WKuLIekM_1740495986 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" Software ISP runs debayering in a separate thread and debayering may emit statsReady when software ISP (including the IPA) is being stopped. The signal waits in a queue and gets invoked later, resulting in an assertion error when attempting to invoke a method on the stopped IPA: FATAL default soft_ipa_proxy.cpp:456 assertion "state_ == ProxyRunning" failed in processStatsThread() Let's prevent this problem by forwarding the ISP stats signal from software ISP only when the IPA is running. To track this, SoftwareISP::running_ variable is introduced. Making processing of the other signals in SoftwareISP more robust is addressed in the followup patches. Signed-off-by: Milan Zamazal Reported-by: Stanislaw Gruszka Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/software_isp.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 440a296d..af0dcc24 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -100,6 +100,7 @@ private: DmaBufAllocator dmaHeap_; std::unique_ptr ipa_; + bool running_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 44baf200..1a39f4d8 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -315,6 +315,7 @@ int SoftwareIsp::start() int ret = ipa_->start(); if (ret) return ret; + running_ = true; ispWorkerThread_.start(); return 0; @@ -328,6 +329,7 @@ void SoftwareIsp::stop() ispWorkerThread_.exit(); ispWorkerThread_.wait(); + running_ = false; ipa_->stop(); } @@ -356,7 +358,8 @@ void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls) void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId) { - ispStatsReady.emit(frame, bufferId); + if (running_) + ispStatsReady.emit(frame, bufferId); } void SoftwareIsp::inputReady(FrameBuffer *input) From patchwork Tue Feb 25 15:06:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22858 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 2CBE5BDB1C for ; Tue, 25 Feb 2025 15:06:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5CBD68722; Tue, 25 Feb 2025 16:06:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cJidTaVx"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 323D6686D6 for ; Tue, 25 Feb 2025 16:06:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740495992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hlhus1X1Oto5RerDOL/ZOig6Lr333eoEhxbmMctUfEE=; b=cJidTaVxxTJu8jYrk5t4ugAlVw6LfaZuwM8g4Xeri8B27kiiQG9T7zIjdqMePEbt39aFH/ MywI8FW1FdmX5BIbIp5rSM/4pKFo4dzr413S9As8fbF5nCgLUdiNsGmA8sBpNjyR5C6nsu 5mM9Rv/Z1PNXRtu+kqo3EpP2hXwmts4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-M5aF26_VPCKFgAjFB8qNow-1; Tue, 25 Feb 2025 10:06:29 -0500 X-MC-Unique: M5aF26_VPCKFgAjFB8qNow-1 X-Mimecast-MFC-AGG-ID: M5aF26_VPCKFgAjFB8qNow_1740495989 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A5C1918D95E0; Tue, 25 Feb 2025 15:06:28 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDFB91800357; Tue, 25 Feb 2025 15:06:26 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 2/6] libcamera: software_isp: Handle queued output buffers on stop Date: Tue, 25 Feb 2025 16:06:08 +0100 Message-ID: <20250225150614.20195-3-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MOddYGMaT9MucxqJWMLT5t6ahxxXhdr0zsFPtKmqNKc_1740495989 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" When SoftwareIsp stops, input and output buffers queued to it may not yet be fully processed. They will be eventually returned but stop means stop, there should be no processing related actions invoked afterwards. Let's stop forwarding processed output buffers from the SoftwareIsp slots once SoftwareIsp is stopped. Let's track the queued output buffers and mark those still pending as canceled in SoftwareIsp::stop and return them to the pipeline handler. Dealing with input buffers is addressed in a separate patch. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- .../internal/software_isp/software_isp.h | 2 ++ src/libcamera/software_isp/software_isp.cpp | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index af0dcc24..5073ce7a 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -101,6 +102,7 @@ private: std::unique_ptr ipa_; bool running_; + std::deque queuedOutputBuffers_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 1a39f4d8..140cddf3 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -13,10 +13,13 @@ #include #include +#include + #include #include #include +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/software_isp/debayer_params.h" @@ -300,8 +303,11 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input, return -EINVAL; } - for (auto iter = outputs.begin(); iter != outputs.end(); iter++) - process(frame, input, iter->second); + for (auto iter = outputs.begin(); iter != outputs.end(); iter++) { + FrameBuffer *const buffer = iter->second; + queuedOutputBuffers_.push_back(buffer); + process(frame, input, buffer); + } return 0; } @@ -331,6 +337,13 @@ void SoftwareIsp::stop() running_ = false; ipa_->stop(); + + for (auto buffer : queuedOutputBuffers_) { + FrameMetadata &metadata = buffer->_d()->metadata(); + metadata.status = FrameMetadata::FrameCancelled; + outputBufferReady.emit(buffer); + } + queuedOutputBuffers_.clear(); } /** @@ -369,7 +382,11 @@ void SoftwareIsp::inputReady(FrameBuffer *input) void SoftwareIsp::outputReady(FrameBuffer *output) { - outputBufferReady.emit(output); + if (running_) { + ASSERT(queuedOutputBuffers_.front() == output); + queuedOutputBuffers_.pop_front(); + outputBufferReady.emit(output); + } } } /* namespace libcamera */ From patchwork Tue Feb 25 15:06:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22860 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 77AD1BDB1C for ; Tue, 25 Feb 2025 15:06:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0187568725; Tue, 25 Feb 2025 16:06:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="WVOXxAKR"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8968668715 for ; Tue, 25 Feb 2025 16:06:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740495997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H32qMEkJX+61AWPrMY3td75sqtOqZS2G4yStvM1eI64=; b=WVOXxAKR3ZNPaHpH+4AX7Vd2dGBGXY7pVkDpx1dWG9Sf/Aj6i/I8qurMypSOnph3dvUK3V 9QgNY0H2/0vcObRXYxMiUF4Kur+hD+mqDQMVEXqlu6b/w0GFlTNObkf00R4IczTehznCG7 SjcPGqqOoU/xiPvXFNvkkki13izepCM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-XGv5gjWwO2yKETv080uwwQ-1; Tue, 25 Feb 2025 10:06:32 -0500 X-MC-Unique: XGv5gjWwO2yKETv080uwwQ-1 X-Mimecast-MFC-AGG-ID: XGv5gjWwO2yKETv080uwwQ_1740495991 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A7AE1801A1A; Tue, 25 Feb 2025 15:06:31 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3770B1800357; Tue, 25 Feb 2025 15:06:28 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 3/6] libcamera: software_isp: Handle queued input buffers on stop Date: Tue, 25 Feb 2025 16:06:09 +0100 Message-ID: <20250225150614.20195-4-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Tdg03x3KHUi8xdNfxQIMtjve8qglk2IATtXL29MbVLs_1740495991 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" When SoftwareIsp stops, input and output buffers queued to it may not yet be fully processed. They will be eventually returned but stop means stop, there should be no processing related actions invoked afterwards. Let's stop forwarding processed input buffers from SoftwareIsp slots when SoftwareIsp is stopped. Let's track the queued input buffers and return them back for capture in SoftwareIsp::stop(). The returned input buffers are marked as canceled. This is not necessary at the moment but it gives the pipeline handlers chance to deal with this if they need to. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- .../internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/software_isp.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 5073ce7a..400a4dc5 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -102,6 +102,7 @@ private: std::unique_ptr ipa_; bool running_; + std::deque queuedInputBuffers_; std::deque queuedOutputBuffers_; }; diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 140cddf3..beac66fc 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -303,6 +303,8 @@ int SoftwareIsp::queueBuffers(uint32_t frame, FrameBuffer *input, return -EINVAL; } + queuedInputBuffers_.push_back(input); + for (auto iter = outputs.begin(); iter != outputs.end(); iter++) { FrameBuffer *const buffer = iter->second; queuedOutputBuffers_.push_back(buffer); @@ -329,6 +331,9 @@ int SoftwareIsp::start() /** * \brief Stops the Software ISP streaming operation + * + * All pending buffers are returned back as canceled before this method + * finishes. */ void SoftwareIsp::stop() { @@ -344,6 +349,13 @@ void SoftwareIsp::stop() outputBufferReady.emit(buffer); } queuedOutputBuffers_.clear(); + + for (auto buffer : queuedInputBuffers_) { + FrameMetadata &metadata = buffer->_d()->metadata(); + metadata.status = FrameMetadata::FrameCancelled; + inputBufferReady.emit(buffer); + } + queuedInputBuffers_.clear(); } /** @@ -377,7 +389,11 @@ void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId) void SoftwareIsp::inputReady(FrameBuffer *input) { - inputBufferReady.emit(input); + if (running_) { + ASSERT(queuedInputBuffers_.front() == input); + queuedInputBuffers_.pop_front(); + inputBufferReady.emit(input); + } } void SoftwareIsp::outputReady(FrameBuffer *output) From patchwork Tue Feb 25 15:06:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22859 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 26597BDB1C for ; Tue, 25 Feb 2025 15:06:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C48456871F; Tue, 25 Feb 2025 16:06:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="TvXiVs9P"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 22B2A6871F for ; Tue, 25 Feb 2025 16:06:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740495996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OipSodZMyJzQcC/vHPpXedrdorXiOZZNFpS0UHYjAyU=; b=TvXiVs9PH/X8bQFkGhC8sfdyoHMGL6z8d4eB2QBvDiREeKHOMvYa9LdmKurm6DHHJi7IOJ 4/GIGqpSGPW+C0KhTl/E26eL1TIx8rqF6eNcxJdjlSzOn0e5ULK5Y9bDWfCxAVA4UXQZW6 HV1HxRKE/D417EY5OoeqasIroweIQWw= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-E0K2pPQxNVWl2vRoNC6d_A-1; Tue, 25 Feb 2025 10:06:34 -0500 X-MC-Unique: E0K2pPQxNVWl2vRoNC6d_A-1 X-Mimecast-MFC-AGG-ID: E0K2pPQxNVWl2vRoNC6d_A_1740495993 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 930B41903080; Tue, 25 Feb 2025 15:06:33 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CA35D1800357; Tue, 25 Feb 2025 15:06:31 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 4/6] libcamera: base: thread: Support dispatching for a specific receiver Date: Tue, 25 Feb 2025 16:06:10 +0100 Message-ID: <20250225150614.20195-5-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: rV6XyZPOew2KUVzVlBqrAh8B0BF9rnNGDWrfHL5eCAE_1740495993 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" The Thread::dispatchMessage() function supports filtering messages based on their type. It can be useful to also dispatch only messages posted for a specific receiver. Add an optional receiver argument to the dispatchMessage() function to do so. When set to null (the default value), the behaviour of the function is not changed. This facility is actually used in followup patches. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/base/thread.h | 3 ++- src/libcamera/base/thread.cpp | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 3cbf6398..b9284c2c 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -48,7 +48,8 @@ public: EventDispatcher *eventDispatcher(); - void dispatchMessages(Message::Type type = Message::Type::None); + void dispatchMessages(Message::Type type = Message::Type::None, + Object *receiver = nullptr); protected: int exec(); diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 319bfda9..4de356c7 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -604,10 +604,12 @@ void Thread::removeMessages(Object *receiver) /** * \brief Dispatch posted messages for this thread * \param[in] type The message type + * \param[in] receiver The receiver whose messages to dispatch * - * This function immediately dispatches all the messages previously posted for - * this thread with postMessage() that match the message \a type. If the \a type - * is Message::Type::None, all messages are dispatched. + * This function immediately dispatches all the messages of the given \a type + * previously posted to this thread for the \a receiver with postMessage(). If + * the \a type is Message::Type::None, all messages types are dispatched. If the + * \a receiver is null, messages to all receivers are dispatched. * * Messages shall only be dispatched from the current thread, typically within * the thread from the run() function. Calling this function outside of the @@ -617,7 +619,7 @@ void Thread::removeMessages(Object *receiver) * same thread from an object's message handler. It guarantees delivery of * messages in the order they have been posted in all cases. */ -void Thread::dispatchMessages(Message::Type type) +void Thread::dispatchMessages(Message::Type type, Object *receiver) { ASSERT(data_ == ThreadData::current()); @@ -634,6 +636,9 @@ void Thread::dispatchMessages(Message::Type type) if (type != Message::Type::None && msg->type() != type) continue; + if (receiver && receiver != msg->receiver_) + continue; + /* * Move the message, setting the entry in the list to null. It * will cause recursive calls to ignore the entry, and the erase @@ -641,12 +646,12 @@ void Thread::dispatchMessages(Message::Type type) */ std::unique_ptr message = std::move(msg); - Object *receiver = message->receiver_; - ASSERT(data_ == receiver->thread()->data_); - receiver->pendingMessages_--; + Object *messageReceiver = message->receiver_; + ASSERT(data_ == messageReceiver->thread()->data_); + messageReceiver->pendingMessages_--; locker.unlock(); - receiver->message(message.get()); + messageReceiver->message(message.get()); message.reset(); locker.lock(); } From patchwork Tue Feb 25 15:06:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22861 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 66238BDB1C for ; Tue, 25 Feb 2025 15:06:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 05F856872D; Tue, 25 Feb 2025 16:06:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="VhiclidK"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A76F16872D for ; Tue, 25 Feb 2025 16:06:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740496001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=svRziI/jFrWfj/h9faDPv+X9EhT3RxsW9byRArjFhWg=; b=VhiclidKV5wBe5qQygfN+aQ9sNON2bTkL9mCXbp0VFScDNdkHFwK7ZnU8BPLhVz0Rp1v7c nrs9X1yQs7MZ4h/DxvT88omfFtwm60Tpdpuqvnj23GL15szLXobF5vjgOkz2xKT5ZUoQFg 70HsDG/9YEgVB9YXuWm2L021vZtFOzM= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-24YRpOz7MfaABwi4n_ZGjw-1; Tue, 25 Feb 2025 10:06:37 -0500 X-MC-Unique: 24YRpOz7MfaABwi4n_ZGjw-1 X-Mimecast-MFC-AGG-ID: 24YRpOz7MfaABwi4n_ZGjw_1740495996 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3F5611800991; Tue, 25 Feb 2025 15:06:36 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 043951800357; Tue, 25 Feb 2025 15:06:33 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 5/6] libcamera: software_isp: Dispatch messages on stop Date: Tue, 25 Feb 2025 16:06:11 +0100 Message-ID: <20250225150614.20195-6-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fLhudNVdyesoC5pVTKbhYA5t7Xho2zDn-E-c3Yqyj9Q_1740495996 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" There may be pending messages in SoftwareIsp message queue when SoftwareIsp stops. The call to IPAProxySoft::stop() will dispatch them before SoftwareIsp::stop() finishes. But this is dependent on IPAProxySoft::stop() implementation, let's break this dependency and dispatch messages to SoftwareIsp explicitly in SoftwareIsp::stop(). This also allows dropping `running_' flag. Since the SoftwareIsp messages get processed and invoke IPA calls before the IPA proxy is set to ProxyStopping state and the SoftwareIsp worker thread is no longer running, it's guaranteed that no new messages come to SoftwareIsp and attempt to call the stopped IPA proxy. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- .../internal/software_isp/software_isp.h | 1 - src/libcamera/software_isp/software_isp.cpp | 24 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index 400a4dc5..133b545c 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -101,7 +101,6 @@ private: DmaBufAllocator dmaHeap_; std::unique_ptr ipa_; - bool running_; std::deque queuedInputBuffers_; std::deque queuedOutputBuffers_; }; diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index beac66fc..193713b9 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -323,7 +324,6 @@ int SoftwareIsp::start() int ret = ipa_->start(); if (ret) return ret; - running_ = true; ispWorkerThread_.start(); return 0; @@ -340,7 +340,8 @@ void SoftwareIsp::stop() ispWorkerThread_.exit(); ispWorkerThread_.wait(); - running_ = false; + Thread::current()->dispatchMessages(Message::Type::InvokeMessage, this); + ipa_->stop(); for (auto buffer : queuedOutputBuffers_) { @@ -383,26 +384,21 @@ void SoftwareIsp::setSensorCtrls(const ControlList &sensorControls) void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId) { - if (running_) - ispStatsReady.emit(frame, bufferId); + ispStatsReady.emit(frame, bufferId); } void SoftwareIsp::inputReady(FrameBuffer *input) { - if (running_) { - ASSERT(queuedInputBuffers_.front() == input); - queuedInputBuffers_.pop_front(); - inputBufferReady.emit(input); - } + ASSERT(queuedInputBuffers_.front() == input); + queuedInputBuffers_.pop_front(); + inputBufferReady.emit(input); } void SoftwareIsp::outputReady(FrameBuffer *output) { - if (running_) { - ASSERT(queuedOutputBuffers_.front() == output); - queuedOutputBuffers_.pop_front(); - outputBufferReady.emit(output); - } + ASSERT(queuedOutputBuffers_.front() == output); + queuedOutputBuffers_.pop_front(); + outputBufferReady.emit(output); } } /* namespace libcamera */ From patchwork Tue Feb 25 15:06:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22862 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 44B59BDB1C for ; Tue, 25 Feb 2025 15:06:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9752B68733; Tue, 25 Feb 2025 16:06:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="VOO4hd/W"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC0AE6872E for ; Tue, 25 Feb 2025 16:06:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740496001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZuPCzEfx4qxZr/u+d34K/HNNhtVHIfsTeqRhlZHqItM=; b=VOO4hd/W882QgCKZfKM4jbd86dDKspUF57JAHyBT8+R+0bgfuc19NleKkeWnw0dhgUZUr0 PiF1hKHyDBlPgewycPm/LYeOgCb+8ntDWAB6y1iaxu0+n/aUU0sh1y2kM1K3xZrohZDb/X tN4lzJCwl0xGJFdYi9v7K4XBAU3/f0U= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-L2vzkXk5Po-uRLvdc4CVog-1; Tue, 25 Feb 2025 10:06:39 -0500 X-MC-Unique: L2vzkXk5Po-uRLvdc4CVog-1 X-Mimecast-MFC-AGG-ID: L2vzkXk5Po-uRLvdc4CVog_1740495998 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B762019373DC; Tue, 25 Feb 2025 15:06:38 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.119]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CE455180035F; Tue, 25 Feb 2025 15:06:36 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v3 6/6] utils: ipc: Only dispatch messages for proxy when stopping thread Date: Tue, 25 Feb 2025 16:06:12 +0100 Message-ID: <20250225150614.20195-7-mzamazal@redhat.com> In-Reply-To: <20250225150614.20195-1-mzamazal@redhat.com> References: <20250225150614.20195-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: UqBf8PDxMtU6gq6PmKVgKg3ybYGqtXVZRk60oxkXkuk_1740495998 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" When stopping the proxy thread, all messages of InvokeMessage type posted to the pipeline handler thread are dispatched, to ensure that all signals emitted from the proxy thread and queued for delivery to the proxy are delivered synchronously. This unnecessarily delivers queued signals for other objects in the pipeline handler thread, possibly delaying processing of higher priority events. Improve the implementation by limiting synchronous delivery to messages posted for the proxy. Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- .../ipc/generators/libcamera_templates/proxy_functions.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl index b5797b14..25476990 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl @@ -34,7 +34,7 @@ thread_.exit(); thread_.wait(); - Thread::current()->dispatchMessages(Message::Type::InvokeMessage); + Thread::current()->dispatchMessages(Message::Type::InvokeMessage, this); state_ = ProxyStopped; {%- endmacro -%}