Skip to contentSkip to conversation

eventfd+KAIO - eventfd core ...

PATCH New Davide Libenzi 1 participant 1 message Mar 15, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/5 eventfd+KAIO - 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). When used in the kernel, it can offer an fd-bridge to enable functionalities like KAIO or syslets/threadlets to signal to an fd the completion of certain operations.
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), read(2) and write(2). The read(2) function reads the __u64 counter value, and reset the internal value to zero. 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.

- Davide

fs/Makefile +1 -1
Index: linux-2.6.20.ep2/fs/Makefile
===================================================================
@@ -11,7 +11,7 @@
 		attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
 		seq_file.o xattr.o libfs.o fs-writeback.o \
 		pnode.o drop_caches.o splice.o sync.o utimes.o \
-		stack.o anon_inodes.o signalfd.o timerfd.o
+		stack.o anon_inodes.o signalfd.o timerfd.o eventfd.o
 
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=	buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
include/linux/syscalls.h +1 -0
Index: linux-2.6.20.ep2/include/linux/syscalls.h
===================================================================
@@ -605,6 +605,7 @@
 asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask);
 asmlinkage long sys_timerfd(int ufd, int clockid, int flags,
 			    const struct itimerspec __user *utmr);
+asmlinkage long sys_eventfd(unsigned int count);
 
 int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
 
fs/eventfd.c new file +259 -0

259 lines not on this page · raw message

include/linux/eventfd.h new file +18 -0
Index: linux-2.6.20.ep2/include/linux/eventfd.h
===================================================================
@@ -0,0 +1,18 @@
+/*
+ *  include/linux/eventfd.h
+ *
+ *  Copyright (C) 2007  Davide Libenzi <[email protected]>
+ *
+ */
+
+#ifndef _LINUX_EVENTFD_H
+#define _LINUX_EVENTFD_H
+
+
+
+struct file *eventfd_fget(int fd);
+int eventfd_signal(struct file *file, unsigned int n);
+
+
+#endif /* _LINUX_EVENTFD_H */
+