Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Nov 2000 19:10:29 -0600 (CST)
From:      Mike Meyer <mwm@mired.org>
To:        "Brian F. Feldman" <green@FreeBSD.org>
Cc:        cvs-all@freebsd.org
Subject:   Re: cvs commit: src/usr.sbin/inetd builtins.c 
Message-ID:  <14884.22405.22813.41567@guru.mired.org>
In-Reply-To: <80189770@toto.iv>

next in thread | previous in thread | raw e-mail | index | archive | help
Brian F. Feldman <green@FreeBSD.org> types:
> Warner Losh <imp@village.org> wrote:
> > In message <20001126182240.A8051@fw.wintelcom.net> Alfred Perlstein writes:
> > : -	if ((to.tv_usec += tv.tv_usec) >= 1000000) {
> > : +	to.tv_usec += tv.tv_usec;
> > : +	if (to.tv_usec >= 1000000) {
> > :  		to.tv_usec -= 1000000;
> > :  		to.tv_sec++;
> > :  	}
> > 
> > Shouldn't this be
> > 	if (to.tv_usec >= 1000000) {
> > 		to.tv_sec += to.tv_usec / 1000000;
> > 		to.tv_usec %= 1000000;
> > 	}
> 
> I asked Poul-Henning the same thing with regard to similar checks in the 
> kernel code.  The reply was that, although this is the "most correct" way of 
> doing things, a properly done calculation of to.tv_usec + tv.tv_usec in 
> this (and many other) case(s) will result in a maximum of 1999998, so at 
> most one subtraction and increment will be necessary.
> 
> If it's not possible to have a higher tv_usec, you save the REALLY expensive 
> divide-family instructions.

Does it make sense to be paranoid about this, and do:

	while (to.tv_usec >= 1000000) {
  		to.tv_usec -= 1000000;
  		to.tv_sec++;
  	}

Which costs one extra compare in the normal case, but insures that the
value is right if the assumption happens to fail (but will do so
slowly)?

	<mike


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




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