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).
This commit is contained in:
Azat Khuzhin 2020-03-01 16:01:12 +03:00
parent 4e5a41ca0f
commit 9a9b92ed06
2 changed files with 15 additions and 1 deletions

View File

@ -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);

View File

@ -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,
};
/**