Skip to contentSkip to conversation

kevent: Socket notifications.

PATCH New Evgeniy Polyakov 9 participants 68 messages Sep 12, 2006 – Oct 18, 2006 1 message not in the archive

Subsystems (6)
Networking Network drivers VFS TCP +2 more subsystems
lore
Share & tools
lore
#4 lore raw

PATCH 3/4 kevent: Socket notifications.

In reply to Evgeniy Polyakov

Socket notifications.

This patch include 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 benchmark and server itself (evserver_kevent.c) can be found on project's homepage.

fs/inode.c +7 -0
index 0bf9f04..181521d 100644
@@ -21,6 +21,7 @@ #include <linux/pagemap.h>
 #include <linux/cdev.h>
 #include <linux/bootmem.h>
 #include <linux/inotify.h>
+#include <linux/kevent.h>
 #include <linux/mount.h>
 
 /*
@@ -165,12 +166,18 @@ #endif
 		}
 		memset(&inode->u, 0, sizeof(inode->u));
 		inode->i_mapping = mapping;
+#if defined CONFIG_KEVENT_SOCKET
+		kevent_storage_init(inode, &inode->st);
+#endif
 	}
 	return inode;
 }
 
 void destroy_inode(struct inode *inode) 
 {
+#if defined CONFIG_KEVENT_SOCKET
+	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
index 2561020..a697930 100644
@@ -236,6 +236,7 @@ #include <linux/prio_tree.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/mutex.h>
+#include <linux/kevent.h>
 
 #include <asm/atomic.h>
 #include <asm/semaphore.h>
@@ -546,6 +547,10 @@ #ifdef CONFIG_INOTIFY
 	struct mutex		inotify_mutex;	/* protects the watches list */
 #endif
 
+#ifdef CONFIG_KEVENT_SOCKET
+	struct kevent_storage	st;
+#endif
+
 	unsigned long		i_state;
 	unsigned long		dirtied_when;	/* jiffies of first dirtying */
 
@@ -698,6 +703,9 @@ #ifdef CONFIG_EPOLL
 	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;
include/net/sock.h +17 -15
index 324b3ea..5d71ed7 100644
@@ -48,6 +48,7 @@ #include <linux/lockdep.h>
 #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_kio
 	return 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
index 7a093d0..69f4ad2 100644
@@ -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 +126 -0

126 lines not on this page · raw message

net/core/sock.c +9 -1
index 51fcfbc..4f91615 100644
@@ -1406,6 +1406,7 @@ static void sock_def_wakeup(struct sock 
 	if (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)
@@ -1415,6 +1416,7 @@ static void sock_def_error_report(struct
 		wake_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)
@@ -1424,6 +1426,7 @@ static void sock_def_readable(struct soc
 		wake_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)
@@ -1443,6 +1446,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)
@@ -1493,6 +1497,8 @@ #endif
 	sk->sk_state		=	TCP_CLOSE;
 	sk->sk_socket		=	sock;
 
+	kevent_sk_reinit(sk);
+
 	sock_set_flag(sk, SOCK_ZAPPED);
 
 	if(sock)
@@ -1559,8 +1565,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
index d1d7dec..2878c2a 100644
@@ -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
index 104af5d..14cee12 100644
@@ -3112,6 +3112,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
index 4b04c3e..cda1500 100644
@@ -61,6 +61,7 @@ #include <linux/cache.h>
 #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>
@@ -867,6 +868,7 @@ #endif
 	   	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
index b4848ce..42e19e2 100644
@@ -85,6 +85,7 @@ #include <linux/compat.h>
 #include <linux/kmod.h>
 #include <linux/audit.h>
 #include <linux/wireless.h>
+#include <linux/kevent.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -526,6 +527,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;
#5 lore raw

PATCH 4/4 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.

kernel/kevent/kevent_timer.c new file +113 -0
new file mode 100644
index 0000000..04acc46
@@ -0,0 +1,113 @@
+/*
+ * 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;
+
+	printk("%s: jiffies: %lu, timer: %p.\n", __func__, jiffies, &t->ktimer);
+	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);
+
#1 lore raw

cover kevent: Generic event handling mechanism.

In reply to a message not in the archive

Generic event handling mechanism.

Consider for inclusion.

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.

#2 lore raw

PATCH 1/4 kevent: Core files.

Core files.

This patch includes core kevent files:
- userspace controlling
- kernelspace interfaces
- initialization
- notification state machines

arch/i386/kernel/syscall_table.S +3 -0
index dd63d47..c10698e 100644
@@ -317,3 +317,6 @@ ENTRY(sys_call_table)
 	.long sys_tee			/* 315 */
 	.long sys_vmsplice
 	.long sys_move_pages
+	.long sys_kevent_get_events
+	.long sys_kevent_ctl
+	.long sys_kevent_wait		/* 320 */
arch/x86_64/ia32/ia32entry.S +4 -1
index 5d4a7d1..a06b76f 100644
@@ -710,7 +710,10 @@ #endif
 	.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_kevent_get_events
+	.quad sys_kevent_ctl
+	.quad sys_kevent_wait		/* 320 */
 ia32_syscall_end:		
include/asm-i386/unistd.h +4 -1
index fc1c8dd..68072b5 100644
@@ -323,10 +323,13 @@ #define __NR_sync_file_range	314
 #define __NR_tee		315
 #define __NR_vmsplice		316
 #define __NR_move_pages		317
+#define __NR_kevent_get_events	318
+#define __NR_kevent_ctl		319
+#define __NR_kevent_wait	320
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 318
+#define NR_syscalls 321
 
 /*
  * user-visible error numbers are in the range -1 - -128: see
include/asm-x86_64/unistd.h +7 -1
index 94387c9..ee907ad 100644
@@ -619,10 +619,16 @@ #define __NR_vmsplice		278
 __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)
 
 #ifdef __KERNEL__
 
-#define __NR_syscall_max __NR_move_pages
+#define __NR_syscall_max __NR_kevent_wait
 
 #ifndef __NO_STUBS
 
include/linux/kevent.h new file +195 -0

195 lines not on this page · raw message

include/linux/kevent_storage.h new file +11 -0
new file mode 100644
index 0000000..a38575d
@@ -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 +4 -0
index 008f04c..9d4690f 100644
@@ -597,4 +597,8 @@ asmlinkage long sys_get_robust_list(int 
 asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
 				    size_t len);
 
+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 start, unsigned int num, __u64 timeout);
 #endif
include/linux/ukevent.h new file +159 -0

159 lines not on this page · raw message

init/Kconfig +2 -0
index a099fc6..c550fcc 100644
@@ -218,6 +218,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
index d62ec66..2d7a6dd 100644
@@ -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 +40 -0
new file mode 100644
index 0000000..85ad472
@@ -0,0 +1,40 @@
+config KEVENT
+	bool "Kernel event notification mechanism"
+	help
+	  This option enables event queue mechanism.
+	  It can be used as replacement for poll()/select(), AIO callback
+	  invocations, advanced timer notifications and other kernel
+	  object status changes.
+
+config KEVENT_USER_STAT
+	bool "Kevent user statistic"
+	depends on KEVENT
+	default N
+	help
+	  This option will turn kevent_user statistic collection on.
+	  Statistic data includes total number of kevent, number of kevents
+	  which are ready immediately at insertion time and number of kevents
+	  which were removed through readiness completion.
+	  It will be printed each time control kevent descriptor is closed.
+
+config KEVENT_TIMER
+	bool "Kernel event notifications for timers"
+	depends on KEVENT
+	help
+	  This option allows to use timers through KEVENT subsystem.
+
+config KEVENT_POLL
+	bool "Kernel event notifications for poll()/select()"
+	depends on KEVENT
+	help
+	  This option allows to use kevent subsystem for poll()/select()
+	  notifications.
+
+config KEVENT_SOCKET
+	bool "Kernel event notifications for sockets"
+	depends on NET && KEVENT
+	help
+	  This option enables notifications through KEVENT subsystem of 
+	  sockets operations, like new packet receiving conditions, 
+	  ready for accept conditions and so on.
+	
kernel/kevent/Makefile new file +4 -0
new file mode 100644
index 0000000..9130cad
@@ -0,0 +1,4 @@
+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
kernel/kevent/kevent.c new file +227 -0

227 lines not on this page · raw message

kernel/kevent/kevent_user.c new file +961 -0

961 lines not on this page · raw message

kernel/sys_ni.c +4 -0
index 6991bec..564e618 100644
@@ -122,6 +122,10 @@ cond_syscall(ppc_rtas);
 cond_syscall(sys_spu_run);
 cond_syscall(sys_spu_create);
 
+cond_syscall(sys_kevent_get_events);
+cond_syscall(sys_kevent_wait);
+cond_syscall(sys_kevent_ctl);
+
 /* mmu depending weak syscall entries */
 cond_syscall(sys_mprotect);
 cond_syscall(sys_msync);
#3 lore raw

PATCH 2/4 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.).

include/linux/fs.h +8 -0
index 2561020..a697930 100644
@@ -236,6 +236,7 @@ #include <linux/prio_tree.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/mutex.h>
+#include <linux/kevent.h>
 
 #include <asm/atomic.h>
 #include <asm/semaphore.h>
@@ -546,6 +547,10 @@ #ifdef CONFIG_INOTIFY
 	struct mutex		inotify_mutex;	/* protects the watches list */
 #endif
 
+#ifdef CONFIG_KEVENT_SOCKET
+	struct kevent_storage	st;
+#endif
+
 	unsigned long		i_state;
 	unsigned long		dirtied_when;	/* jiffies of first dirtying */
 
@@ -698,6 +703,9 @@ #ifdef CONFIG_EPOLL
 	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 +222 -0

222 lines not on this page · raw message

#8 lore raw

PATCH 2/4 kevent: poll/select() notifications.

In reply to Evgeniy Polyakov

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.).

include/linux/fs.h +8 -0
index 2561020..a697930 100644
@@ -236,6 +236,7 @@ #include <linux/prio_tree.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/mutex.h>
+#include <linux/kevent.h>
 
 #include <asm/atomic.h>
 #include <asm/semaphore.h>
@@ -546,6 +547,10 @@ #ifdef CONFIG_INOTIFY
 	struct mutex		inotify_mutex;	/* protects the watches list */
 #endif
 
+#ifdef CONFIG_KEVENT_SOCKET
+	struct kevent_storage	st;
+#endif
+
 	unsigned long		i_state;
 	unsigned long		dirtied_when;	/* jiffies of first dirtying */
 
@@ -698,6 +703,9 @@ #ifdef CONFIG_EPOLL
 	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 +222 -0

222 lines not on this page · raw message

#6 lore raw

cover kevent: Generic event handling mechanism.

In reply to a message not in the archive

Generic event handling mechanism.

Consider for inclusion.

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.

#10 lore raw

PATCH 4/4 kevent: Timer notifications.

In reply to Evgeniy Polyakov

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.

kernel/kevent/kevent_timer.c new file +113 -0
new file mode 100644
index 0000000..04acc46
@@ -0,0 +1,113 @@
+/*
+ * 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;
+
+	printk("%s: jiffies: %lu, timer: %p.\n", __func__, jiffies, &t->ktimer);
+	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);
+
#9 lore raw

PATCH 3/4 kevent: Socket notifications.

In reply to Evgeniy Polyakov

Socket notifications.

This patch include 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 benchmark and server itself (evserver_kevent.c) can be found on project's homepage.

fs/inode.c +7 -0
index 0bf9f04..181521d 100644
@@ -21,6 +21,7 @@ #include <linux/pagemap.h>
 #include <linux/cdev.h>
 #include <linux/bootmem.h>
 #include <linux/inotify.h>
+#include <linux/kevent.h>
 #include <linux/mount.h>
 
 /*
@@ -165,12 +166,18 @@ #endif
 		}
 		memset(&inode->u, 0, sizeof(inode->u));
 		inode->i_mapping = mapping;
+#if defined CONFIG_KEVENT_SOCKET
+		kevent_storage_init(inode, &inode->st);
+#endif
 	}
 	return inode;
 }
 
 void destroy_inode(struct inode *inode) 
 {
+#if defined CONFIG_KEVENT_SOCKET
+	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
index 2561020..a697930 100644
@@ -236,6 +236,7 @@ #include <linux/prio_tree.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/mutex.h>
+#include <linux/kevent.h>
 
 #include <asm/atomic.h>
 #include <asm/semaphore.h>
@@ -546,6 +547,10 @@ #ifdef CONFIG_INOTIFY
 	struct mutex		inotify_mutex;	/* protects the watches list */
 #endif
 
+#ifdef CONFIG_KEVENT_SOCKET
+	struct kevent_storage	st;
+#endif
+
 	unsigned long		i_state;
 	unsigned long		dirtied_when;	/* jiffies of first dirtying */
 
@@ -698,6 +703,9 @@ #ifdef CONFIG_EPOLL
 	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;
include/net/sock.h +17 -15
index 324b3ea..5d71ed7 100644
@@ -48,6 +48,7 @@ #include <linux/lockdep.h>
 #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_kio
 	return 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
index 7a093d0..69f4ad2 100644
@@ -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 +126 -0

126 lines not on this page · raw message

net/core/sock.c +9 -1
index 51fcfbc..4f91615 100644
@@ -1406,6 +1406,7 @@ static void sock_def_wakeup(struct sock 
 	if (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)
@@ -1415,6 +1416,7 @@ static void sock_def_error_report(struct
 		wake_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)
@@ -1424,6 +1426,7 @@ static void sock_def_readable(struct soc
 		wake_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)
@@ -1443,6 +1446,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)
@@ -1493,6 +1497,8 @@ #endif
 	sk->sk_state		=	TCP_CLOSE;
 	sk->sk_socket		=	sock;
 
+	kevent_sk_reinit(sk);
+
 	sock_set_flag(sk, SOCK_ZAPPED);
 
 	if(sock)
@@ -1559,8 +1565,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
index d1d7dec..2878c2a 100644
@@ -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
index 104af5d..14cee12 100644
@@ -3112,6 +3112,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
index 4b04c3e..cda1500 100644
@@ -61,6 +61,7 @@ #include <linux/cache.h>
 #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>
@@ -867,6 +868,7 @@ #endif
 	   	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
index b4848ce..42e19e2 100644
@@ -85,6 +85,7 @@ #include <linux/compat.h>
 #include <linux/kmod.h>
 #include <linux/audit.h>
 #include <linux/wireless.h>
+#include <linux/kevent.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -526,6 +527,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;
#7 lore raw

PATCH 1/4 kevent: Core files.

In reply to Evgeniy Polyakov

Core files.

This patch includes core kevent files:
- userspace controlling
- kernelspace interfaces
- initialization
- notification state machines

arch/i386/kernel/syscall_table.S +3 -0
index dd63d47..c10698e 100644
@@ -317,3 +317,6 @@ ENTRY(sys_call_table)
 	.long sys_tee			/* 315 */
 	.long sys_vmsplice
 	.long sys_move_pages
+	.long sys_kevent_get_events
+	.long sys_kevent_ctl
+	.long sys_kevent_wait		/* 320 */
arch/x86_64/ia32/ia32entry.S +4 -1
index 5d4a7d1..a06b76f 100644
@@ -710,7 +710,10 @@ #endif
 	.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_kevent_get_events
+	.quad sys_kevent_ctl
+	.quad sys_kevent_wait		/* 320 */
 ia32_syscall_end:		
include/asm-i386/unistd.h +4 -1
index fc1c8dd..68072b5 100644
@@ -323,10 +323,13 @@ #define __NR_sync_file_range	314
 #define __NR_tee		315
 #define __NR_vmsplice		316
 #define __NR_move_pages		317
