From: Arjan van de Ven <arjan@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: Arjan van de Ven <arjan@infradead.org>,
torvalds@linux-foundation.org, dwmw2@infradead.org,
drepper@redhat.com, mingo@elte.hu, tglx@tglx.de
Subject: [PATCH 13/13] hrtimer: make select() and poll() use the hrtimer range feature
Date: Mon, 1 Sep 2008 16:14:59 -0700 [thread overview]
Message-ID: <20080901161459.0990a16b@infradead.org> (raw)
In-Reply-To: <20080901160343.75a89ec9@infradead.org>
From: Arjan van de Ven <arjan@linux.intel.com>
Subject: [PATCH] hrtimer: make select() and poll() use the hrtimer range feature
This patch makes the select() and poll() hrtimers use the new range
feature and settings from the task struct.
In addition, this includes the estimate_accuracy() function that Linus
posted to lkml (but with a few steps added based on experiments).
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
fs/select.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/fs/select.c b/fs/select.c
index f6dceb5..21bf77d 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -28,6 +28,62 @@
#include <asm/uaccess.h>
+
+/* Estimate expected accuracy in ns from a timeval */
+
+static unsigned long __estimate_accuracy(struct timespec *tv)
+{
+ /*
+ * Tens of ms if we're looking at seconds, even
+ * more for 10s+ sleeping
+ */
+ if (tv->tv_sec) {
+ /* 100 milliseconds for long sleeps */
+ if (tv->tv_sec > 10)
+ return 100 * NSEC_PER_MSEC;
+
+ /*
+ * Tens of ms for second-granularity sleeps. This,
+ * btw, is the historical Linux 100Hz timer range.
+ */
+ return 10 * NSEC_PER_MSEC;
+ }
+
+ /* 5 msec if we're looking at 100+ milliseconds */
+ if (tv->tv_nsec > 100 * NSEC_PER_MSEC)
+ return 5 * NSEC_PER_MSEC;
+
+ /* A msec if we're looking at 10+ milliseconds */
+ if (tv->tv_nsec > 10 * NSEC_PER_MSEC)
+ return NSEC_PER_MSEC;
+
+ /* half a msec if we're looking at milliseconds */
+ if (tv->tv_nsec > NSEC_PER_MSEC)
+ return NSEC_PER_MSEC/2;
+
+ /* Single usecs if we're looking at microseconds */
+ if (tv->tv_nsec > NSEC_PER_USEC)
+ return NSEC_PER_USEC;
+
+ /* Aim for tenths of nanosecs otherwise */
+ return 10;
+}
+
+static unsigned long estimate_accuracy(struct timespec *tv)
+{
+ unsigned long ret;
+ struct timespec now;
+
+ ktime_get_ts(&now);
+ now = timespec_sub(*tv, now);
+ ret = __estimate_accuracy(&now);
+ if (ret < current->timer_slack_ns)
+ return current->timer_slack_ns;
+ return ret;
+}
+
+
+
struct poll_table_page {
struct poll_table_page * next;
struct poll_table_entry * entry;
@@ -262,6 +318,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
struct poll_wqueues table;
poll_table *wait;
int retval, i, timed_out = 0;
+ unsigned long slack = 0;
rcu_read_lock();
retval = max_select_fd(n, fds);
@@ -278,6 +335,9 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
timed_out = 1;
}
+ if (end_time)
+ slack = estimate_accuracy(end_time);
+
retval = 0;
for (;;) {
unsigned long *rinp, *routp, *rexp, *inp, *outp, *exp;
@@ -353,7 +413,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
to = &expire;
}
- if (!schedule_hrtimeout(to, HRTIMER_MODE_ABS))
+ if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
timed_out = 1;
}
__set_current_state(TASK_RUNNING);
@@ -593,6 +653,7 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
poll_table* pt = &wait->pt;
ktime_t expire, *to = NULL;
int timed_out = 0, count = 0;
+ unsigned long slack = 0;
/* Optimise the no-wait case */
if (end_time && !end_time->tv_sec && !end_time->tv_nsec) {
@@ -600,6 +661,9 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
timed_out = 1;
}
+ if (end_time)
+ slack = estimate_accuracy(end_time);
+
for (;;) {
struct poll_list *walk;
@@ -646,7 +710,7 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
to = &expire;
}
- if (!schedule_hrtimeout(to, HRTIMER_MODE_ABS))
+ if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
timed_out = 1;
}
__set_current_state(TASK_RUNNING);
--
1.5.5.1
next prev parent reply other threads:[~2008-09-01 23:17 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 23:03 [PATCH 0/13] Turn hrtimers into a range capable timer Arjan van de Ven
2008-09-01 23:05 ` [PATCH 1/13] hrtimer: add abstraction functions for accessing the "expires" member Arjan van de Ven
2008-09-01 23:05 ` [PATCH 2/13] hrtimer: convert kvm to the new hrtimer apis Arjan van de Ven
2008-09-01 23:06 ` [PATCH 3/13] hrtimer: convert timerfd " Arjan van de Ven
2008-09-01 23:07 ` [PATCH 4/13] hrtimer: convert net::sched_cbq " Arjan van de Ven
2008-09-01 23:08 ` [PATCH 5/13] hrtimer: convert kernel/* " Arjan van de Ven
2008-09-01 23:09 ` [PATCH 6/13] hrtimer: convert powerpc/oprofile " Arjan van de Ven
2008-09-01 23:09 ` [PATCH 7/13] hrtimer: convert kvm-ia64 " Arjan van de Ven
2008-09-01 23:10 ` [PATCH 8/13] hrtimer: convert s390 " Arjan van de Ven
2008-09-01 23:11 ` [PATCH 9/13] hrtimer: convert sound/ " Arjan van de Ven
2008-09-01 23:12 ` [PATCH 10/13] hrtimer: rename the "expires" struct member to avoid accidental usage Arjan van de Ven
2008-09-01 23:12 ` Arjan van de Ven
2008-09-01 23:13 ` [PATCH 11/13] hrtimer: turn hrtimers into range timers Arjan van de Ven
2008-09-02 8:22 ` Peter Zijlstra
2008-09-02 11:08 ` Peter Zijlstra
2008-09-02 11:15 ` Peter Zijlstra
2008-09-02 13:06 ` Arjan van de Ven
2008-09-02 13:05 ` Arjan van de Ven
2008-09-02 13:47 ` Peter Zijlstra
2008-09-02 16:02 ` Arjan van de Ven
2008-09-01 23:14 ` [PATCH 12/13] hrtimer: create a "timer_slack" field in the task struct Arjan van de Ven
2008-09-02 10:04 ` Pavel Machek
2008-09-02 13:03 ` Arjan van de Ven
2008-09-08 13:27 ` Pavel Machek
2008-09-08 13:40 ` Arjan van de Ven
2008-09-08 14:15 ` Pavel Machek
2008-09-08 14:22 ` Arjan van de Ven
2008-09-13 16:24 ` Pavel Machek
2008-09-14 15:21 ` Ulrich Drepper
2008-09-14 15:27 ` Arjan van de Ven
2008-09-14 15:57 ` Pavel Machek
2008-09-14 16:04 ` Ulrich Drepper
2008-09-14 16:14 ` Arjan van de Ven
2008-09-17 7:42 ` Pavel Machek
2008-09-30 5:16 ` KOSAKI Motohiro
2008-09-30 8:28 ` Arjan van de Ven
2008-09-30 8:54 ` KOSAKI Motohiro
2008-09-01 23:14 ` Arjan van de Ven [this message]
2008-09-02 8:22 ` [PATCH 13/13] hrtimer: make select() and poll() use the hrtimer range feature Peter Zijlstra
2008-09-02 16:03 ` Arjan van de Ven
2008-09-06 14:56 ` [PATCH 0/13] Turn hrtimers into a range capable timer Ingo Molnar
2008-09-06 16:30 ` Arjan van de Ven
2008-09-06 16:33 ` Ingo Molnar
2008-09-12 3:39 ` Rusty Russell
2008-09-12 5:42 ` Arjan van de Ven
2008-09-12 20:24 ` Thomas Gleixner
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=20080901161459.0990a16b@infradead.org \
--to=arjan@infradead.org \
--cc=drepper@redhat.com \
--cc=dwmw2@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
all inboxes | Powered by JetHome®