From: Mauro Carvalho Chehab <mchehab@kernel.org>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Cc: tfiga@chromium.org, m.szyprowski@samsung.com,
ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de,
hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rockchip@lists.infradead.org, kernel@collabora.com
Subject: Re: [PATCH v21 6/9] media: core: Free range of buffers
Date: Thu, 21 Mar 2024 15:18:24 +0100 [thread overview]
Message-ID: <20240321151824.282798de@coco.lan> (raw)
In-Reply-To: <20240314153226.197445-7-benjamin.gaignard@collabora.com>
Em Thu, 14 Mar 2024 16:32:23 +0100
Benjamin Gaignard <benjamin.gaignard@collabora.com> escreveu:
> Improve __vb2_queue_free() and __vb2_free_mem() to free
> range of buffers and not only the last few buffers.
> Introduce starting index to be flexible on range and change the loops
> according to this parameter.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Patches 4-6 require some testing and better check.
I'm ok with the general concept of such changes, so:
Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org>
> ---
> .../media/common/videobuf2/videobuf2-core.c | 56 +++++++++----------
> 1 file changed, 26 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index ec81426d4d79..009cea95d662 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -540,17 +540,16 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
> }
>
> /*
> - * __vb2_free_mem() - release all video buffer memory for a given queue
> + * __vb2_free_mem() - release video buffer memory for a given range of
> + * buffers in a given queue
> */
> -static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
> +static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count)
> {
> - unsigned int buffer;
> + unsigned int i;
> struct vb2_buffer *vb;
> - unsigned int q_num_buffers = vb2_get_num_buffers(q);
>
> - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers;
> - ++buffer) {
> - vb = vb2_get_buffer(q, buffer);
> + for (i = start; i < start + count; i++) {
> + vb = vb2_get_buffer(q, i);
> if (!vb)
> continue;
>
> @@ -565,35 +564,33 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
> }
>
> /*
> - * __vb2_queue_free() - free buffers at the end of the queue - video memory and
> + * __vb2_queue_free() - free @count buffers from @start index of the queue - video memory and
> * related information, if no buffers are left return the queue to an
> * uninitialized state. Might be called even if the queue has already been freed.
> */
> -static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
> +static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count)
> {
> - unsigned int buffer;
> - unsigned int q_num_buffers = vb2_get_num_buffers(q);
> + unsigned int i;
>
> lockdep_assert_held(&q->mmap_lock);
>
> /* Call driver-provided cleanup function for each buffer, if provided */
> - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers;
> - ++buffer) {
> - struct vb2_buffer *vb = vb2_get_buffer(q, buffer);
> + for (i = start; i < start + count; i++) {
> + struct vb2_buffer *vb = vb2_get_buffer(q, i);
>
> if (vb && vb->planes[0].mem_priv)
> call_void_vb_qop(vb, buf_cleanup, vb);
> }
>
> /* Release video buffer memory */
> - __vb2_free_mem(q, buffers);
> + __vb2_free_mem(q, start, count);
>
> #ifdef CONFIG_VIDEO_ADV_DEBUG
> /*
> * Check that all the calls were balanced during the life-time of this
> * queue. If not then dump the counters to the kernel log.
> */
> - if (q_num_buffers) {
> + if (vb2_get_num_buffers(q)) {
> bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming ||
> q->cnt_prepare_streaming != q->cnt_unprepare_streaming ||
> q->cnt_wait_prepare != q->cnt_wait_finish;
> @@ -619,8 +616,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
> q->cnt_stop_streaming = 0;
> q->cnt_unprepare_streaming = 0;
> }
> - for (buffer = 0; buffer < vb2_get_num_buffers(q); buffer++) {
> - struct vb2_buffer *vb = vb2_get_buffer(q, buffer);
> + for (i = start; i < start + count; i++) {
> + struct vb2_buffer *vb = vb2_get_buffer(q, i);
> bool unbalanced;
>
> if (!vb)
> @@ -637,7 +634,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>
> if (unbalanced) {
> pr_info("unbalanced counters for queue %p, buffer %d:\n",
> - q, buffer);
> + q, i);
> if (vb->cnt_buf_init != vb->cnt_buf_cleanup)
> pr_info(" buf_init: %u buf_cleanup: %u\n",
> vb->cnt_buf_init, vb->cnt_buf_cleanup);
> @@ -671,9 +668,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
> #endif
>
> /* Free vb2 buffers */
> - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers;
> - ++buffer) {
> - struct vb2_buffer *vb = vb2_get_buffer(q, buffer);
> + for (i = start; i < start + count; i++) {
> + struct vb2_buffer *vb = vb2_get_buffer(q, i);
>
> if (!vb)
> continue;
> @@ -713,7 +709,7 @@ EXPORT_SYMBOL(vb2_buffer_in_use);
> static bool __buffers_in_use(struct vb2_queue *q)
> {
> unsigned int buffer;
> - for (buffer = 0; buffer < vb2_get_num_buffers(q); ++buffer) {
> + for (buffer = 0; buffer < q->max_num_buffers; ++buffer) {
> struct vb2_buffer *vb = vb2_get_buffer(q, buffer);
>
> if (!vb)
> @@ -899,7 +895,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
> * queued without ever calling STREAMON.
> */
> __vb2_queue_cancel(q);
> - __vb2_queue_free(q, q_num_bufs);
> + __vb2_queue_free(q, 0, q->max_num_buffers);
> mutex_unlock(&q->mmap_lock);
>
> q->is_busy = 0;
> @@ -1001,7 +997,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
> * from already queued buffers and it will reset q->memory to
> * VB2_MEMORY_UNKNOWN.
> */
> - __vb2_queue_free(q, allocated_buffers);
> + __vb2_queue_free(q, first_index, allocated_buffers);
> mutex_unlock(&q->mmap_lock);
> return ret;
> }
> @@ -1126,7 +1122,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
> * from already queued buffers and it will reset q->memory to
> * VB2_MEMORY_UNKNOWN.
> */
> - __vb2_queue_free(q, allocated_buffers);
> + __vb2_queue_free(q, *first_index, allocated_buffers);
> mutex_unlock(&q->mmap_lock);
> return -ENOMEM;
> }
> @@ -1741,7 +1737,7 @@ static int vb2_start_streaming(struct vb2_queue *q)
> * Forcefully reclaim buffers if the driver did not
> * correctly return them to vb2.
> */
> - for (i = 0; i < vb2_get_num_buffers(q); ++i) {
> + for (i = 0; i < q->max_num_buffers; ++i) {
> vb = vb2_get_buffer(q, i);
>
> if (!vb)
> @@ -2147,7 +2143,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
> * to vb2 in stop_streaming().
> */
> if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
> - for (i = 0; i < vb2_get_num_buffers(q); i++) {
> + for (i = 0; i < q->max_num_buffers; i++) {
> struct vb2_buffer *vb = vb2_get_buffer(q, i);
>
> if (!vb)
> @@ -2191,7 +2187,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
> * call to __fill_user_buffer() after buf_finish(). That order can't
> * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
> */
> - for (i = 0; i < vb2_get_num_buffers(q); i++) {
> + for (i = 0; i < q->max_num_buffers; i++) {
> struct vb2_buffer *vb;
> struct media_request *req;
>
> @@ -2618,7 +2614,7 @@ void vb2_core_queue_release(struct vb2_queue *q)
> __vb2_cleanup_fileio(q);
> __vb2_queue_cancel(q);
> mutex_lock(&q->mmap_lock);
> - __vb2_queue_free(q, vb2_get_num_buffers(q));
> + __vb2_queue_free(q, 0, q->max_num_buffers);
> vb2_core_free_buffers_storage(q);
> q->is_busy = 0;
> mutex_unlock(&q->mmap_lock);
Thanks,
Mauro
next prev parent reply other threads:[~2024-03-21 14:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 15:32 [PATCH v21 0/9] Add REMOVE_BUF ioctl Benjamin Gaignard
2024-03-14 15:32 ` [PATCH v21 1/9] media: videobuf2: Update vb2_is_busy() logic Benjamin Gaignard
2024-03-21 13:49 ` Mauro Carvalho Chehab
2024-03-14 15:32 ` [PATCH v21 2/9] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Benjamin Gaignard
2024-03-21 13:52 ` Mauro Carvalho Chehab
2024-08-21 23:28 ` Laurent Pinchart
2024-08-22 1:29 ` Tomasz Figa
2024-08-22 6:11 ` Hans Verkuil
2024-08-22 12:20 ` Laurent Pinchart
2024-08-23 8:08 ` Hans Verkuil
2024-03-14 15:32 ` [PATCH v21 3/9] media: test-drivers: Set REQBUFS minimum number of buffers Benjamin Gaignard
2024-03-18 10:06 ` Hans Verkuil
2024-03-18 13:06 ` Hans Verkuil
2024-03-21 13:53 ` Mauro Carvalho Chehab
2024-03-14 15:32 ` [PATCH v21 4/9] media: core: Rework how create_buf index returned value is computed Benjamin Gaignard
2024-03-14 15:32 ` [PATCH v21 5/9] media: core: Add bitmap manage bufs array entries Benjamin Gaignard
2024-03-14 15:32 ` [PATCH v21 6/9] media: core: Free range of buffers Benjamin Gaignard
2024-03-21 14:18 ` Mauro Carvalho Chehab [this message]
2024-03-14 15:32 ` [PATCH v21 7/9] media: v4l2: Add REMOVE_BUFS ioctl Benjamin Gaignard
2024-03-21 14:14 ` Mauro Carvalho Chehab
2024-03-21 14:24 ` Hans Verkuil
2024-03-21 15:03 ` Mauro Carvalho Chehab
2024-03-22 7:54 ` Hans Verkuil
2024-03-22 9:51 ` Benjamin Gaignard
2024-03-14 15:32 ` [PATCH v21 8/9] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2024-03-21 14:15 ` Mauro Carvalho Chehab
2024-03-14 15:32 ` [PATCH v21 9/9] media: verisilicon: Support removing buffers on capture queue Benjamin Gaignard
2024-03-21 14:16 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240321151824.282798de@coco.lan \
--to=mchehab@kernel.org \
--cc=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=nicolas@ndufresne.ca \
--cc=p.zabel@pengutronix.de \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).