From: Stefani Seibold <stefani@seibold.net>
This is a complete reimplementation of the new kfifo API, which is now
really generic, type save and type definable.
The API is still stable, no code which use the current kfifo API must
be modified!
Here are the results of the text section usage:
Example 1:
kfifo_put/_get kfifo_in/out current kfifo
dynamic allocated 0x000002a8 0x00000291 0x00000299
in place 0x00000291 0x0000026e 0x00000273
kfifo.c new old
text section size 0x00000be5 0x000008b2
As you can see, kfifo_put/kfifo_get creates a little bit more code than
kfifo_in/kfifo_out, but it is much faster (the code is inline).
The code is complete hand crafted and optimized. The text section size is as
small as possible. You get all the fifo handling in only 3 kb. This includes
type safe fix size records, dynamic records and DMA handling.
This should be the final version. All requested features are implemented.
Note: Most features of this API doesn't have any users. All functions which
are not used in the next 9 months will be removed. So, please adapt your
drivers and other sources as soon as possible to the new API and post it.
This are the features which are currently not used in the kernel:
kfifo_to_user()
kfifo_from_user()
kfifo_dma_....() macros
kfifo_esize()
kfifo_recsize()
kfifo_put()
kfifo_get()
the fixed size record elements, exclude "unsigned char" fifo's and
the variable size records fifo's
ChangeLog:
20.04.2010 Fix possible break of the kernel build by the patch sequence
18.04.2010 Sync with kernel 2.6.34-rc4
12.02.2010 Sync with kernel 2.6.33-rc7
Add example code to the kernel sample directory
Make more exact comments for the kerneldoc tools
Split the patch
05.02.2010 Sync with kernel 2.6.33-rc6
Fix comments for the kerneldoc tools
Fix kernel-api.tmpl
...From: Stefani Seibold <stefani@seibold.net>
User of the kernel fifo should never bypass the API and directly access
the fifo structure. Otherwise it will be very hard to maintain the API.
Signed-off-by: Stefani Seibold <stefani@seibold.net>
---
drivers/char/nozomi.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index a663800..d578449 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1741,8 +1741,7 @@ static int ntty_write_room(struct tty_struct *tty)
if (dc) {
mutex_lock(&port->tty_sem);
if (port->port.count)
- room = port->fifo_ul.size -
- kfifo_len(&port->fifo_ul);
+ room = kfifo_avail(&port->fifo_ul);
mutex_unlock(&port->tty_sem);
}
return room;
--
1.7.0.4
--
From: Stefani Seibold <stefani@seibold.net> add the new version of the kfifo API files kfifo.c and kfifo.h. Signed-off-by: Stefani Seibold <stefani@seibold.net> --- include/linux/kfifo-new.h | 844 +++++++++++++++++++++++++++++++++++++++++++++ kernel/kfifo-new.c | 602 ++++++++++++++++++++++++++++++++ 2 files changed, 1446 insertions(+), 0 deletions(-) create mode 100644 include/linux/kfifo-new.h create mode 100644 kernel/kfifo-new.c diff --git a/include/linux/kfifo-new.h b/include/linux/kfifo-new.h new file mode 100644 index 0000000..311f875 --- /dev/null +++ b/include/linux/kfifo-new.h @@ -0,0 +1,844 @@ +/* + * A generic kernel FIFO implementation + * + * Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef _LINUX_KFIFO_H +#define _LINUX_KFIFO_H + +/* + * How to porting drivers to the new generic FIFO API: + * + * - Modify the declaration of the "struct kfifo *" object into a + * in-place "struct kfifo" object + * - Init the in-place object with kfifo_alloc() or kfifo_init() + * Note: The address of the in-place "struct kfifo" object must be + * passed as the first argument to this functions + * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get + * into kfifo_out + * - Replace the use of ...
From: Stefani Seibold <stefani@seibold.net> This patch add four examples to the kernel sample directory. It shows how to handle: - a byte stream fifo - a integer type fifo - a dynamic record sized fifo - the fifo DMA functions Signed-off-by: Stefani Seibold <stefani@seibold.net> --- samples/Kconfig | 10 ++ samples/Makefile | 2 +- samples/kfifo/Makefile | 1 + samples/kfifo/bytestream-example.c | 163 +++++++++++++++++++++++++++++++++++ samples/kfifo/dma-example.c | 115 +++++++++++++++++++++++++ samples/kfifo/inttype-example.c | 157 +++++++++++++++++++++++++++++++++ samples/kfifo/record-example.c | 167 ++++++++++++++++++++++++++++++++++++ 7 files changed, 614 insertions(+), 1 deletions(-) create mode 100644 samples/kfifo/Makefile create mode 100644 samples/kfifo/bytestream-example.c create mode 100644 samples/kfifo/dma-example.c create mode 100644 samples/kfifo/inttype-example.c create mode 100644 samples/kfifo/record-example.c diff --git a/samples/Kconfig b/samples/Kconfig index 8924f72..954a1d5 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -44,4 +44,14 @@ config SAMPLE_HW_BREAKPOINT help This builds kernel hardware breakpoint example modules. +config SAMPLE_KFIFO + tristate "Build kfifo examples -- loadable modules only" + depends on m + help + This config option will allow you to build a number of + different kfifo sample modules showing how to use the + generic kfifo API. + + If in doubt, say "N" here. + endif # SAMPLES diff --git a/samples/Makefile b/samples/Makefile index 0f15e6d..76b3c34 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -1,4 +1,4 @@ # Makefile for Linux samples code obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \ - hw_breakpoint/ + hw_breakpoint/ kfifo/ diff --git a/samples/kfifo/Makefile b/samples/kfifo/Makefile new file mode 100644 index 0000000..bcc9484 --- ...
If you have features that have no users, why add them? Do you think that some drivers need/want these features? thanks, greg k-h --
Some developers ask me for this features, so i am a nice girl and implemented it. Especially the kfifo_to_user() and kfifo_from_user() was desired and is IMHO very useful. kfifo_put(), kfifo_get(), kfifo_esize() and kfifo_recsize() didn't coast anything, because there are only macros. Andrew agreed that we add this for a given time period, and have a look what happens. The code overhead is not to much. It is a chicken and egg problem: If we do not provide this features, nobody can use it and everyone will write it's own implementation. I also plan to port some drivers to the new generic kfifo API, where i own the hardware. Stefani --
As a user who has been following this patch set for quite a while, I have uses in my drivers for the kfifo_*_user() functions as well as well as the kfifo_dma_*() functions. I'm not especially comfortable developing against changes that aren't upstream, especially the "core infrastructure" type changes. This is the reason I haven't ported to the updated kfifo API yet. I hunch other "small time" developers have the same worries. Unfortunately, my drivers are not upstream, as they're for very custom hardware, and would not be useful on anything outside of my lab. I'm happy to send the source to anyone interested. Ira --
Drivers with only one user are gladly accepted into the kernel tree, so feel free to submit them. Especially if you start to take advantage of this abi, we want to know who uses it so it isn't deleted in the future :) thanks, greg k-h --
