public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arjan van de Ven <arjan@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: Arjan van de Ven <arjan@infradead.org>,
	mingo@elte.hu, tglx@tglx.de, torvalds@linux-foundation.org
Subject: [PATCH 4/5] select: make select() use schedule_hrtimeout()
Date: Fri, 29 Aug 2008 08:08:09 -0700	[thread overview]
Message-ID: <20080829080809.0e42a323@infradead.org> (raw)
In-Reply-To: <20080829080549.6906b744@infradead.org>


From: Arjan van de Ven <arjan@linux.intel.com>
Date: Thu, 28 Aug 2008 13:45:38 -0700
Subject: [PATCH] select: make select() use schedule_hrtimeout()

now that we have schedule_hrtimeout(), make select() use it.
But only for short delays; really long delays are assumed to not
need the highres level of accuracy but rather want the regular
timer behavior for now.

This is only done for delays shorter than 1 second; currently
the assumption is that longer delays have no desire to get the
higher accuracy.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 fs/select.c |   41 +++++++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 3ce5943..62b9767 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -24,6 +24,7 @@
 #include <linux/fdtable.h>
 #include <linux/fs.h>
 #include <linux/rcupdate.h>
+#include <linux/hrtimer.h>
 
 #include <asm/uaccess.h>
 
@@ -187,6 +188,7 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout, struct timespec *end_time)
 	struct poll_wqueues table;
 	poll_table *wait;
 	int retval, i;
+	int use_hr = 0;
 
 	rcu_read_lock();
 	retval = max_select_fd(n, fds);
@@ -196,6 +198,10 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout, struct timespec *end_time)
 		return retval;
 	n = retval;
 
+	/* Use hrtimers only for short timeouts for now */
+	if (*timeout < HZ && end_time->tv_sec != 0)
+		use_hr = 1;
+
 	poll_initwait(&table);
 	wait = &table.pt;
 	if (!*timeout)
@@ -266,20 +272,31 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout, struct timespec *end_time)
 			break;
 		}
 
-		if (*timeout < 0) {
-			/* Wait indefinitely */
-			__timeout = MAX_SCHEDULE_TIMEOUT;
-		} else if (unlikely(*timeout >= (s64)MAX_SCHEDULE_TIMEOUT - 1)) {
-			/* Wait for longer than MAX_SCHEDULE_TIMEOUT. Do it in a loop */
-			__timeout = MAX_SCHEDULE_TIMEOUT - 1;
-			*timeout -= __timeout;
+		if (use_hr) {
+			struct timespec now;
+			ktime_t expire;
+			schedule_hrtimeout(end_time, HRTIMER_MODE_ABS);
+			getnstimeofday(&now);
+			expire = ktime_sub(timespec_to_ktime(*end_time), timespec_to_ktime(now));
+			if (ktime_to_ns(expire) <= 0)
+				break;
+
 		} else {
-			__timeout = *timeout;
-			*timeout = 0;
+			if (*timeout < 0) {
+				/* Wait indefinitely */
+				__timeout = MAX_SCHEDULE_TIMEOUT;
+			} else if (unlikely(*timeout >= (s64)MAX_SCHEDULE_TIMEOUT - 1)) {
+				/* Wait for longer than MAX_SCHEDULE_TIMEOUT. Do it in a loop */
+				__timeout = MAX_SCHEDULE_TIMEOUT - 1;
+				*timeout -= __timeout;
+			} else {
+				__timeout = *timeout;
+				*timeout = 0;
+			}
+			__timeout = schedule_timeout(__timeout);
+			if (*timeout >= 0)
+				*timeout += __timeout;
 		}
-		__timeout = schedule_timeout(__timeout);
-		if (*timeout >= 0)
-			*timeout += __timeout;
 	}
 	__set_current_state(TASK_RUNNING);
 
-- 
1.5.5.1


  parent reply	other threads:[~2008-08-29 15:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-29 15:05 [patch 0/5] Nano/Microsecond resolution for select() and poll() Arjan van de Ven
2008-08-29 15:06 ` [PATCH 1/5] select: add a timespec version of the timeout to select/poll Arjan van de Ven
2008-08-30  2:10   ` Andrew Morton
2008-08-30  2:54     ` Linus Torvalds
2008-08-29 15:07 ` [PATCH 2/5] select: return accurate remainer in select() and ppoll() Arjan van de Ven
2008-08-29 15:07 ` [PATCH 3/5] select: introduce a schedule_hrtimeout() function Arjan van de Ven
2008-08-29 15:08 ` Arjan van de Ven [this message]
2008-08-29 15:36   ` [PATCH 4/5] select: make select() use schedule_hrtimeout() Arnd Bergmann
2008-08-29 15:59   ` Daniel Walker
2008-08-29 16:20   ` Linus Torvalds
2008-08-29 16:11     ` Alan Cox
2008-08-29 17:26       ` Linus Torvalds
2008-08-29 17:42         ` Arjan van de Ven
2008-08-29 18:18         ` Alan Cox
2008-08-29 18:46           ` Linus Torvalds
2008-08-29 18:33             ` Alan Cox
2008-08-30 15:25               ` Arjan van de Ven
2008-08-29 16:30     ` Arjan van de Ven
2008-08-29 15:08 ` [PATCH 5/5] select: make poll() use schedule_hrtimeout() as well Arjan van de Ven
2008-08-29 15:54 ` [patch 0/5] Nano/Microsecond resolution for select() and poll() Arnd Bergmann
2008-08-29 16:12   ` Arjan van de Ven
2008-08-29 22:15 ` Brian Wellington

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=20080829080809.0e42a323@infradead.org \
    --to=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@tglx.de \
    --cc=torvalds@linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox