Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Mar 2003 06:31:27 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        dacut@kanga.org
Cc:        hackers@FreeBSD.ORG
Subject:   Re: first parameter to select
Message-ID:  <20030314.063127.60417991.imp@bsdimp.com>
In-Reply-To: <3E70D561.1080001@kanga.org>
References:  <3E702BCC.3030208@kanga.org> <20030313083710.GA8225@cirb503493.alcatel.com.au> <3E70D561.1080001@kanga.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <3E70D561.1080001@kanga.org>
            David Cuthbert <dacut@kanga.org> 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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030314.063127.60417991.imp>