Re: Timings for optimised poll(2)

Richard Gooch (rgooch@atnf.CSIRO.AU)
Sun, 24 Aug 1997 09:26:42 +1000


Rogier Wolff writes:
> Richard Gooch wrote:
> > Timings for 1021 file descriptors on a Pentium 100. These numbers look
> > quite promising!
>
> My computer (*) scans 10000 (tenthousand) bits in 15 us. Now
> what were you trying to optimize?
>
> (*) PPro/150, my 486/66 takes 90 us for those 10000 bits.
>
> /* findbit.c -- Benchmark the find_first_zero_bit routine */
> /* Compile with: gcc -Wall -O2 -o findbit findbit.c */
> #include <asm/bitops.h>

There are a few reasons why you would not use the find_first_zero_bit
function in a real-world application:

1) it assumes you are using select(2) and fd_sets. This has the old
problem of hard-wired limits on the fd_set size. Today the limit is
1024. Tomorrow somebody wants more, so you have to recompile your
kernel. If you want to manage a large number of descriptors, you would
use poll(2) instead

2) every time poll(2) or select(2) returns, you may get dozens of
descriptors which are ready. How do you solve this? Call
find_first_zero_bit for each active descriptor (clearing as you go)?

I've appended my latest version test programme. Compile with -O2. This
contains a *realistic* scanning loop. It takes 1.5 milliseconds on a
Pentium 100.

Regards,

Richard....

/* Programme to test how long it would take to scan through a large list of
pollfd structures.
*/
#include <stdio.h>
#include <string.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <unistd.h>

#define MAX_FDS 10000

/* Structure to manage descriptors */
struct managed_fd_type
{
int fd;
void *info;
void (*func) (void *info);
};

void main ()
{
int count, num_ready;
long time_taken;
struct timeval time1, time2;
struct pollfd *pollfd_ptr;
struct managed_fd_type *cbk_ptr;
struct pollfd ufds[MAX_FDS];
struct managed_fd_type cbk_array[MAX_FDS];

/* Ensure no descriptors are actually ready */
memset (ufds, 0, sizeof ufds);
/* Pretend a single descriptor is ready */
num_ready = 1;
gettimeofday (&time1, NULL);
for (count = 0, pollfd_ptr = ufds, cbk_ptr = cbk_array;
(num_ready > 0) && (count < MAX_FDS);
++count, ++pollfd_ptr, ++cbk_ptr)
{
if (pollfd_ptr->revents == 0) continue;
/* Dummy code: will not be executed */
--num_ready;
/* Call the callback */
(*cbk_ptr->func) (cbk_ptr->info);
}
gettimeofday (&time2, NULL);
time_taken = (time2.tv_sec - time1.tv_sec) * 1000000;
time_taken += time2.tv_usec - time1.tv_usec;
fprintf (stderr, "real time taken: %ld us\n", time_taken);
} /* End Function main */