Re: [PATCH] [0/6] kfifo fixes/improvements

From: Stefani Seibold
Date: Tue Dec 29 2009 - 03:41:16 EST


Am Montag, den 28.12.2009, 21:40 +0100 schrieb Andi Kleen:


> OK i checked and they all use power-of-two currently so by sheer
> luck (I doubt it is by design) they work. Still I think that
> open deathtrap should be fixed.
>

It is fixed, and i hope it will be included in 2.6.34.

> I also don't understand how that patch "breaks your future work"
> Please elaborate on that.
>

Very difficult to explain in a email, but i will try it:

The new macro based kfifo API handles everything as elements of a given
type. So you can have the old "unsigned char"-fifo, but also fifo of
every other type like int's, struct's and so on. The kfifo_in() and
kfifo_out() len parameter is than in the meaning of elements not bytes.
So you are able to process more than one value at a time and the macros
will return the number of processed elements (not bytes).

kfifo_in(), kfifo_out() and kfifi_out_peek() are more in a meaning of a
max. memcpy(). For a single value it is better to use new introduced
macros kfifo_put(), kfifo_get() and kfifo_peek(), which doesn't require
the len parameter and are faster pod data types.

With this solution i have full compatibility to the orig kfifo
implementation, i can fill a fifo with a minimum of operations, and
the desynchronization problem is also gone.

Have a look at example:

#include "kfifo.h"

#define FIFO_ELEMS 32

// declare a fifo named test with 32 int's
static DECLARE_KFIFO(test, int, FIFO_ELEMS);

void testfunc(void)
{
int i;
int buf[6];
unsigned int ret;

INIT_KFIFO(test);

for(i = 20; i != 30; i++)
kfifo_put(&test, &i);

// show the number of elements in the fifo
printk("queue len: %u\n", kfifo_len(&test));

// get max. two int elements from the fifo
ret = kfifo_out(&test, buf, 2);

// show the number of processed elements
printk("ret: %d\n", ret);

// put max. two int elements in the fifo
ret = kfifo_in(&test, buf, 2);

// show the number of processed elements
printk("ret: %d\n", ret);

if (kfifo_peek(&test, &i))
printk("%d\n", i);

while(kfifo_get(&test, &i))
printk("%d\n", i);
}

> -Andi
>
> P.S.: I must say you make it really hard to use kfifos.
>

Sorry, that was not my intention. But the old API was much harder to
use ;-)

Stefani


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/