Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2430115rdb; Mon, 5 Feb 2024 06:28:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeDCTFHJrE1AzYbTcfUQnc9sGGJXuDHzOzDcnwbDbzzjVF2dB7ouqkITBKKcHza/ASLK0P X-Received: by 2002:a92:c5a3:0:b0:363:8249:595 with SMTP id r3-20020a92c5a3000000b0036382490595mr9279244ilt.5.1707143323545; Mon, 05 Feb 2024 06:28:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707143323; cv=pass; d=google.com; s=arc-20160816; b=gFjBTddM7paUHrbz946vPeABNzTimhyV+JcYqBh7EkPdiFXmFGMoYxF/gKp/Kf1/t7 EmpkFp7rzud4uZ6CX3Q0mRFvwSQTIj+lNY23jRP6M/gPmvKS2O2WbXsi+e2qo/PyqtoA cTTblFRejXmn2T6bw/dhn3K4UATbreR+ntqkq/0vMBeZrKFM6ILBa561Ij4NXPONS3ch b83IFLJChOQ/vLCl4YpESfWXaCCG6F70w8RVvSKop7Dz/6h4MU0l30WV5b4+kipWfIEf NuGtc6FalDZSJY92yQKKrMRAV8nHnr1ruj0xdJdwBCeFv8kMBGHRva2AiLPWb3wsDCT4 kB0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=MXHRKWZuYk7yVO/rqNxf0kJY/3s2I6sCNs7eu9xA6Uk=; fh=/UNp7YE+Js0LFOSiUpBzshuKHIBtAvHgjJXfI9kZIjQ=; b=dPEKr24uKI39+BWVO3joOBRax7uEQUf0Aur5ESkFVxU255msDNFXNyyt2t2z5y3Wkx oC3wGCiEdETUcdON8zt+ZYWN8O9T7tTnji5fOj0YbGXSm7jn8Z2yGS0HgpHNDEG0N2W8 N2dNrjNN3FT4wFIpSYXWPYR6eWJxcCgfugjX2upIF1Z9AjVOJhYCoMxOt/M4qUwumwOR rFHweJk4DgniP+hXNO0pl8V6pDtRcfra9txDDaycLFb8j0qHgxfi14cn+ht5cqzBkCSE 82TAKoTel3x/gQYVxsURT0KKFUqpWC1qaVaR4Ce3Cyn7wihXc9fo45tI1VawBd2S0LSM ZGOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-52765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl X-Forwarded-Encrypted: i=1; AJvYcCULWahjUdk6lTrGGb/M+UGSLKv32eFuLIM2jPxpl6YRscLmX5cJHqTEylg/ccZoCCn5tLZ/RN5XY8eB9N1HcOMJgdp05fnNrO4SqasQLw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bx29-20020a056a02051d00b005dc1b5b386asi1632821pgb.339.2024.02.05.06.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 06:28:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-52765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EC72FB233D7 for ; Mon, 5 Feb 2024 13:59:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5CC728DD8; Mon, 5 Feb 2024 13:59:10 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1674E249F7; Mon, 5 Feb 2024 13:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707141550; cv=none; b=JGd73PVvq8VP0fShoLc9b3UrWQne5hEahfkrzG49Y4YCE1u4tnHdjta/W69GO3jBPgVYO9Pa4MbtBlly13WepVpYRwxNnwf7OmykzKixlgIQqi/QChxzI5XyDwSl4CYEraYvEeWU85C27PKScGwbcS6W8KL+i6J6J205MPFI4bY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707141550; c=relaxed/simple; bh=VHpZlVcuYhfVnBfVfZ5cAUJ2dzJcZlT4YbyXdSuQ8oM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iXS3Gkr/4ybR7Z5lQvRjdzzEXJMBc5ccshgjD+xSCJZOHzciSOcOvNWXCj2djKj5qz1XJbnE3P57fpYcVGY76JDHlJNGw4g628rHWnfDYVKAWKvKglD/u/ftYhr0EIaAu+Bwkl6ErzJT2gAsvx8ziW3SSEaoV/8W7t6VGJrwbQc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21D9DC433C7; Mon, 5 Feb 2024 13:59:07 +0000 (UTC) Message-ID: Date: Mon, 5 Feb 2024 14:59:06 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 1/9] media: videobuf2: Update vb2_is_busy() logic Content-Language: en-US, nl To: Benjamin Gaignard , mchehab@kernel.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, kernel@collabora.com References: <20240126110141.135896-1-benjamin.gaignard@collabora.com> <20240126110141.135896-2-benjamin.gaignard@collabora.com> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM8tCkdD8YNXXKyKqNl UVqXnarz8m2JC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CkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240126110141.135896-2-benjamin.gaignard@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 26/01/2024 12:01, Benjamin Gaignard wrote: > Do not rely on the number of allocated buffers to know if the > queue is busy but on flag set when at least buffer has been allocated flag -> a flag buffer -> one buffer > by REQBUFS or CREATE_BUFS ioctl. > The flag is reset when REQBUFS is called with count = 0 or close the > file handle. close the file handle -> the file handle is closed > This is needed because delete buffers feature will be able to remove > all the buffers from a queue while streaming so relying in the number in -> on > of allocated buffers in the queue won't be possible. > > Signed-off-by: Benjamin Gaignard > --- > drivers/media/common/videobuf2/videobuf2-core.c | 6 +++++- > include/media/videobuf2-core.h | 4 +++- > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > index b6bf8f232f48..8aa6057df581 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -858,8 +858,10 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, > * In case of REQBUFS(0) return immediately without calling > * driver's queue_setup() callback and allocating resources. > */ > - if (*count == 0) > + if (*count == 0) { > + q->is_busy = 0; No, this line should actually go before the 'if'. VIDIOC_REQBUFS is a bit odd: if you call it with count > 0, then it will first delete all existing buffers and implicitly go out of the 'busy' state. Then it attempts to allocate the new buffers, and if that is successful, then it is back to the busy state. So regardless of the count value, you need to set is_busy to 0 here. > return 0; > + } > } > > /* > @@ -966,6 +968,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 +1094,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; > You missed vb2_core_queue_release(): that's called when the file handle is closed, so that should set q->is_busy to 0 as well. > diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h > index 56719a26a46c..b317286a7b08 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; > } > > /** Regards, Hans