media: core: Add bitmap manage bufs array entries
Add a bitmap field to know which of bufs array entries are used or not. Remove no more used num_buffers field from queue structure. Use bitmap_find_next_zero_area() to find the first possible range when creating new buffers to fill the gaps. If no suitable range is found try to allocate less buffers than requested. Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
committed by
Hans Verkuil
parent
6e423b75d0
commit
a286b0837e
@@ -346,8 +346,8 @@ struct vb2_buffer {
|
||||
* describes the requested number of planes and sizes\[\]
|
||||
* contains the requested plane sizes. In this case
|
||||
* \*num_buffers are being allocated additionally to
|
||||
* q->num_buffers. If either \*num_planes or the requested
|
||||
* sizes are invalid callback must return %-EINVAL.
|
||||
* the buffers already allocated. If either \*num_planes
|
||||
* or the requested sizes are invalid callback must return %-EINVAL.
|
||||
* @wait_prepare: release any locks taken while calling vb2 functions;
|
||||
* it is called before an ioctl needs to wait for a new
|
||||
* buffer to arrive; required to avoid a deadlock in
|
||||
@@ -571,8 +571,9 @@ struct vb2_buf_ops {
|
||||
* @mmap_lock: private mutex used when buffers are allocated/freed/mmapped
|
||||
* @memory: current memory type used
|
||||
* @dma_dir: DMA mapping direction.
|
||||
* @bufs: videobuf2 buffer structures
|
||||
* @num_buffers: number of allocated/used buffers
|
||||
* @bufs: videobuf2 buffer structures. If it is non-NULL then
|
||||
* bufs_bitmap is also non-NULL.
|
||||
* @bufs_bitmap: bitmap tracking whether each bufs[] entry is used
|
||||
* @max_num_buffers: upper limit of number of allocated/used buffers.
|
||||
* If set to 0 v4l2 core will change it VB2_MAX_FRAME
|
||||
* for backward compatibility.
|
||||
@@ -643,7 +644,7 @@ struct vb2_queue {
|
||||
unsigned int memory;
|
||||
enum dma_data_direction dma_dir;
|
||||
struct vb2_buffer **bufs;
|
||||
unsigned int num_buffers;
|
||||
unsigned long *bufs_bitmap;
|
||||
unsigned int max_num_buffers;
|
||||
|
||||
struct list_head queued_list;
|
||||
@@ -1173,7 +1174,10 @@ static inline bool vb2_fileio_is_active(struct vb2_queue *q)
|
||||
*/
|
||||
static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q)
|
||||
{
|
||||
return q->num_buffers;
|
||||
if (q->bufs_bitmap)
|
||||
return bitmap_weight(q->bufs_bitmap, q->max_num_buffers);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1282,7 +1286,7 @@ static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
|
||||
if (index >= q->max_num_buffers)
|
||||
return NULL;
|
||||
|
||||
if (index < q->num_buffers)
|
||||
if (test_bit(index, q->bufs_bitmap))
|
||||
return q->bufs[index];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user