From patchwork Fri Oct 18 07:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21666 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 93D37C32FC for ; Fri, 18 Oct 2024 07:59:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 272086538E; Fri, 18 Oct 2024 09:59:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="caWPpEPm"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB49E65390 for ; Fri, 18 Oct 2024 09:59:51 +0200 (CEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-71e5a62031aso1259884b3a.1 for ; Fri, 18 Oct 2024 00:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729238389; x=1729843189; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N2LcTi4jGw13ltNq1rVNh6Kk02jZAT/tlEseKphVCtM=; b=caWPpEPmPnpQd9+TP/jnXbTh+8tq1e/k5KAChwg7nnEC/1tQnvvXl6JsOW0U8gTUym +9G3SjNoBSyjmdUQFWNYRXT5DeSNzsdpa2GMC8YtREmkZ6VtbRJrjXBXULv3EFxCqMUC fofIIPvesazAL1ZFr5HESWXChzHMujrPynxss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729238389; x=1729843189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N2LcTi4jGw13ltNq1rVNh6Kk02jZAT/tlEseKphVCtM=; b=RAcus9G1bzS+FY4n3xHKe0Kzg0YYt7FBTHDqxUXFZBmCM+gRHZVrXK+IsIiN/XqJIo RhNZ6vfCXjc94bJdxLC2nKWp3pu+pLzokqeYoL+aIjjPCJmWCuysAetnJ+YWOA6WER4c w6XNSt3/y8IyXh/IUBPjYIih5PBykZnM++a5cwCG4+IotutmN4HsBlaQGZTkP2sBmxrm bGd79FC7ZoGHXg9eTzwSuZG7fjVWx8WdQ4iKNlg1Suxox4piH9bn8ZnPW/9O9mFIm/KQ mxUfFrrZN86KVyKs02N5s//UaBUskFfpGafiIAg0B3nBnKEj85wgdo4AOCs+u+hUwsNp yLNA== X-Gm-Message-State: AOJu0YynqKkwhFR+8Zpk4f3Vk6JSaVHMw9bjYmXTqiDRHlGOV4cCQqze 46d5ZYmmwPYWyV+H0oqXYsIQbfTwjqsYVlrmbXyl0YzPh2pQDgxNms0xoRKodKCxXFMC4AmqDd4 = X-Google-Smtp-Source: AGHT+IHDqqE8uPioHbgeggKX8eCwKFk4GN6MkMjTJUJOB4r+yH8oAGUKP6+/LlZiFuambgEaw7j06A== X-Received: by 2002:a05:6a00:17a9:b0:71e:21:d2d8 with SMTP id d2e1a72fcca58-71ea314b973mr2552732b3a.7.1729238389468; Fri, 18 Oct 2024 00:59:49 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345b0c3sm901274b3a.172.2024.10.18.00.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 00:59:49 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Han-Lin Chen Subject: [PATCH 1/4] libcamera: Add signal disconnected for IPC Date: Fri, 18 Oct 2024 07:57:34 +0000 Message-ID: <20241018075942.1150378-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241018075942.1150378-1-chenghaoyang@chromium.org> References: <20241018075942.1150378-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This CL also adds an API in Camera::Private to trigger Camera::disconnected signal. Signed-off-by: Harvey Yang Co-developed-by: Han-Lin Chen Signed-off-by: Han-Lin Chen --- include/libcamera/internal/camera.h | 2 ++ .../libcamera/internal/ipc_pipe_unixsocket.h | 2 ++ include/libcamera/internal/ipc_unixsocket.h | 2 ++ src/libcamera/camera.cpp | 10 ++++++++ src/libcamera/ipc_pipe_unixsocket.cpp | 8 +++++++ src/libcamera/ipc_unixsocket.cpp | 24 +++++++++++++++++-- .../module_ipa_proxy.cpp.tmpl | 8 +++++++ .../module_ipa_proxy.h.tmpl | 2 ++ 8 files changed, 56 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 0add0428b..0bef0980e 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -33,6 +33,8 @@ public: PipelineHandler *pipe() { return pipe_.get(); } + void notifyDisconnection(); + std::list queuedRequests_; ControlInfoMap controlInfo_; ControlList properties_; diff --git a/include/libcamera/internal/ipc_pipe_unixsocket.h b/include/libcamera/internal/ipc_pipe_unixsocket.h index 8c972613f..09f65b102 100644 --- a/include/libcamera/internal/ipc_pipe_unixsocket.h +++ b/include/libcamera/internal/ipc_pipe_unixsocket.h @@ -28,6 +28,8 @@ public: int sendAsync(const IPCMessage &data) override; + Signal<> *disconnected(); + private: struct CallData { IPCUnixSocket::Payload *response; diff --git a/include/libcamera/internal/ipc_unixsocket.h b/include/libcamera/internal/ipc_unixsocket.h index 48bb7a942..a1e326b6b 100644 --- a/include/libcamera/internal/ipc_unixsocket.h +++ b/include/libcamera/internal/ipc_unixsocket.h @@ -39,6 +39,8 @@ public: Signal<> readyRead; + Signal<> disconnected; + private: struct Header { uint32_t data; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index a86f552a4..ef5a6725f 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -603,6 +603,16 @@ Camera::Private::~Private() * \return The pipeline handler that created this camera */ +/** + * \brief Notify the application that camera is disconnected with signal + * Camera::disconnected + */ +void Camera::Private::notifyDisconnection() +{ + Camera *o = LIBCAMERA_O_PTR(); + o->disconnected.emit(); +} + /** * \fn Camera::Private::validator() * \brief Retrieve the control validator related to this camera diff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp index 668ec73b9..51fd3b1fb 100644 --- a/src/libcamera/ipc_pipe_unixsocket.cpp +++ b/src/libcamera/ipc_pipe_unixsocket.cpp @@ -84,6 +84,14 @@ int IPCPipeUnixSocket::sendAsync(const IPCMessage &data) return 0; } +Signal<> *IPCPipeUnixSocket::disconnected() +{ + if (socket_) + return &socket_->disconnected; + + return nullptr; +} + void IPCPipeUnixSocket::readyRead() { IPCUnixSocket::Payload payload; diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp index 002053e35..3d0248857 100644 --- a/src/libcamera/ipc_unixsocket.cpp +++ b/src/libcamera/ipc_unixsocket.cpp @@ -186,11 +186,16 @@ int IPCUnixSocket::send(const Payload &payload) if (!hdr.data && !hdr.fds) return -EINVAL; - ret = ::send(fd_.get(), &hdr, sizeof(hdr), 0); + ret = ::send(fd_.get(), &hdr, sizeof(hdr), MSG_NOSIGNAL); if (ret < 0) { ret = -errno; LOG(IPCUnixSocket, Error) << "Failed to send: " << strerror(-ret); + if (errno == ECONNRESET) { + disconnected.emit(); + fd_.reset(); + } + return ret; } @@ -241,6 +246,11 @@ int IPCUnixSocket::receive(Payload *payload) * \brief A Signal emitted when a message is ready to be read */ +/** + * \var IPCUnixSocket::disconnected + * \brief A Signal emitted when the Unix socket IPC is disconnected + */ + int IPCUnixSocket::sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num) { @@ -266,10 +276,15 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, if (fds) memcpy(CMSG_DATA(cmsg), fds, num * sizeof(uint32_t)); - if (sendmsg(fd_.get(), &msg, 0) < 0) { + if (sendmsg(fd_.get(), &msg, MSG_NOSIGNAL) < 0) { int ret = -errno; LOG(IPCUnixSocket, Error) << "Failed to sendmsg: " << strerror(-ret); + if (errno == ECONNRESET) { + disconnected.emit(); + fd_.reset(); + } + return ret; } @@ -324,6 +339,11 @@ void IPCUnixSocket::dataNotifier() ret = -errno; LOG(IPCUnixSocket, Error) << "Failed to receive header: " << strerror(-ret); + if (errno == ECONNRESET) { + disconnected.emit(); + fd_.reset(); + } + return; } diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl index ce3cc5ab6..27f03417a 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl @@ -104,6 +104,14 @@ namespace {{ns}} { } } +Signal<> *{{proxy_name}}::disconnected() +{ + if (ipc_) + return ipc_->disconnected(); + + return nullptr; +} + {% if interface_event.methods|length > 0 %} void {{proxy_name}}::recvMessage(const IPCMessage &data) { diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl index e213b18a0..2b7ba872e 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl @@ -53,6 +53,8 @@ public: > {{method.mojom_name}}; {% endfor %} + Signal<> *disconnected(); + private: void recvMessage(const IPCMessage &data); From patchwork Fri Oct 18 07:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21667 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 B3B2CC32FC for ; Fri, 18 Oct 2024 07:59:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D44565390; Fri, 18 Oct 2024 09:59:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cyQbgRdW"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9556D65387 for ; Fri, 18 Oct 2024 09:59:53 +0200 (CEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-71e592d7f6eso1173452b3a.3 for ; Fri, 18 Oct 2024 00:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729238392; x=1729843192; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lW2cNMVwigeRVpF1Gtevk7QOmbQNzwnJV93oTQIgePA=; b=cyQbgRdWZyRhYR/MGNwmX1f6CMxxIJ4uXqhVsTov/OIJfeeC2o6ceqHYX9++PtO1vf jf5IvT4LxbmLbk+W7YOGBCBKRJb96bYa7v/eitaqPZM9hTTdV89YV+oMthwk6ZONVSSj Fzuo+u92aI9CgJaXR7VEk4Q5Srwqt4p6feCWQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729238392; x=1729843192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lW2cNMVwigeRVpF1Gtevk7QOmbQNzwnJV93oTQIgePA=; b=S6HRhC6u+xpkqueAjmj2MR8qwF/HeWYy/vMmzgMAydafY3q8isXQhti6zvYivH3sIx 9mj2U+cquAFGoh8blQ0t0DYO9wlys9cOgS0DZIcVzmE2/oMOi6fsovtLez4C3Q0Xdcdt 02zy2FG5cPPF0eLGFxFVBIahcktrJG537xPvgbU9lg1N7XQC1jA9xGioWJynasgqx2XR k8OE+D1AyU2xDHIDPVOhcqP6WrXT41wf8k90fUHtJcMc/xAfOOffMkwbhNUlYTGnCBFq nTZvbZJUhcy5seCG3R4A7LIsT5XExoADkcTSe9zgvQSPD3tkwgSvGetAR+o5mgTr/Gva emrg== X-Gm-Message-State: AOJu0Yz4aySmXvjNuo3fIOMZMUmoG4EjDMhSjkNSkIdkhTFvzTcVcmQq yMyN180683Fa0ha+kjzcbSWaWLClrrgPMA1p5h2O1CmweXDQt/JLUA/NURqfCKuTAPN1sm6nU6A = X-Google-Smtp-Source: AGHT+IHR5SRAbTYxjDC+C2Q9IuiA5Ye+afUHDmi24J+SbFTqB6Rtfomfc1YFZnOG9Nu7A3MWNwgKQQ== X-Received: by 2002:a05:6a00:1993:b0:718:ea3c:35c3 with SMTP id d2e1a72fcca58-71ea316a93bmr2280495b3a.15.1729238391599; Fri, 18 Oct 2024 00:59:51 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345b0c3sm901274b3a.172.2024.10.18.00.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 00:59:51 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Yudhistira Erlandinata Subject: [PATCH 2/4] libcamera: Use disconnect signal in ipa proxy worker Date: Fri, 18 Oct 2024 07:57:35 +0000 Message-ID: <20241018075942.1150378-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241018075942.1150378-1-chenghaoyang@chromium.org> References: <20241018075942.1150378-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously the worker might not receive the disconnect signal, and the forked process might stay alive forever. This CL also helps DMA buf recycling, as the algo process might hold DMA buf file descriptors. Signed-off-by: Harvey Yang Co-developed-by: Yudhistira Erlandinata Signed-off-by: Yudhistira Erlandinata --- .../libcamera_templates/module_ipa_proxy_worker.cpp.tmpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl index 1f990d3f9..68d68c4a5 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl @@ -60,6 +60,10 @@ public: ~{{proxy_worker_name}}() {} + void disconnected() { + exit_ = true; + } + void readyRead() { IPCUnixSocket::Payload _message; @@ -131,6 +135,7 @@ public: return EXIT_FAILURE; } socket_.readyRead.connect(this, &{{proxy_worker_name}}::readyRead); + socket_.disconnected.connect(this, &{{proxy_worker_name}}::disconnected); ipa_ = dynamic_cast<{{interface_name}} *>(ipam->createInterface()); if (!ipa_) { From patchwork Fri Oct 18 07:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21668 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 BC5ACC32FC for ; Fri, 18 Oct 2024 08:00:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D29D065395; Fri, 18 Oct 2024 09:59:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="me2Y4Pmw"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB5636538B for ; Fri, 18 Oct 2024 09:59:54 +0200 (CEST) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-71e5a1c9071so1404981b3a.0 for ; Fri, 18 Oct 2024 00:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729238393; x=1729843193; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yci7oVr/bgnEF/hXg58IG8sMXvpOTd+bGIWcstS8MbU=; b=me2Y4PmwK2YKI7GZzzvIcPrXzqOImo+7jTBr3xNb7izRyp4hIrf+hw1UFgJ6USHBoz npak9GIM5M/FMPBlIfCN6zl73pN9tGoJUDy3vPe5Z7FjnLOuCxKekT1Lr4NgyoPRIL6A 9J5n9WnusUdTRurZEipxB/wPsGkXPGSc26xcg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729238393; x=1729843193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yci7oVr/bgnEF/hXg58IG8sMXvpOTd+bGIWcstS8MbU=; b=aJvVf8J5/DicbXydpo6alD+ejDMgPFo2tr8I+oIMN3Bf3p4Ldh0zIB7paX82TWyrF2 xHYbJOpW6ircxMzVR3cUs2p4ZheOITc0VXYtD8aBXuaFmFTPk5v/q1Px9HhliuXYN+OK X64fSrdHiDFjhNIQe9eTPiLxyuwHbeH22cN78hQiDxvT1mzrgvxBhIoMhSuZeWgLf9cQ lf1niy0FkAy/6WP7EgEXHWXQMssaL+OeeuLXnbkE5HXwKV0kEG9x3wwUdrsM0FPvp6CD NjfxOXDtgM6iokaOQMr+90YguzYJDVT18xw7i2TFQoNfGr51sEH2LCq8NIsp0oDzzjlx BP3Q== X-Gm-Message-State: AOJu0YzDyK1OBXAoRqGH4p2CGAshaginAHwdU6KcEPu+ZtoHAomrPUKr oJmXhsxNQWovErerajjKFMYJ6/8oXObXlIsA0SrEbjxHt9AN9lqBXEgj0qIbZ4APLaK6tFHru5c = X-Google-Smtp-Source: AGHT+IGvoLanVK8O8Qe7p6il9oCWUUvslUlkoHNJzXqF3qbhoNoId7vjvz1uPdAKJkxm2uujl/Rrcw== X-Received: by 2002:a05:6a00:896:b0:71e:7174:3ae with SMTP id d2e1a72fcca58-71ea320dfa0mr2290324b3a.11.1729238393114; Fri, 18 Oct 2024 00:59:53 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345b0c3sm901274b3a.172.2024.10.18.00.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 00:59:52 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Yudhistira Erlandinata Subject: [PATCH 3/4] libcamera: Detect IPC disconnection with poll Date: Fri, 18 Oct 2024 07:57:36 +0000 Message-ID: <20241018075942.1150378-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241018075942.1150378-1-chenghaoyang@chromium.org> References: <20241018075942.1150378-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously an IPC disconnection will only be detected when there's an IPC message. This CL fixes the issue with poll event: POLLHUP. Signed-off-by: Harvey Yang Co-developed-by: Yudhistira Erlandinata Signed-off-by: Yudhistira Erlandinata --- include/libcamera/base/event_notifier.h | 1 + include/libcamera/internal/ipc_unixsocket.h | 1 + src/libcamera/base/event_dispatcher_poll.cpp | 9 +++++++++ src/libcamera/base/event_notifier.cpp | 5 +++++ src/libcamera/ipc_unixsocket.cpp | 8 ++++++++ 5 files changed, 24 insertions(+) diff --git a/include/libcamera/base/event_notifier.h b/include/libcamera/base/event_notifier.h index 158f2d44b..9ddc1824f 100644 --- a/include/libcamera/base/event_notifier.h +++ b/include/libcamera/base/event_notifier.h @@ -35,6 +35,7 @@ public: void setEnabled(bool enable); Signal<> activated; + Signal<> disconnected; protected: void message(Message *msg) override; diff --git a/include/libcamera/internal/ipc_unixsocket.h b/include/libcamera/internal/ipc_unixsocket.h index a1e326b6b..535be6fbf 100644 --- a/include/libcamera/internal/ipc_unixsocket.h +++ b/include/libcamera/internal/ipc_unixsocket.h @@ -51,6 +51,7 @@ private: int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num); void dataNotifier(); + void EventNotifierDisconnected(); UniqueFD fd_; bool headerReceived_; diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp index 52bfb34e2..fdfeeff06 100644 --- a/src/libcamera/base/event_dispatcher_poll.cpp +++ b/src/libcamera/base/event_dispatcher_poll.cpp @@ -263,6 +263,15 @@ void EventDispatcherPoll::processNotifiers(const std::vector &pol if (!notifier) continue; + if (pfd.revents & POLLHUP) { + LOG(Event, Debug) << "Got signal POLLHUP." + << " Disconnecting IPC"; + + notifier->disconnected.emit(); + unregisterEventNotifier(notifier); + continue; + } + /* * If the file descriptor is invalid, disable the * notifier immediately. diff --git a/src/libcamera/base/event_notifier.cpp b/src/libcamera/base/event_notifier.cpp index 495c281d9..a5a583ac6 100644 --- a/src/libcamera/base/event_notifier.cpp +++ b/src/libcamera/base/event_notifier.cpp @@ -131,6 +131,11 @@ void EventNotifier::setEnabled(bool enable) * parameter. */ +/** + * \var EventNotifier::disconnected + * \brief Signal emitted when the file descriptor is disconnected + */ + void EventNotifier::message(Message *msg) { if (msg->type() == Message::ThreadMoveMessage) { diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp index 3d0248857..609549b6f 100644 --- a/src/libcamera/ipc_unixsocket.cpp +++ b/src/libcamera/ipc_unixsocket.cpp @@ -133,9 +133,17 @@ int IPCUnixSocket::bind(UniqueFD fd) notifier_ = new EventNotifier(fd_.get(), EventNotifier::Read); notifier_->activated.connect(this, &IPCUnixSocket::dataNotifier); + notifier_->disconnected.connect( + this, &IPCUnixSocket::EventNotifierDisconnected); + return 0; } +void IPCUnixSocket::EventNotifierDisconnected() +{ + disconnected.emit(); +} + /** * \brief Close the IPC channel * From patchwork Fri Oct 18 07:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21669 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 04299C32FF for ; Fri, 18 Oct 2024 08:00:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5506465391; Fri, 18 Oct 2024 10:00:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="iMiv3Jig"; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 83A1E65396 for ; Fri, 18 Oct 2024 09:59:56 +0200 (CEST) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-7163489149eso1452971a12.1 for ; Fri, 18 Oct 2024 00:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729238395; x=1729843195; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hfrj4edOfJQQuugH+68k4Cui4kLDvuRKByjOOu3KAFw=; b=iMiv3JigucTUJMriKyn4UPF83ubgM3eyZGgQSXPoTwihTKGlETp+b79QLGNvr7bkBD LfcB7NVrF4dLKlCkz7ks29iYJQu21ubkfvnBdR9+Rzq1PZnIRIwjbGzyavMCmTM1zxZr VJZG/RK6o+Ty61W2ci9RR3/UpkTTPvvyw1tdw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729238395; x=1729843195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hfrj4edOfJQQuugH+68k4Cui4kLDvuRKByjOOu3KAFw=; b=R63bZIGmLhSwjj3WlBXmUJV3AjhMKd01aUTci5enc6w6vvkMUC4NaQmmeSfggMr0p7 Yml/A+amYc9C/fXy2/2Vdaen5ctS4BmHuJeKDUgrg+biZUOaIM75isMleJKLPZj0h2Gx MqlmSSMxgMWEyV3btXfpcvE+pWUt7g0BFVsX2pNEp7FLwi0rihBXeEeqMHmF1zkMed5o 9EpBDX3cjUPSCdskWweHNWRUI9OEjSX81+F681WA1nCLvMmbHX59IX/EMvfDKaEotWGG +n/EJcXV+/6qOuT0z2gGqraj+m75FFuX7Oq8mEVkv7HRjq5aEe3OkTN3/Fc9QD1LWcWL +uvg== X-Gm-Message-State: AOJu0Yw5eeQFivyXe7FQLr2/zR1eZPlX4LIsZE7Mh2UvFMEiWaKu1nBL ElilixmrO825n+9YkZ8z7WvuTi1IlCMtPXuO47VTX96HDsnL0ycELq421uT6zDtex4ps1M0I8ps = X-Google-Smtp-Source: AGHT+IGMkGWtc4zZ0GJpKnPkLT9xm+q0yfOPE53hqYDrflXPHwAMVwHWqyaEzUy+FEjwVYhoncYyfQ== X-Received: by 2002:a05:6a21:181a:b0:1d9:2846:997e with SMTP id adf61e73a8af0-1d92c4babf6mr1981600637.4.1729238394745; Fri, 18 Oct 2024 00:59:54 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345b0c3sm901274b3a.172.2024.10.18.00.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 00:59:54 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Yudhistira Erlandinata Subject: [PATCH 4/4] libcamera: Make Camera::Private::isAcquired() protected Date: Fri, 18 Oct 2024 07:57:37 +0000 Message-ID: <20241018075942.1150378-5-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241018075942.1150378-1-chenghaoyang@chromium.org> References: <20241018075942.1150378-1-chenghaoyang@chromium.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As some pipeline handlers need to know if a CameraData is currently acquired, this patch makes the function protected, instead of private. For example, the upcoming mtkisp7 needs the information to determine if it should send camera disconnect signal. Signed-off-by: Harvey Yang Co-developed-by: Yudhistira Erlandinata Signed-off-by: Yudhistira Erlandinata --- include/libcamera/internal/camera.h | 4 +++- src/libcamera/camera.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 0bef0980e..fe47a49b7 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -43,6 +43,9 @@ public: const CameraControlValidator *validator() const { return validator_.get(); } +protected: + bool isAcquired() const; + private: enum State { CameraAvailable, @@ -52,7 +55,6 @@ private: CameraRunning, }; - bool isAcquired() const; bool isRunning() const; int isAccessAllowed(State state, bool allowDisconnected = false, const char *from = __builtin_FUNCTION()) const; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index ef5a6725f..38aa4ad22 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -670,6 +670,9 @@ static const char *const camera_state_names[] = { "Running", }; +/** + * \return True if the camera is acquired, false otherwise + */ bool Camera::Private::isAcquired() const { return state_.load(std::memory_order_acquire) != CameraAvailable;