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 */