In message: <[EMAIL PROTECTED]>
David Cuthbert <[EMAIL PROTECTED]> writes:
: Given that a poll() descriptor is 12 bytes and fd_set is usually at
: least 128 bytes (does select() copy the entire fd_set? I believe this
: is the case, but don't have access to the source atm), the savings kicks
: in at 12 descriptors.
That's not the case. The source clearly says so, and has been this
way since 4.2BSD.
int
kern_select(struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou,
fd_set *fd_ex, struct timeval *tvp)
{
...
/*
* Allocate just enough bits for the non-null fd_sets. Use the
* preallocated auto buffer if possible.
*/
nfdbits = roundup(nd, NFDBITS);
ncpbytes = nfdbits / NBBY;
...
#define getbits(name, x) \
do { \
if (name == NULL) \
ibits[x] = NULL; \
else { \
ibits[x] = sbp + nbufbytes / 2 / sizeof *sbp; \
obits[x] = sbp; \
sbp += ncpbytes / sizeof *sbp; \
error = copyin(name, ibits[x], ncpbytes); \
if (error != 0) \
goto done_nosellock; \
} \
} while (0)
getbits(fd_in, 0);
getbits(fd_ou, 1);
getbits(fd_ex, 2);
So clearly only the part of the select set that's passed in with fd is
used. Most programs I've seen actually pass in fn as max(fd,...) + 1.
So if you have only a few sockets, or less than 96/N (N is the number
of fd_sets you are using), select's copyin/out mechanism moves fewer
bits accross the kernel transom.
Warner
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message