From: Arjan van de Ven <arjan@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: tglx@tglx.de, mingo@elte.hu, torvalds@linux-foundation.org,
Arnd Bergmann <arnd@arndb.de>
Subject: [patch v2 0/5] Nano/Microsecond resolution for select() and poll()
Date: Sun, 31 Aug 2008 09:28:28 -0700 [thread overview]
Message-ID: <20080831092828.13ae0279@infradead.org> (raw)
New in this version:
* With lots of help from Thomas Gleixner, select() and poll() now
exclusively use hrtimers
* Several key cleanups from Thomas actually simplify and clean the
code up so that it's an overall improvement in code quality
* Various interesting bugs were encountered during the switchover on this
level. The Fedora/Red Hat "nash" program deserves a special mention for
both asking for a 1 nanosecond ppoll() timeout AND depending on the
implementation to set this to 0 nanoseconds in userspace memory at
the end of the first iteration.
fs/compat.c | 187 +++++++++--------------
fs/select.c | 346 +++++++++++++++++++++-----------------------
include/linux/hrtimer.h | 2
include/linux/poll.h | 8 -
include/linux/thread_info.h | 8 +
include/linux/time.h | 4
kernel/hrtimer.c | 65 ++++++++
kernel/time.c | 18 ++
8 files changed, 344 insertions(+), 294 deletions(-)
(the bulk of actual linecount growth is just newly added comments)
----
Today in Linux, select() and poll() operate in jiffies resolution
(granularity), meaning an effective resolution of 1 millisecond (HZ=1000) to
10 milliseconds (HZ=100). Delays shorter than this are not possible, and all
delays are in multiples of this granularity.
The effect is that applications that want (on average) to specify more
accurate delays (for example multimedia or other interactive apps) just
cannot do that; this creates more than needed jitter.
With this patch series, the internals of select() and poll() interfaces are
changed such that they work on the nanosecond level (using hrtimers). The
userspace interface for select() is in microseconds, for pselect() and
ppoll() this is in nanoseconds.
[actual behavior obviously on what resolution the hardware timers work, on
modern PCs this is pretty good though]
To show this effect I made a test application to measure the error made
in the select() timing.
For example, a userspace application asking for a 1200 microsecond delay, on
a HZ=1000 kernel, will in practice get a 1997 microsecond delay, a delta of
almost 800 microseconds (which is of course a high percentage of 1200). The
extreme case is asking for 1 microsecond, and getting 998 microseconds
delay... with the patch we get a 250 times improvement in behavior (!).
A graph of various inputs with the jitter can be seen at
http://www.tglx.de/~arjan/select_benefits.png
One thing to note is that on my machine, the current select() implementation
will return after 1997 microseconds when asked for 1999 microseconds; this
can be seen in a zoom in of the graph above:
http://www.tglx.de/~arjan/zoom.png
E.g. select() is returning too early in current Linux kernels; and this is
also fixed (by nature) by this patch series.
In the graph there's a 4 microsecond delta for most data points, this is
basically the measurement overhead (C-state exit, a few system calls, a
loop and some math).
Note:
even though poll() (as opposed to ppoll()) only accepts milliseconds
as userspace interface, the behavior will still improve because the current
time no longer needs to be rounded up to the next jiffie, so on average
a 500 microseconds behavior improvement.
next reply other threads:[~2008-08-31 16:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-31 16:28 Arjan van de Ven [this message]
2008-08-31 16:29 ` [PATCH 1/5] select: Introduce a hrtimeout function Arjan van de Ven
2008-08-31 16:29 ` [PATCH 2/5] select: add a timespec_add_safe() function Arjan van de Ven
2008-08-31 16:30 ` [PATCH 3/5] select: add poll_select_set_timeout() and poll_select_copy_remaining() helpers Arjan van de Ven
2008-08-31 16:30 ` [PATCH 4/5] select: add a poll specific struct to the restart_block union Arjan van de Ven
2008-08-31 16:31 ` [PATCH 5/5] select: switch select() and poll() over to hrtimers Arjan van de Ven
2008-08-31 16:55 ` [patch v2 0/5] Nano/Microsecond resolution for select() and poll() Willy Tarreau
2008-08-31 21:13 ` Davide Libenzi
2008-08-31 21:28 ` Arjan van de Ven
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=20080831092828.13ae0279@infradead.org \
--to=arjan@infradead.org \
--cc=arnd@arndb.de \
--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®