Skip to content

Commit

Permalink
Add EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD flag (fixes: #958)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
azat committed Mar 1, 2020
1 parent 4e5a41c commit 9a9b92e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion include/event2/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand Down

0 comments on commit 9a9b92e

Please sign in to comment.