From 9a9b92ed06249be8326d82e2483b87e1a1b4caac Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 1 Mar 2020 16:01:12 +0300 Subject: [PATCH] Add EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD flag (fixes: #958) By default we are using CLOCK_MONOTONIC_COARSE, but if EVENT_BASE_FLAG_PRECISE_TIMER isset, then CLOCK_MONOTONIC will be used, however this will also enable timerfd, while this is not always what someone wants, hence add a flag to control this (by default the old behavior is preserved, set new flag to change it). --- epoll.c | 1 + include/event2/event.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/epoll.c b/epoll.c index a0df0d21bf..1d4393e6ca 100644 --- a/epoll.c +++ b/epoll.c @@ -189,6 +189,7 @@ epoll_init(struct event_base *base) event_base, we can try to use timerfd to give them finer granularity. */ if ((base->flags & EVENT_BASE_FLAG_PRECISE_TIMER) && + !(base->flags & EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD) && base->monotonic_timer.monotonic_clock == CLOCK_MONOTONIC) { int fd; fd = epollop->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC); diff --git a/include/event2/event.h b/include/event2/event.h index 2dd5088a2b..85df418a8d 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -570,7 +570,20 @@ enum event_base_config_flag { however, we use less efficient more precise timer, assuming one is present. */ - EVENT_BASE_FLAG_PRECISE_TIMER = 0x20 + EVENT_BASE_FLAG_PRECISE_TIMER = 0x20, + + /** With EVENT_BASE_FLAG_PRECISE_TIMER, + epoll backend will use timerfd for more accurate timers, this will + allows to disable this. + + That said that this is something in between lack of + (CLOCK_MONOTONIC_COARSE) and enabled EVENT_BASE_FLAG_PRECISE_TIMER + (CLOCK_MONOTONIC + timerfd). + + This flag has no effect if you wind up using a backend other than + epoll and if you do not have EVENT_BASE_FLAG_PRECISE_TIMER enabled. + */ + EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD = 0x40, }; /**