Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1054807rdb; Wed, 24 Jan 2024 03:38:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDLh8O8uDdseUuhTmeurg8jav+LqvE2znnoMuUpYn5l7gpdJimhw8cUUr4zt5MWmgCtk10 X-Received: by 2002:a17:90a:51c5:b0:290:b361:8a9d with SMTP id u63-20020a17090a51c500b00290b3618a9dmr2858303pjh.18.1706096294583; Wed, 24 Jan 2024 03:38:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706096294; cv=pass; d=google.com; s=arc-20160816; b=GFT9kvHRNvwplstXeUw7qm2QAXbXW3DA4xnuoVq2KPyD/rxW43Biiy3nalnYykO8fq 0dJP+UiYZnkNui4bG3ebXxj6MafpzEIYuOQPymg7JOVFx55Ze+0hwOr9H5BDGNJ+8BJE 6C1PSesxQumyduy7GJGamU+AiEvgUXkRWlZP2LZDinqh4YZvgNYVxdD27DG9RuqoAVCs gJH/S4o0+/wcIZBKrsf2Xxu014EGX6sxmW1ohPR2aWXPDXSa4pc/6uu8ykxnAgNZRKN5 AO972Wo8oYIURkS+m5am4VgKJAFOuaXF64b0u7K9ZsPEJLC0aSH3/N9fDceI5M7VsfCt A0iA== 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=j7ym94j2ABky5o15qNVMUecwc6jcp3V/iib5FERG1k0=; fh=JA5CkwWQaCWbhBvBUXS2prPFrwCGT4l48Srp7tLe1bE=; b=Dj7aGq15jtEKPzntLJhi4+TqtlX5euq0tWhDH1YqONPZnkYyZ7jX0qNdLnMu6pbyfA vbw3l4wsstCDkuSo/k89bKf654aOHYaYfVdqfRVJhFjoLTx7rBrmMMTvXxEthYbHbl6J 9QiEfsoQxllf1vvzBoP+4d4yjsRSod4mu8Z02SZoa1esQprNGOj8tE46MDJ0+06uJ2Ct qzT8KpScJHOG7cBwLMb3MXDPM1OS5yP36X0TT6KTV1q8QMpKaTCFs/whBifWBm5ed8GR kFQMrFqeoPqs03lrNbhUvuAxvR4JNZsjJLfCHK7QrB6Nua99lzZ8yz3KlHi7oJqSirBN 8q3Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-36868-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36868-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. [139.178.88.99]) by mx.google.com with ESMTPS id ck21-20020a17090afe1500b0028e7059780bsi11514282pjb.24.2024.01.24.03.38.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 03:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36868-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-36868-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36868-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 41EC4293275 for ; Wed, 24 Jan 2024 11:31:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BDD41B285; Wed, 24 Jan 2024 11:31:30 +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 B61BD1B274; Wed, 24 Jan 2024 11:31:29 +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=1706095889; cv=none; b=gddQEXbwT4iw7+KwpF6ql1DQVMLVMAuTxTaIYN2Q1CLeZvlZxQs2fePMyDpegZJ91eTX1+DzgK73agl6iVWKIfvMZVPnXZR+1lQeUFktI9byLHg6MOY1KPuBjqgMx2zXRcuyCT5oBRw7WySZ5WSHd5+NRw7xVPTm7XoFmDU1pXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706095889; c=relaxed/simple; bh=YM+pwVYzlyAQYJ3JpZPE2nv1mlIQqlIEfzNo0unMESg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=teYb92aMCyEyOu4WWVKQ2CXGOIrU7z9TUDuhZ6cYFRPdf3qMAcuskthxTpJj+RFg0LRG9K45f3CILBVg5kK7jV680TSRaR3WKFjjCMw6h9fkG+3e2J1+A6bcKOkDhhCR7a64zb3Q9GyGqmOsm8kJZeZW/oDOQZ2lmeJYiO0B348= 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 32BF5C433C7; Wed, 24 Jan 2024 11:31:28 +0000 (UTC) Message-ID: Date: Wed, 24 Jan 2024 12:31:26 +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 v17 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: <20240119094944.26763-1-benjamin.gaignard@collabora.com> <20240119094944.26763-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 UVqXnarz8m2JCbHgjEkUlAJCNd6m3pfESLZwSWsLYL49R5yxIwARAQABzSFIYW5zIFZlcmt1 aWwgPGh2ZXJrdWlsQHhzNGFsbC5ubD7CwZUEEwECACgFAlQ84W0CGwMFCRLMAwAGCwkIBwMC BhUIAgkKCwQWAgMBAh4BAheAACEJEL0tYUhmFDtMFiE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FTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240119094944.26763-2-benjamin.gaignard@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit The language needs tightening up a bit: On 19/01/2024 10:49, Benjamin Gaignard wrote: > Add 'min_reqbufs_allocation' field in vb2_queue structure so drivers in -> in the > can specificy the minimum number of buffers to allocate when calling specificy -> specify > VIDIOC_REQBUFS. > When initializing the queue, v4l2 core makes sure that the following > constraint are respected: constraint -> constraints > - minimum number of buffers to allocate should be at least 2 because minimum -> the minimum should -> must > one buffer is used by the hardware and other processed by userspace. and other -> while the other is being > - if a minimum number of buffers before start streaming is specify > the minimum number of buffers to allocate should be min_queued_buffers > + 1 to keep one buffer available for userspace. Replace this with: - if the driver needs 'min_queued_buffers' in the queue before calling start_streaming(), then the minimum requirement is 'min_queued_buffers + 1' to keep at least one buffer available for userspace. > > Simplify __vb2_init_fileio() by using 'min_reqbufs_allocation' directly > to avoid duplicating the minimum number of buffers to allocate computation. > > Signed-off-by: Benjamin Gaignard > --- > version 17: > - rewrite commit message. > - simplify __vb2_init_fileio() code. > - rewrite documentation > > .../media/common/videobuf2/videobuf2-core.c | 37 +++++++++++-------- > include/media/videobuf2-core.h | 15 +++++++- > 2 files changed, 36 insertions(+), 16 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > index b6bf8f232f48..d74e93d00f58 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,24 @@ int vb2_core_queue_init(struct vb2_queue *q) > if (WARN_ON(q->supports_requests && q->min_queued_buffers)) > return -EINVAL; > > + /* > + * The minimum requirement should really be 2: one buffer is used should really be -> is > + * by the hardware and one other processed by userspace. and one other -> while the other is being > + */ > + if (q->min_reqbufs_allocation < 2) > + q->min_reqbufs_allocation = 2; > + > + /* > + * If the driver needs 'min_queued_buffers' before start streaming before -> in the queue before calling start streaming -> calling start_streaming(), > + * then the minimum requirement is min_queued_buffers + 1 to keep Add quotes around 'min_queued_buffers + 1' > + * at least one buffer available for userspace > + */ > + if (q->min_reqbufs_allocation < q->min_queued_buffers + 1) > + 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); > @@ -2713,7 +2731,6 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) > struct vb2_fileio_data *fileio; > struct vb2_buffer *vb; > int i, ret; > - unsigned int count = 0; > > /* > * Sanity check > @@ -2734,18 +2751,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) > if (q->streaming || vb2_get_num_buffers(q) > 0) > return -EBUSY; > > - /* > - * Start with q->min_queued_buffers + 1, driver can increase it in > - * queue_setup() > - * > - * 'min_queued_buffers' buffers need to be queued up before you > - * can start streaming, plus 1 for userspace (or in this case, > - * kernelspace) processing. > - */ > - count = max(2, q->min_queued_buffers + 1); > - > dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", > - (read) ? "read" : "write", count, q->fileio_read_once, > + (read) ? "read" : "write", q->min_reqbufs_allocation, q->fileio_read_once, > q->fileio_write_immediately); > > fileio = kzalloc(sizeof(*fileio), GFP_KERNEL); > @@ -2759,7 +2766,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) > * Request buffers and use MMAP type to force driver > * to allocate buffers by itself. > */ > - fileio->count = count; > + fileio->count = q->min_reqbufs_allocation; > fileio->memory = VB2_MEMORY_MMAP; > fileio->type = q->type; > q->fileio = fileio; > diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h > index 56719a26a46c..fe3423ff3807 100644 > --- a/include/media/videobuf2-core.h > +++ b/include/media/videobuf2-core.h > @@ -550,9 +550,21 @@ struct vb2_buf_ops { > * @start_streaming can be called. Used when a DMA engine > * cannot be started unless at least this number of buffers > * have been queued into the driver. > - * VIDIOC_REQBUFS will ensure at least @min_queued_buffers > + * VIDIOC_REQBUFS will ensure at least @min_queued_buffers + 1 > * 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. 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]; >