[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAFQd5AH6x461-a2=2JmzUhW2pWacgwj1w3SZH1kfMBbsmaZ3A@mail.gmail.com>
Date: Thu, 9 Nov 2023 16:28:20 +0900
From: Tomasz Figa <tfiga@...omium.org>
To: Benjamin Gaignard <benjamin.gaignard@...labora.com>
Cc: mchehab@...nel.org, m.szyprowski@...sung.com, ming.qian@....com,
ezequiel@...guardiasur.com.ar, p.zabel@...gutronix.de,
gregkh@...uxfoundation.org, hverkuil-cisco@...all.nl,
nicolas.dufresne@...labora.com, linux-media@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org, linux-arm-msm@...r.kernel.org,
linux-rockchip@...ts.infradead.org, linux-staging@...ts.linux.dev,
kernel@...labora.com
Subject: Re: [PATCH v14 52/56] media: core: Add bitmap manage bufs array entries
On Thu, Nov 9, 2023 at 12:30 AM Benjamin Gaignard
<benjamin.gaignard@...labora.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
Powered by blists - more mailing lists