Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 218624
b: refs/heads/master
c: 95aac7b
h: refs/heads/master
v: v3
  • Loading branch information
Shawn Bohrer authored and Linus Torvalds committed Oct 28, 2010
1 parent b377a33 commit 07da9e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 231f3d393f63f6e3b505afa179999bba491d0f08
refs/heads/master: 95aac7b1cd224f568fb83937044cd303ff11b029
35 changes: 19 additions & 16 deletions trunk/fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
/* Maximum number of nesting allowed inside epoll sets */
#define EP_MAX_NESTS 4

/* Maximum msec timeout value storeable in a long int */
#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ)

#define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))

#define EP_UNACTIVE_PTR ((void *) -1L)
Expand Down Expand Up @@ -1117,18 +1114,22 @@ static int ep_send_events(struct eventpoll *ep,
static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
int maxevents, long timeout)
{
int res, eavail;
int res, eavail, timed_out = 0;
unsigned long flags;
long jtimeout;
long slack;
wait_queue_t wait;

/*
* Calculate the timeout by checking for the "infinite" value (-1)
* and the overflow condition. The passed timeout is in milliseconds,
* that why (t * HZ) / 1000.
*/
jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ?
MAX_SCHEDULE_TIMEOUT : (timeout * HZ + 999) / 1000;
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);
slack = select_estimate_accuracy(&end_time);
to = &expires;
*to = timespec_to_ktime(end_time);
} else if (timeout == 0) {
timed_out = 1;
}

retry:
spin_lock_irqsave(&ep->lock, flags);
Expand All @@ -1150,15 +1151,17 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
* to TASK_INTERRUPTIBLE before doing the checks.
*/
set_current_state(TASK_INTERRUPTIBLE);
if (!list_empty(&ep->rdllist) || !jtimeout)
if (!list_empty(&ep->rdllist) || timed_out)
break;
if (signal_pending(current)) {
res = -EINTR;
break;
}

spin_unlock_irqrestore(&ep->lock, flags);
jtimeout = schedule_timeout(jtimeout);
if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
timed_out = 1;

spin_lock_irqsave(&ep->lock, flags);
}
__remove_wait_queue(&ep->wq, &wait);
Expand All @@ -1176,7 +1179,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
* more luck.
*/
if (!res && eavail &&
!(res = ep_send_events(ep, events, maxevents)) && jtimeout)
!(res = ep_send_events(ep, events, maxevents)) && !timed_out)
goto retry;

return res;
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static long __estimate_accuracy(struct timespec *tv)
return slack;
}

static long select_estimate_accuracy(struct timespec *tv)
long select_estimate_accuracy(struct timespec *tv)
{
unsigned long ret;
struct timespec now;
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ extern void poll_initwait(struct poll_wqueues *pwq);
extern void poll_freewait(struct poll_wqueues *pwq);
extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
ktime_t *expires, unsigned long slack);
extern long select_estimate_accuracy(struct timespec *tv);


static inline int poll_schedule(struct poll_wqueues *pwq, int state)
{
Expand Down

0 comments on commit 07da9e8

Please sign in to comment.