From patchwork Wed Feb 21 15:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 13565783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A28EC5478C for ; Wed, 21 Feb 2024 15:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zj5WadDjACbFg3lDXuSp+MRdeXgHifhShFXCE4yb9Oo=; b=OP70FVbQ9rHnDn AYesf6RLZzRJ2RFen6VILLDYcF3/AzLTPcv4DNqzWmZ3vsWC2xCXdPDYFlTbq3JIdGroPv+SEeEmr sm1lz26fdCrxn1+WDM7NFuycCTZ+pG8O/K6e6QMI96pdq/Rw97Q5hFHFZkbE78/Tf7MUP7O7e3Wi7 DuD3JJrpcaGIZ8z+/xkwHxeF5/4/PKTJEqyC54utEy9v5KgTEXRrla/htrlrowc+U9G3WzoJIr/ox LmY4FR8GsaqGIyPwxOxEru3hWwQbFZ4IBdDMzrP0pB8zyQpHearULQ+wOMnXDnWHGX2msrkJ4Hp3p uJdmUuk2yZCzYeX+Ku6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcovv-00000001aEX-1Lbo; Wed, 21 Feb 2024 15:54:55 +0000 Received: from madrid.collaboradmins.com ([46.235.227.194]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcovl-00000001a6w-1F15 for linux-rockchip@lists.infradead.org; Wed, 21 Feb 2024 15:54:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530882; bh=5ckXgkvWFGC5NNON9KbJM0pNpOmn7g6OdSSL28pZpt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTWPvWxYB8aVG/Jmtt/SUn5NTob7J1BmlHCtcdzMsWgTT9WZo0TTHgr4kIlbgGlku DZKNh1V+54ivHckBGQlXY6jEzyjH/ndW81IcImNUNa9OpGArULe1lAYtUS10vNSqEO NBSJkpoK/g7Fn+bSy6C1UFMwZ0pqVT7CwttuvW6Pieb1weagKokdfVieay2ob9VYUK NdN3R465hTJ/zDY1ohkUdDS+IK7fgfShzyPHPgeYtgnXgDQiWtadW9IusaJcpwMVvp d8CjrldwRyBsTU36BsbpnnTALH2ZZn0+cCFqsvvbAZgllG3yWD6/taawXLktXpbGMK x9alJ9bYdyAJQ== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 309033780C13; Wed, 21 Feb 2024 15:54:42 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 1/9] media: videobuf2: Update vb2_is_busy() logic Date: Wed, 21 Feb 2024 16:54:27 +0100 Message-Id: <20240221155435.100093-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240221_075445_596935_F7361EB0 X-CRM114-Status: GOOD ( 16.20 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Do not rely on the number of allocated buffers to know if the queue is busy but on a flag set when at least one buffer has been allocated by REQBUFS or CREATE_BUFS ioctl. The flag is reset when REQBUFS is called with count = 0 or the file handle is closed. This is needed because remove buffers feature will be able to remove all the buffers from a queue while streaming so relying on the number of allocated buffers in the queue won't be possible. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 4 ++++ include/media/videobuf2-core.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index b6bf8f232f48..d8b3c04cb3b5 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -854,6 +854,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, __vb2_queue_free(q, q_num_bufs); mutex_unlock(&q->mmap_lock); + q->is_busy = 0; /* * In case of REQBUFS(0) return immediately without calling * driver's queue_setup() callback and allocating resources. @@ -966,6 +967,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, */ *count = allocated_buffers; q->waiting_for_buffers = !q->is_output; + q->is_busy = 1; return 0; @@ -1091,6 +1093,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * to the userspace. */ *count = allocated_buffers; + q->is_busy = 1; return 0; @@ -2555,6 +2558,7 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_queue_free(q, vb2_get_num_buffers(q)); kfree(q->bufs); q->bufs = NULL; + q->is_busy = 0; mutex_unlock(&q->mmap_lock); } EXPORT_SYMBOL_GPL(vb2_core_queue_release); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index d9c6b5d4e990..6ad36da91f8d 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -579,6 +579,7 @@ struct vb2_buf_ops { * called since poll() needs to return %EPOLLERR in that situation. * @is_multiplanar: set if buffer type is multiplanar * @is_output: set if buffer type is output + * @is_busy: set if at least one buffer has been allocated at some time. * @copy_timestamp: set if vb2-core should set timestamps * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the * last decoded buffer was already dequeued. Set for capture queues @@ -644,6 +645,7 @@ struct vb2_queue { unsigned int waiting_in_dqbuf:1; unsigned int is_multiplanar:1; unsigned int is_output:1; + unsigned int is_busy:1; unsigned int copy_timestamp:1; unsigned int last_buffer_dequeued:1; @@ -1163,7 +1165,7 @@ static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q) */ static inline bool vb2_is_busy(struct vb2_queue *q) { - return vb2_get_num_buffers(q) > 0; + return !!q->is_busy; } /**