Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp445800rdb; Mon, 15 Jan 2024 02:27:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtGmixzO4Cby8OO+ZYjNbCayLVyFG6IjvPOLtQgI8cbLPLKkoZ3jL/u/8d4VZYLUJKtYO2 X-Received: by 2002:a05:6808:1b13:b0:3bd:7e0d:52a9 with SMTP id bx19-20020a0568081b1300b003bd7e0d52a9mr1287816oib.91.1705314441108; Mon, 15 Jan 2024 02:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705314441; cv=none; d=google.com; s=arc-20160816; b=ZWgQg7+E5QyNjOfjGyg1qt8e3ZJyHBGPuoC7cgNB+9bwGT5uBIpYOQqD2N7Lr48DUk id6Vy8Ohtnua+37QDWPNlZ3Iu0dhFg1SaERMukMHzsvywlosuUcSYyPw+7uDVml9QWtW UfFmrUMXoLv8k4SoDJ631PSNaqfIXvfhlZrghqVUEguJJse2flq2LA8UKDtWKJwzO26J WvENO4m2wcm0cf6fXPDNtiifA7/zezMtYeF4RujDWA3KEzenoq57wleWtvXZVo9q1UV0 Wt8I+b5KWj32er59TaJOz9z5fENz3BCSVeEho5qZ2dRMO9BUPXdIfXq/jKsJOWWwTM7o 7S8A== ARC-Message-Signature: i=1; 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=kxgY3fPto7M+hq4msv55jg1GMDtBjRBIP5Lgva7wpvs=; fh=JA5CkwWQaCWbhBvBUXS2prPFrwCGT4l48Srp7tLe1bE=; b=SShWlOIDAAC8PE3dkOFPWlT7IzW1mKw54Xk3GAt46UNFiQUxBcf2V6K18+jsc7svqO ZpGxor8ggAPij4Ob/K1zm9Qv5y7mBCNeS6YfTNpipZ5Q0E/vpGptdYnhsmc+8PrELjpj +zO1QY8vxKnk5bqOejkBw0FeOA/+xbf8Jx7Hr98ijiMOQ/Gdk1+NurW72ae9WU8BubLx 8KR5t1iCvOWffEqWjCJeJHaekdGYeqxg/4pgb/R0WwDny9uASwkFY+Dc9lDhBjwlRkC9 pi5yj62JsyhSWykptep8wfgkM4+nwQajh0m2jH6QA7T7RINzvsMdQBXEs+nTJuc0N/Vq H00w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ch10-20020a056a00288a00b006d9ac879d9csi1234794pfb.171.2024.01.15.02.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:27:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25889-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B8A1C2820FD for ; Mon, 15 Jan 2024 10:27:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE44C1E865; Mon, 15 Jan 2024 10:27:09 +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 5DD8A101C1; Mon, 15 Jan 2024 10:27:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B80C0C433F1; Mon, 15 Jan 2024 10:27:07 +0000 (UTC) Message-ID: <8073593c-aaac-43e1-9f90-51d5134df070@xs4all.nl> Date: Mon, 15 Jan 2024 11:27:05 +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 v16 1/8] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure 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: <20231215090813.15610-1-benjamin.gaignard@collabora.com> <20231215090813.15610-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/c1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CVHk/woaMZv c1Dm4Uvkv0Ilelt3Pb9J7zhcx6sm5T7v16VceF96jG61bnJ2GFS+QZerZp3PY27XgtPxRxYj AmFUeF486PHx/2Yi4u1rQpIpC5inPxIgR1+ZFvQrAV36SvLFfuMhyCAxV6WBlQc85ArOiQZB Wm7L0repwr7zEJFEkdy8C81WRhMdPvHkAIh3RoY1SGcdB7rB3wCzfYkAuCBqaF7Zgfw8xkad KEiQTexRbM1sc/I8ACpla3N26SfQwrfg6V7TIoweP0RwDrcf5PVvwSWsRQp2LxFCkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20231215090813.15610-2-benjamin.gaignard@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/12/2023 10:08, Benjamin Gaignard wrote: > Add 'min_reqbufs_allocation' field in vb2_queue structure so drivers > can specificy the minimum number of buffers to allocate when calling > VIDIOC_REQBUFS. > If used this minimum should be higher than the minimum number of > queued buffers needed to start streaming. > > Signed-off-by: Benjamin Gaignard > --- > drivers/media/common/videobuf2/videobuf2-core.c | 10 ++++++++-- > include/media/videobuf2-core.h | 13 +++++++++++++ > 2 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > index 41a832dd1426..a183edf11586 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -865,7 +865,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, > /* > * Make sure the requested values and current defaults are sane. > */ > - num_buffers = max_t(unsigned int, *count, q->min_queued_buffers); > + num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation); > num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); > memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); > /* > @@ -917,7 +917,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, > * There is no point in continuing if we can't allocate the minimum > * number of buffers needed by this vb2_queue. > */ > - if (allocated_buffers < q->min_queued_buffers) > + if (allocated_buffers < q->min_reqbufs_allocation) > ret = -ENOMEM; > > /* > @@ -2521,6 +2521,12 @@ int vb2_core_queue_init(struct vb2_queue *q) > if (WARN_ON(q->supports_requests && q->min_queued_buffers)) > return -EINVAL; > > + q->min_reqbufs_allocation = max_t(unsigned int, > + q->min_reqbufs_allocation, > + q->min_queued_buffers + 1); I have been thinking about this a bit more. The problem is that if min_queued_buffers == 0, then min_reqbufs_allocation becomes 1. But the minimum requirement should really be 2: one buffer is used to capture a new frame, the other is processed by userspace. So this should be modified as well. I would write this as 'if' statements as well: if (q->min_reqbufs_allocation < q->min_queued_buffers + 1) q->min_reqbufs_allocation = q->min_queued_buffers + 1; if (q->min_reqbufs_allocation < 2) q->min_reqbufs_allocation = 2; You can add comments before each 'if' to clarify why. I'm also wondering what this change to calculating q->min_reqbufs_allocation when the driver leaves it to 0 shouldn't be done in a separate patch, either before or after this one. We're changing the default behavior of REQBUFS slightly, and mixing that in with this patch feels wrong. Note that __vb2_init_fileio() also needs to be updated: it currently uses the same calculation of the initial 'count' value for reqbufs, but that can now just use q->min_reqbufs_allocation directly. Regards, Hans > + if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) > + return -EINVAL; > + > INIT_LIST_HEAD(&q->queued_list); > INIT_LIST_HEAD(&q->done_list); > spin_lock_init(&q->done_lock); > diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h > index 56719a26a46c..7b84b4e2e273 100644 > --- a/include/media/videobuf2-core.h > +++ b/include/media/videobuf2-core.h > @@ -553,6 +553,18 @@ struct vb2_buf_ops { > * VIDIOC_REQBUFS will ensure at least @min_queued_buffers > * buffers will be allocated. Note that VIDIOC_CREATE_BUFS will not > * modify the requested buffer count. > + * @min_reqbufs_allocation: the minimum number of buffers to be allocated when > + * calling VIDIOC_REQBUFS. Drivers can set this if there has to > + * be a certain number of buffers available for the hardware to > + * work effectively. If set, then @min_reqbufs_allocation must be > + * larger than @min_queued_buffers + 1. > + * This field is only used by VIDIOC_REQBUFS. This allows calling > + * that ioctl with a buffer count of 1 and it will be automatically > + * adjusted to a workable buffer count. VIDIOC_CREATE_BUFS will not > + * modify the requested buffer count. > + * If this field is > 3, then it is highly recommended that the > + * driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT > + * control. > */ > /* > * Private elements (won't appear at the uAPI book): > @@ -618,6 +630,7 @@ struct vb2_queue { > u32 timestamp_flags; > gfp_t gfp_flags; > u32 min_queued_buffers; > + u32 min_reqbufs_allocation; > > struct device *alloc_devs[VB2_MAX_PLANES]; >