aboutsummaryrefslogtreecommitdiffstats
path: root/fs/eventpoll.c
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-02-01 18:52:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-02-02 19:03:18 -0500
commit0781b909b5586f4db720b5d1838b78f9d8e42f14 (patch)
tree767e53bf2cd3bebbc1a94f64632b53fdad31828d /fs/eventpoll.c
parent48db54ee2f41e8ae2faf330b55db34a9fffb5b3c (diff)
epoll: epoll_wait() should not use timespec_add_ns()
commit 95aac7b1cd224f ("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>
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r--fs/eventpoll.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index cc8a9b7d6064..267d0ada4541 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1114,6 +1114,17 @@ static int ep_send_events(struct eventpoll *ep,
1114 return ep_scan_ready_list(ep, ep_send_events_proc, &esed); 1114 return ep_scan_ready_list(ep, ep_send_events_proc, &esed);
1115} 1115}
1116 1116
1117static inline struct timespec ep_set_mstimeout(long ms)
1118{
1119 struct timespec now, ts = {
1120 .tv_sec = ms / MSEC_PER_SEC,
1121 .tv_nsec = NSEC_PER_MSEC * (ms % MSEC_PER_SEC),
1122 };
1123
1124 ktime_get_ts(&now);
1125 return timespec_add_safe(now, ts);
1126}
1127
1117static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, 1128static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
1118 int maxevents, long timeout) 1129 int maxevents, long timeout)
1119{ 1130{
@@ -1121,12 +1132,11 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
1121 unsigned long flags; 1132 unsigned long flags;
1122 long slack; 1133 long slack;
1123 wait_queue_t wait; 1134 wait_queue_t wait;
1124 struct timespec end_time;
1125 ktime_t expires, *to = NULL; 1135 ktime_t expires, *to = NULL;
1126 1136
1127 if (timeout > 0) { 1137 if (timeout > 0) {
1128 ktime_get_ts(&end_time); 1138 struct timespec end_time = ep_set_mstimeout(timeout);
1129 timespec_add_ns(&end_time, (u64)timeout * NSEC_PER_MSEC); 1139
1130 slack = select_estimate_accuracy(&end_time); 1140 slack = select_estimate_accuracy(&end_time);
1131 to = &expires; 1141 to = &expires;
1132 *to = timespec_to_ktime(end_time); 1142 *to = timespec_to_ktime(end_time);