[PATCH v14 52/56] media: core: Add bitmap manage bufs array entries
Tomasz Figa
tfiga at chromium.org
Wed Nov 8 23:28:20 PST 2023
On Thu, Nov 9, 2023 at 12:30 AM Benjamin Gaignard
<benjamin.gaignard at collabora.com> wrote:
>
>
> Le 08/11/2023 à 11:44, Tomasz Figa a écrit :
> > On Tue, Oct 31, 2023 at 05:31:00PM +0100, Benjamin Gaignard wrote:
[snip]
> >> @@ -1150,7 +1150,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 0;
> >> +
> >> + return bitmap_weight(q->bufs_bitmap, q->max_num_buffers);
> > Hmm, could we just cache the number of buffers we have, so that we don't
> > have to go over the entire bitmap every time? (Basically just keep the
> > code that we had for handling q->num_buffers before this patch.)
>
> I would prefer no duplicate how the number of buffers in a queue is computed
> and bitmap offer helpers for that. Why not use it ?
>
bitmap_weight() can become costly when the number of buffers grows.
Since it's easy to track how many buffers we add and remove, we could
just cache that number and then any code could call
vb2_get_num_buffers() whenever it needs the buffer count without
caring how costly it is.
> >
> >> }
> >>
> >> /**
> >> @@ -1253,13 +1256,13 @@ 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 (!q->bufs)
> >> + if (!q->bufs_bitmap)
> >> return NULL;
> >>
> >> if (index >= q->max_num_buffers)
> >> return NULL;
> >>
> >> - if (index < q->num_buffers)
> >> + if (test_bit(index, q->bufs_bitmap))
> > Aha, I see why we need the extra condition above now. Perhaps it should've
> > been added in this patch instead?
>
> For me it was more explicit do introduce it at the same time that
> max_num_buffers field.
Okay. I don't have a strong opinion, especially since it was just an
intermediate patch.
Best regards,
Tomasz
More information about the linux-arm-kernel
mailing list