lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1295110837-3061-2-git-send-email-shawn.bohrer@gmail.com>
Date:	Sat, 15 Jan 2011 11:00:36 -0600
From:	Shawn Bohrer <shawn.bohrer@...il.com>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Jack Stone <jwjstone@...tmail.fm>,
	Viresh Kumar <viresh.kumar@...com>,
	linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
	viro@...iv.linux.org.uk, Davide Libenzi <davidel@...ilserver.org>,
	Shawn Bohrer <shawn.bohrer@...il.com>
Subject: [PATCH 2/3] epoll: short circuit the timeout==0 case

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@...il.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