Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 1997 01:37:35 +0300 (MSK)
From:      =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= <ache@nagual.ru>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        peter@spinner.dialix.com, cvs-all@freefall.freebsd.org, CVS-committers@freefall.freebsd.org, cvs-sys@freefall.freebsd.org, mpp@freefall.freebsd.org
Subject:   Re: cvs commit: src/sys/sys types.h
Message-ID:  <Pine.BSF.3.95q.970217013428.575B-100000@nagual.ru>
In-Reply-To: <199702161404.BAA20251@godzilla.zeta.org.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 17 Feb 1997, Bruce Evans wrote:

> >+ #define FD_ROUNDSIZE 256
> >+ 
> 
> Change to something like (2048 / 6) = 341.  Now that's an odd size :-).

I change it (see update patch below) but still not understand
why 2048 is here. p_selbits_size increasing constant will be 44 in this
case, is it good value for you too?

> Don't use this except possibly for very large ni together with unusual
> combinations of fds.  Put 3 contiguous copyout buffers first (readfds,
> writefds, exexptfds), then 3 copyin buffers, and bzero 1*ni, 2*ni or
> 3*ni bits as necessary (exceptfds is usually NULL so the bzero doesn't
> need to cover it).  The old code got this wrong mainly by spacing the
> buffers with separation p->p_selbits_size instead of ni.

I try to implement what you say, see the patch below:

*** sys_generic.c.orig	Tue Jan 14 23:11:28 1997
--- sys_generic.c	Mon Feb 17 01:33:11 1997
***************
*** 508,513 ****
--- 508,515 ----
  	return (error);
  }
  
+ #define FD_ROUNDSIZE (2048 / (3 + 3))
+ 
  static int	nselcoll;
  int	selwait;
  
***************
*** 539,545 ****
  		uap->nd = p->p_fd->fd_nfiles;   /* forgiving; slightly wrong */
  
  	/* The amount of space we need to allocate */
! 	ni = howmany(roundup2 (uap->nd, FD_SETSIZE), NFDBITS) *
  		sizeof(fd_mask);
  
  	if (ni > p->p_selbits_size) {
--- 541,547 ----
  		uap->nd = p->p_fd->fd_nfiles;   /* forgiving; slightly wrong */
  
  	/* The amount of space we need to allocate */
! 	ni = howmany(roundup2 (uap->nd, FD_ROUNDSIZE), NFDBITS) *
  		sizeof(fd_mask);
  
  	if (ni > p->p_selbits_size) {
***************
*** 547,571 ****
  			free (p->p_selbits, M_SELECT);
  
  		while (p->p_selbits_size < ni)
! 			p->p_selbits_size += 32; /* Increase by 256 bits */
  
  		p->p_selbits = malloc(p->p_selbits_size * 6, M_SELECT,
  			M_WAITOK);
  	}
- 	for (i = 0; i < 3; i++) {
- 		ibits[i] = (fd_mask *)(p->p_selbits + i * p->p_selbits_size);
- 		obits[i] = (fd_mask *)(p->p_selbits + (i + 3) *
- 			p->p_selbits_size);
- 	}
- 
- 	/*
- 	 * This buffer is usually very small therefore it's probably faster
- 	 * to just zero it, rather than calculate what needs to be zeroed.
- 	 */
- 	bzero (p->p_selbits, p->p_selbits_size * 6);
  
  	/* The amount of space we need to copyin/copyout */
  	ni = howmany(uap->nd, NFDBITS) * sizeof(fd_mask);
  
  #define	getbits(name, x) \
  	if (uap->name && \
--- 549,579 ----
  			free (p->p_selbits, M_SELECT);
  
  		while (p->p_selbits_size < ni)
! 			p->p_selbits_size +=
! 				howmany(FD_ROUNDSIZE, NFDBITS) *
! 				sizeof(fd_mask);
  
  		p->p_selbits = malloc(p->p_selbits_size * 6, M_SELECT,
  			M_WAITOK);
  	}
  
  	/* The amount of space we need to copyin/copyout */
  	ni = howmany(uap->nd, NFDBITS) * sizeof(fd_mask);
+ 
+ 	for (i = 0; i < 3; i++) {
+ 		obits[i] = (fd_mask *)(p->p_selbits + i * ni);
+ 		ibits[i] = (fd_mask *)(p->p_selbits + (i + 3) * ni);
+ 	}
+ 	if (uap->ex)
+ 		i = 3;
+ 	else if (uap->ou)
+ 		i = 2;
+ 	else if (uap->in)
+ 		i = 1;
+ 	else
+ 		i = 0;
+ 	if (i)
+ 		bzero(p->p_selbits, i * ni);
  
  #define	getbits(name, x) \
  	if (uap->name && \


-- 
Andrey A. Chernov
<ache@null.net>
http://www.nagual.ru/~ache/




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95q.970217013428.575B-100000>