Skip to content

Commit

Permalink
epoll: epoll_wait() should not use timespec_add_ns()
Browse files Browse the repository at this point in the history
commit 95aac7b ("epoll: make epoll_wait() use the hrtimer range
feature") added a performance regression because it uses timespec_add_ns()
with potential very large 'ns' values.

[akpm@linux-foundation.org: s/epoll_set_mstimeout/ep_set_mstimeout/, per Davide]
Reported-by: Simon Kirby <sim@hostway.ca>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Shawn Bohrer <shawn.bohrer@gmail.com>
Acked-by: Davide Libenzi <davidel@xmailserver.org>
Cc: <stable@kernel.org>		[2.6.37.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Eric Dumazet authored and Linus Torvalds committed Feb 3, 2011
1 parent 48db54e commit 0781b90
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,19 +1114,29 @@ static int ep_send_events(struct eventpoll *ep,
return ep_scan_ready_list(ep, ep_send_events_proc, &esed);
}

static inline struct timespec ep_set_mstimeout(long ms)
{
struct timespec now, ts = {
.tv_sec = ms / MSEC_PER_SEC,
.tv_nsec = NSEC_PER_MSEC * (ms % MSEC_PER_SEC),
};

ktime_get_ts(&now);
return timespec_add_safe(now, ts);
}

static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
int maxevents, long timeout)
{
int res, eavail, timed_out = 0;
unsigned long flags;
long slack;
wait_queue_t wait;
struct timespec end_time;
ktime_t expires, *to = NULL;

if (timeout > 0) {
ktime_get_ts(&end_time);
timespec_add_ns(&end_time, (u64)timeout * NSEC_PER_MSEC);
struct timespec end_time = ep_set_mstimeout(timeout);

slack = select_estimate_accuracy(&end_time);
to = &expires;
*to = timespec_to_ktime(end_time);
Expand Down

0 comments on commit 0781b90

Please sign in to comment.