kevent: Core files.
Subsystems (11)
PATCH 1/6 kevent: Description.
In reply to Evgeniy PolyakovDescription.
Documentation/kevent.txt new file +230 -0
@@ -0,0 +1,230 @@ +Description. + +int kevent_init(struct kevent_ring *ring, unsigned int ring_size); + +num - size of the ring buffer in events +ring - pointer to allocated ring buffer + +Return value: kevent control file descriptor or negative error value. + + struct kevent_ring + { + unsigned int ring_kidx, ring_uidx, ring_over; + struct ukevent event[0]; + } + +ring_kidx - index in the ring buffer where kernel will put new events + when kevent_wait() or kevent_get_events() is called +ring_uidx - index of the first entry userspace can start reading from +ring_over - number of overflows of ring_uidx happend from the start. + Overflow counter is used to prevent situation when two threads + are going to free the same events, but one of them was scheduled + away for too long, so ring indexes were wrapped, so when that + thread will be awakened, it will free not those events, which + it suppose to free. + +Example userspace code (ring_buffer.c) can be found on project's homepage. + +Each kevent syscall can be so called cancellation point in glibc, i.e. when +thread has been cancelled in kevent syscall, thread can be safely removed +and no events will be lost, since each syscall (kevent_wait() or +kevent_get_events()) will copy event into special ring buffer, accessible +from other threads or even processes (if shared memory is used). + +When kevent is removed (not dequeued when it is ready, but just removed), +even if it was ready, it is not copied into ring buffer, since if it is +removed, no one cares about it (otherwise user would wait until it becomes +ready and got it through usual way using kevent_get_events() or kevent_wait()) +and thus no need to copy it to the ring buffer. + +------------------------------------------------------------------------------- + + +int kevent_ctl(int fd, unsigned int cmd, unsigned int num, struct ukevent *arg); + +fd - is the file descriptor referring to the kevent queue to manipulate. +It is created by opening "/dev/kevent" char device, which is created with +dynamic minor number and major number assigned for misc devices. + +cmd - is the requested operation. It can be one of the following: + KEVENT_CTL_ADD - add event notification + KEVENT_CTL_REMOVE - remove event notification + KEVENT_CTL_MODIFY - modify existing notification + +num - number of struct ukevent in the array pointed to by arg +arg - array of struct ukevent + +Return value: + number of events processed or negative error value. + +When called, kevent_ctl will carry out the operation specified in the +cmd parameter. +------------------------------------------------------------------------------- + + int kevent_get_events(int ctl_fd, unsigned int min_nr, unsigned int max_nr, + __u64 timeout, struct ukevent *buf, unsigned flags); + +ctl_fd - file descriptor referring to the kevent queue +min_nr - minimum number of completed events that kevent_get_events will block + waiting for +max_nr - number of struct ukevent in buf +timeout - number of nanoseconds to wait before returning less than min_nr + events. If this is -1, then wait forever. +buf - pointer to an array of struct ukevent. +flags - unused + +Return value: + number of events copied or negative error value. + +kevent_get_events will wait timeout milliseconds for at least min_nr completed +events, copying completed struct ukevents to buf and deleting any +KEVENT_REQ_ONESHOT event requests. In nonblocking mode it returns as many +events as possible, but not more than max_nr. In blocking mode it waits until +timeout or if at least min_nr events are ready. + +This function copies event into ring buffer if it was initialized, if ring buffer +is full, KEVENT_RET_COPY_FAILED flag is set in ret_flags field. +------------------------------------------------------------------------------- + + int kevent_wait(int ctl_fd, unsigned int num, __u64 timeout); + +ctl_fd - file descriptor referring to the kevent queue +num - number of processed kevents +timeout - this timeout specifies number of nanoseconds to wait until there is + free space in kevent queue + +Return value: + number of events copied into ring buffer or negative error value. + +This syscall waits until either timeout expires or at least one event becomes +ready. It also copies events into special ring buffer. If ring buffer is full, +it waits until there are ready events and then return. +If kevent is one-shot kevent it is removed in this syscall. +If kevent is edge-triggered (KEVENT_REQ_ET flag is set in 'req_flags') it is +requeued in this syscall for performance reasons. +------------------------------------------------------------------------------- + + int kevent_commit(int ctl_fd, unsigned int start, + unsigned int num, unsigned int over); + +ctl_fd - file descriptor referring to the kevent queue +start - index of the first index in the ring buffer to start to commit from +num - number of kevents to commit +over - overflow count for given $start value + +Return value: + number of committed kevents or negative error value. + +This function commits, i.e. marks as empty, slots in the ring buffer, so +they can be reused when userspace completes that entries processing. + +Overflow counter is used to prevent situation when two threads are going +to free the same events, but one of them was scheduled away for too long, +so ring indexes were wrapped, so when that thread will be awakened, it +will free not those events, which it suppose to free. + +It is possible that returned number of committed events will be smaller than +requested number - it is possible when several threads try to commit the +same events. +------------------------------------------------------------------------------- + +The bulk of the interface is entirely done through the ukevent struct. +It is used to add event requests, modify existing event requests, +specify which event requests to remove, and return completed events. + +struct ukevent contains the following members: + +struct kevent_id id + Id of this request, e.g. socket number, file descriptor and so on +__u32 type + Event type, e.g. KEVENT_SOCK, KEVENT_INODE, KEVENT_TIMER and so on +__u32 event + Event itself, e.g. SOCK_ACCEPT, INODE_CREATED, TIMER_FIRED +__u32 req_flags + Per-event request flags, + + KEVENT_REQ_ONESHOT + event will be removed when it is ready + + KEVENT_REQ_WAKEUP_ALL + Kevent wakes up only first thread interested in given event, + or all threads if this flag is set. + + KEVENT_REQ_ET + Edge Triggered behaviour. It is an optimisation which allows to move + ready and dequeued (i.e. copied to userspace) event to move into set + of interest for given storage (socket, inode and so on) again. It is + very usefull for cases when the same event should be used many times + (like reading from pipe). It is similar to epoll()'s EPOLLET flag. + + KEVENT_REQ_LAST_CHECK + if set allows to perform the last check on kevent (call appropriate + callback) when kevent is marked as ready and has been removed from + ready queue. If it will be confirmed that kevent is ready + (k->callbacks.callback(k) returns true) then kevent will be copied + to userspace, otherwise it will be requeued back to storage. + Second (checking) call is performed with this bit cleared, so callback + can detect when it was called from kevent_storage_ready() - bit is set, + or kevent_dequeue_ready() - bit is cleared. If kevent will be requeued, + bit will be set again. + + KEVENT_REQ_ALWAYS_QUEUE + If this flag is set kevent will be queued into ready queue if it is + ready at enqueue time, otherwise it will be copied back to userspace + and will not be queued into the storage. + +__u32 ret_flags + Per-event return flags + + KEVENT_RET_BROKEN + Kevent is broken + + KEVENT_RET_DONE + Kevent processing was finished successfully + + KEVENT_RET_COPY_FAILED + Kevent was not copied into ring buffer due to some error conditions. + +__u32 ret_data + Event return data. Event originator fills it with anything it likes + (for example timer notifications put number of milliseconds when timer + has fired +union { __u32 user[2]; void *ptr; } + User's data. It is not used, just copied to/from user. The whole structure + is aligned to 8 bytes already, so the last union is aligned properly. + +------------------------------------------------------------------------------- + +Usage + +For KEVENT_CTL_ADD, all fields relevant to the event type must be filled +(id, type, event, req_flags). +After kevent_ctl(..., KEVENT_CTL_ADD, ...) returns each struct's ret_flags +should be checked to see if the event is already broken or done. + +For KEVENT_CTL_MODIFY, the id, req_flags, and user and event fields must be +set and an existing kevent request must have matching id and user fields. If +match is found, req_flags and event are replaced with the newly supplied +values and requeueing is started, so modified kevent can be checked and +probably marked as ready immediately. If a match can't be found, the +passed in ukevent's ret_flags has KEVENT_RET_BROKEN set. KEVENT_RET_DONE is +always set. + +For KEVENT_CTL_REMOVE, the id and user fields must be set and an existing +kevent request must have matching id and user fields. If a match is found, +the kevent request is removed. If a match can't be found, the passed in +ukevent's ret_flags has KEVENT_RET_BROKEN set. KEVENT_RET_DONE is always set. + +For kevent_get_events, the entire structure is returned. + +------------------------------------------------------------------------------- + +Usage cases + +kevent_timer +struct ukevent should contain following fields: + type - KEVENT_TIMER + event - KEVENT_TIMER_FIRED + req_flags - KEVENT_REQ_ONESHOT if you want to fire that timer only once + id.raw[0] - number of seconds after commit when this timer shout expire + id.raw[0] - additional to number of seconds number of nanoseconds
PATCH 2/6 kevent: Core files.
Core files.
This patch includes core kevent files:
* userspace controlling
* kernelspace interfaces
* initialization
* notification state machines
Some bits of documentation can be found on project's homepage (and links from there):
http://tservice.net.ru/~s0mbre/old/?section=projects&item=kevent
arch/i386/kernel/syscall_table.S +5 -0
@@ -318,3 +318,8 @@ ENTRY(sys_call_table) .long sys_vmsplice .long sys_move_pages .long sys_getcpu + .long sys_kevent_get_events + .long sys_kevent_ctl /* 320 */ + .long sys_kevent_wait + .long sys_kevent_commit + .long sys_kevent_init
arch/x86_64/ia32/ia32entry.S +6 -1
@@ -714,8 +714,13 @@ ia32_sys_call_table: .quad compat_sys_get_robust_list .quad sys_splice .quad sys_sync_file_range - .quad sys_tee + .quad sys_tee /* 315 */ .quad compat_sys_vmsplice .quad compat_sys_move_pages .quad sys_getcpu + .quad sys_kevent_get_events + .quad sys_kevent_ctl /* 320 */ + .quad sys_kevent_wait + .quad sys_kevent_commit + .quad sys_kevent_init ia32_syscall_end:
include/asm-i386/unistd.h +6 -1
@@ -324,10 +324,15 @@#define __NR_vmsplice 316#define __NR_move_pages 317#define __NR_getcpu 318 +#define __NR_kevent_get_events 319 +#define __NR_kevent_ctl 320 +#define __NR_kevent_wait 321 +#define __NR_kevent_commit 322 +#define __NR_kevent_init 323#ifdef __KERNEL__ -#define NR_syscalls 319 +#define NR_syscalls 324#include <linux/err.h> /*
include/asm-x86_64/unistd.h +11 -1
@@ -619,10 +619,20 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_kevent_get_events 280 +__SYSCALL(__NR_kevent_get_events, sys_kevent_get_events) +#define __NR_kevent_ctl 281 +__SYSCALL(__NR_kevent_ctl, sys_kevent_ctl) +#define __NR_kevent_wait 282 +__SYSCALL(__NR_kevent_wait, sys_kevent_wait) +#define __NR_kevent_commit 283 +__SYSCALL(__NR_kevent_commit, sys_kevent_commit) +#define __NR_kevent_init 284 +__SYSCALL(__NR_kevent_init, sys_kevent_init)#ifdef __KERNEL__ -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_kevent_init#include <linux/err.h> #ifndef __NO_STUBS
include/linux/kevent.h new file +230 -0
230 lines not on this page · raw message
include/linux/kevent_storage.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __KEVENT_STORAGE_H +#define __KEVENT_STORAGE_H + +struct kevent_storage +{ +void *origin;/* Originator's pointer, e.g. struct sock or struct file. Can be NULL. */ +struct list_head list;/* List of queued kevents. */ +spinlock_t lock;/* Protects users queue. */ +}; + +#endif /* __KEVENT_STORAGE_H */
include/linux/syscalls.h +8 -0
@@ -54,6 +54,8 @@ struct compat_stat;struct compat_timeval ;struct robust_list_head ;struct getcpu_cache ; +struct ukevent ; +struct kevent_ring ;#include <linux/types.h> #include <linux/aio_abi.h>
@@ -599,4 +601,10 @@ asmlinkage long sys_set_robust_list(stru size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_kevent_get_events (int ctl_fd,unsigned int min,unsigned int max, +__u64 timeout,struct ukevent __user *buf,unsigned flags); +asmlinkage long sys_kevent_ctl (int ctl_fd,unsigned int cmd,unsigned int num,struct ukevent __user *buf); +asmlinkage long sys_kevent_wait (int ctl_fd,unsigned int num,__u64 timeout); +asmlinkage long sys_kevent_commit (int ctl_fd,unsigned int start,unsigned int num,unsigned int over); +asmlinkage long sys_kevent_init (int ctl_fd,struct kevent_ring __user *ring,unsigned int num);#endif
include/linux/ukevent.h new file +178 -0
178 lines not on this page · raw message
init/Kconfig +2 -0
@@ -201,6 +201,8 @@ config AUDITSYSCALL such as SELinux. To use audit's filesystem watch feature, please ensure that INOTIFY is configured. +source "kernel/kevent/Kconfig" + config IKCONFIG bool "Kernel .config support" ---help---
kernel/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_DETECT_SOFTLOCKUP) += softl obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ obj-$(CONFIG_SECCOMP) += seccomp.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o +obj-$(CONFIG_KEVENT) += kevent/ obj-$(CONFIG_RELAY) += relay.o obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o obj-$(CONFIG_TASKSTATS) += taskstats.o
kernel/kevent/Kconfig new file +60 -0
60 lines not on this page · raw message
kernel/kevent/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +obj-y := kevent.o kevent_user.o +obj-$(CONFIG_KEVENT_TIMER) += kevent_timer.o +obj-$(CONFIG_KEVENT_POLL) += kevent_poll.o +obj-$(CONFIG_KEVENT_SOCKET) += kevent_socket.o +obj-$(CONFIG_KEVENT_PIPE) += kevent_pipe.o +obj-$(CONFIG_KEVENT_SIGNAL) += kevent_signal.o
kernel/kevent/kevent.c new file +232 -0
232 lines not on this page · raw message
kernel/kevent/kevent_user.c new file +1181 -0
1,181 lines not on this page · raw message
kernel/sys_ni.c +6 -0
@@ -122,6 +122,12 @@ cond_syscall(ppc_rtas);cond_syscall (sys_spu_run);cond_syscall (sys_spu_create); +cond_syscall (sys_kevent_get_events); +cond_syscall (sys_kevent_ctl); +cond_syscall (sys_kevent_wait); +cond_syscall (sys_kevent_commit); +cond_syscall (sys_kevent_init); +/* mmu depending weak syscall entries */ cond_syscall (sys_mprotect);cond_syscall (sys_msync);
PATCH 3/6 kevent: poll/select() notifications.
poll/select() notifications.
This patch includes generic poll/select notifications. kevent_poll works simialr to epoll and has the same issues (callback is invoked not from internal state machine of the caller, but through process awake, a lot of allocations and so on).
fs/file_table.c +3 -0
@@ -20,6 +20,7 @@#include <linux/cdev.h> #include <linux/fsnotify.h> #include <linux/sysctl.h> +#include <linux/kevent.h> #include <linux/percpu_counter.h> #include <asm/atomic.h>
@@ -119,6 +120,7 @@ struct file *get_empty_filp(void) f->f_uid = tsk->fsuid; f->f_gid = tsk->fsgid;eventpoll_init_file (f); +kevent_init_file (f);/* f->f_version: 0 */ return f;
@@ -164,6 +166,7 @@ void fastcall __fput(struct file *file)* in the file cleanup chain. */ eventpoll_release (file); +kevent_cleanup_file (file);locks_remove_flock (file);if (file->f_op && file->f_op->release)
fs/inode.c +7 -0
@@ -21,6 +21,7 @@#include <linux/cdev.h> #include <linux/bootmem.h> #include <linux/inotify.h> +#include <linux/kevent.h> #include <linux/mount.h> /*
@@ -164,12 +165,18 @@ static struct inode *alloc_inode(struct } inode->i_private =0 ; inode->i_mapping = mapping; +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_init (inode, &inode->st); +#endif }return inode; }void destroy_inode (struct inode *inode) { +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_fini (&inode->st); +#endif BUG_ON (inode_has_buffers (inode));security_inode_free (inode);if (inode->i_sb->s_op->destroy_inode)
include/linux/fs.h +8 -0
@@ -276,6 +276,7 @@ extern int dir_notify_enable;#include <linux/init.h> #include <linux/sched.h> #include <linux/mutex.h> +#include <linux/kevent_storage.h> #include <asm/atomic.h> #include <asm/semaphore.h>
@@ -586,6 +587,10 @@ struct inode {struct mutex inotify_mutex;/* protects the watches list */ #endif +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +struct kevent_storage st; +#endif +unsigned long i_state;unsigned long dirtied_when;/* jiffies of first dirtying */
@@ -739,6 +744,9 @@ struct file {struct list_head f_ep_links;spinlock_t f_ep_lock;#endif /* #ifdef CONFIG_EPOLL */ +#ifdef CONFIG_KEVENT_POLL +struct kevent_storage st; +#endif struct address_space *f_mapping; };extern spinlock_t files_lock;
kernel/kevent/kevent_poll.c new file +232 -0
232 lines not on this page · raw message
PATCH 4/6 kevent: Socket notifications.
Socket notifications.
This patch includes socket send/recv/accept notifications. Using trivial web server based on kevent and this features instead of epoll it's performance increased more than noticebly. More details about various benchmarks and server itself (evserver_kevent.c) can be found on project's homepage.
fs/inode.c +7 -0
@@ -21,6 +21,7 @@#include <linux/cdev.h> #include <linux/bootmem.h> #include <linux/inotify.h> +#include <linux/kevent.h> #include <linux/mount.h> /*
@@ -164,12 +165,18 @@ static struct inode *alloc_inode(struct } inode->i_private =0 ; inode->i_mapping = mapping; +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_init (inode, &inode->st); +#endif }return inode; }void destroy_inode (struct inode *inode) { +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_fini (&inode->st); +#endif BUG_ON (inode_has_buffers (inode));security_inode_free (inode);if (inode->i_sb->s_op->destroy_inode)
include/net/sock.h +17 -15
@@ -48,6 +48,7 @@#include <linux/netdevice.h> #include <linux/skbuff.h> /* struct sk_buff */ #include <linux/security.h> +#include <linux/kevent.h> #include <linux/filter.h>
@@ -450,6 +451,21 @@ static inline int sk_stream_memory_free(extern void sk_stream_rfree (struct sk_buff *skb); +struct socket_alloc { +struct socket socket; +struct inode vfs_inode; +}; + +static inline struct socket *SOCKET_I (struct inode *inode) +{ + return &container_of(inode, struct socket_alloc, vfs_inode)->socket; +} + +static inline struct inode *SOCK_INODE (struct socket *socket) +{ + return &container_of(socket, struct socket_alloc, socket)->vfs_inode; +} +static inline void sk_stream_set_owner_r (struct sk_buff *skb,struct sock *sk) { skb->sk = sk;
@@ -477,6 +493,7 @@ static inline void sk_add_backlog(struct sk->sk_backlog.tail = skb; } skb->next =NULL ; +kevent_socket_notify (sk,KEVENT_SOCKET_RECV ); }#define sk_wait_event (__sk, __timeo, __condition) \
@@ -679,21 +696,6 @@ static inline struct kiocb *siocb_to_kioreturn si->kiocb; } -struct socket_alloc { -struct socket socket; -struct inode vfs_inode; -}; - -static inline struct socket *SOCKET_I (struct inode *inode) -{ - return &container_of(inode, struct socket_alloc, vfs_inode)->socket; -} - -static inline struct inode *SOCK_INODE (struct socket *socket) -{ - return &container_of(socket, struct socket_alloc, socket)->vfs_inode; -} -extern void __sk_stream_mem_reclaim (struct sock *sk);extern int sk_stream_mem_schedule (struct sock *sk,int size,int kind);
include/net/tcp.h +1 -0
@@ -857,6 +857,7 @@ static inline int tcp_prequeue(struct so tp->ucopy.memory =0 ; }else if (skb_queue_len (&tp->ucopy.prequeue) ==1 ) {wake_up_interruptible (sk->sk_sleep); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND );if (!inet_csk_ack_scheduled (sk)) inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, (3 * TCP_RTO_MIN) / 4,
kernel/kevent/kevent_socket.c new file +142 -0
142 lines not on this page · raw message
net/core/sock.c +9 -1
@@ -1402,6 +1402,7 @@ static void sock_def_wakeup(struct sockif (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible_all (sk->sk_sleep);read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_error_report (struct sock *sk)
@@ -1411,6 +1412,7 @@ static void sock_def_error_report(structwake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,0 ,POLL_ERR );read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_readable (struct sock *sk,int len)
@@ -1420,6 +1422,7 @@ static void sock_def_readable(struct socwake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,1 ,POLL_IN );read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_write_space (struct sock *sk)
@@ -1439,6 +1442,7 @@ static void sock_def_write_space(struct }read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV ); }static void sock_def_destruct (struct sock *sk)
@@ -1489,6 +1493,8 @@ void sock_init_data(struct socket *sock, sk->sk_state =TCP_CLOSE ; sk->sk_socket = sock; +kevent_sk_reinit (sk); +sock_set_flag (sk,SOCK_ZAPPED );if (sock)
@@ -1555,8 +1561,10 @@ void fastcall release_sock(struct sock *if (sk->sk_backlog.tail)__release_sock (sk); sk->sk_lock.owner =NULL ; -if (waitqueue_active (&sk->sk_lock.wq)) +if (waitqueue_active (&sk->sk_lock.wq)) {wake_up (&sk->sk_lock.wq); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); + }spin_unlock_bh (&sk->sk_lock.slock); }EXPORT_SYMBOL (release_sock);
net/core/stream.c +1 -0
@@ -36,6 +36,7 @@ void sk_stream_write_space(struct sock *wake_up_interruptible (sk->sk_sleep);if (sock->fasync_list && !(sk->sk_shutdown &SEND_SHUTDOWN ))sock_wake_async (sock,2 ,POLL_OUT ); +kevent_socket_notify (sk,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV ); } }
net/ipv4/tcp_input.c +1 -0
@@ -3119,6 +3119,7 @@ static void tcp_ofo_queue(struct sock *s__skb_unlink (skb, &tp->out_of_order_queue);__skb_queue_tail (&sk->sk_receive_queue, skb); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV ); tp->rcv_nxt =TCP_SKB_CB (skb)->end_seq;if (skb->h.th->fin)tcp_fin (skb, sk, skb->h.th);
net/ipv4/tcp_ipv4.c +2 -0
@@ -61,6 +61,7 @@#include <linux/jhash.h> #include <linux/init.h> #include <linux/times.h> +#include <linux/kevent.h> #include <net/icmp.h> #include <net/inet_hashtables.h>
@@ -870,6 +871,7 @@ int tcp_v4_conn_request(struct sock *sk,reqsk_free (req); }else {inet_csk_reqsk_queue_hash_add (sk, req,TCP_TIMEOUT_INIT ); +kevent_socket_notify (sk,KEVENT_SOCKET_ACCEPT ); }return 0 ;
net/socket.c +3 -0
@@ -85,6 +85,7 @@#include <linux/kmod.h> #include <linux/audit.h> #include <linux/wireless.h> +#include <linux/kevent.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -490,6 +491,8 @@ static struct socket *sock_alloc(void) inode->i_uid = current->fsuid; inode->i_gid = current->fsgid; +kevent_socket_reinit (sock); +get_cpu_var (sockets_in_use)++;put_cpu_var (sockets_in_use);return sock;
PATCH 5/6 kevent: Timer notifications.
Timer notifications.
Timer notifications can be used for fine grained per-process time management, since interval timers are very inconvenient to use, and they are limited.
This subsystem uses high-resolution timers.
id.raw[0] is used as number of seconds
id.raw[1] is used as number of nanoseconds
kernel/kevent/kevent_timer.c new file +112 -0
@@ -0,0 +1,112 @@ +/* +* 2006 Copyright (c) Evgeniy Polyakov <[email protected]> +* All rights reserved. +* +* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/hrtimer.h> +#include <linux/jiffies.h> +#include <linux/kevent.h> + +struct kevent_timer +{ +struct hrtimer ktimer; +struct kevent_storage ktimer_storage; +struct kevent *ktimer_event; +}; + +static int kevent_timer_func (struct hrtimer *timer) +{ + struct kevent_timer *t = container_of(timer, struct kevent_timer, ktimer); +struct kevent *k = t->ktimer_event; + +kevent_storage_ready (&t->ktimer_storage,NULL ,KEVENT_MASK_ALL ); +hrtimer_forward (timer, timer->base->softirq_time, +ktime_set (k->event.id.raw[0 ], k->event.id.raw[1 ])); +return HRTIMER_RESTART ; +} + +static struct lock_class_key kevent_timer_key; + +static int kevent_timer_enqueue (struct kevent *k) +{ +int err; +struct kevent_timer *t; + + t =kmalloc (sizeof (struct kevent_timer ),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + +hrtimer_init (&t->ktimer,CLOCK_MONOTONIC ,HRTIMER_REL ); + t->ktimer.expires =ktime_set (k->event.id.raw[0 ], k->event.id.raw[1 ]); + t->ktimer.function = kevent_timer_func; + t->ktimer_event = k; + + err =kevent_storage_init (&t->ktimer, &t->ktimer_storage); +if (err) + goto err_out_free; +lockdep_set_class (&t->ktimer_storage.lock, &kevent_timer_key); + + err =kevent_storage_enqueue (&t->ktimer_storage, k); +if (err) + goto err_out_st_fini; + +hrtimer_start (&t->ktimer, t->ktimer.expires,HRTIMER_REL ); + +return 0 ; + +err_out_st_fini: +kevent_storage_fini (&t->ktimer_storage); +err_out_free: +kfree (t); + +return err; +} + +static int kevent_timer_dequeue (struct kevent *k) +{ +struct kevent_storage *st = k->st; + struct kevent_timer *t = container_of(st, struct kevent_timer, ktimer_storage); + +hrtimer_cancel (&t->ktimer); +kevent_storage_dequeue (st, k); +kfree (t); + +return 0 ; +} + +static int kevent_timer_callback (struct kevent *k) +{ + k->event.ret_data[0 ] =jiffies_to_msecs (jiffies); +return 1 ; +} + +static int __init kevent_init_timer (void ) +{ +struct kevent_callbacks tc = { + .callback = &kevent_timer_callback, + .enqueue = &kevent_timer_enqueue, + .dequeue = &kevent_timer_dequeue}; + +return kevent_add_callbacks (&tc,KEVENT_TIMER ); +} +module_init (kevent_init_timer); +
PATCH 6/6 kevent: Pipe notifications.
Pipe notifications.
fs/pipe.c +6 -0
@@ -16,6 +16,7 @@#include <linux/uio.h> #include <linux/highmem.h> #include <linux/pagemap.h> +#include <linux/kevent.h> #include <asm/uaccess.h> #include <asm/ioctls.h>
@@ -312,6 +313,7 @@ redo:break ; }if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND );wake_up_interruptible_sync (&pipe->wait);kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
@@ -321,6 +323,7 @@ redo:/* Signal writers asynchronously that there is more room. */ if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND );wake_up_interruptible (&pipe->wait);kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
@@ -490,6 +493,7 @@ redo2:break ; }if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_RECV );wake_up_interruptible_sync (&pipe->wait);kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); do_wakeup =0 ;
@@ -501,6 +505,7 @@ redo2: out:mutex_unlock (&inode->i_mutex);if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_RECV );wake_up_interruptible (&pipe->wait);kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); }
@@ -605,6 +610,7 @@ pipe_release(struct inode *inode, int defree_pipe_info (inode); }else {wake_up_interruptible (&pipe->wait); +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV );kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN );kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
kernel/kevent/kevent_pipe.c new file +117 -0
117 lines not on this page · raw message
Re: [take25 6/6] kevent: Pipe notifications.
Quoted 6 lines · Evgeniy Polyakov
Pipe notifications.
kernel/kevent/kevent_pipe.c new file +4
-0+int kevent_pipe_enqueue (struct kevent *k) +{ +struct file *pipe; +int err = -EBADF ;
kernel/kevent/kevent_pipe.c line 65
Quoted 10 lines
kernel/kevent/kevent_pipe.c new file +10
-0+struct inode *inode; + + pipe =fget (k->event.id.raw[0 ]); +if (!pipe) + goto err_out_exit; + + inode =igrab (pipe->f_dentry->d_inode); +if (!inode) + goto err_out_fput; +
Well...
How can you be sure 'pipe/inode' really refers to a pipe/fifo here ?
Hint : i_pipe <> NULL is not sufficient because i_pipe, i_bdev, i_cdev share the same location. (check pipe_info() in fs/splice.c)
So I guess you need :
err = -EINVAL;
if (!S_ISFIFO(inode->i_mode))
goto err_out_iput;
Eric
Re: [take25 6/6] kevent: Pipe notifications.
Quoted 22 lines · Eric Dumazet
Quoted 6 lines · Evgeniy Polyakov
Pipe notifications.
kernel/kevent/kevent_pipe.c new file +4
-0+int kevent_pipe_enqueue (struct kevent *k) +{ +struct file *pipe; +int err = -EBADF ;kernel/kevent/kevent_pipe.c line 65
Quoted 10 lines
kernel/kevent/kevent_pipe.c new file +10
-0+struct inode *inode; + + pipe =fget (k->event.id.raw[0 ]); +if (!pipe) + goto err_out_exit; + + inode =igrab (pipe->f_dentry->d_inode); +if (!inode) + goto err_out_fput; +Well...
How can you be sure 'pipe/inode' really refers to a pipe/fifo here ?
Quoted 8 lines
Hint :
i_pipe<> NULL is not sufficient becausei_pipe,i_bdev,i_cdevshare the same location. (checkpipe_info()infs/splice.c)So I guess you need :
err =
-EINVAL;
if (!S_ISFIFO(inode->i_mode))goto err_out_iput;
You are correct, I did not perform that check, since all pipe open functions do rely on the i_pipe, which can not be block device at that point, but with kevent file descriptor can be anything, so that check must be performed.
I will put it into the tree, thanks Eric.
Quoted 1 line
Eric
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
In reply to Evgeniy PolyakovDocumentation/kevent.txt line 97
Quoted 9 lines · Evgeniy Polyakov
+ int
kevent_wait(int ctl_fd, unsigned int num, __u64 timeout);Documentation/kevent.txt new file +8
-0+ +ctl_fd - file descriptor referring to the kevent queue +num - number of processed kevents +timeout - this timeout specifies number of nanoseconds to wait until there is + free space in kevent queue + +Return value: + number of events copied into ring buffer or negative error value.
This is not quite sufficient. What we also need is a parameter which specifies which ring buffer the code assumes is currently active. This is just like the EWOULDBLOCK error in the futex. I.e., the kernel doesn't move the thread on the wait list if the index has changed. Otherwise asynchronous ring buffer filling is impossible. Assume this
thread kernel
get current ring buffer idx
front and tail pointer the same
add new entry to ring buffer
bump front pointer
call kevent_wait()
With the interface above this leads to a deadlock. The kernel delivered the event and is done with it.
If the kevent_wait() syscall gets an additional parameter which specifies the expected front pointer the kernel wouldn't put the thread to sleep since, in this case, the front pointer changed since last checked.
The kernel cannot and should not check the ring buffer is empty. Userlevel should maintain the tail pointer all by itself. And even if the tail pointer is available to the kernel, the program might want to handle the queued events differently.
The above also comes to bear without asynchronous queuing if a thread waits for more than one event and it is possible to handle both events concurrently in two threads.
Passing in the expected front pointer value is flexible and efficient.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 25 lines · Ulrich Drepper
Documentation/kevent.txt line 97
Quoted 9 lines · Evgeniy Polyakov
+ int
kevent_wait(int ctl_fd, unsigned int num, __u64 timeout);Documentation/kevent.txt new file +4
-0+ +ctl_fd - file descriptor referring to the kevent queue +num - number of processed kevents +timeout - this timeout specifies number of nanoseconds to wait untilthere is + free space in kevent queue
Documentation/kevent.txt new file +3
-0+ +Return value: + number of events copied into ring buffer or negative error value.This is not quite sufficient. What we also need is a parameter which specifies which ring buffer the code assumes is currently active. This is just like the EWOULDBLOCK error in the futex. I.e., the kernel doesn't move the thread on the wait list if the index has changed. Otherwise asynchronous ring buffer filling is impossible. Assume this
thread kernel
get current ring buffer idx
front and tail pointer the same
add new entry to ring buffer
Quoted 7 lines
bump front pointer
call
kevent_wait()With the interface above this leads to a deadlock. The kernel delivered the event and is done with it.
Kernel does not put there a new entry, it is only done inside kevent_wait(). Entries are put into queue (in any context), where they can be obtained from only kevent_wait() or kevent_get_events().
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 3 lines · Evgeniy Polyakov
Kernel does not put there a new entry, it is only done inside
kevent_wait(). Entries are put into queue (in any context), where they can be obtained from onlykevent_wait()orkevent_get_events().
I know this is how it's done now. But it is not where it has to end. IMO we have to get to a solution where new events are posted to the ring buffer asynchronously, i.e., without a thread calling kevent_wait. And then you need the extra parameter and verification. Even if it's today not needed we have to future-proof the interface since it cannot be changed once in use.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 6 lines · Ulrich Drepper
Quoted 4 lines · Evgeniy Polyakov
Kernel does not put there a new entry, it is only done inside
kevent_wait(). Entries are put into queue (in any context), where they can be obtained
from onlykevent_wait()orkevent_get_events().
Quoted 6 lines
I know this is how it's done now. But it is not where it has to end. IMO we have to get to a solution where new events are posted to the ring buffer asynchronously, i.e., without a thread calling
kevent_wait. And then you need the extra parameter and verification. Even if it's today not needed we have to future-proof the interface since it cannot be changed once in use.
There is a special flag in kevent_user to wake it if there are no ready events - kernel thread which has added new events will set it and thus subsequent kevent_wait() will return with updated indexes - userspace must check indexes after kevent_wait().
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 6 lines · Evgeniy Polyakov
Quoted 1 line
I know this is how it's done now. But it is not where it has to end. IMO we have to get to a solution where new events are posted to the ring buffer asynchronously, i.e., without a thread calling
kevent_wait. And then you need the extra parameter and verification. Even if it's today not needed we have to future-proof the interface since it cannot be changed once in use.There is a special flag in
kevent_userto wake it if there are no ready events - kernel thread which has added new events will set it and thus subsequentkevent_wait()will return with updated indexes - userspace must check indexes afterkevent_wait().
You misunderstand. I don't want to return without waiting unconditionally.
There is a race which has to be closed. It's exactly the same as in the futex syscall. I've shown the interaction between the kernel and the thread in the previous mail. There is inevitably a time difference between the thread checking whether the ring buffer is empty and the kernel putting the thread to sleep in the kevent_wait call.
This is no problem with the current kevent_wait implementation since the ring buffer is not filled asynchronously. But if/when it will be the kernel might add something to the ring buffer _after_ the thread checks for an empty ring buffer and _before_ it enters the kernel in the kevent_wait syscall.
The kevent_wait syscall will only wake the thread when a new event is posted. We do not in general want it to be woken when the ring buffer is non empty. This would create far too many unnecessary wakeups it there is more than one thread working on the queue.
With the addition parameters for kevent_wait indicating when the calling thread last checked the ring buffer the kernel can find out whether the decision to call kevent_wait was made based on outdated information or not. Outdated in the case a new event has been posted. In this case the thread is not put to sleep but instead returns.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 32 lines · Ulrich Drepper
Quoted 11 lines · Evgeniy Polyakov
Quoted 6 lines
I know this is how it's done now. But it is not where it has to end. IMO we have to get to a solution where new events are posted to the ring buffer asynchronously, i.e., without a thread calling
kevent_wait. And then you need the extra parameter and verification. Even if it's today not needed we have to future-proof the interface since it cannot be changed once in use.There is a special flag in
kevent_userto wake it if there are no ready events - kernel thread which has added new events will set it and thus subsequentkevent_wait()will return with updated indexes - userspace must check indexes afterkevent_wait().You misunderstand. I don't want to return without waiting unconditionally.
There is a race which has to be closed. It's exactly the same as in the futex syscall. I've shown the interaction between the kernel and the thread in the previous mail. There is inevitably a time difference between the thread checking whether the ring buffer is empty and the kernel putting the thread to sleep in the
kevent_waitcall.This is no problem with the current
kevent_waitimplementation since the ring buffer is not filled asynchronously. But if/when it will be the kernel might add something to the ring buffer _after_ the thread checks for an empty ring buffer and _before_ it enters the kernel in thekevent_waitsyscall.The
kevent_waitsyscall will only wake the thread when a new event is posted. We do not in general want it to be woken when the ring buffer is non empty. This would create far too many unnecessary wakeups it there is more than one thread working on the queue.
Quoted 5 lines
With the addition parameters for
kevent_waitindicating when the calling thread last checked the ring buffer the kernel can find out whether the decision to callkevent_waitwas made based on outdated information or not. Outdated in the case a new event has been posted. In this case the thread is not put to sleep but instead returns.
Read my mail again.
If kernel has put data asynchronously it will setup special flag, thus kevent_wait() will not sleep and will return, so thread will check new entries and process them.
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 3 lines · Evgeniy Polyakov
If kernel has put data asynchronously it will setup special flag, thus
kevent_wait()will not sleep and will return, so thread will check new entries and process them.
For the clarification - only kevent_wait() updates index, userspace will not detect that it has changed after thread has put there new data.
In case kernel thread will updated index too, you are correct, kevent_wait() should get index as parameter.
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
In reply to Evgeniy PolyakovQuoted 2 lines · Evgeniy Polyakov
If kernel has put data asynchronously it will setup special flag, thus
kevent_wait()will not sleep and will return, so thread will check new entries and process them.
This is not sufficient.
The userlevel code does not commit the events until they are processed.
So assume two threads at userlevel, one event is asynchronously
posted. The first thread picks it up, the second call kevent_wait.
With your scheme it will not be put to sleep and unnecessarily returns to userlevel.
What I propose and what has been proven to work in many situations is to have part of the kevent_wait syscall the information about "I am aware of all events up to XX; wake me only if anything beyond that is added".
Please take a look at how futexes work, it's really the same concept. And it's really also simpler for the implementation. Having such a flag is much more complicated than adding a simple index comparison before going to sleep.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
In reply to Evgeniy PolyakovDocumentation/kevent.txt line 18
Quoted 7 lines · Evgeniy Polyakov
+ struct
kevent_ring
+ {Documentation/kevent.txt new file +5
-0+ unsigned int ring_kidx, ring_uidx, ring_over; + struct ukevent event[0]; + } + [...] +ring_uidx - index of the first entry userspace can start reading from
Do we need this value in the structure? Userlevel cannot and should not be able to modify it. So, userland has in any case to track the tail pointer itself. Why then have this value at all?
After kevent_init() the tail pointer is implicitly assumed to be 0. Since the front pointer (well index) is also zero nothing is available for reading.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 9 lines · Ulrich Drepper
Documentation/kevent.txt line 18
Quoted 7 lines · Evgeniy Polyakov
+ struct
kevent_ring
+ {Documentation/kevent.txt new file +5
-0+ unsigned int ring_kidx, ring_uidx, ring_over; + struct ukevent event[0]; + } + [...] +ring_uidx - index of the first entry userspace can start reading from
Quoted 7 lines
Do we need this value in the structure? Userlevel cannot and should not be able to modify it. So, userland has in any case to track the tail pointer itself. Why then have this value at all?
After
kevent_init()the tail pointer is implicitly assumed to be 0. Since the front pointer (well index) is also zero nothing is available for reading.
uidx is an index, starting from which there are unread entries. It is updated by userspace when it commits entries, so it is 'consumer' pointer, while kidx is an index where kernel will put new entries, i.e. 'producer' index. We definitely need them both.
Userspace can only update (implicitly by calling kevent_commit()) uidx.
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 5 lines · Evgeniy Polyakov
uidx is an index, starting from which there are unread entries. It is updated by userspace when it commits entries, so it is 'consumer' pointer, while kidx is an index where kernel will put new entries, i.e. 'producer' index. We definitely need them both.
Userspace can only update (implicitly by callingkevent_commit()) uidx.
Right, which is why exporting this entry is not needed. Keep the interface as small as possible.
Userlevel has to maintain its own index. Just assume kevent_wait returns 10 new entries and you have multiple threads. In this case all threads take their turns and pick an entry from the ring buffer. This basically has to be done with something like this (I ignore wrap-arounds here to simplify the example):
int getidx() {
while (uidx < kidx)
if (atomic_cmpxchg(uidx, uidx + 1, uidx) == 0)
return uidx;
return -1;
}Very much simplified but it should show that we need a writable copy of the uidx. And this value at any time must be consistent with the index the kernel assumes.
The current ring_uidx value can at best be used to reinitialize the userlevel uidx value after each kevent_wait call but this is unnecessary at best (since uidx must already have this value) and racy in problem cases (what if more than one thread gets woken concurrently with uidx having the same value and one thread stores the uidx value and immediately increments it to get an index; the second store would overwrite the increment).
I can assure you that any implementation I write would not use the ring_uidx value. Only trivial, single-threaded examples like you ring_buffer.c could ever take advantage of this value. It's not worth it.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 16 lines · Ulrich Drepper
Quoted 5 lines · Evgeniy Polyakov
uidx is an index, starting from which there are unread entries. It is updated by userspace when it commits entries, so it is 'consumer' pointer, while kidx is an index where kernel will put new entries, i.e. 'producer' index. We definitely need them both.
Userspace can only update (implicitly by callingkevent_commit()) uidx.Right, which is why exporting this entry is not needed. Keep the interface as small as possible.
Userlevel has to maintain its own index. Just assume
kevent_waitreturns 10 new entries and you have multiple threads. In this case all threads take their turns and pick an entry from the ring buffer. This basically has to be done with something like this (I ignore wrap-arounds here to simplify the example):
Quoted 6 lines
int getidx() {
while (uidx < kidx)
if (atomic_cmpxchg(uidx, uidx + 1, uidx) == 0)
return uidx;
return -1;
}I don't know if this falls under the simplification, but wouldn't there be a race when reading/copying the event data? I guess this could be solved with an extra user index.
--
Hans Henrik Happe
Re: [take25 1/6] kevent: Description.
Quoted 1 line · Hans Henrik Happe
I don't know if this falls under the simplification, but wouldn't there be a race when reading/copying the event data? I guess this could be solved with an extra user index.
That's what I said, reading the value from the ring buffer structure's head would be racy. All this can only work for single threaded code.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 7 lines · Ulrich Drepper
Quoted 3 lines · Hans Henrik Happe
I don't know if this falls under the simplification, but wouldn't there be a race when reading/copying the event data? I guess this could be solved with an extra user index.
That's what I said, reading the value from the ring buffer structure's head would be racy. All this can only work for single threaded code.
Value in the userspace ring is updated each time it is changed in kernel (when userspace calls kevent_commit()), when userspace has read its old value it is guaranteed that requested number of events _is_ there (although it is possible that there are more than that value).
Ulrich, why didn't you comment on previous interface, which had exactly _one_ index exported to userspace - it is only required to add implicit uidx and (if you prefer that way) additional syscall, since in previous interface both waiting and commit was handled by kevent_wait() with different parameters.
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 5 lines · Evgeniy Polyakov
Ulrich, why didn't you comment on previous interface, which had exactly _one_ index exported to userspace - it is only required to add implicit uidx and (if you prefer that way) additional syscall, since in previous interface both waiting and commit was handled by
kevent_wait()with different parameters.
If you read my old mails you'll find that I'm pretty consistent wrt to the ring buffer interface. The old code had other problems, not the missing exposure of the uidx value.
There is really not much disagreement here. I just don't like the interface unnecessarily and misleadingly large by exposing the uidx value which is not useful to the userlevel code. Just remove the element and stuff it into a kernel-internal struct for the queue and you're done.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
In reply to Ulrich DrepperQuoted 9 lines · Ulrich Drepper
Quoted 5 lines · Evgeniy Polyakov
uidx is an index, starting from which there are unread entries. It is updated by userspace when it commits entries, so it is 'consumer' pointer, while kidx is an index where kernel will put new entries, i.e. 'producer' index. We definitely need them both.
Userspace can only update (implicitly by callingkevent_commit()) uidx.Right, which is why exporting this entry is not needed. Keep the interface as small as possible.
If there are several callers of kevent_commit(), uidx can be changed far than first user expects, so there should be possibility to check that value. It is thus exported into shared ring buffer structure.
Quoted 13 lines
Userlevel has to maintain its own index. Just assume
kevent_waitreturns 10 new entries and you have multiple threads. In this case all threads take their turns and pick an entry from the ring buffer. This basically has to be done with something like this (I ignore wrap-arounds here to simplify the example):int getidx() { while (uidx < kidx) if (atomic_cmpxchg(uidx, uidx + 1, uidx) == 0) return uidx; return -1; }
Quoted 3 lines
Very much simplified but it should show that we need a writable copy of the uidx. And this value at any time must be consistent with the index the kernel assumes.
I seriously doubt it is simpler than having index provided by kernel.
Quoted 11 lines
The current
ring_uidxvalue can at best be used to reinitialize the userlevel uidx value after eachkevent_waitcall but this is unnecessary at best (since uidx must already have this value) and racy in problem cases (what if more than one thread gets woken concurrently with uidx having the same value and one thread stores the uidx value and immediately increments it to get an index; the second store would overwrite the increment).I can assure you that any implementation I write would not use the
ring_uidxvalue. Only trivial, single-threaded examples like youring_buffer.ccould ever take advantage of this value. It's not worth it.
You propose to make uidx shared local variable - it is doable, but it is not required - userspace can use kernel's variable, since it is updated exactly in the places where that index is changed.
Quoted 7 lines
Signature · 6 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖ - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 3 lines · Evgeniy Polyakov
Quoted 1 line
Very much simplified but it should show that we need a writable copy of the uidx. And this value at any time must be consistent with the index the kernel assumes.
I seriously doubt it is simpler than having index provided by kernel.
What has simpler to do with it? The userlevel code should not modify the ring buffer structure at all. If we'd do this then all operations, at least on the uidx field, would have to be atomic operations. This is currently not the case for the kernel side since it's protected by a lock for the event queue. Using the uidx field from userlevel would therefore just make things slower.
And for what? Changing the uidx value would make the commit syscall unnecessary. This might be an argument but it sounds too dangerous. IMO the value should be protected by the kernel.
And in any case, the uidx value cannot be updated until the event actually has been processed. But the threads still need to coordinate distributing the events from the ring buffer amongst themselves. This will in any case require a second variable.
So, if you want to do away with the commit syscall, keep the uidx value.
This also requires that the ring buffer head will always be writable
(something I'd like to avoid making part of the interface but I'm flexible on this). Otherwise, the ring_uidx element can go away, it's not needed and will only make people think about wrong approaches to use it.
Quoted 3 lines
You propose to make uidx shared local variable - it is doable, but it is not required - userspace can use kernel's variable, since it is updated exactly in the places where that index is changed.
As said above, we always need another variable and uidx is only a replacement for the commit call. Until the event is processed the uidx cannot be incremented since otherwise the ring buffer entry might be overwritten.
And kernel people of all should be happy to limit the exposure of the implementation. So, leave the problem of keeping track of the tail pointer to the userlevel code.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 5 lines · Ulrich Drepper
Quoted 4 lines · Evgeniy Polyakov
Quoted 3 lines
Very much simplified but it should show that we need a writable copy of the uidx. And this value at any time must be consistent with the index the kernel assumes.
Quoted 8 lines
Quoted 1 line
I seriously doubt it is simpler than having index provided by kernel.
What has simpler to do with it? The userlevel code should not modify the ring buffer structure at all. If we'd do this then all operations, at least on the uidx field, would have to be atomic operations. This is currently not the case for the kernel side since it's protected by a lock for the event queue. Using the uidx field from userlevel would therefore just make things slower.
That index is provided by kernel for userspace so that userspace could determine where indexes are - of course userspace can maintain it itself, but it can also use provided by kernel. It is not written explicitly, but only through kevent_commit().
Quoted 9 lines
And for what? Changing the uidx value would make the commit syscall unnecessary. This might be an argument but it sounds too dangerous. IMO the value should be protected by the kernel.
And in any case, the uidx value cannot be updated until the event actually has been processed. But the threads still need to coordinate distributing the events from the ring buffer amongst themselves. This will in any case require a second variable.
Quoted 5 lines
So, if you want to do away with the commit syscall, keep the uidx value.
This also requires that the ring buffer head will always be writable
(something I'd like to avoid making part of the interface but I'm flexible on this). Otherwise, thering_uidxelement can go away, it's not needed and will only make people think about wrong approaches to use it.
No, head will not be writeable - it is absolutely.
I do not care actually about that index, but as you have probably noticed, there was such an interface already, and I changed it. So, this will be the last change of the interface. You think it should not be exported - fine, it will not be.
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 3 lines · Evgeniy Polyakov
That index is provided by kernel for userspace so that userspace could determine where indexes are - of course userspace can maintain it itself, but it can also use provided by kernel.
Indeed. That's what I said. But I also pointed out that the field is only useful in simple minded programs and certainly not in the wrappers the runtime (glibc) will provide.
As you said yourself, there is no real need for the value being there, userland can keep track of it by itself. So, let's reduce the interface.
Quoted 2 lines
I do not care actually about that index, but as you have probably noticed, there was such an interface already, and I changed it. So, this will be the last change of the interface. You think it should not be exported - fine, it will not be.
Thanks.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
In reply to Evgeniy PolyakovDocumentation/kevent.txt line 108
Quoted 2 lines · Evgeniy Polyakov
+ int kevent_commit(int
ctl_fd, unsigned int start,Documentation/kevent.txt new file +1
-0+ unsigned int num, unsigned int over);
I think we can simplify this interface:
int kevent_commit(int ctl_fd, unsigned int new_tail,
unsigned int over);
The kernel sets the ring_uidx value to the 'new_tail' value if the tail pointer would be incremented (module wrap around) and is not higher then the current front pointer. The test will be a bit complicated but not more so than what the current code has to do to check for mistakes.
This approach has the advantage that the commit calls don't have to be synchronized. If one thread sets the tail pointer to, say, 10 and another to 12, then it does not matter whether the first thread is delayed. If it will eventually be executed the result is simply a no-op and since second thread's action supersedes it.
Maybe the current form is even impossible to use with explicit locking at userlevel. What if one thread, which is about to call kevent_commit, if indefinitely delayed. Then this commit request's value is never taken into account and the tail pointer is always short of what it should be.
There is one more thing to consider. Oftentimes the commit request will be immediately followed by a kevent_wait call. It would be good to merge this pair of calls. The two parameters new_tail and over could also be passed to the kevent_wait call and the commit can happen before the thread looks for new events and eventually goes to sleep. If this can be implemented then the kevent_commit syscall by itself might not be needed at all. Instead you'd call kevent_wait() and make the maximum number of events which can be returned zero.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 6 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov
+ int kevent_commit(int
ctl_fd, unsigned int start, + unsigned int
num, unsigned int over);I think we can simplify this interface:
Quoted 8 lines
int kevent_commit(int
ctl_fd, unsigned intnew_tail,unsigned int over);The kernel sets the
ring_uidxvalue to the 'new_tail' value if the tail pointer would be incremented (module wrap around) and is not higher then the current front pointer. The test will be a bit complicated but not more so than what the current code has to do to check for mistakes.This approach has the advantage that the commit calls don't have to be synchronized. If one thread sets the tail pointer to, say, 10 and another to 12, then it does not matter whether the first thread is delayed. If it will eventually be executed the result is simply a no-op and since second thread's action supersedes it.
Maybe the current form is even impossible to use with explicit locking at userlevel. What if one thread, which is about to call
kevent_commit, if indefinitely delayed. Then this commit request's value is never taken into account and the tail pointer is always short of what it should be.
I'm really wondering is designing for N-threads-to-1-ring is the wisest choice?
Considering current designs, it seems more likely that a single thread polls for socket activity, then dispatches work. How often do you really see in userland multiple threads polling the same set of fds, then fighting to decide who will handle raised events?
More likely, you will see "prefork" (start N threads, each with its own ring) or a worker pool (single thread receives events, then dispatches to multiple threads for execution) or even one-thread-per-fd (single thread receives events, then starts new thread for handling).
If you have multiple threads accessing the same ring -- a poor design choice -- I would think the burden should be on the application, to provide proper synchronization.
If the desire is to have the kernel distributes events directly to multiple threads, then the app should dup(2) the fd to be watched, and create a ring buffer for each separate thread.
Jeff
Re: [take25 1/6] kevent: Description.
Quoted 3 lines · Jeff Garzik
Considering current designs, it seems more likely that a single thread polls for socket activity, then dispatches work. How often do you really see in userland multiple threads polling the same set of fds, then fighting to decide who will handle raised events?
More likely, you will see "prefork" (start N threads, each with its own ring) or a worker pool (single thread receives events, then dispatches to multiple threads for execution) or even one-thread-per-fd (single thread receives events, then starts new thread for handling).
No, absolutely not. This is exactly not what should/is/will happen.
You create worker threads to handle to work for the entire program. Look at something like a web server. When creating several queues, how do you distribute all the connections to the different queues? To ensure every connection is handled as quickly as possible you stuff them all in the same queue and then have all threads use this one queue. Whenever an event is posted a thread is woken. _One_ thread. If two events are posted, two threads are woken. In this situation we have a few atomic ops at userlevel to make sure that the two threads don't pick the same event but that's all there is wrt "fighting".
The alternative is the sorry state we have now. In nscd, for instance, we have one single thread waiting for incoming connections and it then has to wake up a worker thread to handle the processing. This is done because we cannot "park" all threads in the accept() call since when a new connection is announced _all_ the threads are woken. With the new event handling this wouldn't be the case, one thread only is woken and we don't have to wake worker threads. All threads can be worker threads.
Quoted 1 line
If you have multiple threads accessing the same ring -- a poor design choice
To the contrary. It is the perfect means to distribute the workload to multiple threads. Beside, how would you implement asynchronous filling of the ring buffer to avoid unnecessary syscalls if you have many different queues?
Quoted 2 lines
-- I would think the burden should be on the application, to provide proper synchronization.
Sure, as much as possible. But there is no reason to design the commit interface in the way which requires expensive synchronization when there is another design which can do exactly the same work but does not require synchronization. The currently proposed kevent_commit and my proposed variant are functionally equivalent.
Quoted 1 line
If the desire is to have the kernel distributes events directly to multiple threads, then the app should dup(2) the fd to be watched, and create a ring buffer for each separate thread.
And how would you synchronize the file descriptor use across the threads? The event would be sent to all the event queues so that you would a) unnecessarily wake all threads and b) have all but one thread see the operation (say, read or write on a socket) fail with EWOULDBLOCK. That's just silly, we can have that today and continue to waste precious CPU cycles.
If you say that you post exactly one event per file description (not handle) then what do you do if the programmer wants the opposite? And again, what do you do for asynchronous ring buffer filling. Which queue do you pick? Pick the wrong one and the event might be in the ring buffer for a long time which another thread handling another queue is ready.
Using a single central queue is the perfect means to distribute the load to a number of threads. Nobody is forcing you to do it, you're free to use separate queues if you want. But the model should not enforce this.
Overall, I cannot see at all where your problem is. I agree that the synchronization of the access to the ring buffer must be done at userlevel. This is why the uidx exposure isn't needed. The wakeup in any case has to take threads into account. The only change I proposed to enable better multi-thread handling is the revised commit interface and this change in no way hinders single-threaded users. The interface is not hindered in any way or form by the use of threads.
Oh, and when I say "threads" I should have said "threads or processes".
The whole also applies to multi-process applications. They can share
event queues by placing them in shared memory. And I hope that everyone agrees that programs have to go into the direction of having more than one execution context to take advantage of increased CPU power in future. CMP is only becoming more and more important.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 4 lines · Ulrich Drepper
You create worker threads to handle to work for the entire program. Look at something like a web server. When creating several queues, how do you distribute all the connections to the different queues? To ensure every connection is handled as quickly as possible you stuff them all in the same queue and then have all threads use this one queue. Whenever an event is posted a thread is woken. _One_ thread. If two events are posted, two threads are woken. In this situation we have a few atomic ops at userlevel to make sure that the two threads don't pick the same event but that's all there is wrt "fighting".
The alternative is the sorry state we have now. In nscd, for instance, we have one single thread waiting for incoming connections and it then has to wake up a worker thread to handle the processing. This is done because we cannot "park" all threads in the
accept()call since when a new connection is announced _all_ the threads are woken. With the new event handling this wouldn't be the case, one thread only is woken and we don't have to wake worker threads. All threads can be worker threads.
Having one specialized thread handling the distribution of work to worker threads is better most of the time. This thread can be a worker thread by itself (to avoid context switchs), but can decide to wake up 'slave threads' if he believes it has too (for example if he can notice that a *lot* of requests are pending)
This is because with moderate load, it's better to have only one CPU running 80% of its time, keeping its cache hot, than 'distribute' the work on four CPU, that would be used 25% of their time, but with lot of cache line ping pongs and poor cache reuse.
If you let 'kevent'/'dumb kernel dispatcher'/'futex'/'whatever' decide to wake up one thread for each new event, you *may* have lower performance, because of higher system overhead (system means : system scheduler/internals, but also bus trafic)
Only the application writer can have a clue of average use of its worker
threads, and can decide to dynamically adjust parameters if needed to handle load spikes.
SMP machines are nice, but for many workloads, it's better to avoid spreading a working set on several CPUS that fight for common resources (memory).
Back to 'kevent':
-----------------
I think that having a syscall to commit events should not be mandatory. A syscall is needed only to wait for new events if the ring is empty. But then maybe we dont need yet a new syscall to perform a wait :
We already have nice synchronisations primitives (futex for example).
User program should be able to update a 'uidx' in user space (using atomic ops only if multi-threaded), and could just use futex infrastructure if ring buffer is empty (uidx == kidx) , and call FUTEX_WAIT( &kidx, current value = uidx)
I think I already gave my opinion on a ring buffer, but let just rephrase it :
One part should be read/write for application (to be able to change uidx) (or User app just give at init time to kernel the address of a futex in its vm space)
One part could be read only for application (but could be read/write : we dont care if user application is stupid) : kernel writes its kidx (or a copy of it) and events.
For best performance, uidx and kidx should be on different cache lines (basic isolation of producer / consumer)
When kernel wants to queue a new event in a ring buffer it can :
See if user program did consume some events since last invocation (kernel fetches uidx and compare it with its own uidx value : no syscall needed) Check if a slot is available in ring buffer.
Copy the event in ring buffer, perform a memory barrier, then increment kidx.
call futex_wake(&kidx, 1 thread)
User application is free to have one thread/process or several threads/processes waiting for new events (or even no thread at all :) )
Eric
Re: [take25 1/6] kevent: Description.
Quoted 10 lines · On Fri, 24 Nov 2006 01:48:32 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 7 lines
The alternative is the sorry state we have now. In nscd, for instance, we have one single thread waiting for incoming connections and it then has to wake up a worker thread to handle the processing. This is done because we cannot "park" all threads in the
accept()call since when a new connection is announced _all_ the threads are woken. With the new event handling this wouldn't be the case, one thread only is woken and we don't have to wake worker threads. All threads can be worker threads.Having one specialized thread handling the distribution of work to worker threads is better most of the time.
It might be now. Think "commodity 128-way". Your single distribution thread will run out of steam.
What Ulrich is proposing is faster. This is a new interface. Let's design it to be fast.
Re: [take25 1/6] kevent: Description.
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 24 Nov 2006 01:48:32 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 1 line
The alternative is the sorry state we have now. In nscd, for instance, we have one single thread waiting for incoming connections and it then has to wake up a worker thread to handle the processing. This is done because we cannot "park" all threads in the
accept()call since when a new connection is announced _all_ the threads are woken. With the new event handling this wouldn't be the case, one thread only is woken and we don't have to wake worker threads. All threads can be worker threads.Having one specialized thread handling the distribution of work to worker threads is better most of the time.
It might be now. Think "commodity 128-way". Your single distribution thread will run out of steam.
What Ulrich is proposing is faster. This is a new interface. Let's design it to be fast.
Hum... I guess you didnt read my mail... I basically agree with Ulrich.
I just wanted to say that a fast application cannot rely only on a "let's park N threads waiting for single event in this queue", and hope kernel will be smart for us.
Even with 128-ways, you still hit a central point of coordination (it can be a mutex in kevent code, a atomic uidx in userland, or whatever) for a 'kevent queue'. Once you paid the cache lines ping/pong, you wont be *fast*.
I wish *you* dont think of kevent of only dispatching HTTP 1.0 trivial web requests.
Being able to direct a particular request on a particular CPU is certainly something that cannot be hardcoded in 'the new kevent interface'.
Eric
Re: [take25 1/6] kevent: Description.
Quoted 1 line · Eric Dumazet
Being able to direct a particular request on a particular CPU is certainly something that cannot be hardcoded in 'the new kevent interface'.
Nobody is proposing this. Although I have proposed that if the kernel knows which CPU can best service a request it might hint as much.
But in general, you're free to decentralize as much as you want. But this does not mean it should not also be possible to use a number of threads in the same loop and the same kevent queue. That's the part which needs designing, the separate queues will always be possible.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
In reply to Ulrich DrepperIn article <[email protected]>,
Quoted 13 lines · Ulrich Drepper
Quoted 9 lines · Jeff Garzik
Considering current designs, it seems more likely that a single thread polls for socket activity, then dispatches work. How often do you really see in userland multiple threads polling the same set of fds, then fighting to decide who will handle raised events?
More likely, you will see "prefork" (start N threads, each with its own ring) or a worker pool (single thread receives events, then dispatches to multiple threads for execution) or even one-thread-per-fd (single thread receives events, then starts new thread for handling).
No, absolutely not. This is exactly not what should/is/will happen.
Quoted 9 lines
You create worker threads to handle to work for the entire program. Look at something like a web server. When creating several queues, how do you distribute all the connections to the different queues? To ensure every connection is handled as quickly as possible you stuff them all in the same queue and then have all threads use this one queue. Whenever an event is posted a thread is woken. _One_ thread. If two events are posted, two threads are woken. In this situation we have a few atomic ops at userlevel to make sure that the two threads don't pick the same event but that's all there is wrt "fighting".
What you really want is if one thread is able to do all the work, only keep that one thread busy. Only wake up other threads when the currently running threads cannot handle the load.
Say you have 8 threads blocked in kevent_wait(). One or more events become available. You wake one thread, and let it run.
If the one thread has done its work and returns to kevent_wait() before its timeslice has run out, deliver the next event(s) (which may already be outstanding) to the same thread, don't wake another one.
If the running thread blocks on say disk i/o, or its timeslice runs out, the scheduler runs and wakes another thread that is waiting in kevent_wait().
Mike.
Re: [take25 1/6] kevent: Description.
In reply to Jeff GarzikQuoted 7 lines · Jeff Garzik
I'm really wondering is designing for N-threads-to-1-ring is the wisest choice?
Considering current designs, it seems more likely that a single thread polls for socket activity, then dispatches work. How often do you really see in userland multiple threads polling the same set of fds, then fighting to decide who will handle raised events?
They should not fight, but gently divide event handling work.
Quoted 2 lines
More likely, you will see "prefork" (start N threads, each with its own ring)
One ring could be more busy than others, leaving all the work to one thread.
Quoted 3 lines
or a worker pool (single thread receives events, then dispatches to multiple threads for execution) or even one-thread-per-fd (single thread receives events, then starts new thread for handling).
This is more like fighting :-)
It adds context switches and therefore extra latency for event handling.
Quoted 3 lines
If you have multiple threads accessing the same ring -- a poor design choice -- I would think the burden should be on the application, to provide proper synchronization.
Comming from the HPC world I do not agree. Context switches should be avoided. This paper is a good example from the HPC world:
http://cobweb.ecn.purdue.edu/~vpai/Publications/majumder-lacsi04.pdf.
The latency problems introduced by context switches in this work calls for even more functionality in event handling. I will not go into details now. There are enough problems with kevent's current feature set and I believe these extra features can be added later without breaking the API.
--
Hans Henrik Happe
Re: [take25 1/6] kevent: Description.
In reply to Ulrich DrepperQuoted 20 lines · Ulrich Drepper
Documentation/kevent.txt line 108
Quoted 2 lines · Evgeniy Polyakov
+ int kevent_commit(int
ctl_fd, unsigned int start,Documentation/kevent.txt new file +1
-0+ unsigned int num, unsigned int over);I think we can simplify this interface:
int kevent_commit(int
ctl_fd, unsigned intnew_tail,unsigned int over);The kernel sets the
ring_uidxvalue to the 'new_tail' value if the tail pointer would be incremented (module wrap around) and is not higher then the current front pointer. The test will be a bit complicated but not more so than what the current code has to do to check for mistakes.This approach has the advantage that the commit calls don't have to be synchronized. If one thread sets the tail pointer to, say, 10 and another to 12, then it does not matter whether the first thread is delayed. If it will eventually be executed the result is simply a no-op and since second thread's action supersedes it.
Quoted 5 lines
Maybe the current form is even impossible to use with explicit locking at userlevel. What if one thread, which is about to call
kevent_commit, if indefinitely delayed. Then this commit request's value is never taken into account and the tail pointer is always short of what it should be.
I like this interface, although current one does not allow special synchronization in userspace, since it calculates if new commit is in the area where previous commit was.
Will change for the next release.
Quoted 8 lines
There is one more thing to consider. Oftentimes the commit request will be immediately followed by a
kevent_waitcall. It would be good to merge this pair of calls. The two parametersnew_tailand over could also be passed to thekevent_waitcall and the commit can happen before the thread looks for new events and eventually goes to sleep. If this can be implemented then thekevent_commitsyscall by itself might not be needed at all. Instead you'd callkevent_wait()and make the maximum number of events which can be returned zero.
It _IS_ how previous interface worked.
EXACTLY!
There was one syscall which committed requested number of events and waited when there are new ready events. The only thing it missed, was userspace index (it assumed that if userspace waits for something, then all previous work is done).
Ulrich, I'm not going to think for other people all over the world and blindly implementing ideas, which in a day or two will be commented as redundant, since flow of mind has changed, and they had not enough time to check previous version.
I will wait for some time until you and other people made theirs comments on interfaces and release final version in about a week, and now I will go to hack netchannels.
NO INTERFACE CHANGES AFTER THAT DAY.
COMPLETELY.
So, feel free to think about perfect interface anyone will be happy with. But please release your thoughts not in form of abstract words, but more precisely, at least like in this e-mail, so I could understand what _you_ want from _your_ interface.
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
Quoted 21 lines · Evgeniy Polyakov
Quoted 20 lines · Ulrich Drepper
Documentation/kevent.txt line 108
Quoted 2 lines · Evgeniy Polyakov
+ int kevent_commit(int
ctl_fd, unsigned int start,Documentation/kevent.txt new file +1
-0+ unsigned int num, unsigned int over);I think we can simplify this interface:
int kevent_commit(int
ctl_fd, unsigned intnew_tail,unsigned int over);The kernel sets the
ring_uidxvalue to the 'new_tail' value if the tail pointer would be incremented (module wrap around) and is not higher then the current front pointer. The test will be a bit complicated but not more so than what the current code has to do to check for mistakes.This approach has the advantage that the commit calls don't have to be synchronized. If one thread sets the tail pointer to, say, 10 and another to 12, then it does not matter whether the first thread is delayed. If it will eventually be executed the result is simply a no-op and since second thread's action supersedes it.
Quoted 7 lines
Quoted 5 lines
Maybe the current form is even impossible to use with explicit locking at userlevel. What if one thread, which is about to call
kevent_commit, if indefinitely delayed. Then this commit request's value is never taken into account and the tail pointer is always short of what it should be.I like this interface, although current one does not allow special
...does not require...
Quoted 3 lines
synchronization in userspace, since it calculates if new commit is in the area where previous commit was.
Will change for the next release.
Signature · 1 line
Evgeniy Polyakov
Re: [take25 1/6] kevent: Description.
In reply to Evgeniy PolyakovQuoted 3 lines · Evgeniy Polyakov
It _IS_ how previous interface worked.
EXACTLY!
No, the old interface committed everything not only up to a given index.
This is the huge difference which makes or breaks it.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [take25 1/6] kevent: Description.
Quoted 7 lines · Ulrich Drepper
Quoted 3 lines · Evgeniy Polyakov
It _IS_ how previous interface worked.
EXACTLY!
No, the old interface committed everything not only up to a given index.
This is the huge difference which makes or breaks it.
Interface was the same - logic behind it was differnet, the only thing required was to add consumer's index - that is all, no need to change a lot of declarations, userspace and so on - just use existing interface and extend its functionality.
But it does not matter anymore, later this week I will collect all proposed changes and implement (hopefully) last release, which will close most of the questions regarding userspace interfaces (except signal mask, it is in fluent state), so we could concentrate on internals and/or new kernel users.
Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
Evgeniy Polyakov
cover kevent: Generic event handling mechanism.
In reply to a message not in the archiveGeneric event handling mechanism.
Kevent is a generic subsytem which allows to handle event notifications. It supports both level and edge triggered events. It is similar to poll/epoll in some cases, but it is more scalable, it is faster and allows to work with essentially eny kind of events.
Events are provided into kernel through control syscall and can be read back through ring buffer or using usual syscalls.
Kevent update (i.e. readiness switching) happens directly from internals of the appropriate state machine of the underlying subsytem (like network, filesystem, timer or any other).
Homepage:
http://tservice.net.ru/~s0mbre/old/?section=projects&item=kevent
Documentation page (will update Dec 1):
http://linux-net.osdl.org/index.php/Kevent
I installed slightly used, but still functional (bought on ebay) remote mind reader, and set it up to read Ulrich's alpha brain waves (I hope he agrees that it is a good decision), which took me the whole week. So I think the last ring buffer implementation is what we all wanted. Details in documentation part.
It seems that setup was correct and we finially found what we wanted from interface part.
Changes from 'take35' patchset:
* use timespec as timeout parameter.
* added high-resolution timer to handle absolute timeouts.
* added flags to waiting and initialization syscalls.
* kevent_commit() has new_uidx parameter.
* kevent_wait() has old_uidx parameter, which, if not equal to u->uidx, results in immediate wakeup (usefull for the case when entries
are added asynchronously from kernel (not supported for now)).
* added interface to mark any event as ready.
* event POSIX timers support.
* return -ENOSYS if there is no registered event type.
* provided file descriptor must be checked for fifo type (spotted by Eric Dumazet).
* documentation update.
* lighttpd patch updated (the latest benchmarks with lighttpd patch can be found in blog).
Changes from 'take24' patchset:
* new (old (new)) ring buffer implementation with kernel and user indexes.
* added initialization syscall instead of opening /dev/kevent
* kevent_commit() syscall to commit ring buffer entries
* changed KEVENT_REQ_WAKEUP_ONE flag to KEVENT_REQ_WAKEUP_ALL, kevent wakes only first thread always if that flag is not set
* KEVENT_REQ_ALWAYS_QUEUE flag. If set, kevent will be queued into ready queue instead of copying back to userspace when kevent is ready immediately when it is added.
* lighttpd patch (Hail! Although nothing really outstanding compared to epoll)
Changes from 'take23' patchset:
* kevent PIPE notifications
* KEVENT_REQ_LAST_CHECK flag, which allows to perform last check at dequeueing time
* fixed poll/select notifications (were broken due to tree manipulations)
* made Documentation/kevent.txt look nice in 80-col terminal
* fix for copy_to_user() failure report for the first kevent (Andrew Morton)
* minor function renames
Changes from 'take22' patchset:
* new ring buffer implementation in process' memory
* wakeup-one-thread flag
* edge-triggered behaviour
Changes from 'take21' patchset:
* minor cleanups (different return values, removed unneded variables, whitespaces and so on)
* fixed bug in kevent removal in case when kevent being removed
is the same as overflow_kevent (spotted by Eric Dumazet)
Changes from 'take20' patchset:
* new ring buffer implementation
* removed artificial limit on possible number of kevents
Changes from 'take19' patchset:
* use __init instead of __devinit
* removed 'default N' from config for user statistic
* removed kevent_user_fini() since kevent can not be unloaded
* use KERN_INFO for statistic output
Changes from 'take18' patchset:
* use __init instead of __devinit
* removed 'default N' from config for user statistic
* removed kevent_user_fini() since kevent can not be unloaded
* use KERN_INFO for statistic output
Changes from 'take17' patchset:
* Use RB tree instead of hash table.
At least for a web sever, frequency of addition/deletion of new kevent is comparable with number of search access, i.e. most of the time events are added, accesed only couple of times and then removed, so it justifies RB tree usage over AVL tree, since the latter does have much slower deletion time (max O(log(N)) compared to 3 ops),
although faster search time (1.44*O(log(N)) vs. 2*O(log(N))).
So for kevents I use RB tree for now and later, when my AVL tree implementation is ready, it will be possible to compare them.
* Changed readiness check for socket notifications.
With both above changes it is possible to achieve more than 3380 req/second compared to 2200, sometimes 2500 req/second for epoll() for trivial web-server and httperf client on the same hardware.
It is possible that above kevent limit is due to maximum allowed kevents in a time limit, which is 4096 events.
Changes from 'take16' patchset:
* misc cleanups (__read_mostly, const ...)
* created special macro which is used for mmap size (number of pages) calculation
* export kevent_socket_notify(), since it is used in network protocols which can be built as modules (IPv6 for example)
Changes from 'take15' patchset:
* converted kevent_timer to high-resolution timers, this forces timer API update at
http://linux-net.osdl.org/index.php/Kevent
* use struct ukevent* instead of void * in syscalls (documentation has been updated)
* added warning in kevent_add_ukevent() if ring has broken index (for testing)
Changes from 'take14' patchset:
* added kevent_wait()
This syscall waits until either timeout expires or at least one event becomes ready. It also commits that @num events from @start are processed by userspace and thus can be be removed or rearmed (depending on it's flags). It can be used for commit events read by userspace through mmap interface. Example userspace code (evtest.c) can be found on project's homepage.
* added socket notifications (send/recv/accept)
Changes from 'take13' patchset:
* do not get lock aroung user data check in __kevent_search()
* fail early if there were no registered callbacks for given type of kevent
* trailing whitespace cleanup
Changes from 'take12' patchset:
* remove non-chardev interface for initialization
* use pointer to kevent_mring instead of unsigned longs
* use aligned 64bit type in raw user data (can be used by high-res timer if needed)
* simplified enqueue/dequeue callbacks and kevent initialization
* use nanoseconds for timeout
* put number of milliseconds into timer's return data
* move some definitions into user-visible header
* removed filenames from comments
Changes from 'take11' patchset:
* include missing headers into patchset
* some trivial code cleanups (use goto instead of if/else games and so on)
* some whitespace cleanups
* check for ready_callback() callback before main loop which should save us some ticks
Changes from 'take10' patchset:
* removed non-existent prototypes
* added helper function for kevent_registered_callbacks
* fixed 80 lines comments issues
* added shared between userspace and kernelspace header instead of embedd them in one
* core restructuring to remove forward declarations
* s o m e w h i t e s p a c e c o d y n g s t y l e c l e a n u p
* use vm_insert_page() instead of remap_pfn_range()
Changes from 'take9' patchset:
* fixed ->nopage method
Changes from 'take8' patchset:
* fixed mmap release bug
* use module_init() instead of late_initcall()
* use better structures for timer notifications
Changes from 'take7' patchset:
* new mmap interface (not tested, waiting for other changes to be acked)
- use nopage() method to dynamically substitue pages
- allocate new page for events only when new added kevent requres it
- do not use ugly index dereferencing, use structure instead
- reduced amount of data in the ring (id and flags), maximum 12 pages on x86 per kevent fd
Changes from 'take6' patchset:
* a lot of comments!
* do not use list poisoning for detection of the fact, that entry is in the list
* return number of ready kevents even if copy*user() fails
* strict check for number of kevents in syscall
* use ARRAY_SIZE for array size calculation
* changed superblock magic number
* use SLAB_PANIC instead of direct panic() call
* changed -E* return values
* a lot of small cleanups and indent fixes
Changes from 'take5' patchset:
* removed compilation warnings about unused wariables when lockdep is not turned on
* do not use internal socket structures, use appropriate (exported) wrappers instead
* removed default 1 second timeout
* removed AIO stuff from patchset
Changes from 'take4' patchset:
* use miscdevice instead of chardevice
* comments fixes
Changes from 'take3' patchset:
* removed serializing mutex from kevent_user_wait()
* moved storage list processing to RCU
* removed lockdep screaming - all storage locks are initialized in the same function, so it was
learned
to differentiate between various cases
* remove kevent from storage if is marked as broken after callback
* fixed a typo in mmaped buffer implementation which would end up in wrong index calcualtion
Changes from 'take2' patchset:
* split kevent_finish_user() to locked and unlocked variants
* do not use KEVENT_STAT ifdefs, use inline functions instead
* use array of callbacks of each type instead of each kevent callback initialization
* changed name of ukevent guarding lock
* use only one kevent lock in kevent_user for all hash buckets instead of per-bucket locks
* do not use kevent_user_ctl structure instead provide needed arguments as syscall parameters
* various indent cleanups
* added optimisation, which is aimed to help when a lot of kevents are being copied from
userspace
* mapped buffer (initial) implementation (no userspace yet)
Changes from 'take1' patchset:
- rebased against 2.6.18-git tree
- removed ioctl controlling
- added new syscall kevent_get_events(int fd, unsigned int min_nr, unsigned int max_nr, unsigned int timeout, void __user *buf, unsigned flags)
- use old syscall kevent_ctl for creation/removing, modification and initial kevent initialization
- use mutuxes instead of semaphores
- added file descriptor check and return error if provided descriptor does not match kevent file operations
- various indent fixes
- removed aio_sendfile() declarations.
Thank you.
PATCH 1/8 kevent: Description.
Description.
Documentation/kevent.txt new file +240 -0
@@ -0,0 +1,240 @@ +Description. + +int kevent_init(struct kevent_ring *ring, unsigned int ring_size, + unsigned int flags); + +num - size of the ring buffer in events +ring - pointer to allocated ring buffer +flags - various flags, see KEVENT_FLAGS_* definitions. + +Return value: kevent control file descriptor or negative error value. + + struct kevent_ring + { + unsigned int ring_kidx, ring_over; + struct ukevent event[0]; + } + +ring_kidx - index in the ring buffer where kernel will put new events + when kevent_wait() or kevent_get_events() is called +ring_over - number of overflows of ring_uidx happend from the start. + Overflow counter is used to prevent situation when two threads + are going to free the same events, but one of them was scheduled + away for too long, so ring indexes were wrapped, so when that + thread will be awakened, it will free not those events, which + it suppose to free. + +Example userspace code (ring_buffer.c) can be found on project's homepage. + +Each kevent syscall can be so called cancellation point in glibc, i.e. when +thread has been cancelled in kevent syscall, thread can be safely removed +and no events will be lost, since each syscall (kevent_wait() or +kevent_get_events()) will copy event into special ring buffer, accessible +from other threads or even processes (if shared memory is used). + +When kevent is removed (not dequeued when it is ready, but just removed), +even if it was ready, it is not copied into ring buffer, since if it is +removed, no one cares about it (otherwise user would wait until it becomes +ready and got it through usual way using kevent_get_events() or kevent_wait()) +and thus no need to copy it to the ring buffer. + +------------------------------------------------------------------------------- + + +int kevent_ctl(int fd, unsigned int cmd, unsigned int num, struct ukevent *arg); + +fd - is the file descriptor referring to the kevent queue to manipulate. +It is created by opening "/dev/kevent" char device, which is created with +dynamic minor number and major number assigned for misc devices. + +cmd - is the requested operation. It can be one of the following: + KEVENT_CTL_ADD - add event notification + KEVENT_CTL_REMOVE - remove event notification + KEVENT_CTL_MODIFY - modify existing notification + KEVENT_CTL_READY - mark existing events as ready, if number of events is zero, + it just wakes up parked in syscall thread + +num - number of struct ukevent in the array pointed to by arg +arg - array of struct ukevent + +Return value: + number of events processed or negative error value. + +When called, kevent_ctl will carry out the operation specified in the +cmd parameter. +------------------------------------------------------------------------------- + + int kevent_get_events(int ctl_fd, unsigned int min_nr, unsigned int max_nr, + struct timespec timeout, struct ukevent *buf, unsigned flags); + +ctl_fd - file descriptor referring to the kevent queue +min_nr - minimum number of completed events that kevent_get_events will block + waiting for +max_nr - number of struct ukevent in buf +timeout - time to wait before returning less than min_nr + events. If this is -1, then wait forever. +buf - pointer to an array of struct ukevent. +flags - various flags, see KEVENT_FLAGS_* definitions. + +Return value: + number of events copied or negative error value. + +kevent_get_events will wait timeout milliseconds for at least min_nr completed +events, copying completed struct ukevents to buf and deleting any +KEVENT_REQ_ONESHOT event requests. In nonblocking mode it returns as many +events as possible, but not more than max_nr. In blocking mode it waits until +timeout or if at least min_nr events are ready. + +This function copies event into ring buffer if it was initialized, if ring buffer +is full, KEVENT_RET_COPY_FAILED flag is set in ret_flags field. +------------------------------------------------------------------------------- + + int kevent_wait(int ctl_fd, unsigned int num, unsigned int old_uidx, + struct timespec timeout, unsigned int flags); + +ctl_fd - file descriptor referring to the kevent queue +num - number of processed kevents +old_uidx - the last index user is aware of +timeout - time to wait until there is free space in kevent queue +flags - various flags, see KEVENT_FLAGS_* definitions. + +Return value: + number of events copied into ring buffer or negative error value. + +This syscall waits until either timeout expires or at least one event becomes +ready. It also copies events into special ring buffer. If ring buffer is full, +it waits until there are ready events and then return. +If kevent is one-shot kevent it is removed in this syscall. +If kevent is edge-triggered (KEVENT_REQ_ET flag is set in 'req_flags') it is +requeued in this syscall for performance reasons. +------------------------------------------------------------------------------- + + int kevent_commit(int ctl_fd, unsigned int new_idx, unsigned int over); + +ctl_fd - file descriptor referring to the kevent queue +new_uidx - the last committed kevent +over - overflow count for given $new_idx value + +Return value: + number of committed kevents or negative error value. + +This function commits, i.e. marks as empty, slots in the ring buffer, so +they can be reused when userspace completes that entries processing. + +Overflow counter is used to prevent situation when two threads are going +to free the same events, but one of them was scheduled away for too long, +so ring indexes were wrapped, so when that thread will be awakened, it +will free not those events, which it suppose to free. + +It is possible that returned number of committed events will be smaller than +requested number - it is possible when several threads try to commit the +same events. +------------------------------------------------------------------------------- + +The bulk of the interface is entirely done through the ukevent struct. +It is used to add event requests, modify existing event requests, +specify which event requests to remove, and return completed events. + +struct ukevent contains the following members: + +struct kevent_id id + Id of this request, e.g. socket number, file descriptor and so on +__u32 type + Event type, e.g. KEVENT_SOCK, KEVENT_INODE, KEVENT_TIMER and so on +__u32 event + Event itself, e.g. SOCK_ACCEPT, INODE_CREATED, TIMER_FIRED +__u32 req_flags + Per-event request flags, + + KEVENT_REQ_ONESHOT + event will be removed when it is ready + + KEVENT_REQ_WAKEUP_ALL + Kevent wakes up only first thread interested in given event, + or all threads if this flag is set. + + KEVENT_REQ_ET + Edge Triggered behaviour. It is an optimisation which allows to move + ready and dequeued (i.e. copied to userspace) event to move into set + of interest for given storage (socket, inode and so on) again. It is + very usefull for cases when the same event should be used many times + (like reading from pipe). It is similar to epoll()'s EPOLLET flag. + + KEVENT_REQ_LAST_CHECK + if set allows to perform the last check on kevent (call appropriate + callback) when kevent is marked as ready and has been removed from + ready queue. If it will be confirmed that kevent is ready + (k->callbacks.callback(k) returns true) then kevent will be copied + to userspace, otherwise it will be requeued back to storage. + Second (checking) call is performed with this bit cleared, so callback + can detect when it was called from kevent_storage_ready() - bit is set, + or kevent_dequeue_ready() - bit is cleared. If kevent will be requeued, + bit will be set again. + + KEVENT_REQ_ALWAYS_QUEUE + If this flag is set kevent will be queued into ready queue if it is + ready at enqueue time, otherwise it will be copied back to userspace + and will not be queued into the storage. + +__u32 ret_flags + Per-event return flags + + KEVENT_RET_BROKEN + Kevent is broken + + KEVENT_RET_DONE + Kevent processing was finished successfully + + KEVENT_RET_COPY_FAILED + Kevent was not copied into ring buffer due to some error conditions. + +__u32 ret_data + Event return data. Event originator fills it with anything it likes + (for example timer notifications put number of milliseconds when timer + has fired +union { __u32 user[2]; void *ptr; } + User's data. It is not used, just copied to/from user. The whole structure + is aligned to 8 bytes already, so the last union is aligned properly. + +------------------------------------------------------------------------------- + +Kevent waiting syscall flags. + +KEVENT_FLAGS_ABSTIME - provided timespec parameter contains absolute time, + for example Aug 27, 2194, or time(NULL) + 10. + +------------------------------------------------------------------------------- + +Usage + +For KEVENT_CTL_ADD, all fields relevant to the event type must be filled +(id, type, event, req_flags). +After kevent_ctl(..., KEVENT_CTL_ADD, ...) returns each struct's ret_flags +should be checked to see if the event is already broken or done. + +For KEVENT_CTL_MODIFY, the id, req_flags, and user and event fields must be +set and an existing kevent request must have matching id and user fields. If +match is found, req_flags and event are replaced with the newly supplied +values and requeueing is started, so modified kevent can be checked and +probably marked as ready immediately. If a match can't be found, the +passed in ukevent's ret_flags has KEVENT_RET_BROKEN set. KEVENT_RET_DONE is +always set. + +For KEVENT_CTL_REMOVE, the id and user fields must be set and an existing +kevent request must have matching id and user fields. If a match is found, +the kevent request is removed. If a match can't be found, the passed in +ukevent's ret_flags has KEVENT_RET_BROKEN set. KEVENT_RET_DONE is always set. + +For kevent_get_events, the entire structure is returned. + +------------------------------------------------------------------------------- + +Usage cases + +kevent_timer +struct ukevent should contain following fields: + type - KEVENT_TIMER + event - KEVENT_TIMER_FIRED + req_flags - KEVENT_REQ_ONESHOT if you want to fire that timer only once + id.raw[0] - number of seconds after commit when this timer shout expire + id.raw[0] - additional to number of seconds number of nanoseconds
PATCH 2/8 kevent: Core files.
Core files.
This patch includes core kevent files:
* userspace controlling
* kernelspace interfaces
* initialization
* notification state machines
Some bits of documentation can be found on project's homepage (and links from there):
http://tservice.net.ru/~s0mbre/old/?section=projects&item=kevent
arch/i386/kernel/syscall_table.S +5 -0
@@ -318,3 +318,8 @@ ENTRY(sys_call_table) .long sys_vmsplice .long sys_move_pages .long sys_getcpu + .long sys_kevent_get_events + .long sys_kevent_ctl /* 320 */ + .long sys_kevent_wait + .long sys_kevent_commit + .long sys_kevent_init
arch/x86_64/ia32/ia32entry.S +6 -1
@@ -714,8 +714,13 @@ ia32_sys_call_table: .quad compat_sys_get_robust_list .quad sys_splice .quad sys_sync_file_range - .quad sys_tee + .quad sys_tee /* 315 */ .quad compat_sys_vmsplice .quad compat_sys_move_pages .quad sys_getcpu + .quad sys_kevent_get_events + .quad sys_kevent_ctl /* 320 */ + .quad sys_kevent_wait + .quad sys_kevent_commit + .quad sys_kevent_init ia32_syscall_end:
include/asm-i386/unistd.h +6 -1
@@ -324,10 +324,15 @@#define __NR_vmsplice 316#define __NR_move_pages 317#define __NR_getcpu 318 +#define __NR_kevent_get_events 319 +#define __NR_kevent_ctl 320 +#define __NR_kevent_wait 321 +#define __NR_kevent_commit 322 +#define __NR_kevent_init 323#ifdef __KERNEL__ -#define NR_syscalls 319 +#define NR_syscalls 324#include <linux/err.h> /*
include/asm-x86_64/unistd.h +11 -1
@@ -619,10 +619,20 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_kevent_get_events 280 +__SYSCALL(__NR_kevent_get_events, sys_kevent_get_events) +#define __NR_kevent_ctl 281 +__SYSCALL(__NR_kevent_ctl, sys_kevent_ctl) +#define __NR_kevent_wait 282 +__SYSCALL(__NR_kevent_wait, sys_kevent_wait) +#define __NR_kevent_commit 283 +__SYSCALL(__NR_kevent_commit, sys_kevent_commit) +#define __NR_kevent_init 284 +__SYSCALL(__NR_kevent_init, sys_kevent_init)#ifdef __KERNEL__ -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_kevent_init#include <linux/err.h> #ifndef __NO_STUBS
include/linux/kevent.h new file +238 -0
238 lines not on this page · raw message
include/linux/kevent_storage.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __KEVENT_STORAGE_H +#define __KEVENT_STORAGE_H + +struct kevent_storage +{ +void *origin;/* Originator's pointer, e.g. struct sock or struct file. Can be NULL. */ +struct list_head list;/* List of queued kevents. */ +spinlock_t lock;/* Protects users queue. */ +}; + +#endif /* __KEVENT_STORAGE_H */
include/linux/syscalls.h +9 -0
@@ -54,6 +54,8 @@ struct compat_stat;struct compat_timeval ;struct robust_list_head ;struct getcpu_cache ; +struct ukevent ; +struct kevent_ring ;#include <linux/types.h> #include <linux/aio_abi.h>
@@ -599,4 +601,11 @@ asmlinkage long sys_set_robust_list(stru size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_kevent_get_events (int ctl_fd,unsigned int min,unsigned int max, +struct timespec timeout,struct ukevent __user *buf,unsigned flags); +asmlinkage long sys_kevent_ctl (int ctl_fd,unsigned int cmd,unsigned int num,struct ukevent __user *buf); +asmlinkage long sys_kevent_wait (int ctl_fd,unsigned int num,unsigned int old_uidx, +struct timespec timeout,unsigned int flags); +asmlinkage long sys_kevent_commit (int ctl_fd,unsigned int new_uidx,unsigned int over); +asmlinkage long sys_kevent_init (int ctl_fd,struct kevent_ring __user *ring,unsigned int num,unsigned int flags);#endif
include/linux/ukevent.h new file +183 -0
183 lines not on this page · raw message
init/Kconfig +2 -0
@@ -201,6 +201,8 @@ config AUDITSYSCALL such as SELinux. To use audit's filesystem watch feature, please ensure that INOTIFY is configured. +source "kernel/kevent/Kconfig" + config IKCONFIG bool "Kernel .config support" ---help---
kernel/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_DETECT_SOFTLOCKUP) += softl obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ obj-$(CONFIG_SECCOMP) += seccomp.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o +obj-$(CONFIG_KEVENT) += kevent/ obj-$(CONFIG_RELAY) += relay.o obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o obj-$(CONFIG_TASKSTATS) += taskstats.o
kernel/kevent/Kconfig new file +60 -0
60 lines not on this page · raw message
kernel/kevent/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +obj-y := kevent.o kevent_user.o +obj-$(CONFIG_KEVENT_TIMER) += kevent_timer.o +obj-$(CONFIG_KEVENT_POLL) += kevent_poll.o +obj-$(CONFIG_KEVENT_SOCKET) += kevent_socket.o +obj-$(CONFIG_KEVENT_PIPE) += kevent_pipe.o +obj-$(CONFIG_KEVENT_SIGNAL) += kevent_signal.o
kernel/kevent/kevent.c new file +247 -0
247 lines not on this page · raw message
kernel/kevent/kevent_user.c new file +1344 -0
1,344 lines not on this page · raw message
kernel/sys_ni.c +6 -0
@@ -122,6 +122,12 @@ cond_syscall(ppc_rtas);cond_syscall (sys_spu_run);cond_syscall (sys_spu_create); +cond_syscall (sys_kevent_get_events); +cond_syscall (sys_kevent_ctl); +cond_syscall (sys_kevent_wait); +cond_syscall (sys_kevent_commit); +cond_syscall (sys_kevent_init); +/* mmu depending weak syscall entries */ cond_syscall (sys_mprotect);cond_syscall (sys_msync);
PATCH 3/8 kevent: poll/select() notifications.
poll/select() notifications.
This patch includes generic poll/select notifications. kevent_poll works simialr to epoll and has the same issues (callback is invoked not from internal state machine of the caller, but through process awake, a lot of allocations and so on).
fs/file_table.c +3 -0
@@ -20,6 +20,7 @@#include <linux/cdev.h> #include <linux/fsnotify.h> #include <linux/sysctl.h> +#include <linux/kevent.h> #include <linux/percpu_counter.h> #include <asm/atomic.h>
@@ -119,6 +120,7 @@ struct file *get_empty_filp(void) f->f_uid = tsk->fsuid; f->f_gid = tsk->fsgid;eventpoll_init_file (f); +kevent_init_file (f);/* f->f_version: 0 */ return f;
@@ -164,6 +166,7 @@ void fastcall __fput(struct file *file)* in the file cleanup chain. */ eventpoll_release (file); +kevent_cleanup_file (file);locks_remove_flock (file);if (file->f_op && file->f_op->release)
include/linux/fs.h +8 -0
@@ -276,6 +276,7 @@ extern int dir_notify_enable;#include <linux/init.h> #include <linux/sched.h> #include <linux/mutex.h> +#include <linux/kevent_storage.h> #include <asm/atomic.h> #include <asm/semaphore.h>
@@ -586,6 +587,10 @@ struct inode {struct mutex inotify_mutex;/* protects the watches list */ #endif +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +struct kevent_storage st; +#endif +unsigned long i_state;unsigned long dirtied_when;/* jiffies of first dirtying */
@@ -739,6 +744,9 @@ struct file {struct list_head f_ep_links;spinlock_t f_ep_lock;#endif /* #ifdef CONFIG_EPOLL */ +#ifdef CONFIG_KEVENT_POLL +struct kevent_storage st; +#endif struct address_space *f_mapping; };extern spinlock_t files_lock;
kernel/kevent/kevent_poll.c new file +232 -0
232 lines not on this page · raw message
PATCH 4/8 kevent: Socket notifications.
Socket notifications.
This patch includes socket send/recv/accept notifications. Using trivial web server based on kevent and this features instead of epoll it's performance increased more than noticebly. More details about various benchmarks and server itself (evserver_kevent.c) can be found on project's homepage.
fs/inode.c +7 -0
@@ -21,6 +21,7 @@#include <linux/cdev.h> #include <linux/bootmem.h> #include <linux/inotify.h> +#include <linux/kevent.h> #include <linux/mount.h> /*
@@ -164,12 +165,18 @@ static struct inode *alloc_inode(struct } inode->i_private =0 ; inode->i_mapping = mapping; +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_init (inode, &inode->st); +#endif }return inode; }void destroy_inode (struct inode *inode) { +#if definedCONFIG_KEVENT_SOCKET || definedCONFIG_KEVENT_PIPE +kevent_storage_fini (&inode->st); +#endif BUG_ON (inode_has_buffers (inode));security_inode_free (inode);if (inode->i_sb->s_op->destroy_inode)
include/net/sock.h +17 -15
@@ -48,6 +48,7 @@#include <linux/netdevice.h> #include <linux/skbuff.h> /* struct sk_buff */ #include <linux/security.h> +#include <linux/kevent.h> #include <linux/filter.h>
@@ -450,6 +451,21 @@ static inline int sk_stream_memory_free(extern void sk_stream_rfree (struct sk_buff *skb); +struct socket_alloc { +struct socket socket; +struct inode vfs_inode; +}; + +static inline struct socket *SOCKET_I (struct inode *inode) +{ + return &container_of(inode, struct socket_alloc, vfs_inode)->socket; +} + +static inline struct inode *SOCK_INODE (struct socket *socket) +{ + return &container_of(socket, struct socket_alloc, socket)->vfs_inode; +} +static inline void sk_stream_set_owner_r (struct sk_buff *skb,struct sock *sk) { skb->sk = sk;
@@ -477,6 +493,7 @@ static inline void sk_add_backlog(struct sk->sk_backlog.tail = skb; } skb->next =NULL ; +kevent_socket_notify (sk,KEVENT_SOCKET_RECV ); }#define sk_wait_event (__sk, __timeo, __condition) \
@@ -679,21 +696,6 @@ static inline struct kiocb *siocb_to_kioreturn si->kiocb; } -struct socket_alloc { -struct socket socket; -struct inode vfs_inode; -}; - -static inline struct socket *SOCKET_I (struct inode *inode) -{ - return &container_of(inode, struct socket_alloc, vfs_inode)->socket; -} - -static inline struct inode *SOCK_INODE (struct socket *socket) -{ - return &container_of(socket, struct socket_alloc, socket)->vfs_inode; -} -extern void __sk_stream_mem_reclaim (struct sock *sk);extern int sk_stream_mem_schedule (struct sock *sk,int size,int kind);
include/net/tcp.h +1 -0
@@ -857,6 +857,7 @@ static inline int tcp_prequeue(struct so tp->ucopy.memory =0 ; }else if (skb_queue_len (&tp->ucopy.prequeue) ==1 ) {wake_up_interruptible (sk->sk_sleep); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND );if (!inet_csk_ack_scheduled (sk)) inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, (3 * TCP_RTO_MIN) / 4,
kernel/kevent/kevent_socket.c new file +142 -0
142 lines not on this page · raw message
net/core/sock.c +9 -1
@@ -1402,6 +1402,7 @@ static void sock_def_wakeup(struct sockif (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible_all (sk->sk_sleep);read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_error_report (struct sock *sk)
@@ -1411,6 +1412,7 @@ static void sock_def_error_report(structwake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,0 ,POLL_ERR );read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_readable (struct sock *sk,int len)
@@ -1420,6 +1422,7 @@ static void sock_def_readable(struct socwake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,1 ,POLL_IN );read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); }static void sock_def_write_space (struct sock *sk)
@@ -1439,6 +1442,7 @@ static void sock_def_write_space(struct }read_unlock (&sk->sk_callback_lock); +kevent_socket_notify (sk,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV ); }static void sock_def_destruct (struct sock *sk)
@@ -1489,6 +1493,8 @@ void sock_init_data(struct socket *sock, sk->sk_state =TCP_CLOSE ; sk->sk_socket = sock; +kevent_sk_reinit (sk); +sock_set_flag (sk,SOCK_ZAPPED );if (sock)
@@ -1555,8 +1561,10 @@ void fastcall release_sock(struct sock *if (sk->sk_backlog.tail)__release_sock (sk); sk->sk_lock.owner =NULL ; -if (waitqueue_active (&sk->sk_lock.wq)) +if (waitqueue_active (&sk->sk_lock.wq)) {wake_up (&sk->sk_lock.wq); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV |KEVENT_SOCKET_SEND ); + }spin_unlock_bh (&sk->sk_lock.slock); }EXPORT_SYMBOL (release_sock);
net/core/stream.c +1 -0
@@ -36,6 +36,7 @@ void sk_stream_write_space(struct sock *wake_up_interruptible (sk->sk_sleep);if (sock->fasync_list && !(sk->sk_shutdown &SEND_SHUTDOWN ))sock_wake_async (sock,2 ,POLL_OUT ); +kevent_socket_notify (sk,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV ); } }
net/ipv4/tcp_input.c +1 -0
@@ -3119,6 +3119,7 @@ static void tcp_ofo_queue(struct sock *s__skb_unlink (skb, &tp->out_of_order_queue);__skb_queue_tail (&sk->sk_receive_queue, skb); +kevent_socket_notify (sk,KEVENT_SOCKET_RECV ); tp->rcv_nxt =TCP_SKB_CB (skb)->end_seq;if (skb->h.th->fin)tcp_fin (skb, sk, skb->h.th);
net/ipv4/tcp_ipv4.c +2 -0
@@ -61,6 +61,7 @@#include <linux/jhash.h> #include <linux/init.h> #include <linux/times.h> +#include <linux/kevent.h> #include <net/icmp.h> #include <net/inet_hashtables.h>
@@ -870,6 +871,7 @@ int tcp_v4_conn_request(struct sock *sk,reqsk_free (req); }else {inet_csk_reqsk_queue_hash_add (sk, req,TCP_TIMEOUT_INIT ); +kevent_socket_notify (sk,KEVENT_SOCKET_ACCEPT ); }return 0 ;
net/socket.c +3 -0
@@ -85,6 +85,7 @@#include <linux/kmod.h> #include <linux/audit.h> #include <linux/wireless.h> +#include <linux/kevent.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -490,6 +491,8 @@ static struct socket *sock_alloc(void) inode->i_uid = current->fsuid; inode->i_gid = current->fsgid; +kevent_socket_reinit (sock); +get_cpu_var (sockets_in_use)++;put_cpu_var (sockets_in_use);return sock;
PATCH 5/8 kevent: Timer notifications.
Timer notifications.
Timer notifications can be used for fine grained per-process time management, since interval timers are very inconvenient to use, and they are limited.
This subsystem uses high-resolution timers.
id.raw[0] is used as number of seconds
id.raw[1] is used as number of nanoseconds
kernel/kevent/kevent_timer.c new file +112 -0
@@ -0,0 +1,112 @@ +/* +* 2006 Copyright (c) Evgeniy Polyakov <[email protected]> +* All rights reserved. +* +* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/hrtimer.h> +#include <linux/jiffies.h> +#include <linux/kevent.h> + +struct kevent_timer +{ +struct hrtimer ktimer; +struct kevent_storage ktimer_storage; +struct kevent *ktimer_event; +}; + +static int kevent_timer_func (struct hrtimer *timer) +{ + struct kevent_timer *t = container_of(timer, struct kevent_timer, ktimer); +struct kevent *k = t->ktimer_event; + +kevent_storage_ready (&t->ktimer_storage,NULL ,KEVENT_MASK_ALL ); +hrtimer_forward (timer, timer->base->softirq_time, +ktime_set (k->event.id.raw[0 ], k->event.id.raw[1 ])); +return HRTIMER_RESTART ; +} + +static struct lock_class_key kevent_timer_key; + +static int kevent_timer_enqueue (struct kevent *k) +{ +int err; +struct kevent_timer *t; + + t =kmalloc (sizeof (struct kevent_timer ),GFP_KERNEL ); +if (!t) +return -ENOMEM ; + +hrtimer_init (&t->ktimer,CLOCK_MONOTONIC ,HRTIMER_REL ); + t->ktimer.expires =ktime_set (k->event.id.raw[0 ], k->event.id.raw[1 ]); + t->ktimer.function = kevent_timer_func; + t->ktimer_event = k; + + err =kevent_storage_init (&t->ktimer, &t->ktimer_storage); +if (err) + goto err_out_free; +lockdep_set_class (&t->ktimer_storage.lock, &kevent_timer_key); + + err =kevent_storage_enqueue (&t->ktimer_storage, k); +if (err) + goto err_out_st_fini; + +hrtimer_start (&t->ktimer, t->ktimer.expires,HRTIMER_REL ); + +return 0 ; + +err_out_st_fini: +kevent_storage_fini (&t->ktimer_storage); +err_out_free: +kfree (t); + +return err; +} + +static int kevent_timer_dequeue (struct kevent *k) +{ +struct kevent_storage *st = k->st; + struct kevent_timer *t = container_of(st, struct kevent_timer, ktimer_storage); + +hrtimer_cancel (&t->ktimer); +kevent_storage_dequeue (st, k); +kfree (t); + +return 0 ; +} + +static int kevent_timer_callback (struct kevent *k) +{ + k->event.ret_data[0 ] =jiffies_to_msecs (jiffies); +return 1 ; +} + +static int __init kevent_init_timer (void ) +{ +struct kevent_callbacks tc = { + .callback = &kevent_timer_callback, + .enqueue = &kevent_timer_enqueue, + .dequeue = &kevent_timer_dequeue}; + +return kevent_add_callbacks (&tc,KEVENT_TIMER ); +} +module_init (kevent_init_timer); +
PATCH 6/8 kevent: Pipe notifications.
Pipe notifications.
fs/pipe.c +6 -0
@@ -16,6 +16,7 @@#include <linux/uio.h> #include <linux/highmem.h> #include <linux/pagemap.h> +#include <linux/kevent.h> #include <asm/uaccess.h> #include <asm/ioctls.h>
@@ -312,6 +313,7 @@ redo:break ; }if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND );wake_up_interruptible_sync (&pipe->wait);kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
@@ -321,6 +323,7 @@ redo:/* Signal writers asynchronously that there is more room. */ if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND );wake_up_interruptible (&pipe->wait);kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
@@ -490,6 +493,7 @@ redo2:break ; }if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_RECV );wake_up_interruptible_sync (&pipe->wait);kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); do_wakeup =0 ;
@@ -501,6 +505,7 @@ redo2: out:mutex_unlock (&inode->i_mutex);if (do_wakeup) { +kevent_pipe_notify (inode,KEVENT_SOCKET_RECV );wake_up_interruptible (&pipe->wait);kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); }
@@ -605,6 +610,7 @@ pipe_release(struct inode *inode, int defree_pipe_info (inode); }else {wake_up_interruptible (&pipe->wait); +kevent_pipe_notify (inode,KEVENT_SOCKET_SEND |KEVENT_SOCKET_RECV );kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN );kill_fasync (&pipe->fasync_writers,SIGIO ,POLL_OUT ); }
kernel/kevent/kevent_pipe.c new file +121 -0
121 lines not on this page · raw message
PATCH 7/8 kevent: Signal notifications.
Signal notifications.
This type of notifications allows to deliver signals through kevent queue. One can find example application signal.c on project homepage.
If KEVENT_SIGNAL_NOMASK bit is set in raw_u64 id then signal will be delivered only through queue, otherwise both delivery types are used - old through update of mask of pending signals and through queue.
If signal is delivered only through kevent queue mask of pending signals is not updated at all, which is equal to putting signal into blocked mask, but with delivery of that signal through kevent queue.
include/linux/sched.h +5 -0
@@ -80,6 +80,7 @@ struct sched_param {#include <linux/resource.h> #include <linux/timer.h> #include <linux/hrtimer.h> +#include <linux/kevent_storage.h> #include <asm/processor.h>
@@ -1013,6 +1014,10 @@ struct task_struct {#ifdef CONFIG_TASK_DELAY_ACCT struct task_delay_info *delays;#endif +#ifdef CONFIG_KEVENT_SIGNAL +struct kevent_storage st; +u32 kevent_signals; +#endif };static inline pid_t process_group (struct task_struct *tsk)
kernel/fork.c +8 -0
@@ -46,6 +46,7 @@#include <linux/delayacct.h> #include <linux/taskstats_kern.h> #include <linux/random.h> +#include <linux/kevent.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -115,6 +116,9 @@ void __put_task_struct(struct task_strucWARN_ON (atomic_read (&tsk->usage));WARN_ON (tsk == current); +#ifdef CONFIG_KEVENT_SIGNAL +kevent_storage_fini (&tsk->st); +#endif security_task_free (tsk);free_uid (tsk->user);put_group_info (tsk->group_info);
@@ -1121,6 +1125,10 @@ static struct task_struct *copy_process(if (retval) goto bad_fork_cleanup_namespace; +#ifdef CONFIG_KEVENT_SIGNAL +kevent_storage_init (p, &p->st); +#endif + p->set_child_tid = (clone_flags &CLONE_CHILD_SETTID ) ? child_tidptr :NULL ;/* * Clear TID on mm_release()?
kernel/kevent/kevent_signal.c new file +92 -0
92 lines not on this page · raw message
kernel/signal.c +26 -0
@@ -23,6 +23,7 @@#include <linux/ptrace.h> #include <linux/signal.h> #include <linux/capability.h> +#include <linux/kevent.h> #include <asm/param.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -703,6 +704,9 @@ static int send_signal(int sig, struct s {struct sigqueue * q =NULL ;int ret =0 ; + +if (kevent_signal_notify (t, sig)) +return 1 ;/* * fast-pathed signals for kernel-internal things like SIGSTOP
@@ -782,6 +786,17 @@ specific_send_sig_info(int sig, struct s ret =send_signal (sig, info, t, &t->pending);if (!ret && !sigismember (&t->blocked, sig))signal_wake_up (t, sig ==SIGKILL ); +#ifdef CONFIG_KEVENT_SIGNAL +/* +* Kevent allows to deliver signals through kevent queue, +* it is possible to setup kevent to not deliver +* signal through the usual way, in that case send_signal() +* returns 1 and signal is delivered only through kevent queue. +* We simulate successfull delivery notification through this hack: +*/ +if (ret ==1 ) + ret =0 ; +#endif out:return ret; }
@@ -971,6 +986,17 @@ __group_send_sig_info(int sig, struct si* to avoid several races. */ ret =send_signal (sig, info, p, &p->signal->shared_pending); +#ifdef CONFIG_KEVENT_SIGNAL +/* +* Kevent allows to deliver signals through kevent queue, +* it is possible to setup kevent to not deliver +* signal through the usual way, in that case send_signal() +* returns 1 and signal is delivered only through kevent queue. +* We simulate successfull delivery notification through this hack: +*/ +if (ret ==1 ) + ret =0 ; +#endif if (unlikely (ret))return ret;
PATCH 8/8 kevent: Kevent posix timer notifications.
Kevent posix timer notifications.
Simple extensions to POSIX timers which allows
to deliver notification of the timer expiration
through kevent queue.
Example application posix_timer.c can be found
in archive on project homepage.
include/asm-generic/siginfo.h +3 -0
@@ -235,6 +235,7 @@ typedef struct siginfo {#define SIGEV_NONE 1/* other notification: meaningless */ #define SIGEV_THREAD 2/* deliver via thread creation */ #define SIGEV_THREAD_ID 4/* deliver to thread */ +#define SIGEV_KEVENT 8/* deliver through kevent queue */ /* * This works because the alignment is ok on all current architectures
@@ -260,6 +261,8 @@ typedef struct sigevent {void (*_function)(sigval_t );void *_attribute;/* really pthread_attr_t */ } _sigev_thread; + +int kevent_fd; } _sigev_un; } sigevent_t;
include/linux/posix-timers.h +4 -0
@@ -4,6 +4,7 @@#include <linux/spinlock.h> #include <linux/list.h> #include <linux/sched.h> +#include <linux/kevent_storage.h> union cpu_time_count {cputime_t cpu;
@@ -49,6 +50,9 @@ struct k_itimer {sigval_t it_sigev_value;/* value word of sigevent struct */ struct task_struct *it_process;/* process to send signal to */ struct sigqueue *sigq;/* signal queue entry. */ +#ifdef CONFIG_KEVENT_TIMER +struct kevent_storage st; +#endif union { struct { struct hrtimer timer;
kernel/posix-timers.c +168 -48
261 lines not on this page · raw message