Skip to content

Commit 491daf4

Browse files
committed
iv_fd_epoll: Add support for epoll_pwait2().
The main advantage of this is high-resolution (nanosecond) timeouts. Signed-off-by: Lennert Buytenhek <[email protected]>
1 parent 18aec2f commit 491daf4

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/iv_fd_epoll.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ static void iv_fd_epoll_flush_pending(struct iv_state *st)
143143
}
144144
}
145145

146+
#ifdef __NR_epoll_pwait2
147+
static int epoll_pwait2_support = 1;
148+
#endif
149+
150+
static int iv_fd_epoll_wait(struct iv_state *st, struct epoll_event *events,
151+
int maxevents, const struct timespec *abs)
152+
{
153+
int epfd = st->u.epoll.epoll_fd;
154+
155+
#ifdef __NR_epoll_pwait2
156+
if (epoll_pwait2_support) {
157+
struct timespec rel;
158+
int ret;
159+
160+
ret = syscall(__NR_epoll_pwait2, epfd, events, maxevents,
161+
to_relative(st, &rel, abs), NULL);
162+
if (ret == 0 || errno != ENOSYS)
163+
return ret;
164+
165+
epoll_pwait2_support = 0;
166+
}
167+
#endif
168+
169+
return epoll_wait(epfd, events, maxevents, to_msec(st, abs));
170+
}
171+
146172
static int iv_fd_epoll_poll(struct iv_state *st,
147173
struct iv_list_head *active,
148174
const struct timespec *abs)
@@ -154,8 +180,7 @@ static int iv_fd_epoll_poll(struct iv_state *st,
154180

155181
iv_fd_epoll_flush_pending(st);
156182

157-
ret = epoll_wait(st->u.epoll.epoll_fd, batch, ARRAY_SIZE(batch),
158-
to_msec(st, abs));
183+
ret = iv_fd_epoll_wait(st, batch, ARRAY_SIZE(batch), abs);
159184

160185
__iv_invalidate_now(st);
161186

@@ -433,8 +458,7 @@ static int iv_fd_epoll_timerfd_poll(struct iv_state *st,
433458

434459
run_timers = !!(abs != NULL);
435460

436-
ret = epoll_wait(st->u.epoll.epoll_fd, batch, ARRAY_SIZE(batch),
437-
to_msec(st, abs));
461+
ret = iv_fd_epoll_wait(st, batch, ARRAY_SIZE(batch), abs);
438462

439463
__iv_invalidate_now(st);
440464

0 commit comments

Comments
 (0)