Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp184467lqb; Thu, 14 Mar 2024 08:33:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWT72dSlgLk8KvKIDyi30+dCedIoy6RL9esDRZMDDHe3slYQfMMOnl97IrzQitDE/cFXp6jjYbkgDV4mpyG31LP0UzJbaS3+dA+34Rmw== X-Google-Smtp-Source: AGHT+IE0gwQQeaKudWnzJwTYNx7qGLWeQUsJ8PB+FAozeia9Zx2Tl+DmTsn7gmSQargPRP0o/XP1 X-Received: by 2002:a05:620a:4fa:b0:789:cf1f:126 with SMTP id b26-20020a05620a04fa00b00789cf1f0126mr991046qkh.8.1710430384168; Thu, 14 Mar 2024 08:33:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710430384; cv=pass; d=google.com; s=arc-20160816; b=I6zpxQrU6UiAb67z+xefPk0d1v5tnPKnPFe+3+T27JMtlz93jPs1D2T90R+mHZbLSg 74osg3KEgLK9wa7bTCydpoO/0rPjYinYw8IdRJwtU2Wj/Q0Alua0yJAWLQERm2Q/CkCy l0AQ5LVIhz6bqz9zH6ivvYbG+y505KDNU/NYOdhFNioz82gD/Xrc8A0ctakO7aS0dsKd JRKOxt4Q5ZjgYVC3Xu7/kh+Ln/lfwjzlY9bU/Lp+VNrT0V+72AUzlSyNxLiMDaiBp140 ULpA2MAEddkcTmTSK49SwhJmJsd2wvFyCSTMfSNbhTN2Oz0yKLtqbo8CwzAXmZKTb3LQ I8yQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=StDYDV2lu3de6x2QKkXC1TTL9HZZMQHRCvcofTW7RP4=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=yVcL0j+sV8n1pP4sgINTO5ThXpOMTIZvlm7cDCRiu/PQO4TT8nsr7E43bMX5opHci8 ZAVFUGkQzXoGy0Fxry/M4dvKwpYE0UkFqjnPiW2NN/thLLeltQK00NDdNQrEhu4md2Uw Ki7L9lQGF3KFLK0Ntw1d70Lm0snWimSm6pPn6BQOI9VJozXzvciQRepXkzNlh+815SOJ UP64LjBLqdIybSWsuIuGOMY9avTHWvgkhq96q7AyoCYriocJcClwWn1S6+VQymifjcKt OpCyitmjMWPi4o/zPB8mTvK8pIilfjhiaFQRRAkPUzMI83cBEV2Gn95N0rchwz3UXRhD Jnqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="j/kf/jVr"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-103498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v13-20020a05620a122d00b007882f7f74c6si1687157qkj.257.2024.03.14.08.33.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 08:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="j/kf/jVr"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-103498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DF8241C20C91 for ; Thu, 14 Mar 2024 15:33:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8DA773508; Thu, 14 Mar 2024 15:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="j/kf/jVr" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 539357175F; Thu, 14 Mar 2024 15:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710430357; cv=none; b=QYo22JxYcvi6FKOT91FI1hTIvlrcTbK/v4GD9yMqibHooDN0xGa/Izups/GGZeVSDLTx/mNdzTKwiR66fO1P1BovqvU9p9O5Z2ojkoDbPOKBvVISJs6ANp5rXwrImDZoCpWPLfy+qhiJyWcRcLAEVI6f6fp7bGpANYgW+uLdd1Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710430357; c=relaxed/simple; bh=kghUcSURPBJoB0fmxL1r0Y9N1XZdT/r3cDKOOvYVX9w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HxjJl80ydDvHSUmf1KFtmgNmmXcCI37bD299bXlcFr1LIRyRQozgOxE0HbrWP2UDuhVc1fzgeuENcEFgjtmI5KHx4raErqqgJ9HHX11WaKidMWL0KoDosTboCn3k9IdM+viUGn0FqmVAon+xwNuGdHNWJinBG44xyfY410ET/gY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=j/kf/jVr; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1710430353; bh=kghUcSURPBJoB0fmxL1r0Y9N1XZdT/r3cDKOOvYVX9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/kf/jVrjp7W2NII/rxpmOhKm8oAJ5alSNrSLUM1dPrOPrGAS9lTzjBU+b+uSFPjD GlBl1UPD2sunY0CLxTT1nDRnzFPZNu5LlQEVa7hIBMIMMr+FSaMrncG1yxa/lWfmUx L1njzmWkj7eIN/SiUc4GmfGbdTwaI2EJq7zhswG+BgmDtTuFx3PzYXeF1A1TjjSSET KHEigPFabFHa0zuVgHEIYXuFJNFmnvW0t5/f6xoBZJsiPNCORrBR0ddFFYlvtVgmWg M4R8uBrYqPOzbPZ4XrbnJ/OHIRaV06ImJaavEaRwCdvg+Nchsd44/ldZqYJ0w5hqQr P5eTgB4Hd2kjg== 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 4B30037820F5; Thu, 14 Mar 2024 15:32:33 +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 v21 1/9] media: videobuf2: Update vb2_is_busy() logic Date: Thu, 14 Mar 2024 16:32:18 +0100 Message-Id: <20240314153226.197445-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240314153226.197445-1-benjamin.gaignard@collabora.com> References: <20240314153226.197445-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 8b86996b2719..667bf9ee1101 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -582,6 +582,7 @@ struct vb2_buf_ops { * released. Used to prevent destroying the queue by other threads. * @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 @@ -647,6 +648,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; @@ -1166,7 +1168,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; } /** -- 2.40.1