From patchwork Mon Feb 24 12:08:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22841 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 6609CC324E for ; Mon, 24 Feb 2025 12:09:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A0B2686EF; Mon, 24 Feb 2025 13:09:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="gnmz6WXA"; 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 89D5C686DD for ; Mon, 24 Feb 2025 13:09:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740398952; 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=gnmz6WXAeWvGo2m9FsQmWVruESz0NrQCGCO2uCbFZ6GzYYRzQp5NrHpwPbtxX6Zd5rPMfG EisNeo4G9OKzBXQwirDfbeU/Fu/a++nHr9z8n7e4qToigiFadjY95cFtKQprPdGFlL99H4 CFZ6XKJ3ifXKng9Pv+EgmcgmUys7jSg= 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-133-b0rJY_TIPoufVig3I7ZQdA-1; Mon, 24 Feb 2025 07:09:08 -0500 X-MC-Unique: b0rJY_TIPoufVig3I7ZQdA-1 X-Mimecast-MFC-AGG-ID: b0rJY_TIPoufVig3I7ZQdA_1740398948 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 8AF441801A18; Mon, 24 Feb 2025 12:09:07 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A973E19560AA; Mon, 24 Feb 2025 12:09:05 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH 1/5] libcamera: software_isp: Emit ispStatsReady only if IPA is running Date: Mon, 24 Feb 2025 13:08:50 +0100 Message-ID: <20250224120854.19747-2-mzamazal@redhat.com> In-Reply-To: <20250224120854.19747-1-mzamazal@redhat.com> References: <20250224120854.19747-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9gDoWCidBHPqId3JBgWKyCkS-gfMWTFw0nlTYoDH-GQ_1740398948 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 --- 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 12:08:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22842 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 14EBFC324E for ; Mon, 24 Feb 2025 12:09:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA59A686F0; Mon, 24 Feb 2025 13:09:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Er+LhnpF"; 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 6399F686E1 for ; Mon, 24 Feb 2025 13:09:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740398954; 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=Er+LhnpFPXzZnwtmEFv1UHSO4hEiW6m1T8Kke7Y1uK2MBJSEdGO97bVE62YX0CduX0XYMA P2ZlzEhK23g6ut1sgnpZhJ6A7Bm9p3gznc/3tSQugRgxEJ3bawwRqcE7QZAh8tG9SRUIfS xGlfOsWeClEXvZdkHRtwRkCJ9ODiQ9I= 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-138-yJpioRJWMGCM6jP2zjMVbg-1; Mon, 24 Feb 2025 07:09:11 -0500 X-MC-Unique: yJpioRJWMGCM6jP2zjMVbg-1 X-Mimecast-MFC-AGG-ID: yJpioRJWMGCM6jP2zjMVbg_1740398950 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 D0265180087E; Mon, 24 Feb 2025 12:09:09 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 158C719560AA; Mon, 24 Feb 2025 12:09:07 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH 2/5] libcamera: software_isp: Handle queued output buffers on stop Date: Mon, 24 Feb 2025 13:08:51 +0100 Message-ID: <20250224120854.19747-3-mzamazal@redhat.com> In-Reply-To: <20250224120854.19747-1-mzamazal@redhat.com> References: <20250224120854.19747-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: i9-8ydsV0xf92jmea00Ku91JuY9jMw8LgTJvFiFU2sc_1740398950 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 12:08:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22843 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 B8D47C324E for ; Mon, 24 Feb 2025 12:09:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C104686F0; Mon, 24 Feb 2025 13:09:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="gvGJitKe"; 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 CD2B4686ED for ; Mon, 24 Feb 2025 13:09:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740398956; 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=gvGJitKeBmeKC+wi8c6lWFOLwbnl/fBaj4rlaiMThrbuLY4WZEHh+E+CQrqkbLZoc+USvs jMnuoYF43Xubj74Xs1XMfRzhp5BBiYqZDPfqGcTs8OeCiX0nIQVHXXhOQ6Ake/QYdPcvH5 OVAtq7RtLVDFuQDdi5vR4fgqCWkJvRI= 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-316-tTYMY2GoPHW9K5vYuCNqLQ-1; Mon, 24 Feb 2025 07:09:13 -0500 X-MC-Unique: tTYMY2GoPHW9K5vYuCNqLQ-1 X-Mimecast-MFC-AGG-ID: tTYMY2GoPHW9K5vYuCNqLQ_1740398952 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 5E56E1801A13; Mon, 24 Feb 2025 12:09:12 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 53E1119560AA; Mon, 24 Feb 2025 12:09:10 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH 3/5] libcamera: software_isp: Handle queued input buffers on stop Date: Mon, 24 Feb 2025 13:08:52 +0100 Message-ID: <20250224120854.19747-4-mzamazal@redhat.com> In-Reply-To: <20250224120854.19747-1-mzamazal@redhat.com> References: <20250224120854.19747-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ZMgBRry2Pw61GMcox-rVcVrFWKWeYKVPGuLJNtawj6k_1740398952 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 12:08:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22844 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 CF5AAC324E for ; Mon, 24 Feb 2025 12:09:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72BA5686FA; Mon, 24 Feb 2025 13:09:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="gWVmhpEp"; 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 63E18686F4 for ; Mon, 24 Feb 2025 13:09:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740398960; 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=gWVmhpEpnE+m9yz94HczBtsR8uOH4Pffdyhh/rGNT2NHqz5REffyC3j/8R4jv5djCY1UKt DU5aUSqeJYYwp/HfrM6rLXIEgjRsrefMrjLyRO191clYXow6ky7+G4KHnb3TYASWmMvCn5 6rP+7cmSgrkuJhubn25Uz/9D/Szuo2E= 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-91-0CX69NwiNCii2PGiCqwnFQ-1; Mon, 24 Feb 2025 07:09:16 -0500 X-MC-Unique: 0CX69NwiNCii2PGiCqwnFQ-1 X-Mimecast-MFC-AGG-ID: 0CX69NwiNCii2PGiCqwnFQ_1740398955 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 E4E3319560BC; Mon, 24 Feb 2025 12:09:14 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC89219560AA; Mon, 24 Feb 2025 12:09:12 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH 4/5] libcamera: base: Fix formatting in thread.cpp Date: Mon, 24 Feb 2025 13:08:53 +0100 Message-ID: <20250224120854.19747-5-mzamazal@redhat.com> In-Reply-To: <20250224120854.19747-1-mzamazal@redhat.com> References: <20250224120854.19747-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: p0fCIdwvTjpElKQNDyITWGYFC_Al48BPi8p43LKt7rI_1740398955 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 12:08:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22845 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 D6A81C32C2 for ; Mon, 24 Feb 2025 12:09:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53ACC686F9; Mon, 24 Feb 2025 13:09:24 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="K6v5HW2C"; 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 B0027686F4 for ; Mon, 24 Feb 2025 13:09:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740398961; 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=vommuU7mKkaVRfL0lYXIdRZQCLVVNLDOpQA66iiz7rE=; b=K6v5HW2CmRJrgG47jyrId1z3+RK6p6PT2PJBV1gMbnr9cqR4cRyQYPHcwE9kdrjYNvG1mk Xq77YPSFUrR9xN0WgTXWS8CIVRF3rKMUsxsJx6puQs8/kLq34yWqFNyrNyjhjokf4i/jxZ LNlBcKVXHzbzyjVGGavMx9zB+WF1E7k= 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-336-RqpnhuoyOBuEIe21BMOOLA-1; Mon, 24 Feb 2025 07:09:18 -0500 X-MC-Unique: RqpnhuoyOBuEIe21BMOOLA-1 X-Mimecast-MFC-AGG-ID: RqpnhuoyOBuEIe21BMOOLA_1740398957 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 6AECB1800875; Mon, 24 Feb 2025 12:09:17 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.225.60]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 816B819560AB; Mon, 24 Feb 2025 12:09:15 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Stanislaw Gruszka , Laurent Pinchart , Kieran Bingham Subject: [PATCH 5/5] libcamera: software_isp: Modify dispatching messages on stop Date: Mon, 24 Feb 2025 13:08:54 +0100 Message-ID: <20250224120854.19747-6-mzamazal@redhat.com> In-Reply-To: <20250224120854.19747-1-mzamazal@redhat.com> References: <20250224120854.19747-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 86FtDa__4BGjze9YI5SFsh9ajcRePAiR-iexkDtN-ec_1740398957 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 | 14 +++++++++----- src/libcamera/software_isp/software_isp.cpp | 3 +++ .../libcamera_templates/proxy_functions.tmpl | 2 +- 4 files changed, 15 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..2fde2959 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()); @@ -640,12 +642,14 @@ 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_; + if (receiver && receiver != messageReceiver) + continue; + 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 -%}