Patch for poll(2)

Richard Gooch (rgooch@atnf.CSIRO.AU)
Sat, 23 Aug 1997 00:48:54 +1000


I wrote:
> Martin von Loewis writes:
> > > So, what do people think? I've looked at the code for poll() and it
> > > looks pretty easy to implement.
> >
> > I'd say: implement it, and perform some bench marks. Further discussion
> > could then be based on facts.
> > My feeling is that the scanning does not matter: the time spent in
> > read(2) afterwards once you find the ready descriptor is much larger
> > than the time you spend for scanning the table.
>
> This may be true if read(2) has to grab something off disc, but if
> instead you are reading either from a file with the required bit in
> the cache, or from a pipe/terminal/whatever then it should take far
> less than a couple of milliseconds to read(2).
> I timed the sample loop I sent in my last message: 2.3 milliseconds
> for 10 000 iterations.

Further to this, I timed how long it takes to do a poll(2) with a
timeout of 0 (don't wait) for 1021 file descriptors (once again on a
Pentium 100). It took 4.9 ms. Now, in trying to understand the code, I
noticed that even if you call poll(2) with a timeout of 0, the kernel
still manipulates wait queues. I patched the kernel to *not* put the
process on wait queues for 0 timeout, and the time taken went down to
2.9 ms.

Linus, could you please apply this patch?

Regards,

Richard....

diff -urN linux-2.1.51/fs/select.c linux/fs/select.c
--- linux-2.1.51/fs/select.c Tue Jun 17 09:35:59 1997
+++ linux/fs/select.c Sat Aug 23 00:27:25 1997
@@ -423,7 +423,7 @@
wait_table.nr = 0;
wait_table.entry = entry;

- fdcount = do_poll(nfds, fds, &wait_table);
+ fdcount = do_poll(nfds, fds, (timeout == 0) ? NULL : &wait_table);
current->timeout = 0;

free_wait(&wait_table);