From: Stefani Seibold <stefani@seibold.net>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: Re: [PATCH] [0/6] kfifo fixes/improvements
Date: Tue, 29 Dec 2009 09:40:56 +0100 [thread overview]
Message-ID: <1262076056.23095.21.camel@wall-e> (raw)
In-Reply-To: <20091228204003.GH4994@basil.fritz.box>
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
next prev parent reply other threads:[~2009-12-29 8:41 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-27 21:03 [PATCH] [0/6] kfifo fixes/improvements Andi Kleen
2009-12-27 21:03 ` [PATCH] [1/6] kfifo: Use void * pointers for user buffers Andi Kleen
2009-12-27 21:48 ` Stefani Seibold
2009-12-27 21:03 ` [PATCH] [2/6] kfifo: Make kfifo_in atomic Andi Kleen
2009-12-27 21:46 ` Stefani Seibold
2009-12-27 21:03 ` [PATCH] [3/6] kfifo: Sanitize *_user error handling Andi Kleen
2009-12-27 21:38 ` Stefani Seibold
2009-12-27 23:34 ` Andi Kleen
2009-12-28 7:10 ` Stefani Seibold
2010-01-04 22:33 ` Stefani Seibold
2009-12-27 21:03 ` [PATCH] [4/6] kfifo: add kfifo_out_peek Andi Kleen
2009-12-27 21:49 ` Stefani Seibold
2009-12-27 23:41 ` Andi Kleen
2009-12-28 7:09 ` Stefani Seibold
2010-01-04 21:57 ` Andrew Morton
2010-01-04 22:24 ` Alan Cox
2010-01-04 22:47 ` Stefani Seibold
2010-01-05 0:14 ` Alan Cox
2009-12-27 21:03 ` [PATCH] [5/6] kfifo: Add kfifo_initialized Andi Kleen
2009-12-27 21:53 ` Stefani Seibold
2009-12-27 21:03 ` [PATCH] [6/6] kfifo: Document everywhere that size has to be power of two Andi Kleen
2009-12-27 21:50 ` Stefani Seibold
2009-12-27 22:14 ` Dmitry Torokhov
2009-12-27 22:23 ` Stefani Seibold
2009-12-27 23:34 ` Andi Kleen
2009-12-27 21:36 ` [PATCH] [0/6] kfifo fixes/improvements Stefani Seibold
2009-12-27 23:38 ` Andi Kleen
2009-12-28 6:49 ` Stefani Seibold
2009-12-28 7:42 ` Stefani Seibold
2009-12-28 14:57 ` Andi Kleen
2009-12-28 16:08 ` Stefani Seibold
2009-12-28 17:26 ` Andi Kleen
2009-12-28 20:04 ` Stefani Seibold
2009-12-28 20:40 ` Andi Kleen
2009-12-29 8:40 ` Stefani Seibold [this message]
2009-12-29 22:27 ` Dmitry Torokhov
2009-12-30 1:18 ` Vikram Dhillon
2009-12-30 2:08 ` Dmitry Torokhov
2009-12-30 9:29 ` Stefani Seibold
2009-12-30 10:43 ` Dmitry Torokhov
2009-12-30 10:52 ` Stefani Seibold
2009-12-30 11:07 ` Dmitry Torokhov
2009-12-30 11:32 ` Stefani Seibold
2009-12-30 17:29 ` Andy Walls
2009-12-31 7:35 ` Dmitry Torokhov
2009-12-31 8:59 ` Stefani Seibold
2009-12-31 9:33 ` Dmitry Torokhov
2009-12-31 18:03 ` Andy Walls
2009-12-30 17:15 ` Andy Walls
2009-12-28 0:12 ` Roland Dreier
2009-12-28 1:41 ` Andi Kleen
2009-12-28 7:06 ` Stefani Seibold
2009-12-28 14:56 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262076056.23095.21.camel@wall-e \
--to=stefani@seibold.net \
--cc=akpm@osdl.org \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox