From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com,
ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar,
p.zabel@pengutronix.de, gregkh@linuxfoundation.org,
hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
linux-rockchip@lists.infradead.org,
linux-staging@lists.linux.dev, kernel@collabora.com,
Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH v3 02/11] media: videobuf2: Use Xarray instead of static buffers array
Date: Thu, 22 Jun 2023 15:13:40 +0200 [thread overview]
Message-ID: <20230622131349.144160-3-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com>
Instead of a static array change bufs to a dynamically allocated array.
This will allow to store more video buffers if needed.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/common/videobuf2/videobuf2-core.c | 38 +++++++++++--------
include/media/videobuf2-core.h | 6 +--
2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 42fd3984c2bc..f1ff7af34a9f 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -409,18 +409,24 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb)
* vb2_queue_add_buffer() - add a buffer to a queue
* @q: pointer to &struct vb2_queue with videobuf2 queue.
* @vb: pointer to &struct vb2_buffer to be added to the queue.
- * @index: index where add vb2_buffer in the queue
*/
-static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, int index)
+static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb)
{
- if (index < VB2_MAX_FRAME && !q->bufs[index]) {
- q->bufs[index] = vb;
- vb->index = index;
- vb->vb2_queue = q;
- return true;
- }
+ struct xa_limit range = {
+ .max = UINT_MAX,
+ .min = q->num_buffers,
+ };
+ u32 index;
+ int ret;
- return false;
+ ret = xa_alloc(&q->bufs, &index, vb, range, GFP_KERNEL);
+ if (ret)
+ return false;
+
+ vb->index = index;
+ vb->vb2_queue = q;
+
+ return true;
}
/**
@@ -430,10 +436,8 @@ static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, int
*/
static void vb2_queue_remove_buffer(struct vb2_queue *q, struct vb2_buffer *vb)
{
- if (vb->index < VB2_MAX_FRAME) {
- q->bufs[vb->index] = NULL;
- vb->vb2_queue = NULL;
- }
+ xa_erase(&q->bufs, vb->index);
+ vb->vb2_queue = NULL;
}
/*
@@ -474,7 +478,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
}
call_void_bufop(q, init_buffer, vb);
- if (!vb2_queue_add_buffer(q, vb, q->num_buffers + buffer)) {
+ if (!vb2_queue_add_buffer(q, vb)) {
dprintk(q, 1, "failed adding buffer %d to queue\n", buffer);
kfree(vb);
break;
@@ -930,7 +934,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
}
mutex_lock(&q->mmap_lock);
- q->num_buffers = allocated_buffers;
+ q->num_buffers += allocated_buffers;
if (ret < 0) {
/*
@@ -2547,6 +2551,9 @@ int vb2_core_queue_init(struct vb2_queue *q)
mutex_init(&q->mmap_lock);
init_waitqueue_head(&q->done_wq);
+ xa_init_flags(&q->bufs, XA_FLAGS_ALLOC);
+ q->num_buffers = 0;
+
q->memory = VB2_MEMORY_UNKNOWN;
if (q->buf_struct_size == 0)
@@ -2574,6 +2581,7 @@ void vb2_core_queue_release(struct vb2_queue *q)
mutex_lock(&q->mmap_lock);
__vb2_queue_free(q, q->num_buffers);
mutex_unlock(&q->mmap_lock);
+ xa_destroy(&q->bufs);
}
EXPORT_SYMBOL_GPL(vb2_core_queue_release);
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 4b6a9d2ea372..77921cf894ef 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -619,7 +619,7 @@ struct vb2_queue {
struct mutex mmap_lock;
unsigned int memory;
enum dma_data_direction dma_dir;
- struct vb2_buffer *bufs[VB2_MAX_FRAME];
+ struct xarray bufs;
unsigned int num_buffers;
struct list_head queued_list;
@@ -1239,9 +1239,7 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
unsigned int index)
{
- if (index < q->num_buffers)
- return q->bufs[index];
- return NULL;
+ return xa_load(&q->bufs, index);
}
/*
--
2.39.2
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2023-06-22 13:14 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 13:13 [PATCH v3 00/11] Add DELETE_BUF ioctl Benjamin Gaignard
2023-06-22 13:13 ` [PATCH v3 01/11] media: videobuf2: Access vb2_queue bufs array through helper functions Benjamin Gaignard
2023-06-23 15:10 ` kernel test robot
2023-06-24 23:34 ` kernel test robot
2023-06-22 13:13 ` Benjamin Gaignard [this message]
2023-06-22 13:13 ` [PATCH v3 03/11] media: videobuf2: Remove VB2_MAX_FRAME limit on buffer storage Benjamin Gaignard
2023-06-22 13:56 ` Dan Carpenter
2023-06-22 14:11 ` Dan Carpenter
2023-06-22 14:13 ` Benjamin Gaignard
2023-06-23 7:02 ` Hans Verkuil
2023-06-23 7:51 ` Benjamin Gaignard
2023-06-22 13:13 ` [PATCH v3 04/11] media: videobuf2: Stop define VB2_MAX_FRAME as global Benjamin Gaignard
2023-06-30 9:51 ` Hsia-Jun Li
2023-07-03 8:09 ` Benjamin Gaignard
2023-07-03 8:35 ` Hsia-Jun Li
2023-07-03 10:53 ` Benjamin Gaignard
2023-07-03 11:05 ` Hsia-Jun Li
2023-07-12 10:48 ` Tomasz Figa
2023-07-17 7:44 ` Hsia-Jun Li
2023-07-28 6:46 ` Tomasz Figa
2023-07-28 6:55 ` Hsia-Jun Li
2023-07-28 7:03 ` Tomasz Figa
2023-07-28 7:24 ` Hsia-Jun Li
2023-09-07 4:15 ` Tomasz Figa
2023-09-07 6:54 ` Hsia-Jun Li
2023-06-22 13:13 ` [PATCH v3 05/11] media: verisilicon: Refactor postprocessor to store more buffers Benjamin Gaignard
2023-06-22 13:13 ` [PATCH v3 06/11] media: verisilicon: Store chroma and motion vectors offset Benjamin Gaignard
2023-07-02 7:48 ` Markus Elfring
2023-06-22 13:13 ` [PATCH v3 07/11] media: verisilicon: vp9: Use destination buffer height to compute chroma offset Benjamin Gaignard
2023-07-02 9:14 ` Markus Elfring
2023-06-22 13:13 ` [PATCH v3 08/11] media: verisilicon: postproc: Fix down scale test Benjamin Gaignard
2023-06-22 15:27 ` Benjamin Gaignard
2023-06-22 13:13 ` [PATCH v3 09/11] media: verisilicon: vp9: Allow to change resolution while streaming Benjamin Gaignard
2023-07-02 9:33 ` Markus Elfring
2023-06-22 13:13 ` [PATCH v3 10/11] media: v4l2: Add DELETE_BUF ioctl Benjamin Gaignard
2023-06-22 23:12 ` kernel test robot
2023-06-23 0:25 ` kernel test robot
2023-06-26 7:08 ` [EXT] " Ming Qian
2023-06-26 7:48 ` Benjamin Gaignard
2023-06-26 7:50 ` Benjamin Gaignard
2023-06-26 8:13 ` Ming Qian
2023-06-26 8:04 ` Ming Qian
2023-06-27 7:30 ` Hsia-Jun Li
2023-06-27 8:43 ` Benjamin Gaignard
2023-06-27 8:47 ` Hsia-Jun Li
2023-06-30 9:43 ` Hsia-Jun Li
2023-07-03 8:12 ` Benjamin Gaignard
2023-07-03 8:19 ` Hsia-Jun Li
2023-07-03 8:52 ` Benjamin Gaignard
2023-07-03 9:20 ` Hsia-Jun Li
2023-07-03 10:35 ` Benjamin Gaignard
2023-07-03 11:06 ` Hsia-Jun Li
[not found] ` <8ca2f66e-8ff9-e885-274f-51417b581b78@synaptics.com>
2023-07-03 11:17 ` Benjamin Gaignard
2023-07-03 15:42 ` Randy Li
2023-07-13 9:09 ` Tomasz Figa
2023-07-17 2:16 ` Hsia-Jun Li
2023-07-28 6:57 ` Tomasz Figa
2023-07-28 7:26 ` Hsia-Jun Li
2023-07-02 10:20 ` Markus Elfring
2023-06-22 13:13 ` [PATCH v3 11/11] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2023-06-27 7:40 ` [PATCH v3 00/11] Add " Hsia-Jun Li
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=20230622131349.144160-3-benjamin.gaignard@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=nicolas.dufresne@collabora.com \
--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