From patchwork Fri Aug 2 07:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20747 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 CF823BDC71 for ; Fri, 2 Aug 2024 07:24:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5CE0A63387; Fri, 2 Aug 2024 09:24:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CqJ9hnJ3"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CBC56337E for ; Fri, 2 Aug 2024 09:24:22 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2405:201:2015:f873:55d7:c02e:b2eb:ee3f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8E9F17F3; Fri, 2 Aug 2024 09:23:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1722583413; bh=3aE8RBibmfS7XOF6uIaV9DG1Olx5JjQZSaJf29fo5UM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CqJ9hnJ3uLVpsqMAScAvLxxQvNtU8v8DXT7nfM5j9PhoXkwXevgRk/m6bC9+KMh5j diaa4dQJmIgWRNPkMa9RNSAfSajBR26KbTi4W5AHQlIaLMeS9Okr4KAgHY+o83XfpC 3cGYpU9tATAVQGmdY6AhXrJO6gpcSHklEO1KKLqI= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Umang Jain Subject: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR Date: Fri, 2 Aug 2024 12:54:15 +0530 Message-ID: <20240802072416.25297-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240802072416.25297-1-umang.jain@ideasonboard.com> References: <20240802072416.25297-1-umang.jain@ideasonboard.com> 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" V4L userspace API documentation clearly mentions the handling of EINTR on ioctl(). Align with the xioctl() reference provided in [1]. Retry the ::ioctl() if failed with errno == EINTR. Use a do..while{} to check the return value of ::ioctl() and errno value. If the return value is found to be -1, and errno is set with EINTR, the ioctl() call should be retried. [1]: https://docs.kernel.org/userspace-api/media/v4l/capture.c.html Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham --- src/libcamera/v4l2_device.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 4a2048cf..2e92db0f 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -454,11 +454,17 @@ int V4L2Device::setFrameStartEnabled(bool enable) */ int V4L2Device::ioctl(unsigned long request, void *argp) { + int ret; + + do { + ret = ::ioctl(fd_.get(), request, argp); + } while (ret == -1 && errno == EINTR); + /* * Printing out an error message is usually better performed * in the caller, which can provide more context. */ - if (::ioctl(fd_.get(), request, argp) < 0) + if (ret < 0) return -errno; return 0; From patchwork Fri Aug 2 07:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20748 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 91E4ABDC71 for ; Fri, 2 Aug 2024 07:24:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6988A63383; Fri, 2 Aug 2024 09:24:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="owPlY1Pn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF9B26337E for ; Fri, 2 Aug 2024 09:24:22 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2405:201:2015:f873:55d7:c02e:b2eb:ee3f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 71FA7524; Fri, 2 Aug 2024 09:23:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1722583414; bh=NiNB3UOEiuqEFx0eijvV1Pfkasb+IKE4PLlUAkQroYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=owPlY1Pne+WLvNKmN6yHrpsWHW6ABcHRhIlcUUPodbl251XUNffZFSIRSgXMz1pJL lMLNhSvnXUoB1csfXLHQIXwbpbbBe8V2/0K7WbLKuwPXC27iIr6AzWSMQpfAfkBXbG P6L0eN0nIBtkfxnjeKThG4CUAb8OFxdpHZh+2bOo= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Umang Jain Subject: [PATCH 2/2] libcamera: dma_buf_allocator: Retry ::ioctl on EINTR Date: Fri, 2 Aug 2024 12:54:16 +0530 Message-ID: <20240802072416.25297-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240802072416.25297-1-umang.jain@ideasonboard.com> References: <20240802072416.25297-1-umang.jain@ideasonboard.com> 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" V4L userspace API documentation clearly mentions the handling of EINTR on ioctl(). Align with the xioctl() reference provided in [1]. Retry the ::ioctl() if failed with errno == EINTR. Use a do..while{} to check the return value of ::ioctl() and errno value. If the return value is found to be -1, and errno is set with EINTR, the ioctl() call should be retried. [1]: https://docs.kernel.org/userspace-api/media/v4l/capture.c.html Signed-off-by: Umang Jain --- src/libcamera/dma_buf_allocator.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp index be6efb89..5b469b19 100644 --- a/src/libcamera/dma_buf_allocator.cpp +++ b/src/libcamera/dma_buf_allocator.cpp @@ -128,6 +128,8 @@ DmaBufAllocator::~DmaBufAllocator() = default; */ UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size) { + int ret; + /* Size must be a multiple of the page size. Round it up. */ std::size_t pageMask = sysconf(_SC_PAGESIZE) - 1; size = (size + pageMask) & ~pageMask; @@ -144,7 +146,10 @@ UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size) create.offset = 0; create.size = size; - int ret = ::ioctl(providerHandle_.get(), UDMABUF_CREATE, &create); + do { + ret = ::ioctl(providerHandle_.get(), UDMABUF_CREATE, &create); + } while (ret == -1 && errno == EINTR); + if (ret < 0) { ret = errno; LOG(DmaBufAllocator, Error) @@ -165,7 +170,10 @@ UniqueFD DmaBufAllocator::allocFromHeap(const char *name, std::size_t size) alloc.len = size; alloc.fd_flags = O_CLOEXEC | O_RDWR; - ret = ::ioctl(providerHandle_.get(), DMA_HEAP_IOCTL_ALLOC, &alloc); + do { + ret = ::ioctl(providerHandle_.get(), DMA_HEAP_IOCTL_ALLOC, &alloc); + } while (ret == -1 && errno == EINTR); + if (ret < 0) { LOG(DmaBufAllocator, Error) << "dma-heap allocation failure for " << name; @@ -173,7 +181,11 @@ UniqueFD DmaBufAllocator::allocFromHeap(const char *name, std::size_t size) } UniqueFD allocFd(alloc.fd); - ret = ::ioctl(allocFd.get(), DMA_BUF_SET_NAME, name); + + do { + ret = ::ioctl(allocFd.get(), DMA_BUF_SET_NAME, name); + } while (ret == -1 && errno == EINTR); + if (ret < 0) { LOG(DmaBufAllocator, Error) << "dma-heap naming failure for " << name;