further epoll optimisations - please test cvs

Marc Lehmann schmorp at schmorp.de
Thu Oct 23 07:05:09 CEST 2008


Hi!

I further optimised the epoll backend to avoid the ADD/MOD combo that comes
up in some use cases, and instead only do the ADD.

These changes are just above the "trivial" level, so please test current
CVS, if possible.

CVS instructions can, as usual, be found at http://libev.schmorp.de/

Thanks a lot!

The case where this makes a difference is what watchers get stopped
temporarily (one iteration or longer), or when a watcher on an fd is
stopped and another is beign started on the same fd, or when a watcher is
stopped, ev_io_set is called with the same fd, and the watcher is started
again.

In all those cases, due to the way epoll is designed, we need to re-probe
whether the fd still has an active event mask, and this re-probing is
further complicated by epoll insisting on "guessing" whether we want to
ADD or we want to MODify, which is something we don't know in just this
case (which is why we need to re-probe in the first place).

And in all those cases, instead of seeing:

   epoll_ctl(4, EPOLL_CTL_ADD, 0, {EPOLLIN, {u32=0, u64=0}}) = -1 EEXIST (File exists)
   epoll_ctl(4, EPOLL_CTL_MOD, 0, {EPOLLIN, {u32=0, u64=0}}) = 0
   epoll_ctl(4, EPOLL_CTL_ADD, 0, {EPOLLIN, {u32=0, u64=0}}) = -1 EEXIST (File exists)
   epoll_ctl(4, EPOLL_CTL_MOD, 0, {EPOLLIN, {u32=0, u64=0}}) = 0

libev instead does:

   epoll_ctl(4, EPOLL_CTL_ADD, 0, {EPOLLIN, {u32=0, u64=0}}) = -1 EEXIST (File exists)
   epoll_ctl(4, EPOLL_CTL_ADD, 0, {EPOLLIN, {u32=0, u64=0}}) = -1 EEXIST (File exists)

by caching the previous kernel event mask and assuming it didn't change on EEXIST.

I also changed some init functions to direct calls of memset.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at goof.com
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list