From: Shawn Bohrer <shawn.bohrer@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jack Stone <jwjstone@fastmail.fm>,
Viresh Kumar <viresh.kumar@st.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
viro@zeniv.linux.org.uk, Davide Libenzi <davidel@xmailserver.org>,
Shawn Bohrer <shawn.bohrer@gmail.com>
Subject: [PATCH 2/3] epoll: short circuit the timeout==0 case
Date: Sat, 15 Jan 2011 11:00:36 -0600 [thread overview]
Message-ID: <1295110837-3061-2-git-send-email-shawn.bohrer@gmail.com> (raw)
In-Reply-To: <20110115162027.GA2552@lintop>
If a timeout == 0 is specified we will return immediately even if there
are no events so there is no need to enter the polling loop.
Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>
---
fs/eventpoll.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index c24a032..57a77f5 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1121,6 +1121,10 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
struct timespec end_time;
ktime_t expires, *to = NULL;
+ /*
+ * A negative timeout means wait indefinitely and leaves 'to' NULL for
+ * an infinite timeout.
+ */
if (timeout > 0) {
ktime_get_ts(&end_time);
timespec_add_ns(&end_time, (u64)timeout * NSEC_PER_MSEC);
@@ -1128,7 +1132,12 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
to = &expires;
*to = timespec_to_ktime(end_time);
} else if (timeout == 0) {
+ /*
+ * Return immediately even if no events are available.
+ */
timed_out = 1;
+ spin_lock_irqsave(&ep->lock, flags);
+ goto skip;
}
retry:
@@ -1146,9 +1155,10 @@ retry:
for (;;) {
/*
- * We don't want to sleep if the ep_poll_callback() sends us
- * a wakeup in between. That's why we set the task state
- * to TASK_INTERRUPTIBLE before doing the checks.
+ * We don't want to sleep if the ep_poll_callback()
+ * sends us a wakeup in between. That's why we set the
+ * task state to TASK_INTERRUPTIBLE before doing the
+ * checks.
*/
set_current_state(TASK_INTERRUPTIBLE);
if (!list_empty(&ep->rdllist) || timed_out)
@@ -1168,6 +1178,7 @@ retry:
set_current_state(TASK_RUNNING);
}
+skip:
/* Is it worth to try to dig for events ? */
eavail = !list_empty(&ep->rdllist) || ep->ovflist != EP_UNACTIVE_PTR;
--
1.7.3.4
next prev parent reply other threads:[~2011-01-15 17:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-14 11:52 [PATCH resend] fs/eventpoll.c: fix compilation warning Viresh Kumar
2011-01-14 13:07 ` Jack Stone
2011-01-14 14:48 ` Shawn Bohrer
2011-01-14 14:48 ` Shawn Bohrer
2011-01-14 15:21 ` Davide Libenzi
2011-01-15 0:05 ` Andrew Morton
2011-01-15 11:10 ` Jack Stone
2011-01-15 16:20 ` Shawn Bohrer
2011-01-15 17:00 ` [PATCH 1/3] epoll: initialize slack for negative timeout values Shawn Bohrer
2011-01-15 19:06 ` Davide Libenzi
2011-03-18 7:38 ` Mike Frysinger
2011-03-18 7:38 ` Mike Frysinger
2011-01-15 17:00 ` Shawn Bohrer [this message]
2011-01-15 17:00 ` [PATCH 3/3] epoll: remove unnecessary test of ep->ovflist for available events Shawn Bohrer
2011-01-15 19:03 ` Davide Libenzi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295110837-3061-2-git-send-email-shawn.bohrer@gmail.com \
--to=shawn.bohrer@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=davidel@xmailserver.org \
--cc=jwjstone@fastmail.fm \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viresh.kumar@st.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.