[or-cvs] [tor/master] Turn on epoll changelists with libevent 2.0.9-rc and later

nickm at torproject.org nickm at torproject.org
Thu Dec 16 18:37:24 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Thu, 16 Dec 2010 13:35:09 -0500
Subject: Turn on epoll changelists with libevent 2.0.9-rc and later
Commit: dd2ae32bc181efdc134c25359bc67d073c48a1d0

Libevent 2.0 has a "changelist" feature that avoids making redundant
syscalls if we wind up doing a lot of event_add/event_del operations
on the same fd in a row.  Unfortunately, due to a weird design
choice in Linux, it doesn't work right with epoll when multiple fds
refer to the same socket (e.g., one is a dup() of the other).  We
don't dup() anything we give to Libevent, though, so it is safe for
us to explicitly turn this feature on.
---
 src/common/compat_libevent.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index d3b9eb3..7bbad54 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -186,6 +186,12 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
       event_config_set_num_cpus_hint(cfg, torcfg->num_cpus);
 #endif
 
+#if LIBEVENT_VERSION_NUMBER >= V(2,0,9)
+    /* We can enable changelist support with epoll, since we don't give
+     * Libevent any dup'd fds.  This lets us avoid some syscalls. */
+    event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
+#endif
+
     the_event_base = event_base_new_with_config(cfg);
 
     event_config_free(cfg);
-- 
1.7.1



More information about the tor-commits mailing list