Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp419616rdb; Mon, 15 Jan 2024 01:17:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCpXOtO+HME5hGHtMmBwiLtedpgUyAIKXO4eMqSsWnsXOl6IdyGVxdPLRN/Ik3ZgKHUr+1 X-Received: by 2002:a17:907:3ea0:b0:a2d:9ac6:7c2e with SMTP id hs32-20020a1709073ea000b00a2d9ac67c2emr926687ejc.102.1705310247996; Mon, 15 Jan 2024 01:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705310247; cv=none; d=google.com; s=arc-20160816; b=N/EiKTlBGy/aRBgJ3wDQJbft0G28xux4kcF/bq+0brEWfSvRxeAqtEoqScWrKbRLha z+bnz8J28g3JFJ6kpMF2TWu3i8X33QNKPUSs8n1to/R/6Kv0Z2fwym0c5UFOm1g+EmRi k/PsvaTI6ioYRqLh10eF10864xs+6xh3llbYBE9pqL8W8fEQRonJcS0Ykw5C3hbn25zo x+wKf8ahBOwBlSM0hqlRwFRK+aA5LovXXAsfSIULVBWKdw8chwg/p9D3jEnICkk5Bp95 F48ieqqhxIgqzC7r2FLOxP1KJdgzQqQCN1CN7drMosuAEB2OzGSf/IFNIQFD/RHfs1AV AFZw== 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=w9AaUE3ib3cNf/CZzP1SGxu4ShC1PH7gfZ83Gt0spiI=; fh=JA5CkwWQaCWbhBvBUXS2prPFrwCGT4l48Srp7tLe1bE=; b=By7wBAuLBKtiMxa01+OgGy8k2cHarMDKphAd8LS31cPySQIYebtPneJGMhvwV03Lk7 NJRbXnyMG7Dd+2aQ2Ml0fu4B9+hgioX22bIWxE5GC67iJMh0V5xzWUD6fOaCwL8lwcVg UBwnKAoCgraVHHHE9gBsE4eANH5asrue+9glwgpx0yC4OVQxsnCnXzvX+ooP6mJ3xD3Q 5hXtSZcNKitG+nyX9APO+AtQPvQWkqHKAzPr0nHC1y+TlQZd8V37pMwp83ewFo0NA2CN lf+A0vD0G+GmHjQGTJILDgjD7ACyF1sXCGQNcKajWM/ax8SEYmhduMgbanbx64DlnJQL EG2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p9-20020a17090628c900b00a2d2368cd8asi1905288ejd.900.2024.01.15.01.17.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 01:17:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25782-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 881E71F21BE1 for ; Mon, 15 Jan 2024 09:17:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC84EF513; Mon, 15 Jan 2024 09:16:47 +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 05844E55E; Mon, 15 Jan 2024 09:16:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4901AC433C7; Mon, 15 Jan 2024 09:16:45 +0000 (UTC) Message-ID: Date: Mon, 15 Jan 2024 10:16:43 +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/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fq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jG61bnJ2GFS+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 Hi Benjamin, Some comments below: 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. You should also mention that it defaults to min_queued_buffers + 1 instead of min_queued_buffers since otherwise you would not have a buffer available for userspace (or something along those lines). This is a change that needs to be documented in the commit message. > > 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); > + 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 In this comment it still mentions @min_queued_buffers instead of @min_queued_buffers + 1. > * 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. There is not actually any check for that. But I think such a check should be added: it makes it much easier to do a 'git grep min_reqbufs_allocation' and only get those drivers that really set it to a non-standard value. > + * 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 "workable buffer count": nice phrase, I like it! > + * 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. Also a nice final sentence. This is also something that is a nice check to add to v4l2-compliance! A patch would be welcome... I think the sentences need to be reordered. How about this (alignment needs to be fixed): * @min_reqbufs_allocation: the minimum number of buffers to be allocated when * calling VIDIOC_REQBUFS. Note that VIDIOC_CREATE_BUFS will *not* * modify the requested buffer count and does not use this field. * Drivers can set this if there has to * be a certain number of buffers available for the hardware to * work effectively. This allows calling VIDIOC_REQBUFS with a buffer * count of 1 and it will be automatically adjusted to a workable * buffer count. If set, then @min_reqbufs_allocation must be * larger than @min_queued_buffers + 1. * 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]; > Regards, Hans