+#define __NR_kevent_get_events	318
+#define __NR_kevent_ctl		319
+#define __NR_kevent_wait	320
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 318
+#define NR_syscalls 321
 
 /*
  * user-visible error numbers are in the range -1 - -128: see
include/asm-x86_64/unistd.h +7 -1
index 94387c9..ee907ad 100644
@@ -619,10 +619,16 @@ #define __NR_vmsplice		278
 __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)
 
 #ifdef __KERNEL__
 
-#define __NR_syscall_max __NR_move_pages
+#define __NR_syscall_max __NR_kevent_wait
 
 #ifndef __NO_STUBS
 
include/linux/kevent.h new file +195 -0

195 lines not on this page · raw message

include/linux/kevent_storage.h new file +11 -0
new file mode 100644
index 0000000..a38575d
@@ -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 +4 -0
index 008f04c..9d4690f 100644
@@ -597,4 +597,8 @@ asmlinkage long sys_get_robust_list(int 
 asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
 				    size_t len);
 
+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 start, unsigned int num, __u64 timeout);
 #endif
include/linux/ukevent.h new file +159 -0

159 lines not on this page · raw message

init/Kconfig +2 -0
index a099fc6..c550fcc 100644
@@ -218,6 +218,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
index d62ec66..2d7a6dd 100644
@@ -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 +39 -0
new file mode 100644
index 0000000..5ba8086
@@ -0,0 +1,39 @@
+config KEVENT
+	bool "Kernel event notification mechanism"
+	help
+	  This option enables event queue mechanism.
+	  It can be used as replacement for poll()/select(), AIO callback
+	  invocations, advanced timer notifications and other kernel
+	  object status changes.
+
+config KEVENT_USER_STAT
+	bool "Kevent user statistic"
+	depends on KEVENT
+	help
+	  This option will turn kevent_user statistic collection on.
+	  Statistic data includes total number of kevent, number of kevents
+	  which are ready immediately at insertion time and number of kevents
+	  which were removed through readiness completion.
+	  It will be printed each time control kevent descriptor is closed.
+
+config KEVENT_TIMER
+	bool "Kernel event notifications for timers"
+	depends on KEVENT
+	help
+	  This option allows to use timers through KEVENT subsystem.
+
+config KEVENT_POLL
+	bool "Kernel event notifications for poll()/select()"
+	depends on KEVENT
+	help
+	  This option allows to use kevent subsystem for poll()/select()
+	  notifications.
+
+config KEVENT_SOCKET
+	bool "Kernel event notifications for sockets"
+	depends on NET && KEVENT
+	help
+	  This option enables notifications through KEVENT subsystem of 
+	  sockets operations, like new packet receiving conditions, 
+	  ready for accept conditions and so on.
+	
kernel/kevent/Makefile new file +4 -0
new file mode 100644
index 0000000..9130cad
@@ -0,0 +1,4 @@
+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
kernel/kevent/kevent.c new file +227 -0

227 lines not on this page · raw message

kernel/kevent/kevent_user.c new file +954 -0

954 lines not on this page · raw message

kernel/sys_ni.c +4 -0
index 6991bec..564e618 100644
@@ -122,6 +122,10 @@ cond_syscall(ppc_rtas);
 cond_syscall(sys_spu_run);
 cond_syscall(sys_spu_create);
 
+cond_syscall(sys_kevent_get_events);
+cond_syscall(sys_kevent_wait);
+cond_syscall(sys_kevent_ctl);
+
 /* mmu depending weak syscall entries */
 cond_syscall(sys_mprotect);
 cond_syscall(sys_msync);
#48 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 3 lines · On Wed, 20 Sep 2006 13:35:47 +0400 Evgeniy Polyakov <[email protected]> wrote:

Generic event handling mechanism.

Consider for inclusion.

Ulrich's objections sounded substantial, and afaik remain largely
unresolved. How do we sort this out?

#49 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 9 lines · Andrew Morton
Quoted 3 lines · On Wed, 20 Sep 2006 13:35:47 +0400 Evgeniy Polyakov <[email protected]> wrote:

Generic event handling mechanism.

Consider for inclusion.

Ulrich's objections sounded substantial, and afaik remain largely
unresolved. How do we sort this out?

There are no objections, but request for additional interface.

The only two things missed in patchset after his suggestions are new POSIX-like interface, which I personally consider as very unconvenient, but in any way it can be implemented as addon, and signal mask change, but Ulrich have not answered how does it differ from blocking in userspace and then calling appropriate syscall, I expect the difference is only in reduced number of syscalls.

Signature · 1 line
	Evgeniy Polyakov
#54 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 3 lines · On Wed, 20 Sep 2006 13:35:47 +0400 Evgeniy Polyakov <[email protected]> wrote:

Generic event handling mechanism.

Consider for inclusion.

Ulrich's objections sounded substantial, and afaik remain largely
unresolved. How do we sort this out?

I haven't seen any of Ulrichs points (which mostly is a large subset of my objection) beeing addressed.

#55 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 9 lines · Christoph Hellwig
Quoted 6 lines
Quoted 3 lines

Generic event handling mechanism.

Consider for inclusion.

Ulrich's objections sounded substantial, and afaik remain largely
unresolved. How do we sort this out?

I haven't seen any of Ulrichs points (which mostly is a large subset of my objection) beeing addressed.

Could you please be more specific?

As far as I can see I addressed all suggestions made by Christoph and still waiting for comments about my points after reply to Ulrich's.

Signature · 1 line
	Evgeniy Polyakov
#56 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 4 lines · Evgeniy Polyakov

Generic event handling mechanism.

Consider for inclusion.

I have been told in private what is signal masks about - just to wait until either signal or given condition is ready, but in that case just add additional kevent user like AIO complete or netwrok notification and wait until either requested events are ready or signal is triggered.

Signature · 1 line
	Evgeniy Polyakov
#57 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

On 9/27/06, Evgeniy Polyakov <[email protected]> wrote:
\> I have been told in private what is signal masks about - just to wait

Quoted 3 lines

until either signal or given condition is ready, but in that case just add additional kevent user like AIO complete or netwrok notification and wait until either requested events are ready or signal is triggered.

No, this won't work. Yes, I want signal notification as part of the event handling. But there are situations when this is not suitable. Only if the signal is expected in the same code using the event handling can you do this. But this is not always possible. Especially when the signal handling code is used in other parts of the code than the event handling. E.g., signal handling in a library, event handling in the main code. You cannot assume that all the code is completely integrated.

#58 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 6 lines · Ulrich Drepper

On 9/27/06, Evgeniy Polyakov <[email protected]> wrote:
\> I have been told in private what is signal masks about - just to wait

Quoted 3 lines

until either signal or given condition is ready, but in that case just add additional kevent user like AIO complete or netwrok notification and wait until either requested events are ready or signal is triggered.

Quoted 8 lines

No, this won't work. Yes, I want signal notification as part of the event handling. But there are situations when this is not suitable. Only if the signal is expected in the same code using the event handling can you do this. But this is not always possible. Especially when the signal handling code is used in other parts of the code than the event handling. E.g., signal handling in a library, event handling in the main code. You cannot assume that all the code is completely integrated.

Signals still can be delivered in usual way too.

When we enter sys_ppoll() we specify needed signals as syscall parameter, with kevents we will add them into the queue.

Signature · 1 line
	Evgeniy Polyakov
#50 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

The only two things missed in patchset after his suggestions are new POSIX-like interface, which I personally consider as very unconvenient,

This means you really do not know at all what this is about. We already have these interfaces. Several of them and there will likely be more. These are interfaces for functionality which needs the new event notification. There is *NO* reason whatsoever to not make this

#51 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

[Bah, sent too eaqrly]

Quoted 2 lines · Evgeniy Polyakov

The only two things missed in patchset after his suggestions are new POSIX-like interface, which I personally consider as very unconvenient,

This means you really do not know at all what this is about. We already have these interfaces. Several of them and there will likely be more. These are interfaces for functionality which needs the new event notification. There is *NO* reason whatsoever to not make add this extension and instead invent new interfaces to have notification sent to the event queue.

#53 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 8 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

The only two things missed in patchset after his suggestions are new POSIX-like interface, which I personally consider as very unconvenient,

This means you really do not know at all what this is about. We already have these interfaces. Several of them and there will likely be more. These are interfaces for functionality which needs the new event notification. There is *NO* reason whatsoever to not make this

It looks I'm a bit puzzled...

Let me clarify my position about it.
Kevent as a generic event handling mechanism should not knwo about how events were added. It was designed to be quite flexible, so one could add events from essentially any possible situation.
One of the most common situations is userspace requests - they are added through set of created syscalls. There can exists tons of quadrillions of any other interfaces, I even specially created helper function for kernel subsystems (existing and new ones) which might want to create events using own syscalls and parameters. For example network AIO work that way
- it has own syscalls, which parses parameters, creates ukevent structure and pass them into kevent core, which in turn calls appropriate callbacks back to network AIO.

Everyone can add new interfaces in any way he likes, it would quite silly to created new subsystem which would required strick API and failed to work with different set of interfaces.

So from my point of view, problem is not in case that 'we need only this API', but 'why new API is better that old one'.
It is possible to create new API, which will add events from _existing_ syscalls, it is just one function call from given syscall, I completely agree with it.
I'm just objecting against removing existing interface in favour of new one.

People who need POSIX timer API - feel free to call kevent_user_add_ukevent() from your favorite posix_timer_create(). Who needs signal queueing can do it even in signal() syscall - kevent callback for that subsystem for example can update process' signal mask and add kevents.

Signature · 1 line
	Evgeniy Polyakov
#52 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 6 lines · Ulrich Drepper

[Bah, sent too eaqrly]

Quoted 2 lines · Evgeniy Polyakov

The only two things missed in patchset after his suggestions are new POSIX-like interface, which I personally consider as very unconvenient,

Quoted 6 lines

This means you really do not know at all what this is about. We already have these interfaces. Several of them and there will likely be more. These are interfaces for functionality which needs the new event notification. There is *NO* reason whatsoever to not make add this extension and instead invent new interfaces to have notification sent to the event queue.

As I described in previous e-mail, there are completely _no_ limitations on iterfaces - it is possible to queue events from any place, not matter if it is new interface (which I prefer to use) or any old one, which is more convenient for someone. There is special herlper function for that. One can check network AIO implementation to see how it was done in practice - network AIO has own syscalls (aio_send(), aio_recv() and aio_sendfile(), which create kevent queue and put there own events, it is completely transparent for userspace which does not even know that network AIO is based on kevent).

Signature · 1 line
	Evgeniy Polyakov
#11 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

This patch includes core kevent files:
[...]

I tried to look at the example programs before and failed. I tried again. Where can I find up-to-date example code?

Some other points:

- I really would prefer not to rush all this into the upstream kernel. The main problem is that the ring buffer interface is a shared data structure. These are always tricky. We need to find the right combination between size (as small as possible) and supporting all the interfaces.

- so far only the timer and aio notification is speced out. What about the rest? Are we sure all aspects can be expressed? I am not yet.

- we need an interface to add an event from userlevel. I.e., we need to be able to synthesize events. There are events (like, for instance the async DNS functionality) which come from userlevel code.

I would very much prefer we look at the other events before setting the data structures in stone.

#12 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 6 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

This patch includes core kevent files:
[...]

I tried to look at the example programs before and failed. I tried again. Where can I find up-to-date example code?

http://tservice.net.ru/~s0mbre/archive/kevent/evserver_kevent.c
http://tservice.net.ru/~s0mbre/archive/kevent/evtest.c

Structures were not changed from the beginning of kevent project.

Quoted 7 lines

Some other points:

- I really would prefer not to rush all this into the upstream kernel. The main problem is that the ring buffer interface is a shared data structure. These are always tricky. We need to find the right combination between size (as small as possible) and supporting all the interfaces.

mmap interface itself is in question, since it allows to create dos since there are no rlimits for pinned memory.

Quoted 3 lines

- so far only the timer and aio notification is speced out. What about the rest? Are we sure all aspects can be expressed? I am not yet.

AIO was removed from patchset by request of Cristoph. Timers, network AIO, fs AIO, socket nortifications and poll/select events work well with existing structures.

Quoted 6 lines

- we need an interface to add an event from userlevel. I.e., we need to be able to synthesize events. There are events (like, for instance the async DNS functionality) which come from userlevel code.

I would very much prefer we look at the other events before setting the data structures in stone.

Signals and userspace events (hello solaris) easily fits into existing structures.

It is even possible to create variable sized kevents - each kevent contain pointer to user's data, which can be considered as pointer to additional area (it's size kernel implementation for given kevent type can determine from other parameters or use predefined one and fetch additional data in ->enqueue() callback).

Signature · 1 line
	Evgeniy Polyakov
#59 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

When we enter sys_ppoll() we specify needed signals as syscall parameter, with kevents we will add them into the queue.

No, this is not sufficient as I said in the last mail. Why do you completely ignore what others say. The code which depends on the signal does not have to have access to the event queue. If a library sets up an interrupt handler then it expect the signal to be delivered this way.
In such situations ppoll etc allow the signal to be generally blocked
and enabled only and *ATOMICALLY* around the delays. This is not possible with the current wait interface. We need this signal mask interfaces and the appropriate setup code.

Being able to get signal notifications does not mean this is always the way it can and must happen.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#60 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 13 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

When we enter sys_ppoll() we specify needed signals as syscall parameter, with kevents we will add them into the queue.

No, this is not sufficient as I said in the last mail. Why do you completely ignore what others say. The code which depends on the signal does not have to have access to the event queue. If a library sets up an interrupt handler then it expect the signal to be delivered this way.
In such situations ppoll etc allow the signal to be generally blocked
and enabled only and *ATOMICALLY* around the delays. This is not possible with the current wait interface. We need this signal mask interfaces and the appropriate setup code.

Quoted 2 lines

Being able to get signal notifications does not mean this is always the way it can and must happen.

It is completely possible to do what you describe without special syscall parameters. Just add interesting signals to the queue (and optionally block them globally) and wait on that queue.
When signal's event is generated and appropriate kevent is removed, that signal will be restored in global signal mask (there are appropriate enqueue/dequeue callbacks which can perform operations on signal mask for given process).

My main consern is to not add special cases for something in generic code, especially when gneric code can easily handle that situations.

Quoted 3 lines
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
	Evgeniy Polyakov
#61 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 2 lines · Evgeniy Polyakov

It is completely possible to do what you describe without special syscall parameters.

First of all, I don't see how this is efficiently possible. The mask might change from call to call.

Second, hasn't it sunk in that inventing new ways to pass parameters is bad? Programmers don't want to learn new ways for every new interface.
Reuse is good!

This applies to the signal mask here.

But there is another parameter falling into that category and I meant to mention it before: the timeout value. All other calls except poll and especially all modern interfaces use a timespec pointer. This is the way times are kept in userland code. Don't try to force people to do something else.

Using a timespec also has the advantage that we can add an absolute timeout value mode (optional) instead of the relative timeout value.

In this context, we should/must be able to specify which clock the timeout is for (not as part of the wait call, but another control operation perhaps). It's important to distinguish between CLOCK_REALTIME and CLOCK_MONOTONE. Both have their use.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#13 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

http://tservice.net.ru/~s0mbre/archive/kevent/evserver_kevent.c
http://tservice.net.ru/~s0mbre/archive/kevent/evtest.c

These are simple programs which by themselves have problems. For instance, I consider a very bad idea to hardcode the size of the ring buffer. Specifying macros in the header file counts as hardcoding. Systems grow over time and so will the demand of connections. I have no problem with the kernel hardcoding the value internally (or having a /proc entry to select it) but programs should be able to dynamically learn about the value so they don't have to be recompiled.

But more problematic is that I don't see how the interfaces can be efficiently used in multi-threaded (or multi-process) programs. How would multiple threads using the same kevent queue and running in the same kevent_get_events() loop work out? How do they guarantee that each request is only handled once?

Quoted 1 line

From what I see now this means a second data structure is needed to

keep track of the state of each entry. But even then, how do we even recognized used ring buffer entries?

For instance, assume two threads. Both call get_events, one event is reported, both threads are woken up (which is another thing to consider, more later). One thread uses ring buffer entry, the other goes back to sleep in get_events. Now, how does the kernel know when the other thread is done working on the ring buffer entry? There might be lots of entries coming in overflowing the entire buffer. Heck, you don't even need two threads for this scenario.

When I was thinking about this (and discussing it in Ottawa) I was always assuming that we have a status field in the ring buffer entry which lets the userlevel code indicate whether the entry is free again or not. This requires a writable mapping, yes, and potentially causes cache line ping-pong. I think Zach mentioned he has some ideas about this.

As for the multiple thread wakeup, I mentioned this before. We have to avoid the trampling herd problem. We cannot wakeup all waiters. But we also cannot assume that, without protocols, waking up just one for each available entry is sufficient. So the first question is:
what is the current policy?

Quoted 3 lines

AIO was removed from patchset by request of Cristoph. Timers, network AIO, fs AIO, socket nortifications and poll/select events work well with existing structures.

Well, excuse me if I don't take your word for it. I agree, the AIO code should not be submitted along with this. The same for any other code using the event handling. But we need to check whether the interface is generic enough to accomodate them in a way which actually makes sense. Again, think highly threaded processes or multiple processes sharing the same event queue.

Quoted 5 lines

It is even possible to create variable sized kevents - each kevent contain pointer to user's data, which can be considered as pointer to additional area (it's size kernel implementation for given kevent type can determine from other parameters or use predefined one and fetch additional data in ->enqueue() callback).

That sounds interesting and certainly helps with securing the interface for the future. But if there is anything we can do to avoid unnecessary costs we should do it, even if this means investigation all this further.

#14 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 11 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

http://tservice.net.ru/~s0mbre/archive/kevent/evserver_kevent.c
http://tservice.net.ru/~s0mbre/archive/kevent/evtest.c

These are simple programs which by themselves have problems. For instance, I consider a very bad idea to hardcode the size of the ring buffer. Specifying macros in the header file counts as hardcoding. Systems grow over time and so will the demand of connections. I have no problem with the kernel hardcoding the value internally (or having a /proc entry to select it) but programs should be able to dynamically learn about the value so they don't have to be recompiled.

Well, it is possible to create /sys/proc entry for that, and even now userspace can grow mapping ring until it is forbiden by kernel, which means limit is reached.

Actually the whole idea with global limit of kevents does not sound very good to me, but it is required to remove overflow in mapped buffer.

Quoted 5 lines

But more problematic is that I don't see how the interfaces can be efficiently used in multi-threaded (or multi-process) programs. How would multiple threads using the same kevent queue and running in the same kevent_get_events() loop work out? How do they guarantee that each request is only handled once?

kqueue_dequeue_ready() is atomic and this function removes kevent from ready queue so other thread can not get it.

Quoted 11 lines

From what I see now this means a second data structure is needed to keep track of the state of each entry. But even then, how do we even recognized used ring buffer entries?

For instance, assume two threads. Both call get_events, one event is reported, both threads are woken up (which is another thing to consider, more later). One thread uses ring buffer entry, the other goes back to sleep in get_events. Now, how does the kernel know when the other thread is done working on the ring buffer entry? There might be lots of entries coming in overflowing the entire buffer. Heck, you don't even need two threads for this scenario.

Are you talking about mapped buffer or syscall interface? The former has special syscall kevent_wait(), which reports number of 'processed' events and first processed number, so kernel can remove all appropriate events. The latter is described above - kqueue_dequeue_ready() is atomic, so that event will be removed from the ready queue and optionally from the whole kevent tree.

It is possible to work with both interfaces at the same time, since mapped buffer contains a copy of the event, which is potentially freed and processed by other thread.

Actually I do not like idea of mapped ring anyway, since if application uses a lot of events, it will batch them into big chunks, so syscall overhead is negligible, if application uses small number of events, syscalls will be rare and will not hurt performance.

Quoted 6 lines

When I was thinking about this (and discussing it in Ottawa) I was always assuming that we have a status field in the ring buffer entry which lets the userlevel code indicate whether the entry is free again or not. This requires a writable mapping, yes, and potentially causes cache line ping-pong. I think Zach mentioned he has some ideas about this.

As far as I can see, there are no other ideas on how to implement ring buffer, so I did it like I wanted. It has some limitation indeed, but since I do not see any other code, how can I say what is better or worse?

Quoted 5 lines

As for the multiple thread wakeup, I mentioned this before. We have to avoid the trampling herd problem. We cannot wakeup all waiters. But we also cannot assume that, without protocols, waking up just one for each available entry is sufficient. So the first question is:
what is the current policy?

It is a good practice to _not_ share the same queue between a lot of threads. Currently all waiters are awakened.

Quoted 10 lines
Quoted 3 lines

AIO was removed from patchset by request of Cristoph. Timers, network AIO, fs AIO, socket nortifications and poll/select events work well with existing structures.

Well, excuse me if I don't take your word for it. I agree, the AIO code should not be submitted along with this. The same for any other code using the event handling. But we need to check whether the interface is generic enough to accomodate them in a way which actually makes sense. Again, think highly threaded processes or multiple processes sharing the same event queue.

You missed the point.
I implemented _all_ above and it does work.
Although it was removed from submission patchset.
You can find all patches on kevent homepage, they were posted to lkml@ and netdev@ too many times to miss them.

Quoted 10 lines
Quoted 5 lines

It is even possible to create variable sized kevents - each kevent contain pointer to user's data, which can be considered as pointer to additional area (it's size kernel implementation for given kevent type can determine from other parameters or use predefined one and fetch additional data in ->enqueue() callback).

That sounds interesting and certainly helps with securing the interface for the future. But if there is anything we can do to avoid unnecessary costs we should do it, even if this means investigation all this further.

Ulrich, do _you_ have any ideas on how to change data structures? Not talks about investigations and the like, but real design which covers today's and tomorrow's needs?

Existing structures were not taken from the universe, but are result of quite long thoughts about requests for AIO/epoll and networking development...

Signature · 1 line
	Evgeniy Polyakov
#62 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 6 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

It is completely possible to do what you describe without special syscall parameters.

First of all, I don't see how this is efficiently possible. The mask might change from call to call.

And you can add/remove signal events using existing kevent api between calls.

Quoted 3 lines

Second, hasn't it sunk in that inventing new ways to pass parameters is bad? Programmers don't want to learn new ways for every new interface.
Reuse is good!

And creating special cases for usual events is bad. There is unified way to deal with events in kevent - add/remove/modify/wait on them, signals are just usual events.

Quoted 8 lines

This applies to the signal mask here.

But there is another parameter falling into that category and I meant to mention it before: the timeout value. All other calls except poll and especially all modern interfaces use a timespec pointer. This is the way times are kept in userland code. Don't try to force people to do something else.

Quoted 7 lines

Using a timespec also has the advantage that we can add an absolute timeout value mode (optional) instead of the relative timeout value.

In this context, we should/must be able to specify which clock the timeout is for (not as part of the wait call, but another control operation perhaps). It's important to distinguish between CLOCK_REALTIME and CLOCK_MONOTONE. Both have their use.

I think you wanted to say, that 'all event mechanism except the most commonly used poll/select/epoll use timespec'.
I designed it to be similar to poll(), it is really good interface. Nature of the waiting is to wait for some time, so I put there that 'some time'.

Quoted 3 lines
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
	Evgeniy Polyakov
#15 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 3 lines · Evgeniy Polyakov

Well, it is possible to create /sys/proc entry for that, and even now userspace can grow mapping ring until it is forbiden by kernel, which means limit is reached.

No need for yet another /sys/proc entry.

Right now, I (for example) may have a use for Generic event handling, but for a program that needs XXX.XXX handles, and about XX.XXX events per second.

Right now, this program uses epoll, and reaches no limit at all, once you pass the "ulimit -n", and other kernel wide tunes of course, not related to epoll.

With your current kevent, I cannot switch to it, because of hardcoded limits.

I may be wrong, but what is currently missing for me is :

- No hardcoded limit on the max number of events. (A process that can open XXX.XXX files should be allowed to open a kevent queue with at least XXX.XXX events). Right now thats not clear what happens IF the current limit is reached.

- In order to avoid touching the whole ring buffer, it might be good to be able to reset the indexes to the beginning when ring buffer is empty. (So if the user land is responsive enough to consume events, only first pages of the mapping would be used : that saves L1/L2 cpu caches)

A plus would be

- A working/usable mmap ring buffer implementation, but I think its not mandatory. System calls are not that expensive, especially if you can batch XX events per syscall (like epoll). Nice thing with a ring buffer is that we touch less cache lines than say epoll that have lot of linked structures.

About mmap, I think you might want a hybrid thing :

One writable page where userland can write its index, (and hold one or more futex shared by kernel) (with appropriate thread locking in case multiple threads want to dequeue events). In fast path, no syscalls are needed to maintain this user index.

XXX readonly pages (for user, but r/w for kernel), where kernel write its own index, and events of course.

Using separate cache lines avoid false sharing : kernel can update its own index and events without having to pay the price of cache line ping pongs. It could use futex infrastructure to wakeup one thread 'only' instead of all threads waiting an event.

Eric

#16 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 14 lines · Eric Dumazet
Quoted 3 lines · Evgeniy Polyakov

Well, it is possible to create /sys/proc entry for that, and even now userspace can grow mapping ring until it is forbiden by kernel, which means limit is reached.

No need for yet another /sys/proc entry.

Right now, I (for example) may have a use for Generic event handling, but for a program that needs XXX.XXX handles, and about XX.XXX events per second.

Right now, this program uses epoll, and reaches no limit at all, once you pass the "ulimit -n", and other kernel wide tunes of course, not related to epoll.

Quoted 8 lines

With your current kevent, I cannot switch to it, because of hardcoded limits.

I may be wrong, but what is currently missing for me is :

- No hardcoded limit on the max number of events. (A process that can open XXX.XXX files should be allowed to open a kevent queue with at least XXX.XXX events). Right now thats not clear what happens IF the current limit is reached.

This forces to overflows in fixed sized memory mapped buffer. If we remove memory mapped buffer or will allow to have overflows (and thus skipped entries) keven can easily scale to that limits (tested with xx.xxx events though).

Quoted 4 lines

- In order to avoid touching the whole ring buffer, it might be good to be able to reset the indexes to the beginning when ring buffer is empty. (So if the user land is responsive enough to consume events, only first pages of the mapping would be used : that saves L1/L2 cpu caches)

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Quoted 9 lines

A plus would be

- A working/usable mmap ring buffer implementation, but I think its not mandatory. System calls are not that expensive, especially if you can batch XX events per syscall (like epoll). Nice thing with a ring buffer is that we touch less cache lines than say epoll that have lot of linked structures.

About mmap, I think you might want a hybrid thing :

Quoted 7 lines

One writable page where userland can write its index, (and hold one or more futex shared by kernel) (with appropriate thread locking in case multiple threads want to dequeue events). In fast path, no syscalls are needed to maintain this user index.

XXX readonly pages (for user, but r/w for kernel), where kernel write its own index, and events of course.

The problem is in that xxx pages - how many can we eat per kevent descriptor? It is pinned memory and thus it is possible to have a DoS. If xxx above is not enough to store all events, we will have yet-another-broken behaviour like rt-signal queue overflow.

Quoted 7 lines

Using separate cache lines avoid false sharing : kernel can update its own index and events without having to pay the price of cache line ping pongs. It could use futex infrastructure to wakeup one thread 'only' instead of all threads waiting an event.

Eric

Signature · 1 line
	Evgeniy Polyakov
#17 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 8 lines · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 11:56:24AM +0200, Eric Dumazet ([email protected])

Quoted 6 lines

I may be wrong, but what is currently missing for me is :

- No hardcoded limit on the max number of events. (A process that can open XXX.XXX files should be allowed to open a kevent queue with at least XXX.XXX events). Right now thats not clear what happens IF the current limit is reached.

Quoted 4 lines

This forces to overflows in fixed sized memory mapped buffer. If we remove memory mapped buffer or will allow to have overflows (and thus skipped entries) keven can easily scale to that limits (tested with xx.xxx events though).

What is missing or not obvious is : If events are skipped because of overflows, What happens ? Connections stuck forever ? Hope that everything will restore itself ? Is kernel able to SIGNAL this problem to user land ?

Quoted 8 lines
Quoted 5 lines

- In order to avoid touching the whole ring buffer, it might be good to be able to reset the indexes to the beginning when ring buffer is empty. (So if the user land is responsive enough to consume events, only first pages of the mapping would be used : that saves L1/L2 cpu caches)

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Re-read what I said : when ring buffer is empty.

When ring buffer is empty, kernel can reset index right before adding XX new events. You read 3 events consumed, I said : When all ring buffer is empty, because all previous events were consumed by user land, then we can reset indexes to 0.

Quoted 16 lines
Quoted 16 lines

A plus would be

- A working/usable mmap ring buffer implementation, but I think its not mandatory. System calls are not that expensive, especially if you can batch XX events per syscall (like epoll). Nice thing with a ring buffer is that we touch less cache lines than say epoll that have lot of linked structures.

About mmap, I think you might want a hybrid thing :

One writable page where userland can write its index, (and hold one or more futex shared by kernel) (with appropriate thread locking in case multiple threads want to dequeue events). In fast path, no syscalls are needed to maintain this user index.

Quoted 8 lines
Quoted 2 lines

XXX readonly pages (for user, but r/w for kernel), where kernel write its own index, and events of course.

The problem is in that xxx pages - how many can we eat per kevent descriptor? It is pinned memory and thus it is possible to have a DoS. If xxx above is not enough to store all events, we will have yet-another-broken behaviour like rt-signal queue overflow.

Re-read : I have a process that has the right to open XXX.XXX handles, allocating XXX.XXX tcp sockets, dentries, files structures, inodes, epoll events, its obviously already a DOS risk, but controled by 'ulimit -n'

Allocating XXX.XXX * (32 or 64) bytes is a win if I can zap epoll structures (currently more than 256 bytes per event)

epoll structures are pinned too... what's wrong with that ?

# egrep "filp|poll|TCP|dentries|sock_inode" /proc/slabinfo |cut -c1-50
tw_sock_TCP         1302   2200    192   20    1 :
request_sock_TCP    2046   4260    128   30    1 :
TCP               151509 196910   1472    5    2 :
eventpoll_pwq     146718 199439     72   53    1 :
eventpoll_epi     146718 199360    192   20    1 :
sock_inode_cache  149182 197940    640    6    1 :
filp              149537 202515    256   15    1 :

If you want to protect from DOS, just use ulimit -n 100

Eric

#18 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 11:56:24AM +0200, Eric Dumazet ([email protected])

Quoted 6 lines

I may be wrong, but what is currently missing for me is :

- No hardcoded limit on the max number of events. (A process that can open XXX.XXX files should be allowed to open a kevent queue with at least XXX.XXX events). Right now thats not clear what happens IF the current limit is reached.

Quoted 8 lines
Quoted 4 lines

This forces to overflows in fixed sized memory mapped buffer. If we remove memory mapped buffer or will allow to have overflows (and thus skipped entries) keven can easily scale to that limits (tested with xx.xxx events though).

What is missing or not obvious is : If events are skipped because of overflows, What happens ? Connections stuck forever ? Hope that everything will restore itself ? Is kernel able to SIGNAL this problem to user land ?

Exisitng code does not overflow by design, but can consume a lot of memory. I talked about the case, when there will be some limit on number of entries put into mapped buffer.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

- In order to avoid touching the whole ring buffer, it might be good to be able to reset the indexes to the beginning when ring buffer is empty. (So if the user land is responsive enough to consume events, only first pages of the mapping would be used : that saves L1/L2 cpu caches)

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Quoted 6 lines

Re-read what I said : when ring buffer is empty.

When ring buffer is empty, kernel can reset index right before adding XX new events. You read 3 events consumed, I said : When all ring buffer is empty, because all previous events were consumed by user land, then we can reset indexes to 0.

It is the same.
What if reing buffer was grown upto 3 entry, and is now empty, and we need to put there 4 entries? Grow it again?
It can be done, easily, but it looks like a workaround not as solution. And it is highly unlikely that in situation, when there are a lot of event, ring can be empty.

Quoted 43 lines
Quoted 16 lines
Quoted 16 lines

A plus would be

- A working/usable mmap ring buffer implementation, but I think its not mandatory. System calls are not that expensive, especially if you can batch XX events per syscall (like epoll). Nice thing with a ring buffer is that we touch less cache lines than say epoll that have lot of linked structures.

About mmap, I think you might want a hybrid thing :

One writable page where userland can write its index, (and hold one or more futex shared by kernel) (with appropriate thread locking in case multiple threads want to dequeue events). In fast path, no syscalls are needed to maintain this user index.

Quoted 8 lines
Quoted 2 lines

XXX readonly pages (for user, but r/w for kernel), where kernel write its own index, and events of course.

The problem is in that xxx pages - how many can we eat per kevent descriptor? It is pinned memory and thus it is possible to have a DoS. If xxx above is not enough to store all events, we will have yet-another-broken behaviour like rt-signal queue overflow.

Re-read : I have a process that has the right to open XXX.XXX handles, allocating XXX.XXX tcp sockets, dentries, files structures, inodes, epoll events, its obviously already a DOS risk, but controled by 'ulimit -n'

Allocating XXX.XXX * (32 or 64) bytes is a win if I can zap epoll structures (currently more than 256 bytes per event)

epoll structures are pinned too... what's wrong with that ?

# egrep "filp|poll|TCP|dentries|sock_inode" /proc/slabinfo |cut -c1-50
tw_sock_TCP         1302   2200    192   20    1 :
request_sock_TCP    2046   4260    128   30    1 :
TCP               151509 196910   1472    5    2 :
eventpoll_pwq     146718 199439     72   53    1 :
eventpoll_epi     146718 199360    192   20    1 :
sock_inode_cache  149182 197940    640    6    1 :
filp              149537 202515    256   15    1 :
Quoted 1 line

If you want to protect from DOS, just use ulimit -n 100

epoll() does not have mmap.
Problem is not about how many events can be put into the kernel, but how many of them can be put into mapped buffer.
There is no problem if mmap is turned off.

Quoted 1 line

Eric

Signature · 1 line
	Evgeniy Polyakov
#19 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 10 lines · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 12:45:03PM +0200, Eric Dumazet ([email protected])

Quoted 5 lines

What is missing or not obvious is : If events are skipped because of overflows, What happens ? Connections stuck forever ? Hope that everything will restore itself ? Is kernel able to SIGNAL this problem to user land ?

Exisitng code does not overflow by design, but can consume a lot of memory. I talked about the case, when there will be some limit on number of entries put into mapped buffer.

You still dont answer my question. Please answer the question. Recap : You have a max of XXXX events queued. A network message come and kernel want to add another event. It cannot because limit is reached. How the User Program knows that this problem was hit ?

Quoted 6 lines

It is the same.
What if reing buffer was grown upto 3 entry, and is now empty, and we need to put there 4 entries? Grow it again?
It can be done, easily, but it looks like a workaround not as solution. And it is highly unlikely that in situation, when there are a lot of event, ring can be empty.

I dont speak of re-allocation of ring buffer. I dont care to allocate at startup a big enough buffer.

Say you have allocated a ring buffer of 1024*1024 entries. Then you queue 100 events per second, and dequeue them immediatly. No need to blindly use all 1024*1024 slots in the ring buffer, doing index = (index+1)%(1024*1024)

Quoted 4 lines

epoll() does not have mmap.
Problem is not about how many events can be put into the kernel, but how many of them can be put into mapped buffer.
There is no problem if mmap is turned off.

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

#20 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 8 lines · Eric Dumazet
Quoted 7 lines · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 12:45:03PM +0200, Eric Dumazet ([email protected])

Quoted 5 lines

What is missing or not obvious is : If events are skipped because of overflows, What happens ? Connections stuck forever ? Hope that everything will restore itself ? Is kernel able to SIGNAL this problem to user land ?

Quoted 8 lines
Quoted 3 lines

Exisitng code does not overflow by design, but can consume a lot of memory. I talked about the case, when there will be some limit on number of entries put into mapped buffer.

You still dont answer my question. Please answer the question. Recap : You have a max of XXXX events queued. A network message come and kernel want to add another event. It cannot because limit is reached. How the User Program knows that this problem was hit ?

Existing design does not allow overflow.
If event was added into the queue (like user requested notification, when new data has arrived), it is guaranteed that there will be place to put that event into mapped buffer when it is ready.

If user wants to add anotehr event (for example after accept() user wants to add another socket with request for notification about data arrival into that socket), it can fail though. This limit is introduced only because of mmap buffer.

Quoted 7 lines
Quoted 6 lines

It is the same.
What if reing buffer was grown upto 3 entry, and is now empty, and we need to put there 4 entries? Grow it again?
It can be done, easily, but it looks like a workaround not as solution. And it is highly unlikely that in situation, when there are a lot of event, ring can be empty.

Quoted 7 lines

I dont speak of re-allocation of ring buffer. I dont care to allocate at startup a big enough buffer.

Say you have allocated a ring buffer of 1024*1024 entries. Then you queue 100 events per second, and dequeue them immediatly. No need to blindly use all 1024*1024 slots in the ring buffer, doing index = (index+1)%(1024*1024)

But what if they are not dequeued immediateyl? What if rate is high and while one tries to dequeue, system adds another events?

Quoted 7 lines
Quoted 4 lines

epoll() does not have mmap.
Problem is not about how many events can be put into the kernel, but how many of them can be put into mapped buffer.
There is no problem if mmap is turned off.

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

Initial implementation did not have it.
But I was requested to do it, and it is ready now.
No one likes it, but no one provides an alternative implementation. We are stuck.

Signature · 1 line
	Evgeniy Polyakov
#45 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 1 line · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 11:56:24AM +0200, Eric Dumazet ([email protected])

Quoted 9 lines · wrote:
Quoted 9 lines · Evgeniy Polyakov
Quoted 4 lines

Well, it is possible to create /sys/proc entry for that, and even now userspace can grow mapping ring until it is forbiden by kernel, which means limit is reached.

No need for yet another /sys/proc entry.

Right now, I (for example) may have a use for Generic event handling, but

for

Quoted 3 lines
Quoted 3 lines

a program that needs XXX.XXX handles, and about XX.XXX events per second.

Right now, this program uses epoll, and reaches no limit at all, once you

pass

Quoted 1 line
Quoted 1 line

the "ulimit -n", and other kernel wide tunes of course, not related to

epoll.

Quoted 2 lines
Quoted 2 lines

With your current kevent, I cannot switch to it, because of hardcoded

limits.

Quoted 5 lines
Quoted 5 lines

I may be wrong, but what is currently missing for me is :

- No hardcoded limit on the max number of events. (A process that can open XXX.XXX files should be allowed to open a kevent queue with at least

XXX.XXX

Quoted 10 lines
Quoted 2 lines

events). Right now thats not clear what happens IF the current limit is reached.

This forces to overflows in fixed sized memory mapped buffer. If we remove memory mapped buffer or will allow to have overflows (and thus skipped entries) keven can easily scale to that limits (tested with xx.xxx events though).

Quoted 2 lines

- In order to avoid touching the whole ring buffer, it might be good to be able to reset the indexes to the beginning when ring buffer is empty. (So

if

Quoted 1 line
Quoted 1 line

the user land is responsive enough to consume events, only first pages of

the

Quoted 4 lines
Quoted 1 line

mapping would be used : that saves L1/L2 cpu caches)

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Couldn't there be 3 areas in the mmap buffer:

- Unused: entries that the kernel can alloc from.
- Alloced: entries alloced by kernel but not yet used by user. Kernel can update these if new events requires that.
- Consumed: entries that the user are processing.

The user takes a set of alloced entries and make them consumed. Then it processes the events after which it makes them unused.

If there are no unused entries and the kernel needs some, it has wait for free entries. The user has to notify when unused entries becomes available. It could set a flag in the mmap'ed area to avoid unnessesary wakeups.

The are some details with indexing and wakeup notification that I have left out, but I hope my idea is clear. I could give a more detailed description if requested. Also, I'm a user-level programmer so I might not get the whole picture.

Hans Henrik Happe

#46 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 13 lines · Hans Henrik Happe
Quoted 2 lines

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Couldn't there be 3 areas in the mmap buffer:

- Unused: entries that the kernel can alloc from.
- Alloced: entries alloced by kernel but not yet used by user. Kernel can update these if new events requires that.
- Consumed: entries that the user are processing.

The user takes a set of alloced entries and make them consumed. Then it processes the events after which it makes them unused.

Quoted 8 lines

If there are no unused entries and the kernel needs some, it has wait for free entries. The user has to notify when unused entries becomes available. It could set a flag in the mmap'ed area to avoid unnessesary wakeups.

The are some details with indexing and wakeup notification that I have left out, but I hope my idea is clear. I could give a more detailed description if requested. Also, I'm a user-level programmer so I might not get the whole picture.

This looks good on a picture, but how can you put it into page-based storage without major and complex shared structures, which should be properly locked between kernelspace and userspace?

Quoted 1 line

Hans Henrik Happe

Signature · 1 line
	Evgeniy Polyakov
#63 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

And you can add/remove signal events using existing kevent api between calls.

That's far more expensive than using a mask under control of the program.

Quoted 3 lines

And creating special cases for usual events is bad. There is unified way to deal with events in kevent - add/remove/modify/wait on them, signals are just usual events.

How can this be unified? The installment of the temporary signal mask is unlike the handling of signal for the purpose of reporting them through the signal queue. It's equally completely new functionality. Don't kid yourself in thinking that because this is signal stuff, too, you're "unifying" something. The way this signal mask is used has nothing whatsoever to do with the delivering signals via the event queue. For the latter the signals always must be blocked (similar to sigwait's requirement).

As a result it means you want to introduce a new mechanism for the event queue instead of using the well known and often used method of optionally passing a signal mask to the syscall. That's just insane.

Quoted 2 lines

I think you wanted to say, that 'all event mechanism except the most commonly used poll/select/epoll use timespec'.

Get your facts straight. select uses timeval which is just the predecessor of of timespec. And epoll is just (badly) designed after poll. Fact is therefore that poll plus its spawn is the only interface using such a timeout method.

Quoted 1 line

I designed it to be similar to poll(), it is really good interface.

Not many people agree. All the interfaces designed (not derived) in the last years take a timespec parameter.

Plus, you chose to ignore all the nice things using a timespec allow you like absolute timeout modes etc. See the clock_nanosleep() interface for a way this can be useful.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#47 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 1 line · Evgeniy Polyakov

On Thu, Oct 05, 2006 at 04:01:19PM +0200, Hans Henrik Happe

Quoted 10 lines · ([email protected]) wrote:
Quoted 10 lines
Quoted 2 lines

And what happens when there are 3 empty at the beginning and \we need to put there 4 ready events?

Couldn't there be 3 areas in the mmap buffer:

- Unused: entries that the kernel can alloc from.
- Alloced: entries alloced by kernel but not yet used by user. Kernel can update these if new events requires that.
- Consumed: entries that the user are processing.

Quoted 4 lines
Quoted 4 lines

The user takes a set of alloced entries and make them consumed. Then it processes the events after which it makes them unused.

If there are no unused entries and the kernel needs some, it has wait for

free

Quoted 4 lines
Quoted 4 lines

entries. The user has to notify when unused entries becomes available. It could set a flag in the mmap'ed area to avoid unnessesary wakeups.

The are some details with indexing and wakeup notification that I have

left

Quoted 1 line
Quoted 1 line

out, but I hope my idea is clear. I could give a more detailed description

if

Quoted 6 lines
Quoted 2 lines

requested. Also, I'm a user-level programmer so I might not get the whole picture.

This looks good on a picture, but how can you put it into page-based storage without major and complex shared structures, which should be properly locked between kernelspace and userspace?

I wasn't clear about the structure. I meant a ring-buffer with 3 areas. So it's basically the same model as Eric Dumazet described, only with 3 indexes; 2 in the user-writeable page and 1 in kernel.

When the kernel has alloced an entry it should store it in a way that makes it invalid after user consumsion, which is simply an increment of an index. Sliding-window like schemes should solve this.

Hans Henrik Happe

#64 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 5 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

And you can add/remove signal events using existing kevent api between calls.

That's far more expensive than using a mask under control of the program.

In context you have cut, one updated signal mask between calls to event delivery mechanism (using for example signal()), so it has exactly the same price.

Quoted 13 lines
Quoted 3 lines

And creating special cases for usual events is bad. There is unified way to deal with events in kevent - add/remove/modify/wait on them, signals are just usual events.

How can this be unified? The installment of the temporary signal mask is unlike the handling of signal for the purpose of reporting them through the signal queue. It's equally completely new functionality. Don't kid yourself in thinking that because this is signal stuff, too, you're "unifying" something. The way this signal mask is used has nothing whatsoever to do with the delivering signals via the event queue. For the latter the signals always must be blocked (similar to sigwait's requirement).

Quoted 3 lines

As a result it means you want to introduce a new mechanism for the event queue instead of using the well known and often used method of optionally passing a signal mask to the syscall. That's just insane.

I created it just because I think that POSIX workaround to add signals into the syscall parameters is not good enough.
Exactly with the same logic I created kevent to drive AIO completeness, to work with socket notifications and timers and so on.
All above (listio(), poll(), setitimer() and so on) are known and good interfaces, but practice shows that having one interface, which can easily work with all existing cases is much more convenient than having tons of them.

So, yes, I do introduce new mechanism to solve signal problem here, just because I think all existing have some limitations or problems.

Quoted 7 lines
Quoted 2 lines

I think you wanted to say, that 'all event mechanism except the most commonly used poll/select/epoll use timespec'.

Get your facts straight. select uses timeval which is just the predecessor of of timespec. And epoll is just (badly) designed after poll. Fact is therefore that poll plus its spawn is the only interface using such a timeout method.

And it was designed very good, although it looks like we disagree a bit here...

Quoted 8 lines
Quoted 1 line

I designed it to be similar to poll(), it is really good interface.

Not many people agree. All the interfaces designed (not derived) in the last years take a timespec parameter.

Plus, you chose to ignore all the nice things using a timespec allow you like absolute timeout modes etc. See the clock_nanosleep() interface for a way this can be useful.

You again cut my explanation on why just pure timeout is used. We start a syscall, which can block forever, so we want to limit it's time, and we add special parameter to show how long this syscall should run. Timeout is not about how long we should sleep (which indeed can be absolute), but how long syscall should run - which is related to the time syscall started.

Quoted 2 lines
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Signature · 1 line
	Evgeniy Polyakov
#65 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

Quoted 3 lines · Evgeniy Polyakov

In context you have cut, one updated signal mask between calls to event delivery mechanism (using for example signal()), so it has exactly the same price.

No, it does not. If the signal mask is recomputed by the program for each new wait call then you have a lot more work to do when the signal mask is implicitly specified.

Quoted 2 lines

I created it just because I think that POSIX workaround to add signals into the syscall parameters is not good enough.

Not good enough? It does exactly what it is supposed to do. What can there be "not good enough"?

Quoted 5 lines

You again cut my explanation on why just pure timeout is used.
We start a syscall, which can block forever, so we want to limit it's
time, and we add special parameter to show how long this syscall should run. Timeout is not about how long we should sleep (which indeed can be absolute), but how long syscall should run - which is related to the time syscall started.

I know very well what a timeout is. But the way the timeout can be specified can vary. It is often useful (as for select, poll) to specify relative timeouts.

But there are equally useful uses where the timeout is needed at a specific point in time. Without a syscall interface which can have a absolute timeout parameter we'd have to write as a poor approximation at userlever

    clock_gettime (CLOCK_REALTIME, &ts);
    struct timespec rel;
    rel.tv_sec = abstmo.tv_sec - ts.tv_sec;
    rel.tv_nsec = abstmo.tv_sec - ts.tv_nsec;
    if (rel.tv_nsec < 0) {
      rel.tv_nsec += 1000000000;
      --rel.tv_sec;
    }
    if (rel.tv_sec < 0)
      inttmo = -1;  // or whatever is used for return immediately
    else
      inttmo = rel.tv_sec * UINT64_C(1000000000) + rel.tv_nsec;

     wait(..., inttmo, ...)

Not only is this much more expensive to do at userlevel, it is also inadequate because calls to settimeofday() do not cause a recomputation of the timeout.

See Ingo's RT futex stuff as an example for a kernel interface which does it right.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#21 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 1 line · Evgeniy Polyakov

Existing design does not allow overflow.

And I've pointed out a number of times that this is not practical at best. There are event sources which can create events which cannot be coalesced into one single event as it would be required with your design.

Signals are one example, specifically realtime signals. If we do not want the design to be limited from the start this approach has to be thought over.

Quoted 6 lines
Quoted 1 line

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

Initial implementation did not have it.
But I was requested to do it, and it is ready now.
No one likes it, but no one provides an alternative implementation. We are stuck.

We need the mapped ring buffer. The current design (before it was removed) was broken but this does not mean it shouldn't be implemented.
We just need more time to figure out how to implement it correctly.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#66 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 8 lines · Ulrich Drepper
Quoted 3 lines · Evgeniy Polyakov

In context you have cut, one updated signal mask between calls to event delivery mechanism (using for example signal()), so it has exactly the same price.

No, it does not. If the signal mask is recomputed by the program for each new wait call then you have a lot more work to do when the signal mask is implicitly specified.

One can set number of events before the syscall and do not remove them after syscall. It can be updated if there is need for that.

Quoted 5 lines
Quoted 2 lines

I created it just because I think that POSIX workaround to add signals into the syscall parameters is not good enough.

Not good enough? It does exactly what it is supposed to do. What can there be "not good enough"?

Not to move signals into special case of events. If poll() can not work with them it does not mean, that they need to be specified as additional syscall parameter, instead change poll() to work with them, which can be easily done with kevents.

Quoted 16 lines
Quoted 6 lines

You again cut my explanation on why just pure timeout is used. We start a syscall, which can block forever, so we want to limit it's time, and we add special parameter to show how long this syscall should run. Timeout is not about how long we should sleep (which indeed can be absolute), but how long syscall should run - which is related to the time syscall started.

I know very well what a timeout is. But the way the timeout can be specified can vary. It is often useful (as for select, poll) to specify relative timeouts.

But there are equally useful uses where the timeout is needed at a specific point in time. Without a syscall interface which can have a absolute timeout parameter we'd have to write as a poor approximation at userlever

Quoted 14 lines
    clock_gettime (CLOCK_REALTIME, &ts);
    struct timespec rel;
    rel.tv_sec = abstmo.tv_sec - ts.tv_sec;
    rel.tv_nsec = abstmo.tv_sec - ts.tv_nsec;
    if (rel.tv_nsec < 0) {
      rel.tv_nsec += 1000000000;
      --rel.tv_sec;
    }
    if (rel.tv_sec < 0)
      inttmo = -1;  // or whatever is used for return immediately
    else
      inttmo = rel.tv_sec * UINT64_C(1000000000) + rel.tv_nsec;

     wait(..., inttmo, ...)

Do not mix warm and soft - waiting for some period is not equal to syscall timeout. Waiting is possible with timer kevent user (although only relative timeout, can be changed to support both, not a big problem).

Quoted 6 lines

Not only is this much more expensive to do at userlevel, it is also inadequate because calls to settimeofday() do not cause a recomputation of the timeout.

See Ingo's RT futex stuff as an example for a kernel interface which does it right.

I'm quite sure that absolute timeouts are very usefull, but not as in the case of waiting for syscall completeness. In any way, kevent can be extended to support absolute timeouts in it's timer notifications.

Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, 
CA ❖
Signature · 1 line
	Evgeniy Polyakov
#22 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Ulrich Drepper
Quoted 10 lines · Ulrich Drepper
Quoted 1 line · Evgeniy Polyakov

Existing design does not allow overflow.

And I've pointed out a number of times that this is not practical at best. There are event sources which can create events which cannot be coalesced into one single event as it would be required with your design.

Signals are one example, specifically realtime signals. If we do not want the design to be limited from the start this approach has to be thought over.

The whole idea of mmap buffer seems to be broken, since those who asked for creation do not like existing design and do not show theirs...

According to signals and possibility to overflow in existing ring buffer implementation.
You seems to not checked the code - each event can be marked as ready only one time, which means only one copy and so on.
It was done _specially_. And it is not limitation, but "new" approach. Queue of the same signals or any other events has fundamental flawness (as any other ring buffer implementation, which has queue size) - it's size of the queue and extremely bad case of the overflow. So, the same event may not be ready several times. Any design which allows to create infinite number of events generated for the same case is broken, since consumer can be in situation, when it can not handle that flow. That is why poll() returns only POLLIN when data is ready in network stack, but is not trying to generate some kind of a signal for each byte/packet/MTU/MSS received.
RT signals have design problems, and I will not repeate the same error with similar limits in kevent.

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

Initial implementation did not have it.
But I was requested to do it, and it is ready now.
No one likes it, but no one provides an alternative implementation. We are stuck.

We need the mapped ring buffer. The current design (before it was removed) was broken but this does not mean it shouldn't be implemented.
We just need more time to figure out how to implement it correctly.

In the latest patchset it was removed. I'm waiting for your code.

Mmap implementation can be added separately, since it does not affect kevent core.

Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, 
CA ❖
Signature · 1 line
	Evgeniy Polyakov
#67 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

One can set number of events before the syscall and do not remove them after syscall. It can be updated if there is need for that.

Nobody doubts that it is possible. But it is

a) potentially much expensive

and

b) an alien concept

to have the signal mask to set during the wait call implicitly. Conceptually it doesn't even make sense. This is no event to wait for.
It a parameter for the specific wait call, just like the timeout. And
I fortunately haven't seen you proposing to pass the timeout value implicitly.

Quoted 6 lines
Quoted 1 line

Not good enough? It does exactly what it is supposed to do. What can there be "not good enough"?

Not to move signals into special case of events. If poll() can not work with them it does not mean, that they need to be specified as additional syscall parameter, instead change poll() to work with them, which can be easily done with kevents.

You still seem to be completely missing the point. The signal mask is no event to wait for. It has nothing to do with this that ppoll() takes the signal mask as a parameter. The signal mask is a parameter for the wait call just like the timeout, not more and not less.

Quoted 4 lines

Do not mix warm and soft - waiting for some period is not equal to syscall timeout. Waiting is possible with timer kevent user (although only relative timeout, can be changed to support both, not a big problem).

That's what I'm saying all the time. Of course it can be supported. But for this the timeout parameter must be a timespec pointer. Whatever you could possibly mean by "do not mix warm and soft" I cannot possibly imagine. Fact is that both relative and absolute timeouts are useful. And that for absolute timeouts the change of the clock has to be taken into account.

Quoted 3 lines

I'm quite sure that absolute timeouts are very usefull, but not as in the case of waiting for syscall completeness. In any way, kevent can be extended to support absolute timeouts in it's timer notifications.

That's not the same. If you argue that then the syscall should have no timeout parameter at all. Fact is that setting up a timer is not for free. Since the timeout is used all the time having a timeout parameter is the right answer. And if you do this then do it right just like every other syscall other than poll: use a timespec object. This gives flexibility without measurable cost.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#23 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 2 lines · Evgeniy Polyakov

The whole idea of mmap buffer seems to be broken, since those who asked for creation do not like existing design and do not show theirs...

What kind of argumentation is that?

"Because my attempt to implement it doesn't work and nobody right
away has a better suggestion this means the idea is broken."

Nonsense.

It just means that time should be spend on thinking about this. You cut all this short by rushing out your attempt without any discussions. Unfortunately nobody else really looked at the approach so it lingered around for some weeks. Well, now it is clear that it is not the right approach and we can start thinking about it again.

Quoted 2 lines

You seems to not checked the code - each event can be marked as ready only one time, which means only one copy and so on. It was done _specially_. And it is not limitation, but "new" approach.

I know that it is done deliberately and I tell you that this is wrong and unacceptable. Realtime signals are one event which need to have more than one event queued. This is no description of what you have implemented, it's a description of the reality of realtime signals.

RT signals are queued. They carry a data value (the sigval_t object) which can be unique for each signal delivery. Coalescing the signal events therefore leads to information loss.

Therefore, at the very least for signal we need to have the ability to queue more than one event for each event source. Not having this functionality means that signals and likely other types of events cannot be implemented using kevent queues.

Quoted 3 lines

Queue of the same signals or any other events has fundamental flawness (as any other ring buffer implementation, which has queue size) - it's size of the queue and extremely bad case of the overflow.

Of course there are additional problems. Overflows need to be handled.
But this is nothing which is unsolvable.

Quoted 4 lines

So, the same event may not be ready several times. Any design which allows to create infinite number of events generated for the same case is broken, since consumer can be in situation, when it can not handle that flow.

That's complete nonsense. Again, for RT signals it is very reasonable and not "broken" to have multiple outstanding signals.

Quoted 2 lines

That is why poll() returns only POLLIN when data is ready in
network stack, but is not trying to generate some kind of a signal for each byte/packet/MTU/MSS received.

It makes no sense to drag poll() into this discussion. poll() is a very limited interface. The new event handling is supposed to be the opposite, namely, usable for all kinds of events. Arguing that because poll() does it like this just means you don't see what big step is needed to get to the goal of a unified event handling. The shackles of poll() must be left behind.

Quoted 2 lines

RT signals have design problems, and I will not repeate the same error with similar limits in kevent.

I don't know what to say. You claim to be the source of all wisdom is OS design. Maybe you should design your own OS, from ground up. I wonder how many people would like that since all your arguments are squarely geared towards optimizing the implementation. But: the implementation is irrelevant without users. The functionality users (= programmers) want and need is what must drive the implementation. And RT signals are definitely heavily used and liked by programmers. You have to accept that you try to modify an OS which has that functionality regardless of how much you hate it and want to fight it.

Quoted 2 lines

Mmap implementation can be added separately, since it does not affect kevent core.

That I doubt very much and it is why I would not want the kevent stuff go into any released kernel until that "detail" is resolved.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
#68 lore raw

Re: [take19 0/4] kevent: Generic event handling mechanism.

In reply to Ulrich Drepper
Quoted 10 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

One can set number of events before the syscall and do not remove them after syscall. It can be updated if there is need for that.

Nobody doubts that it is possible. But it is

a) potentially much expensive

and

Quoted 7 lines

b) an alien concept

to have the signal mask to set during the wait call implicitly. Conceptually it doesn't even make sense. This is no event to wait for.
It a parameter for the specific wait call, just like the timeout. And
I fortunately haven't seen you proposing to pass the timeout value implicitly.

Because timeout has it's meaning for syscall processing, but signals are completely separated objects. Why do you want to allow to queue signals _and_ add 'temporal' signal mask for syscall? Just use one way - queue them all.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Not good enough? It does exactly what it is supposed to do. What can there be "not good enough"?

Not to move signals into special case of events. If poll() can not work with them it does not mean, that they need to be specified as additional syscall parameter, instead change poll() to work with them, which can be easily done with kevents.

Quoted 4 lines

You still seem to be completely missing the point. The signal mask is no event to wait for. It has nothing to do with this that ppoll() takes the signal mask as a parameter. The signal mask is a parameter for the wait call just like the timeout, not more and not less.

That's where we have different opinioins (among others places :) - I do not agree that signals are parameters for syscall, I insist that is is usual events. ppoll() shows us that there is no difference between signal reported as usual user - syscall returns and we can check if something was changed (signal was delivered or even was fired), it does not differ from the case when syscall returns and we check what event it reports first - ready signal or some other event.

Quoted 11 lines
Quoted 4 lines

Do not mix warm and soft - waiting for some period is not equal to syscall timeout. Waiting is possible with timer kevent user (although only relative timeout, can be changed to support both, not a big problem).

That's what I'm saying all the time. Of course it can be supported. But for this the timeout parameter must be a timespec pointer. Whatever you could possibly mean by "do not mix warm and soft" I cannot possibly imagine. Fact is that both relative and absolute timeouts are useful. And that for absolute timeouts the change of the clock has to be taken into account.

They are usefull for special waiting, but not for waiting when syscall is called. The former is supported by timer notifications, the latter - by syscall parameter. We can add support for absolute timer notifications as addon to relative ones. But using there timeval structure is not accessible, since it has different sizes on different arches, so there will be problems with 32/64 arches like x86_64. Instead it is possible to use u32/u32 structure for sec/nsec, like what is used for relative timeouts.

Quoted 10 lines
Quoted 3 lines

I'm quite sure that absolute timeouts are very usefull, but not as in the case of waiting for syscall completeness. In any way, kevent can be extended to support absolute timeouts in it's timer notifications.

That's not the same. If you argue that then the syscall should have no timeout parameter at all. Fact is that setting up a timer is not for free. Since the timeout is used all the time having a timeout parameter is the right answer. And if you do this then do it right just like every other syscall other than poll: use a timespec object. This gives flexibility without measurable cost.

It does not introduce any flexibility, since syscall does not have a parameter to specify absolute or relative timeout has been provided. That's one.
I do argue that syscall must have timout parameter, since it is related to syscall behaviour but not to events syscall is working with - which is completely different things: syscall must be interrupted after some time to allow to fail operation or perform other tasks, but timer event can be fired in any time in the future, syscall should not care about underlaying events. That's two.
You say "every other syscall other than poll" - but even aio_suspend() and friends use relative timeouts (although glibc converts them into absolute to be used with pthread_cond_timedwait), so why do you propose to use wariable sized structure (even if it is transferred almost for free in syscall) instead of usual timeout specified in seconds/nanoseconds/anything? That's three.

Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, 
CA ❖
Signature · 1 line
	Evgeniy Polyakov
#24 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Ulrich Drepper
Quoted 10 lines · Ulrich Drepper
Quoted 2 lines · Evgeniy Polyakov

The whole idea of mmap buffer seems to be broken, since those who asked for creation do not like existing design and do not show theirs...

What kind of argumentation is that?

"Because my attempt to implement it doesn't work and nobody right
away has a better suggestion this means the idea is broken."

Nonsense.

Ok, let's reformulate:
My attempt works, but nobody around likes it, I remove it and wait until some other implement it.

Quoted 5 lines

It just means that time should be spend on thinking about this. You cut all this short by rushing out your attempt without any discussions. Unfortunately nobody else really looked at the approach so it lingered around for some weeks. Well, now it is clear that it is not the right approach and we can start thinking about it again.

I talked about it in the last 13 releases of the kevent, and _noone_ said at least some comments. And now I get - 'it is broken, it does not work, there are problems, we do not want it' and the like. I tried hardly to show that it does work and problems shown can not happen, but noone still hears me. Since I think it is not that interface which is 100% required for correct functionality, I removed it. When there are better suggestions and implementation we can return to them of course.

Quoted 9 lines
Quoted 3 lines

You seems to not checked the code - each event can be marked as ready only one time, which means only one copy and so on.
It was done _specially_. And it is not limitation, but "new" approach.

I know that it is done deliberately and I tell you that this is wrong and unacceptable. Realtime signals are one event which need to have more than one event queued. This is no description of what you have implemented, it's a description of the reality of realtime signals.

Quoted 8 lines

RT signals are queued. They carry a data value (the sigval_t object) which can be unique for each signal delivery. Coalescing the signal events therefore leads to information loss.

Therefore, at the very least for signal we need to have the ability to queue more than one event for each event source. Not having this functionality means that signals and likely other types of events cannot be implemented using kevent queues.

Well, my point about rt-signals is that they do not deserve to be resurrected, but it is only my point :)
In case it is still used, each signal setup should create event - many signals means many events, each signal can be sent with different parameters - each event should correspond to one unique case.

Quoted 6 lines
Quoted 3 lines

Queue of the same signals or any other events has fundamental flawness (as any other ring buffer implementation, which has queue size) - it's size of the queue and extremely bad case of the overflow.

Of course there are additional problems. Overflows need to be handled.
But this is nothing which is unsolvable.

I strongly disagree that having design which allows overflows is acceptible - do we really want rt-signals queue overflow problems in new place? Instead some complex allocation scheme can be created.

Quoted 7 lines
Quoted 4 lines

So, the same event may not be ready several times. Any design which allows to create infinite number of events generated for the same case is broken, since consumer can be in situation, when it can not handle that flow.

That's complete nonsense. Again, for RT signals it is very reasonable and not "broken" to have multiple outstanding signals.

The same signal with different payload is acceptible, but when number of them increases ulimit and they are started to be forgotten - that's what I call broken design.

Quoted 10 lines
Quoted 3 lines

That is why poll() returns only POLLIN when data is ready in network stack, but is not trying to generate some kind of a signal for each byte/packet/MTU/MSS received.

It makes no sense to drag poll() into this discussion. poll() is a very limited interface. The new event handling is supposed to be the opposite, namely, usable for all kinds of events. Arguing that because poll() does it like this just means you don't see what big step is needed to get to the goal of a unified event handling. The shackles of poll() must be left behind.

Kevent is that subsystem, and for now it works quite good.

Quoted 12 lines
Quoted 2 lines

RT signals have design problems, and I will not repeate the same error with similar limits in kevent.

I don't know what to say. You claim to be the source of all wisdom is OS design. Maybe you should design your own OS, from ground up. I wonder how many people would like that since all your arguments are squarely geared towards optimizing the implementation. But: the implementation is irrelevant without users. The functionality users (= programmers) want and need is what must drive the implementation. And RT signals are definitely heavily used and liked by programmers. You have to accept that you try to modify an OS which has that functionality regardless of how much you hate it and want to fight it.

No problem, but I hope you agree that they have major problem related to queue length? And I want to design interface which will not have that problem, so I do not introduce situation which allows to create infinite number of events when receiving side can not handle them.

Quoted 5 lines
Quoted 2 lines

Mmap implementation can be added separately, since it does not affect kevent core.

That I doubt very much and it is why I would not want the kevent stuff go into any released kernel until that "detail" is resolved.

I see you point :)

But talk is cheap, and no code has been released by people who argue against kevent, only existing ring buffer implementation.
I have only two arms and one brain, which unfortunately is not capable to remotely read mental waves about possible design of ring buffer, so I'm waiting.

I expect no one will release new code (soon), so it is possible that kevent will wait forever...
If you do argue for that, I can only say that we are on the different sides - one on the ship, and other on the coast.

Quoted 3 lines
Signature · 2 lines
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, 
CA ❖
Signature · 1 line
	Evgeniy Polyakov
#25 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Ulrich Drepper
Quoted 20 lines · Ulrich Drepper
Quoted 1 line · Evgeniy Polyakov

Existing design does not allow overflow.

And I've pointed out a number of times that this is not practical at best. There are event sources which can create events which cannot be coalesced into one single event as it would be required with your design.

Signals are one example, specifically realtime signals. If we do not want the design to be limited from the start this approach has to be thought over.

Quoted 7 lines
Quoted 2 lines

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

Initial implementation did not have it.
But I was requested to do it, and it is ready now.
No one likes it, but no one provides an alternative implementation. We are stuck.

Quoted 5 lines

We need the mapped ring buffer. The current design (before it was removed) was broken but this does not mean it shouldn't be implemented. We just need more time to figure out how to implement it correctly.

Considering the if at all and if then how of ring buffer implemetation I'd like to throw in some ideas I had when reading the discussion and respective code. If I understood Ulrich Drepper right, his notion of a generic event handling interface is, that it has to be flexible enough to transport additional info from origin to userspace, and to support queuing of events from the same origin, so that additional per-event-occurrence data doesn't get lost, which would happen when coalescing multiple events into one until delivery. From what I read he says ring buffer is broken because of insufficient space for additional data (mukevent) and the limited number of events that can be put into ring buffer. Another argument is missing notification of userspace about dropped events in case ring buffer limit is reached. (is that right?) I see no reason why kevent couldn't be modified to fit (all) these needs. While modifying the server-example and writing a client using kevent I came across the coalescing problem, there were more incoming connections than accept events, and I had to work around that. In this case the pure number of coalesced events would suffice, while it wouldn't for the example of RT-signals that Ulrich Drepper gave. So if coalescing can be done at all or if it is impossible depends on the type of event. The same goes for additional data delivered with the events. There might be no panacea for all possible scenarios with one fixed design. Either performance suffers for 'lightweight' events which don't need additional data and/or coalescing is not problematic and/or ring buffer, or kevent is not usable for other types of events. Why not treat different things differently, and let the (kernel-)user decide. I don't know if I got all this right, but if, then ring buffer is needed especially for cases where coalescing is not possible and additional data has to be delivered for each triggered notification (so the pure number of events is not enough; other reasons? performance? ). To me it doesn't make sense to have kevent fill memory and use processor-time if buffer is not used at all, which is the case when using kevent_getevents. So here are my Ideas:
Make usage of ring buffer optional, if not required for specific event-type it might be chosen by userspace-code.
Make limit of events in ring buffer optional and controllable from userspace.
Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait). To my limited understanding it seems that alternative or modified versions of kevent_storage_ready, (__)kevent_requeue and kevent_user_ring_add_event could return a void pointer to the position in buffer, and all kevent has to know about is the size of the struct.
If coalescing doesn't hurt for a specific event-type it might just be modified to notify userspace about the number of coalesced events. Make it depend on type of event.

I know this doesn't address all objections that have been made, and Evgeniy, big sorry for this being just talk again, and maybe not even applicable for some reasons I do not overlook, but maybe it's worth consideration. I'll gladly try to put that into code, and see where it leads. I think kevent is great, and if things can be done to increase it's genericity without sacrifying performance, why not. Sorry for the length of post and repetitions,

Johann

#26 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 3 lines · Johann Borck

Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait).

I'd personally worry about an implementation that used a per-event-type ring buffer, because you're still left having to hack around starvation issues in user-space. It is of course possible under the current model for anyone who wants per-event-type ring buffers to have them - just make separate kevent sets.

I haven't thought this through all the way yet, but why not have variable length event structures and have the kernel fill in a "next" pointer in each one? This could even be used to keep backwards binary compatibility while adding additional fields to the structures over time, though no space would be wasted on modern programs. You still end up with a question of what to do in case of overflow, but I'm thinking the thing to do in that case might be to start pushing overflow events onto a linked list which can be written back into the ring buffer when space becomes available. The appropriate behavior would be to throw new events on the linked list if the linked list had any events, so that things are delivered in order, but write to the mapped buffer directly otherwise.

Deciding when to do that is tricky, and I haven't thought through the implications fully when I say this, but what about activating a bottom half when more space becomes available, and let that drain overflowed events back into the mapped buffer? Or perhaps the time to do it would be in the next blocking wait, when the queue emptied?

I think it is very important to avoid any limits that can not be adjusted on the fly at run-time by CAP_SYS_ADMIN or what have you. Doing it this way may have other problems I've ignored but at least the big one - compile-time capacity limits in the year 2006 - would be largely avoided :P

Nothing real solid yet, just some electrical storms in the grey matter...

Thanks,
Chase

#30 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Johann Borck
Quoted 26 lines · Johann Borck
Quoted 20 lines · Ulrich Drepper
Quoted 1 line · Evgeniy Polyakov

Existing design does not allow overflow.

And I've pointed out a number of times that this is not practical at best. There are event sources which can create events which cannot be coalesced into one single event as it would be required with your design.

Signals are one example, specifically realtime signals. If we do not want the design to be limited from the start this approach has to be thought over.

Quoted 7 lines
Quoted 2 lines

So zap mmap() support completely, since it is not usable at all. We wont discuss on it.

Initial implementation did not have it.
But I was requested to do it, and it is ready now.
No one likes it, but no one provides an alternative implementation. We are stuck.

Quoted 5 lines

We need the mapped ring buffer. The current design (before it was removed) was broken but this does not mean it shouldn't be implemented. We just need more time to figure out how to implement it correctly.

Quoted 12 lines

Considering the if at all and if then how of ring buffer implemetation I'd like to throw in some ideas I had when reading the discussion and respective code. If I understood Ulrich Drepper right, his notion of a generic event handling interface is, that it has to be flexible enough to transport additional info from origin to userspace, and to support queuing of events from the same origin, so that additional per-event-occurrence data doesn't get lost, which would happen when coalescing multiple events into one until delivery. From what I read he says ring buffer is broken because of insufficient space for additional data (mukevent) and the limited number of events that can be put into ring buffer. Another argument is missing notification of userspace about dropped events in case ring buffer limit is reached. (is that right?)

I can add such notification, but its existense _is_ the broken design. After such condition happend, all new events will dissapear (although they are still accessible through usual queue) from mapped buffer.

While writing this I have come to the idea on how to imrove the case of the size of mapped buffer - we can make it with limited size, and when it is full, some bit will be set in the shared area and obviously no new events can be added there, but when user commits some events from that buffer (i.e. says to kernel that appropriate kevents can be freed or requeued according to theirs flags), new ready events from ready queue can be copied into mapped buffer.

It still does not solve (and I do insist that it is broken behaviour) the case when kernel is going to generate infinite number of events for one requested by userspace (as in case of generating new 'data_has_arrived' event when new byte has been received).

Userspace events are only marked as ready, they are not generated - it is high-performance _feature_ of the new design, not some kind of a bug.

Quoted 4 lines

I see no reason why kevent couldn't be modified to fit (all) these needs. While modifying the server-example and writing a client using kevent I came across the coalescing problem, there were more incoming connections than accept events, and I had to work around that. In this

Btw, accept() issue is exactly the same as with usual poll() - repeated insertion of the same kevent will fire immediately, which requires event to be one-shot. One of the initial implementation contained number of ready for accept sockets as one of the returned parameters though.

Quoted 12 lines

case the pure number of coalesced events would suffice, while it wouldn't for the example of RT-signals that Ulrich Drepper gave. So if coalescing can be done at all or if it is impossible depends on the type of event. The same goes for additional data delivered with the events. There might be no panacea for all possible scenarios with one fixed design. Either performance suffers for 'lightweight' events which don't need additional data and/or coalescing is not problematic and/or ring buffer, or kevent is not usable for other types of events. Why not treat different things differently, and let the (kernel-)user decide. I don't know if I got all this right, but if, then ring buffer is needed especially for cases where coalescing is not possible and additional data has to be delivered for each triggered notification (so the pure

Quoted 8 lines

number of events is not enough; other reasons? performance? ). To me it doesn't make sense to have kevent fill memory and use processor-time if buffer is not used at all, which is the case when using kevent_getevents. So here are my Ideas:
Make usage of ring buffer optional, if not required for specific event-type it might be chosen by userspace-code.
Make limit of events in ring buffer optional and controllable from userspace.

It is of course possible, main problem is that existing design of the mapped buffer is not sufficient, and there are no other propositions except that 'it sucks'.

Quoted 10 lines

Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait). To my limited understanding it seems that alternative or modified versions of kevent_storage_ready, (__)kevent_requeue and kevent_user_ring_add_event could return a void pointer to the position in buffer, and all kevent has to know about is the size of the struct.
If coalescing doesn't hurt for a specific event-type it might just be modified to notify userspace about the number of coalesced events. Make it depend on type of event.

It is perfectly ok to add number of the same event fired while it was in the ready queue, it was even done for accept notifications some time ago. It depends on kernel kevent user - each one can add anything it wants into appropriate returned data, that is why it was added.

Quoted 7 lines

I know this doesn't address all objections that have been made, and Evgeniy, big sorry for this being just talk again, and maybe not even applicable for some reasons I do not overlook, but maybe it's worth consideration. I'll gladly try to put that into code, and see where it leads. I think kevent is great, and if things can be done to increase it's genericity without sacrifying performance, why not. Sorry for the length of post and repetitions,

I greatly appreciate you work with kevents Johann, thank you.

Quoted 1 line

Johann

Signature · 1 line
	Evgeniy Polyakov
#27 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Chase Venters
Quoted 11 lines · Chase Venters
Quoted 3 lines · Johann Borck

Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait).

I'd personally worry about an implementation that used a per-event-type ring buffer, because you're still left having to hack around starvation issues in user-space. It is of course possible under the current model for anyone who wants per-event-type ring buffers to have them - just make separate kevent sets.

Quoted 3 lines

I haven't thought this through all the way yet, but why not have variable length event structures and have the kernel fill in a "next" pointer in each one? This could even be used to keep backwards binary compatibility while

Why do we want variable size structures in mmap ring buffer?

Quoted 8 lines

adding additional fields to the structures over time, though no space would be wasted on modern programs. You still end up with a question of what to do in case of overflow, but I'm thinking the thing to do in that case might be to start pushing overflow events onto a linked list which can be written back into the ring buffer when space becomes available. The appropriate behavior would be to throw new events on the linked list if the linked list had any events, so that things are delivered in order, but write to the mapped buffer directly otherwise.

I think in a similar way.
Kevent actually do not require such list, since it has already queue of the ready events.

Signature · 1 line
	Evgeniy Polyakov
#28 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 12:59:47AM -0500, Chase Venters

Quoted 11 lines · ([email protected]) wrote:
Quoted 11 lines · Johann Borck
Quoted 3 lines

Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait).

I'd personally worry about an implementation that used a per-event-type ring buffer, because you're still left having to hack around starvation issues in user-space. It is of course possible under the current model for anyone who wants per-event-type ring buffers to have them - just make separate kevent sets.

Quoted 6 lines
Quoted 4 lines

I haven't thought this through all the way yet, but why not have variable length event structures and have the kernel fill in a "next" pointer in each one? This could even be used to keep backwards binary compatibility while

Why do we want variable size structures in mmap ring buffer?

Flexibility primarily. So when we all decide to add a new event type six months from now, or add more information to an existing one, we don't run the risk that the existing mukevent isn't big enough.

Quoted 9 lines
Quoted 8 lines

adding additional fields to the structures over time, though no space would be wasted on modern programs. You still end up with a question of what to do in case of overflow, but I'm thinking the thing to do in that case might be to start pushing overflow events onto a linked list which can be written back into the ring buffer when space becomes available. The appropriate behavior would be to throw new events on the linked list if the linked list had any events, so that things are delivered in order, but write to the mapped buffer directly otherwise.

Quoted 3 lines

I think in a similar way.
Kevent actually do not require such list, since it has already queue of the ready events.

The current event types coalesce if there are multiple events, correct? It sounds like there may be other event types where coalescing multiple events is not the correct approach.

Thanks,
Chase

#31 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Evgeniy Polyakov
Quoted 12 lines · Evgeniy Polyakov

I can add such notification, but its existense _is_ the broken design. After such condition happend, all new events will dissapear (although they are still accessible through usual queue) from mapped buffer.

While writing this I have come to the idea on how to imrove the case of the size of mapped buffer - we can make it with limited size, and when it is full, some bit will be set in the shared area and obviously no new events can be added there, but when user commits some events from that buffer (i.e. says to kernel that appropriate kevents can be freed or requeued according to theirs flags), new ready events from ready queue can be copied into mapped buffer.

Quoted 4 lines

It still does not solve (and I do insist that it is broken behaviour) the case when kernel is going to generate infinite number of events for one requested by userspace (as in case of generating new 'data_has_arrived' event when new byte has been received).

Behavior is not broken. It's quite usefull and works 99.9999% of time.

I was trying to suggest you but you missed my point.

You dont want to use a bit, but a full sequence counter, 32bits.

A program may handle XXX.XXX handles, but use a 4096 entries ring buffer 'only'.

The user program keeps a local copy of a special word named 'ring_buffer_full_counter'

Each time the kernel cannot queue an event in the ring buffer, it increase the "ring_buffer_was_full_counter" (exported to user app in the mmap view)

When the user application notice the kernel
changed "ring_buffer_was_full_counter" it does a full scan of all file handles (preferably using poll() to get all relevant info in one syscall) :

do {
if (read_event_from_mmap()) {handle_event(fd); continue;} /* ring buffer is empty, check if we missed some events */ if (unlikely(mmap->ring_buffer_full_counter !=

my_ring_buffer_full_counter)) {
	my_ring_buffer_full_counter = mmap->ring_buffer_full_counter;
	/* slow PATH */
	/* can use a big poll() for example, or just a loop without poll() */
	for_all_file_desc_do() {
		check if some event/data is waiting on THIS fd
		}
	/* 
	}
    else  syscall_wait_for_one_available_kevent(queue)
}

This is how a program can recover. If ring buffer has a reasonable size, this kind of event should not happen very frequently. If it does (because events continue to fill ring_buffer during recovery and might hit FULL again), maybe a smart program is able to resize the ring_buffer, and start using it after yet another recovery pass.
If not, we dont care, because a big poll() give us many ready file-descriptors in one syscall, and maybe this is much better than kevent/epoll when XX.XXX events are ready.

Eric

#29 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Chase Venters
Quoted 15 lines · Chase Venters
Quoted 15 lines
Quoted 14 lines
Quoted 3 lines

Regarding mukevent I'm thinking of a event-type specific struct, that is filled by the originating code, and placed into a per-event-type ring buffer (which requires modification of kevent_wait).

I'd personally worry about an implementation that used a per-event-type ring buffer, because you're still left having to hack around starvation issues in user-space. It is of course possible under the current model for anyone who wants per-event-type ring buffers to have them - just make separate kevent sets.

I haven't thought this through all the way yet, but why not have variable length event structures and have the kernel fill in a "next" pointer in each one? This could even be used to keep backwards binary compatibility while

Quoted 5 lines
Quoted 1 line

Why do we want variable size structures in mmap ring buffer?

Flexibility primarily. So when we all decide to add a new event type six months from now, or add more information to an existing one, we don't run the risk that the existing mukevent isn't big enough.

Do we need such flexibility, when we have unique id attached to each event? User can store any information in own buffers, which are indexed by that id.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

adding additional fields to the structures over time, though no space would be wasted on modern programs. You still end up with a question of what to do in case of overflow, but I'm thinking the thing to do in that case might be to start pushing overflow events onto a linked list which can be written back into the ring buffer when space becomes available. The appropriate behavior would be to throw new events on the linked list if the linked list had any events, so that things are delivered in order, but write to the mapped buffer directly otherwise.

Quoted 7 lines
Quoted 3 lines

I think in a similar way.
Kevent actually do not require such list, since it has already queue of the ready events.

The current event types coalesce if there are multiple events, correct? It sounds like there may be other event types where coalescing multiple events is not the correct approach.

There is no events coalescing, I think that it is even incorrect to say, that something is being coalesced in kevents.

There is 'new' (which is well forgotten old) approach - user _asks_ kernel about some information, and kernel says when it is ready. Kernel does not
say: part of the info is ready, part of the info is ready and so on, it just marks user's request as ready - that means that it is possible that there were zillions of events, each one could mark the _same_ userspace request as ready, and exactly what user requested is transferred back. Thus it is very fast and is correct way to deal with problem of pipes of different diameters.

Kernel does not generate events - only user creates requests, which are marked as ready.

I made that decision to remove _any_ kind of possible overflows from kernel side - if user was scheduled away, or has unsufficient space or bad mood, to not introduce any kind of ugly priorities (higher one could fill the whole pipe while lower could not even send a single event). Instead kernel does just what it was requested to do, and it can provide some hints on how that process happend (for example how many sockets are ready for accept(), or how many bytes are in the receiving queue).

And that approach does solve the problem of the cases when it looks like it is logical to _generate_ event - for example in inotify case, where new event is _generated_ each time requested case happens. For example the case when new files are created in the directory - it is possible that there will be queue overflow (btw, watch for each file in the kernel tree takes about 2gb of kernel mem), if many files were created, so userspace must rescan the whole directory to check missed files, so why is it needed at all to generate info about first two or ten files, instead userspace asks kernel to notify it when directory has changed or some new files were created, and kernelspace will answer when directory has been changed or new files were created (with some hint with number of them).

Likely request for generation of events in kernel is a workaround for some other problems, which in long term will hit us with new troubles - queue length and overflows.

Quoted 2 lines

Thanks,
Chase

Signature · 1 line
	Evgeniy Polyakov
#32 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Eric Dumazet
Quoted 31 lines · Eric Dumazet
Quoted 12 lines · Evgeniy Polyakov

I can add such notification, but its existense _is_ the broken design. After such condition happend, all new events will dissapear (although they are still accessible through usual queue) from mapped buffer.

While writing this I have come to the idea on how to imrove the case of the size of mapped buffer - we can make it with limited size, and when it is full, some bit will be set in the shared area and obviously no new events can be added there, but when user commits some events from that buffer (i.e. says to kernel that appropriate kevents can be freed or requeued according to theirs flags), new ready events from ready queue can be copied into mapped buffer.

Quoted 4 lines

It still does not solve (and I do insist that it is broken behaviour) the case when kernel is going to generate infinite number of events for one requested by userspace (as in case of generating new 'data_has_arrived' event when new byte has been received).

Behavior is not broken. It's quite usefull and works 99.9999% of time.

I was trying to suggest you but you missed my point.

You dont want to use a bit, but a full sequence counter, 32bits.

A program may handle XXX.XXX handles, but use a 4096 entries ring buffer 'only'.

The user program keeps a local copy of a special word named 'ring_buffer_full_counter'

Quoted 6 lines

Each time the kernel cannot queue an event in the ring buffer, it increase the "ring_buffer_was_full_counter" (exported to user app in the mmap view)

When the user application notice the kernel
changed "ring_buffer_was_full_counter" it does a full scan of all file handles (preferably using poll() to get all relevant info in one syscall) :

I.e. to scan the rest of the xxx.xxx events?

Quoted 16 lines
do {
   if (read_event_from_mmap()) {handle_event(fd); continue;}
   /* ring buffer is empty, check if we missed some events */
   if (unlikely(mmap->ring_buffer_full_counter !=  
my_ring_buffer_full_counter)) {
	my_ring_buffer_full_counter = mmap->ring_buffer_full_counter;
	/* slow PATH */
	/* can use a big poll() for example, or just a loop without poll() */
	for_all_file_desc_do() {
		check if some event/data is waiting on THIS fd
		}
	/* 
	}
    else  syscall_wait_for_one_available_kevent(queue)
}
Quoted 8 lines

This is how a program can recover. If ring buffer has a reasonable size, this kind of event should not happen very frequently. If it does (because events continue to fill ring_buffer during recovery and might hit FULL again), maybe a smart program is able to resize the ring_buffer, and start using it after yet another recovery pass.
If not, we dont care, because a big poll() give us many ready file-descriptors in one syscall, and maybe this is much better than kevent/epoll when XX.XXX events are ready.

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Quoted 1 line

Eric

Signature · 1 line
	Evgeniy Polyakov
#33 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 03:19:36PM +0200, Eric Dumazet ([email protected])

Quoted 66 lines · wrote:
Quoted 30 lines · Evgeniy Polyakov
Quoted 12 lines

I can add such notification, but its existense _is_ the broken design. After such condition happend, all new events will dissapear (although they are still accessible through usual queue) from mapped buffer.

While writing this I have come to the idea on how to imrove the case of the size of mapped buffer - we can make it with limited size, and when it is full, some bit will be set in the shared area and obviously no new events can be added there, but when user commits some events from that buffer (i.e. says to kernel that appropriate kevents can be freed or requeued according to theirs flags), new ready events from ready queue can be copied into mapped buffer.

Quoted 4 lines

It still does not solve (and I do insist that it is broken behaviour) the case when kernel is going to generate infinite number of events for one requested by userspace (as in case of generating new 'data_has_arrived' event when new byte has been received).

Behavior is not broken. It's quite usefull and works 99.9999% of time.

I was trying to suggest you but you missed my point.

You dont want to use a bit, but a full sequence counter, 32bits.

A program may handle XXX.XXX handles, but use a 4096 entries ring buffer 'only'.

The user program keeps a local copy of a special word named 'ring_buffer_full_counter'

Quoted 8 lines

Each time the kernel cannot queue an event in the ring buffer, it increase the "ring_buffer_was_full_counter" (exported to user app in the mmap view)

When the user application notice the kernel
changed "ring_buffer_was_full_counter" it does a full scan of all file handles (preferably using poll() to get all relevant info in one syscall) :

I.e. to scan the rest of the xxx.xxx events?

Quoted 16 lines
do {
   if (read_event_from_mmap()) {handle_event(fd); continue;}
   /* ring buffer is empty, check if we missed some events */
   if (unlikely(mmap->ring_buffer_full_counter !=
my_ring_buffer_full_counter)) {
	my_ring_buffer_full_counter = mmap->ring_buffer_full_counter;
	/* slow PATH */
	/* can use a big poll() for example, or just a loop without poll() */
	for_all_file_desc_do() {
		check if some event/data is waiting on THIS fd
		}
	/*
	}
    else  syscall_wait_for_one_available_kevent(queue)
}
Quoted 8 lines

This is how a program can recover. If ring buffer has a reasonable size, this kind of event should not happen very frequently. If it does (because events continue to fill ring_buffer during recovery and might hit FULL again), maybe a smart program is able to resize the ring_buffer, and start using it after yet another recovery pass.
If not, we dont care, because a big poll() give us many ready file-descriptors in one syscall, and maybe this is much better than kevent/epoll when XX.XXX events are ready.

Quoted 4 lines

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than ZERO (and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Eric

#34 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 8 lines · Eric Dumazet
Quoted 4 lines

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

Only if user simultaneously uses oth interfaces and remove even from the queue when it's copy was in mapped buffer, but in that case it's user's problem (and if we do want, we can store pointer/index of the ring buffer entry, so when event is removed from the ready queue (using kevent_get_events()), appropriate entry in the ring buffer will be updated to show that it is no longer valid.

Quoted 9 lines

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than ZERO (and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Have I missed something? It looks like the only problematic situation is described above when user simultaneously uses both interfaces.

Quoted 1 line

Eric

Signature · 1 line
	Evgeniy Polyakov
#35 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 03:52:34PM +0200, Eric Dumazet ([email protected])

Quoted 24 lines · wrote:
Quoted 9 lines
Quoted 5 lines

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

Only if user simultaneously uses oth interfaces and remove even from the queue when it's copy was in mapped buffer, but in that case it's user's problem (and if we do want, we can store pointer/index of the ring buffer entry, so when event is removed from the ready queue (using kevent_get_events()), appropriate entry in the ring buffer will be updated to show that it is no longer valid.

Quoted 7 lines

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than ZERO (and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

Quoted 5 lines
Quoted 2 lines

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Have I missed something? It looks like the only problematic situation is described above when user simultaneously uses both interfaces.

In my point of view, user of the 'mmaped ring buffer' should be prepared to use both interfaces. Or else you are forced to presize the ring buffer to insane limits.

That is :
- Most of the time, we expect consuming events via mmaped ring buffer and no syscalls.
- In case we notice a 'mmaped ring buffer overflow', syscalls to get/consume events that could not be stored in mmaped buffer (but queued by kevent subsystem). If not stored by kevent subsystem (memory failure ?), revert to poll() to fetch all 'missed fds' in one row. Go back to normal mode.

- In case of empty ring buffer (or no mmap support at all, because this app doesnt expect lot of events per time unit, or because kevent dont have mmap support) : Be able to syscall and wait for an event.

Eric

#36 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 37 lines · Eric Dumazet
Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 03:52:34PM +0200, Eric Dumazet ([email protected])

Quoted 24 lines · wrote:
Quoted 9 lines
Quoted 5 lines

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

Only if user simultaneously uses oth interfaces and remove even from the queue when it's copy was in mapped buffer, but in that case it's user's problem (and if we do want, we can store pointer/index of the ring buffer entry, so when event is removed from the ready queue (using kevent_get_events()), appropriate entry in the ring buffer will be updated to show that it is no longer valid.

Quoted 7 lines

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than ZERO (and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

Quoted 5 lines
Quoted 2 lines

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Have I missed something? It looks like the only problematic situation is described above when user simultaneously uses both interfaces.

In my point of view, user of the 'mmaped ring buffer' should be prepared to use both interfaces. Or else you are forced to presize the ring buffer to insane limits.

Quoted 7 lines

That is :
- Most of the time, we expect consuming events via mmaped ring buffer and no syscalls.
- In case we notice a 'mmaped ring buffer overflow', syscalls to get/consume events that could not be stored in mmaped buffer (but queued by kevent subsystem). If not stored by kevent subsystem (memory failure ?), revert to poll() to fetch all 'missed fds' in one row. Go back to normal mode.

kevent uses smaller amount of memory than epoll() per event, so it is very unlikely that it will be impossible to store new event there and epoll() will succeed. The same can be applied to poll(), which allocates the whole table in syscall.

Quoted 3 lines

- In case of empty ring buffer (or no mmap support at all, because this app doesnt expect lot of events per time unit, or because kevent dont have mmap support) : Be able to syscall and wait for an event.

So the most complex case is when user is going to use both interfaces, and it's steps when mapped ring buffer has overflow.
In that case user can either read and mark some events as ready in ring buffer (the latter is being done through special syscall), so kevent core will put there new ready events.
User can also get events using usual syscall, in that case events in ring buffer must be updated - and actually I implemented mapped buffer in the way which allows to remove events from the queue - queue is a FIFO, and the first entry to be obtained through syscall is _always_ the first entry in the ring buffer.

So when user reads event through syscall (no matter if we are in overflow case or not), even being read is easily accessible in the ring buffer.

So I propose following design for ring buffer (quite simple):
kernelspace maintains two indexes - to the first and the last events in the ring buffer (and maximum size of the buffer of course). When new event is marked as ready, some info is being copied into ring buffer and index of the last entry is increased.
When event is being read through syscall it is _guaranteed_ that that event will be at the position pointed by the index of the first element, that index is then increased (thus opening new slot in the buffer).
If index of the last entry reaches (with possible wrapping) index of the first entry, that means that overflow has happend. In this case no new events can be copied into ring buffer, so they are only placed into ready queue (accessible through syscall kevent_get_events()).

When user calls kevent_get_events() it will obtain the first element (pointed by index of the first element in the ring buffer), and if there is ready event, which is not placed into the ring buffer, it is copied (with appropriate update of the last index and new overflow condition).

When userspace calls kevent_wait(num), it means that userspace marks as ready first (from index of the first element) $num elements, which thus can be removed (or requeued) and replaced by pending ready events.

Does it sound like clawing over the glass or much better?

Quoted 5 lines

Eric
-
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
#37 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 04:25:00PM +0200, Eric Dumazet ([email protected])

Quoted 86 lines · wrote:
Quoted 40 lines · Evgeniy Polyakov
Quoted 2 lines

On Tue, Oct 17, 2006 at 03:52:34PM +0200, Eric Dumazet ([email protected])

Quoted 25 lines · wrote:
Quoted 10 lines
Quoted 5 lines

What about the case, which I described in other e-mail, when in case of the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

Only if user simultaneously uses oth interfaces and remove even from the queue when it's copy was in mapped buffer, but in that case it's user's problem (and if we do want, we can store pointer/index of the ring buffer entry, so when event is removed from the ready queue (using kevent_get_events()), appropriate entry in the ring buffer will be updated to show that it is no longer valid.

Quoted 7 lines

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than ZERO (and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

Quoted 5 lines
Quoted 2 lines

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Have I missed something? It looks like the only problematic situation is described above when user simultaneously uses both interfaces.

In my point of view, user of the 'mmaped ring buffer' should be prepared to use both interfaces. Or else you are forced to presize the ring buffer to insane limits.

Quoted 8 lines

That is :
- Most of the time, we expect consuming events via mmaped ring buffer and no syscalls.
- In case we notice a 'mmaped ring buffer overflow', syscalls to get/consume events that could not be stored in mmaped buffer (but queued by kevent subsystem). If not stored by kevent subsystem (memory failure ?), revert to poll() to fetch all 'missed fds' in one row. Go back to normal mode.

kevent uses smaller amount of memory than epoll() per event, so it is very unlikely that it will be impossible to store new event there and epoll() will succeed. The same can be applied to poll(), which allocates the whole table in syscall.

Quoted 3 lines

- In case of empty ring buffer (or no mmap support at all, because this app doesnt expect lot of events per time unit, or because kevent dont have mmap support) : Be able to syscall and wait for an event.

So the most complex case is when user is going to use both interfaces, and it's steps when mapped ring buffer has overflow.
In that case user can either read and mark some events as ready in ring buffer (the latter is being done through special syscall), so kevent core will put there new ready events.
User can also get events using usual syscall, in that case events in ring buffer must be updated - and actually I implemented mapped buffer in the way which allows to remove events from the queue - queue is a FIFO, and the first entry to be obtained through syscall is _always_ the first entry in the ring buffer.

So when user reads event through syscall (no matter if we are in overflow case or not), even being read is easily accessible in the ring buffer.

So I propose following design for ring buffer (quite simple):
kernelspace maintains two indexes - to the first and the last events in the ring buffer (and maximum size of the buffer of course). When new event is marked as ready, some info is being copied into ring buffer and index of the last entry is increased.
When event is being read through syscall it is _guaranteed_ that that event will be at the position pointed by the index of the first element, that index is then increased (thus opening new slot in the buffer).
If index of the last entry reaches (with possible wrapping) index of the first entry, that means that overflow has happend. In this case no new events can be copied into ring buffer, so they are only placed into ready queue (accessible through syscall kevent_get_events()).

Quoted 5 lines

When user calls kevent_get_events() it will obtain the first element (pointed by index of the first element in the ring buffer), and if there is ready event, which is not placed into the ring buffer, it is copied (with appropriate update of the last index and new overflow condition).

Well, I'm not sure its good to do this 'move one event from ready list to slot X', one by one, because this event will likely be flushed out of processor cache (because we will have to consume 4096 events before reaching this one). I think its better to batch this kind of 'push XX events' later, XX being small enough not to waste CPU cache, and when ring buffer is empty again.

mmap buffer is good for latency and minimum synchro between user thread and kernel producer. But once we hit an 'overflow', it is better to revert to a mode feeding XX events per syscall, to be sure it fits CPU caches : The user thread will do the copy between kernel memory to user memory, and this thread will shortly use those events in user land.

BTW, maintaining coherency on mmap buffer is expensive : once a event is copied to mmap buffer, kernel has to issue a smp_mb() before updating the index, so that a user thread wont start to consume an event with random values because its CPU see the update on index before updates on data.

Once all the queue is flushed in efficient way, we can switch to mmap mode again.

Eric

#44 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Eric Dumazet
Quoted 2 lines · Eric Dumazet
Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 03:52:34PM +0200, Eric Dumazet

([email protected])

Quoted 2 lines
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line

What about the case, which I described in other e-mail, when in case

of

Quoted 16 lines
Quoted 16 lines
Quoted 8 lines
Quoted 4 lines

the full ring buffer, no new events are written there, and when userspace commits (i.e. marks as ready to be freed or requeued by kernel) some events, new ones will be copied from ready queue into the buffer?

Then, user might receive 'false events', exactly like poll()/select()/epoll() can do sometime. IE a 'ready' indication while there is no current event available on a particular fd / event_source.

Only if user simultaneously uses oth interfaces and remove even from the queue when it's copy was in mapped buffer, but in that case it's user's problem (and if we do want, we can store pointer/index of the ring buffer entry, so when event is removed from the ready queue (using kevent_get_events()), appropriate entry in the ring buffer will be updated to show that it is no longer valid.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This should be safe, since those programs already ignore read() returns -EAGAIN and other similar things.

Programmer prefers to receive two 'event available' indications than

ZERO

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

(and be stuck for infinite time). Of course, hot path (normal cases) should return one 'event' only.

In order words, being ultra fast 99.99 % of the time, but being able to block forever once in a while is not an option.

Quoted 6 lines
Quoted 2 lines

Have I missed something? It looks like the only problematic situation is described above when user simultaneously uses both interfaces.

In my point of view, user of the 'mmaped ring buffer' should be prepared to use both interfaces. Or else you are forced to presize the ring buffer to insane limits.

I don't see why overflow couldn't be handle by a syscall telling the kernel that the buffer is ready for new events. As mentioned most of the time overflow should not happend and if it does the syscall should be amortized nicely by the number of events.

Quoted 11 lines

That is :
- Most of the time, we expect consuming events via mmaped ring buffer and no syscalls.
- In case we notice a 'mmaped ring buffer overflow', syscalls to get/consume events that could not be stored in mmaped buffer (but queued by kevent subsystem). If not stored by kevent subsystem (memory failure ?), revert to poll() to fetch all 'missed fds' in one row. Go back to normal mode.

- In case of empty ring buffer (or no mmap support at all, because this app doesnt expect lot of events per time unit, or because kevent dont have mmap support) : Be able to syscall and wait for an event.

As I see it there are two main problems with a mmapped ring buffer (correct me if I'm wrong):

1. Overflow.
2. Handle multiple kernel event that only needs one user event. I.e. multiple packet arriving at the same socket. The user should only see one IN event at the time he is ready to handle it.

In an earlier post I suggested a scheme that solves these issues. It was based on the assumption that kernel and user-space share index variables and can read/update them atomically without much overhead. Only in cases where the buffer is empty and full system call would be required.

Hans Henrik Happe

#38 lore raw

Re: [take19 1/4] kevent: Core files.

In reply to Eric Dumazet
Quoted 34 lines · Eric Dumazet
Quoted 28 lines

So the most complex case is when user is going to use both interfaces, and it's steps when mapped ring buffer has overflow.
In that case user can either read and mark some events as ready in ring buffer (the latter is being done through special syscall), so kevent core will put there new ready events.
User can also get events using usual syscall, in that case events in ring buffer must be updated - and actually I implemented mapped buffer in the way which allows to remove events from the queue - queue is a FIFO, and the first entry to be obtained through syscall is _always_ the first entry in the ring buffer.

So when user reads event through syscall (no matter if we are in overflow case or not), even being read is easily accessible in the ring buffer.

So I propose following design for ring buffer (quite simple):
kernelspace maintains two indexes - to the first and the last events in the ring buffer (and maximum size of the buffer of course). When new event is marked as ready, some info is being copied into ring buffer and index of the last entry is increased.
When event is being read through syscall it is _guaranteed_ that that event will be at the position pointed by the index of the first element, that index is then increased (thus opening new slot in the buffer).
If index of the last entry reaches (with possible wrapping) index of the first entry, that means that overflow has happend. In this case no new events can be copied into ring buffer, so they are only placed into ready queue (accessible through syscall kevent_get_events()).

Quoted 5 lines

When user calls kevent_get_events() it will obtain the first element (pointed by index of the first element in the ring buffer), and if there is ready event, which is not placed into the ring buffer, it is copied (with appropriate update of the last index and new overflow condition).

Quoted 5 lines

Well, I'm not sure its good to do this 'move one event from ready list to slot X', one by one, because this event will likely be flushed out of processor cache (because we will have to consume 4096 events before reaching this one). I think its better to batch this kind of 'push XX events' later, XX being small enough not to waste CPU cache, and when ring buffer is empty again.

Ok, that's possible.

Quoted 5 lines

mmap buffer is good for latency and minimum synchro between user thread and kernel producer. But once we hit an 'overflow', it is better to revert to a mode feeding XX events per syscall, to be sure it fits CPU caches : The user thread will do the copy between kernel memory to user memory, and this thread will shortly use those events in user land.

User can do both - either get events through syscall, or get them from mapped ring buffer when it is refilled.

Quoted 4 lines

BTW, maintaining coherency on mmap buffer is expensive : once a event is copied to mmap buffer, kernel has to issue a smp_mb() before updating the index, so that a user thread wont start to consume an event with random values because its CPU see the update on index before updates on data.

There will be some tricks with barriers indeed.

Quoted 4 lines

Once all the queue is flushed in efficient way, we can switch to mmap mode again.

Eric

Ok, there is one apologist for mmap buffer implementation, who forced me to create first implementation, which was dropped due to absense of remote mental reading abilities.
Ulrich, does above approach sound good for you?
I actually do not want to reimplement something, that will be pointed to with words 'no matter what you say, it is broken and I do not want it' again :).

Signature · 1 line
	Evgeniy Polyakov
#39 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 7 lines · Evgeniy Polyakov

Ok, there is one apologist for mmap buffer implementation, who forced me to create first implementation, which was dropped due to absense of remote mental reading abilities.
Ulrich, does above approach sound good for you?
I actually do not want to reimplement something, that will be pointed to with words 'no matter what you say, it is broken and I do not want it' again :).

In my humble opinion, you should first write a 'real application', to show how the mmap buffer and kevent syscalls would be used (fast path and slow/recovery paths). I am sure it would be easier for everybody to agree on the API *before* you start coding a *lot* of hard (kernel) stuff : It would certainly save your mental CPU cycles (and ours too :) )

This 'real application' could be the event loop of a simple HTTP server, or a basic 'echo all' server. Adding the bits about timers events and signals should be done too.

Eric

#40 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 16 lines · Eric Dumazet
Quoted 7 lines · Evgeniy Polyakov

Ok, there is one apologist for mmap buffer implementation, who forced me to create first implementation, which was dropped due to absense of remote mental reading abilities.
Ulrich, does above approach sound good for you?
I actually do not want to reimplement something, that will be pointed to with words 'no matter what you say, it is broken and I do not want it' again :).

In my humble opinion, you should first write a 'real application', to show how the mmap buffer and kevent syscalls would be used (fast path and slow/recovery paths). I am sure it would be easier for everybody to agree on the API *before* you start coding a *lot* of hard (kernel) stuff : It would certainly save your mental CPU cycles (and ours too :) )

Quoted 3 lines

This 'real application' could be the event loop of a simple HTTP server, or a basic 'echo all' server. Adding the bits about timers events and signals should be done too.

I wrote one with previous ring buffer implementation - it used timers and echoed when they fired, it was even described in details in one of the lwn.net articles.

I'm not going to waste others and my time implementing feature requests without at least _some_ feedback from those who asked them. In case when person, originally requested some feature, does not answer and there are other opinions, only they will be get into account of course.

Quoted 1 line

Eric

Signature · 1 line
	Evgeniy Polyakov
#41 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 06:26:04PM +0200, Eric Dumazet ([email protected])

Quoted 23 lines · wrote:
Quoted 15 lines · Evgeniy Polyakov
Quoted 7 lines

Ok, there is one apologist for mmap buffer implementation, who forced me to create first implementation, which was dropped due to absense of remote mental reading abilities.
Ulrich, does above approach sound good for you?
I actually do not want to reimplement something, that will be pointed to with words 'no matter what you say, it is broken and I do not want it' again :).

In my humble opinion, you should first write a 'real application', to show how the mmap buffer and kevent syscalls would be used (fast path and slow/recovery paths). I am sure it would be easier for everybody to agree on the API *before* you start coding a *lot* of hard (kernel) stuff : It would certainly save your mental CPU cycles (and ours too :) )

Quoted 3 lines

This 'real application' could be the event loop of a simple HTTP server, or a basic 'echo all' server. Adding the bits about timers events and signals should be done too.

I wrote one with previous ring buffer implementation - it used timers and echoed when they fired, it was even described in details in one of the lwn.net articles.

Quoted 5 lines

I'm not going to waste others and my time implementing feature requests without at least _some_ feedback from those who asked them. In case when person, originally requested some feature, does not answer and there are other opinions, only they will be get into account of course.

I am not sure I understand what you wrote, English is not our native language.

I think many people gave you feedbacks. I feel that all feedback on this mailing list is constructive. Many posts/patches on this list are never commented at all.

Eric

#42 lore raw

Re: [take19 1/4] kevent: Core files.

Quoted 32 lines · Eric Dumazet
Quoted 1 line · Evgeniy Polyakov

On Tue, Oct 17, 2006 at 06:26:04PM +0200, Eric Dumazet ([email protected])

Quoted 23 lines · wrote:
Quoted 15 lines · Evgeniy Polyakov
Quoted 7 lines

Ok, there is one apologist for mmap buffer implementation, who forced me to create first implementation, which was dropped due to absense of remote mental reading abilities.
Ulrich, does above approach sound good for you?
I actually do not want to reimplement something, that will be pointed to with words 'no matter what you say, it is broken and I do not want it' again :).

In my humble opinion, you should first write a 'real application', to show how the mmap buffer and kevent syscalls would be used (fast path and slow/recovery paths). I am sure it would be easier for everybody to agree on the API *before* you start coding a *lot* of hard (kernel) stuff : It would certainly save your mental CPU cycles (and ours too :) )

Quoted 3 lines

This 'real application' could be the event loop of a simple HTTP server, or a basic 'echo all' server. Adding the bits about timers events and signals should be done too.

I wrote one with previous ring buffer implementation - it used timers and echoed when they fired, it was even described in details in one of the lwn.net articles.

Quoted 5 lines

I'm not going to waste others and my time implementing feature requests without at least _some_ feedback from those who asked them. In case when person, originally requested some feature, does not answer and there are other opinions, only they will be get into account of course.

Quoted 5 lines

I am not sure I understand what you wrote, English is not our native language.

I think many people gave you feedbacks. I feel that all feedback on this mailing list is constructive. Many posts/patches on this list are never commented at all.

And I do greatly appreciate feedback from those people!

But I do not understand why I never got feedback on initial design and implementation (and then created as far as I recall at least 10 releases) from Ulrich, who first asked for such a feture.
So right now I'm waiting for his opinion on that problem, even if it will be 'it sucks' again, but at least in that case I will not waste people's time.

Ulrich, could you please comment on design notes sent couple of mail above?

Quoted 1 line

Eric

Signature · 1 line
	Evgeniy Polyakov
#43 lore raw

Re: [take19 1/4] kevent: Core files.

Evgeniy Polyakov a e'crit :

Quoted 5 lines · Eric Dumazet
Quoted 3 lines

I am not sure I understand what you wrote, English is not our native language.

I think many people gave you feedbacks. I feel that all feedback on this mailing list is constructive. Many posts/patches on this list are never commented at all.

Quoted 8 lines

And I do greatly appreciate feedback from those people!

But I do not understand why I never got feedback on initial design and
implementation (and then created as far as I recall at least 10
releases) from Ulrich, who first asked for such a feture. So right now I'm waiting for his opinion on that problem, even if it will be 'it sucks' again, but at least in that case I will not waste people's time.

Ulrich, could you please comment on design notes sent couple of mail above?

Ulrich is a very busy man. We have to live with that.

<rant_mode>
For example, I *complained* one day, that each glibc fopen()/fread()/fclose() pass does a mmap()/munmap() to obtain a single 4KB of memory, without any cache mechanism. This badly hurts performance of multi-threaded programs as we know mmap()/munmap() has to down_write(&mm->mmap_sem); and play VM games.

So to avoid this, I manually call setvbuf() in my own programs, to provide a suitable buffer to glibc, because of its suboptimal default allocation, vestige of an old epoch... </rant_mode>

Eric