From owner-freebsd-hackers Fri Mar 14 5:31:51 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B49BF37B401 for ; Fri, 14 Mar 2003 05:31:49 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id F00AA43F93 for ; Fri, 14 Mar 2003 05:31:48 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.8/8.12.3) with ESMTP id h2EDVlA7097181; Fri, 14 Mar 2003 06:31:48 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Fri, 14 Mar 2003 06:31:27 -0700 (MST) Message-Id: <20030314.063127.60417991.imp@bsdimp.com> To: dacut@kanga.org Cc: hackers@FreeBSD.ORG Subject: Re: first parameter to select From: "M. Warner Losh" In-Reply-To: <3E70D561.1080001@kanga.org> References: <3E702BCC.3030208@kanga.org> <20030313083710.GA8225@cirb503493.alcatel.com.au> <3E70D561.1080001@kanga.org> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message: <3E70D561.1080001@kanga.org> David Cuthbert 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