android_kernel_samsung_msm8976/include
Davide Libenzi e1ad7468c7 signal/timer/event: eventfd core
This is a very simple and light file descriptor, that can be used as event
wait/dispatch by userspace (both wait and dispatch) and by the kernel
(dispatch only).  It can be used instead of pipe(2) in all cases where those
would simply be used to signal events.  Their kernel overhead is much lower
than pipes, and they do not consume two fds.  When used in the kernel, it can
offer an fd-bridge to enable, for example, functionalities like KAIO or
syslets/threadlets to signal to an fd the completion of certain operations.
But more in general, an eventfd can be used by the kernel to signal readiness,
in a POSIX poll/select way, of interfaces that would otherwise be incompatible
with it.  The API is:

int eventfd(unsigned int count);

The eventfd API accepts an initial "count" parameter, and returns an eventfd
fd.  It supports poll(2) (POLLIN, POLLOUT, POLLERR), read(2) and write(2).

The POLLIN flag is raised when the internal counter is greater than zero.

The POLLOUT flag is raised when at least a value of "1" can be written to the
internal counter.

The POLLERR flag is raised when an overflow in the counter value is detected.

The write(2) operation can never overflow the counter, since it blocks (unless
O_NONBLOCK is set, in which case -EAGAIN is returned).

But the eventfd_signal() function can do it, since it's supposed to not sleep
during its operation.

The read(2) function reads the __u64 counter value, and reset the internal
value to zero.  If the value read is equal to (__u64) -1, an overflow happened
on the internal counter (due to 2^64 eventfd_signal() posts that has never
been retired - unlickely, but possible).

The write(2) call writes an __u64 count value, and adds it to the current
counter.  The eventfd fd supports O_NONBLOCK also.

On the kernel side, we have:

struct file *eventfd_fget(int fd);
int eventfd_signal(struct file *file, unsigned int n);

The eventfd_fget() should be called to get a struct file* from an eventfd fd
(this is an fget() + check of f_op being an eventfd fops pointer).

The kernel can then call eventfd_signal() every time it wants to post an event
to userspace.  The eventfd_signal() function can be called from any context.
An eventfd() simple test and bench is available here:

http://www.xmailserver.org/eventfd-bench.c

This is the eventfd-based version of pipetest-4 (pipe(2) based):

http://www.xmailserver.org/pipetest-4.c

Not that performance matters much in the eventfd case, but eventfd-bench
shows almost as double as performance than pipetest-4.

[akpm@linux-foundation.org: fix i386 build]
[akpm@linux-foundation.org: add sys_eventfd to sys_ni.c]
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 08:29:36 -07:00
..
acpi ACPICA: Lindent 2007-05-09 23:34:35 -04:00
asm-alpha Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-arm Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-arm26 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-avr32 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-blackfin rename thread_info to stack 2007-05-09 12:30:56 -07:00
asm-cris Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-frv Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-generic Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-h8300 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-i386 signal/timer/event: timerfd wire up x86 arches 2007-05-11 08:29:36 -07:00
asm-ia64 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-m32r Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-m68k Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-m68knommu Remove tas() 2007-05-08 11:15:20 -07:00
asm-mips Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-parisc Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-powerpc powerpc: fixup hard_irq_disable semantics 2007-05-11 08:29:34 -07:00
asm-ppc Merge branch 'linux-2.6' 2007-05-10 21:08:37 +10:00
asm-s390 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-sh Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-sh64 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-sparc Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-sparc64 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-um uml: iRQ stacks 2007-05-11 08:29:34 -07:00
asm-v850 Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
asm-x86_64 signal/timer/event: timerfd wire up x86 arches 2007-05-11 08:29:36 -07:00
asm-xtensa Consolidate asm/poll.h 2007-05-11 08:29:34 -07:00
crypto
keys
linux signal/timer/event: eventfd core 2007-05-11 08:29:36 -07:00
math-emu Delete unused header file math-emu/extended.h 2007-05-08 11:15:05 -07:00
media
mtd
net Merge branch 'upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-2.6 into upstream 2007-05-09 18:54:49 -04:00
pcmcia add new_id to PCMCIA drivers 2007-05-07 12:12:50 -07:00
rdma IB: Put rlimit accounting struct in struct ib_umem 2007-05-08 18:00:37 -07:00
rxrpc
scsi [SCSI] sas_scsi_host: Convert to use the kthread API 2007-05-06 09:33:17 -05:00
sound
video atyfb: halve XCLK with Mobility and 32bit memory 2007-05-08 11:15:32 -07:00
Kbuild