[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1352876629.7469.3.camel@wall-e>
Date: Wed, 14 Nov 2012 08:03:49 +0100
From: Stefani Seibold <stefani@...bold.net>
To: Yuanhan Liu <yuanhan.liu@...ux.intel.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] kfifo: round up the fifo size power of 2
Am Freitag, den 09.11.2012, 10:32 +0800 schrieb Yuanhan Liu:
> On Thu, Nov 08, 2012 at 01:37:15PM +0100, Stefani Seibold wrote:
> > Am Donnerstag, den 08.11.2012, 20:24 +0800 schrieb Yuanhan Liu:
> Yes, it is. I will try log API then.
>
> Stefani, I found an issue while rework to current API. Say the current
> code of __kfifo_init:
> int __kfifo_init(struct __kfifo *fifo, void *buffer,
> unsigned int size, size_t esize)
> {
> size /= esize;
>
> if (!is_power_of_2(size))
> size = rounddown_pow_of_two(size);
> ....
> }
>
> Even thought I changed the API to something like:
> int __kfifo_init(struct __kfifo *fifo, void *buffer,
> int size_order, size_t esize)
> {
> unsigned int size = 1 << size_order;
>
> size /= esize;
> ...
> }
>
> See? There is still a divide and we can't make it sure that it will be
> power of 2 after that.
>
> So, I came up 2 proposal to fix this.
>
> 1. refactor the meaning of 'size' argument first.
>
> 'size' means the size of pre-allocated buffer. We can refactor it to
> meaning of 'the number of fifo elements' just like __kfifo_alloc, so
> that we don't need do the size /= esize stuff.
>
> 2. remove kfifo_init
>
> As we can't make sure that kfifo will do exactly what users asked(in
> the way of fifo size). It would be safe and good to maintain buffer
> and buffer size inside kfifo. So, I propose to remove it and use
> kfifo_alloc instead.
>
> git grep 'kfifo_init\>' shows that we currently have 2 users only.
>
>
> The first way is hacky, and it doesn't make much sense to me. Since
> buffer is pre-allocated by user but not kfifo. User has to calculate
> element size and the number of elements, which is not friendly.
>
> The second way does make more sense to me.
kfifo_init() was requested by some kernel developers, i never liked it.
If you have a better and cleaner solution than do it, otherwise kick it
away if you like.
- Stefani
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists