Andrey Panin
2004-Aug-23 12:50 UTC
[Dovecot] [PATCH] pass struct io * to io_loop_handle_add()/io_loop_handle_remove()
Hello, currently I'm working on new ioloop handler which uses epoll(4) API introduced in Linux kernel 2.6. In this API each fd added to fd set by epoll_ctl system call can be accompanied with user supplied data (integer or void pointer). epoll_wait syscall reports arrived events as an array of structures containing event mask and user data. Attached patch replaces fd and condition parameters passed to io_loop_handle_add() with struct io pointer. Now io_loop_handle_add() can pass this pointer as user data to epoll_ctl syscall and when event arrives we will have corresponding io structure pointer for free withiot traversing possibly long ioloop->ios list. Please take a look. Best regards. -- Andrey Panin | Linux and UNIX system administrator pazke at donpac.ru | PGP key: wwwkeys.pgp.net -------------- next part -------------- diff -urpNX /usr/share/dontdiff dovecot-1.0-test32.vanilla/src/lib/ioloop.c dovecot-1.0-test32/src/lib/ioloop.c --- dovecot-1.0-test32.vanilla/src/lib/ioloop.c 2004-06-24 12:14:14.000000000 +0400 +++ dovecot-1.0-test32/src/lib/ioloop.c 2004-08-21 18:04:35.000000000 +0400 @@ -56,7 +56,7 @@ struct io *io_add(int fd, enum io_condit if (io->fd > current_ioloop->highest_fd) current_ioloop->highest_fd = io->fd; - io_loop_handle_add(current_ioloop, io->fd, io->condition); + io_loop_handle_add(current_ioloop, io); /* have to append it, or io_destroy() breaks */ io_p = ¤t_ioloop->ios; @@ -79,7 +79,7 @@ void io_remove(struct io *io) i_assert(io->fd <= current_ioloop->highest_fd); /* notify the real I/O handler */ - io_loop_handle_remove(current_ioloop, io->fd, io->condition); + io_loop_handle_remove(current_ioloop, io); io->destroyed = TRUE; diff -urpNX /usr/share/dontdiff dovecot-1.0-test32.vanilla/src/lib/ioloop-internal.h dovecot-1.0-test32/src/lib/ioloop-internal.h --- dovecot-1.0-test32.vanilla/src/lib/ioloop-internal.h 2003-09-07 05:52:06.000000000 +0400 +++ dovecot-1.0-test32/src/lib/ioloop-internal.h 2004-08-21 18:01:13.000000000 +0400 @@ -53,10 +53,8 @@ void io_destroy(struct ioloop *ioloop, s void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p); /* I/O handler calls */ -void io_loop_handle_add(struct ioloop *ioloop, int fd, - enum io_condition condition); -void io_loop_handle_remove(struct ioloop *ioloop, int fd, - enum io_condition condition); +void io_loop_handle_add(struct ioloop *ioloop, struct io *io); +void io_loop_handle_remove(struct ioloop *ioloop, struct io *io); void io_loop_handler_init(struct ioloop *ioloop); void io_loop_handler_deinit(struct ioloop *ioloop); diff -urpNX /usr/share/dontdiff dovecot-1.0-test32.vanilla/src/lib/ioloop-poll.c dovecot-1.0-test32/src/lib/ioloop-poll.c --- dovecot-1.0-test32.vanilla/src/lib/ioloop-poll.c 2003-08-27 01:18:16.000000000 +0400 +++ dovecot-1.0-test32/src/lib/ioloop-poll.c 2004-08-21 18:46:22.000000000 +0400 @@ -45,12 +45,12 @@ void io_loop_handler_deinit(struct ioloo #define IO_POLL_INPUT (POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL) #define IO_POLL_OUTPUT (POLLOUT|POLLERR|POLLHUP|POLLNVAL) -void io_loop_handle_add(struct ioloop *ioloop, int fd, - enum io_condition condition) +void io_loop_handle_add(struct ioloop *ioloop, struct io *io) { struct ioloop_handler_data *data = ioloop->handler_data; + enum io_condition condition = io->condition; unsigned int old_size; - int index; + int index, fd = io->fd; if ((unsigned int) fd >= data->idx_size) { /* grow the fd -> index array */ @@ -97,11 +97,11 @@ void io_loop_handle_add(struct ioloop *i data->fds[index].events |= IO_POLL_OUTPUT; } -void io_loop_handle_remove(struct ioloop *ioloop, int fd, - enum io_condition condition) +void io_loop_handle_remove(struct ioloop *ioloop, struct io *io) { struct ioloop_handler_data *data = ioloop->handler_data; - int index; + enum io_condition condition = io->condition; + int index, fd = io->fd; index = data->fd_index[fd]; i_assert(index >= 0 && (unsigned int) index < data->fds_size); diff -urpNX /usr/share/dontdiff dovecot-1.0-test32.vanilla/src/lib/ioloop-select.c dovecot-1.0-test32/src/lib/ioloop-select.c --- dovecot-1.0-test32.vanilla/src/lib/ioloop-select.c 2003-08-27 01:18:16.000000000 +0400 +++ dovecot-1.0-test32/src/lib/ioloop-select.c 2004-08-21 18:28:38.000000000 +0400 @@ -30,9 +30,11 @@ void io_loop_handler_deinit(struct ioloo p_free(ioloop->pool, ioloop->handler_data); } -void io_loop_handle_add(struct ioloop *ioloop, int fd, - enum io_condition condition) +void io_loop_handle_add(struct ioloop *ioloop, struct io *io) { + enum io_condition condition = io->condition; + int fd = io->fd; + i_assert(fd >= 0); if (fd >= FD_SETSIZE) @@ -44,9 +46,11 @@ void io_loop_handle_add(struct ioloop *i FD_SET(fd, &ioloop->handler_data->write_fds); } -void io_loop_handle_remove(struct ioloop *ioloop, int fd, - enum io_condition condition) +void io_loop_handle_remove(struct ioloop *ioloop, struct io *io) { + enum io_condition condition = io->condition; + int fd = io->fd; + i_assert(fd >= 0 && fd < FD_SETSIZE); if (condition & IO_READ) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <http://dovecot.org/pipermail/dovecot/attachments/20040823/5f24daf9/attachment-0001.bin>
Timo Sirainen
2004-Aug-23 14:04 UTC
[Dovecot] [PATCH] pass struct io * to io_loop_handle_add()/io_loop_handle_remove()
On 23.8.2004, at 15:50, Andrey Panin wrote:> Attached patch replaces fd and condition parameters passed to > io_loop_handle_add() with struct io pointer. Now io_loop_handle_add() > can pass this pointer as user data to epoll_ctl syscall and when > event arrives we will have corresponding io structure pointer > for free withiot traversing possibly long ioloop->ios list.Committed, but you'd also have to change the way io_destroy() works. I guess it could be simply changed to use reference counting instead of the delayed destroying. Hmm. Looks like ioloop code could use several optimizations.. -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part URL: <http://dovecot.org/pipermail/dovecot/attachments/20040823/511a5727/attachment-0001.bin>