From patchwork Mon Feb 24 18:52:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22847 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 82AF3C32A9 for ; Mon, 24 Feb 2025 18:52:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34B76686FC; Mon, 24 Feb 2025 19:52:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="L3oxz9G1"; 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 44BA661856 for ; Mon, 24 Feb 2025 19:52:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740423172; 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=gd2ZKQ0qvhaFzc6uD//mdh4fqOebG9ryBtI040IS3cQ=; b=L3oxz9G1+Gyie7dXY8LYSbAo5hpzlkD5UpNS2x0yOTnDkkuP59KNsZcdoQc6Qs1ZpKRxmE PCbKSaLRzmTlznCl3enSGOQhSRu5r/pBXtjXKYRzepIRbCe6Kbbqm9cjwDpbDiPOEK2tT8 dWw1z6sjjYAyxXVSAHAgcUYVwOlgk2I= 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-295-P73Wc9AEMVCKlbW1shLBVA-1; Mon, 24 Feb 2025 13:52:48 -0500 X-MC-Unique: P73Wc9AEMVCKlbW1shLBVA-1 X-Mimecast-MFC-AGG-ID: P73Wc9AEMVCKlbW1shLBVA_1740423167 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 78A9319373D8; Mon, 24 Feb 2025 18:52:47 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 55C3F1800352; Mon, 24 Feb 2025 18:52:44 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v2 1/5] libcamera: software_isp: Emit ispStatsReady only if IPA is running Date: Mon, 24 Feb 2025 19:52:31 +0100 Message-ID: <20250224185235.43381-2-mzamazal@redhat.com> In-Reply-To: <20250224185235.43381-1-mzamazal@redhat.com> References: <20250224185235.43381-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6VU6Z2ttH9PpmrxM1Zcbufb7hc1TBWSlyuovMM3McS8_1740423167 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 Reviewed-by: Laurent Pinchart --- 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 Mon Feb 24 18:52:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22848 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 574FFC32A9 for ; Mon, 24 Feb 2025 18:52:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 088B3686FF; Mon, 24 Feb 2025 19:52:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="AVdW/hr2"; 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 8AA2361856 for ; Mon, 24 Feb 2025 19:52:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740423173; 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=29/66h17M1IjrZ7ZQh3Q/K4Eiv/s2bDJePsDYud9OVM=; b=AVdW/hr2BlX2fmBJbHFSa7BIXiiCxrzWzBatB2rghcOThdgCn38AHziQb3Yn4X8+iB50RC y0YMJwXn5fDkrWa2sosHLEUaer3ycNq2S1BYxl846OyZudutvjlAHDtrdOEdR2Wh75bdOf Hjl2p8sN3BciN0xlmKZbv7iP3hBKxHA= 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-322-10SBzhVjOE69g0EmB76Qrg-1; Mon, 24 Feb 2025 13:52:51 -0500 X-MC-Unique: 10SBzhVjOE69g0EmB76Qrg-1 X-Mimecast-MFC-AGG-ID: 10SBzhVjOE69g0EmB76Qrg_1740423170 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 D668F180087C; Mon, 24 Feb 2025 18:52:49 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 199C21800352; Mon, 24 Feb 2025 18:52:47 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v2 2/5] libcamera: software_isp: Handle queued output buffers on stop Date: Mon, 24 Feb 2025 19:52:32 +0100 Message-ID: <20250224185235.43381-3-mzamazal@redhat.com> In-Reply-To: <20250224185235.43381-1-mzamazal@redhat.com> References: <20250224185235.43381-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: QJtRUNg4y1_V18j0MNCDAa1jVVVR25aD_M8C5102Ggo_1740423170 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 --- .../internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/software_isp.cpp | 22 ++++++++++++++++--- 2 files changed, 20 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..f2344355 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -101,6 +101,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..4339e547 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -17,6 +17,7 @@ #include #include +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/software_isp/debayer_params.h" @@ -300,8 +301,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 +335,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 +380,12 @@ void SoftwareIsp::inputReady(FrameBuffer *input) void SoftwareIsp::outputReady(FrameBuffer *output) { - outputBufferReady.emit(output); + if (running_) { + queuedOutputBuffers_.erase(find(queuedOutputBuffers_.begin(), + queuedOutputBuffers_.end(), + output)); + outputBufferReady.emit(output); + } } } /* namespace libcamera */ From patchwork Mon Feb 24 18:52:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22849 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 D1EA7C32A9 for ; Mon, 24 Feb 2025 18:52:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BB3268701; Mon, 24 Feb 2025 19:52:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="ZbUytq3F"; 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 9411E686FA for ; Mon, 24 Feb 2025 19:52:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740423176; 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=a2/uxq3M7+7hr2SML4vsDQcWpZ0TRLIggA7kU6LG8zE=; b=ZbUytq3FusSeW/rMNL4+n15TiUiMHgxSeA+/KEk/Bz7HMaiEIANGc+aEhWgBVDesYG+O3h p1Pm5oMZA9BzyWM46ATdttDxGG047o8FYHm7TkaVmioprMEZeIZAlRKWA68TJud80X/Nhn w4IY6qtmiBjd8F6zb8Ui+IWNW3q1cDI= 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-167-HTrxplobPjWaOUgaNU5M2g-1; Mon, 24 Feb 2025 13:52:53 -0500 X-MC-Unique: HTrxplobPjWaOUgaNU5M2g-1 X-Mimecast-MFC-AGG-ID: HTrxplobPjWaOUgaNU5M2g_1740423172 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 56B3A19039C2; Mon, 24 Feb 2025 18:52:52 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5AD1D1800358; Mon, 24 Feb 2025 18:52:50 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v2 3/5] libcamera: software_isp: Handle queued input buffers on stop Date: Mon, 24 Feb 2025 19:52:33 +0100 Message-ID: <20250224185235.43381-4-mzamazal@redhat.com> In-Reply-To: <20250224185235.43381-1-mzamazal@redhat.com> References: <20250224185235.43381-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yojJcimGCQ6lPK4DTdvPgLTFhlcK3EsDOYbqZf1V6Vk_1740423172 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(). Signed-off-by: Milan Zamazal --- .../internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/software_isp.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index f2344355..bfe34725 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 queuedOutputBuffers_; + std::deque queuedInputBuffers_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 4339e547..3a605ab2 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -301,6 +301,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); @@ -327,6 +329,9 @@ int SoftwareIsp::start() /** * \brief Stops the Software ISP streaming operation + * + * All pending buffers are returned back (output buffers as canceled) before + * this method finishes. */ void SoftwareIsp::stop() { @@ -342,6 +347,10 @@ void SoftwareIsp::stop() outputBufferReady.emit(buffer); } queuedOutputBuffers_.clear(); + + for (auto buffer : queuedInputBuffers_) + inputBufferReady.emit(buffer); + queuedInputBuffers_.clear(); } /** @@ -375,7 +384,12 @@ void SoftwareIsp::statsReady(uint32_t frame, uint32_t bufferId) void SoftwareIsp::inputReady(FrameBuffer *input) { - inputBufferReady.emit(input); + if (running_) { + queuedInputBuffers_.erase(find(queuedInputBuffers_.begin(), + queuedInputBuffers_.end(), + input)); + inputBufferReady.emit(input); + } } void SoftwareIsp::outputReady(FrameBuffer *output) From patchwork Mon Feb 24 18:52:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22851 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 151C3C32C2 for ; Mon, 24 Feb 2025 18:53:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 89EE768707; Mon, 24 Feb 2025 19:53:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="RbzPX6rO"; 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 EACC268705 for ; Mon, 24 Feb 2025 19:53:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740423180; 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=VhZSMnTkSMHOBoDCRJqhrex1EQoVkWDnJS7uGdChitc=; b=RbzPX6rO4epI6A0E5cyRbVqiLCB0QMgdaiHpN/T22gNH376BudWB0KkLlwfSjK4+Wy86WX fbj/iEOTTwDnlgy1FikacKjhxHiCQl86M59yJxu+d6GHdN/D504LvIp6ZeGgJHr2Yz0L2q QVx0xyept3P3S0H2H5WcLI+34riNbKg= 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-359-bec1-ZqaO2qYk5eG9bALxQ-1; Mon, 24 Feb 2025 13:52:55 -0500 X-MC-Unique: bec1-ZqaO2qYk5eG9bALxQ-1 X-Mimecast-MFC-AGG-ID: bec1-ZqaO2qYk5eG9bALxQ_1740423174 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 BA1BB1800570; Mon, 24 Feb 2025 18:52:54 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB61F1800352; Mon, 24 Feb 2025 18:52:52 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v2 4/5] libcamera: base: Fix formatting in thread.cpp Date: Mon, 24 Feb 2025 19:52:34 +0100 Message-ID: <20250224185235.43381-5-mzamazal@redhat.com> In-Reply-To: <20250224185235.43381-1-mzamazal@redhat.com> References: <20250224185235.43381-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mSPHW9As5TRsqmI_JFgx05Gfy1dbtINcZZMRM3sWxo0_1740423174 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" Let's make the autoformatter happy with thread.cpp formatting. Signed-off-by: Milan Zamazal --- src/libcamera/base/thread.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 319bfda9..02128f23 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -5,8 +5,6 @@ * Thread support */ -#include - #include #include #include @@ -20,6 +18,7 @@ #include #include #include +#include /** * \page thread Thread Support @@ -657,7 +656,7 @@ void Thread::dispatchMessages(Message::Type type) * the outer calls. */ if (!--data_->messages_.recursion_) { - for (auto iter = messages.begin(); iter != messages.end(); ) { + for (auto iter = messages.begin(); iter != messages.end();) { if (!*iter) iter = messages.erase(iter); else From patchwork Mon Feb 24 18:52:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22850 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 831FCC32A9 for ; Mon, 24 Feb 2025 18:53:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2F1D268709; Mon, 24 Feb 2025 19:53:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="FMifbrJ6"; 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 0DD05686FC for ; Mon, 24 Feb 2025 19:53:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740423180; 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=8gwNhWskfWNIRQdiLRKzt2nM9Eoyun7sJ9adzmnx2gg=; b=FMifbrJ66IQdLOG09dTU+G3j70gkrpJXYlTvM9t1P2yiumT1csZ5lHsfa9daVzGdb2h5fB Jn7V83hReiWeCDdDbg7lACFtYkvadjkLxahRRWRRA4wyVQuB/B6mULWTBhzOruMLSg79nf TX/FzRCwnsrigXBSvdo7iOPvf7CbN2s= 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-158-rhrrHEteN925CfgMpo6Uww-1; Mon, 24 Feb 2025 13:52:58 -0500 X-MC-Unique: rhrrHEteN925CfgMpo6Uww-1 X-Mimecast-MFC-AGG-ID: rhrrHEteN925CfgMpo6Uww_1740423177 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 82D0E1800874; Mon, 24 Feb 2025 18:52:57 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3767E180087A; Mon, 24 Feb 2025 18:52:54 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH v2 5/5] libcamera: software_isp: Modify dispatching messages on stop Date: Mon, 24 Feb 2025 19:52:35 +0100 Message-ID: <20250224185235.43381-6-mzamazal@redhat.com> In-Reply-To: <20250224185235.43381-1-mzamazal@redhat.com> References: <20250224185235.43381-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: I-4xmx0Te749jezyiLX4t4uU0Nntfl1sqgFMl3WG3fw_1740423177 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 and we can do better to ensure they are dispatched before SoftwareIsp::stop() finishes. Let's introduce new `receiver' argument to Thread::dispatchMessages(), limiting dispatching the messages to the given receiver. Now we can flush the messages destined for the SoftwareIsp instance explicitly. And the IPA proxy can flush just the messages destined for itself. Other messages of the given thread remain queued and will be handled elsewhere as appropriate. Signed-off-by: Milan Zamazal --- include/libcamera/base/thread.h | 3 ++- src/libcamera/base/thread.cpp | 15 ++++++++++----- src/libcamera/software_isp/software_isp.cpp | 3 +++ .../libcamera_templates/proxy_functions.tmpl | 2 +- 4 files changed, 16 insertions(+), 7 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 02128f23..6f22f4ed 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -603,6 +603,8 @@ void Thread::removeMessages(Object *receiver) /** * \brief Dispatch posted messages for this thread * \param[in] type The message type + * \param[in] receiver If not null, dispatch only messages for the given + * receiver * * This function immediately dispatches all the messages previously posted for * this thread with postMessage() that match the message \a type. If the \a type @@ -616,7 +618,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()); @@ -633,6 +635,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 @@ -640,12 +645,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(); } diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 3a605ab2..8f5ee774 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -339,6 +341,7 @@ void SoftwareIsp::stop() ispWorkerThread_.wait(); running_ = false; + Thread::current()->dispatchMessages(Message::Type::InvokeMessage, this); ipa_->stop(); for (auto buffer : queuedOutputBuffers_) { 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 -%}