Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jan 2000 08:58:36 +1100
From:      Peter Jeremy <peter.jeremy@alcatel.com.au>
To:        stable@FreeBSD.org, FreeBSD-gnats-submit@FreeBSD.org
Subject:   Re: kern/13644
Message-ID:  <00Jan25.085841est.115243@border.alcanet.com.au>
In-Reply-To: <200001241659.LAA34219@misha.cisco.com>; from mi@aldan.algebra.com on Tue, Jan 25, 2000 at 04:02:28AM %2B1100
References:  <14476.31150.689748.108097@onceler.kcilink.com> <200001241659.LAA34219@misha.cisco.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2000-Jan-25 04:02:28 +1100, Mikhail Teterin <mi@aldan.algebra.com> wrote:
>  It  does  not  explain   the  consistent  9-10  msecs  excess.

_That_ might be a bug.  The select(2) delay is converted from a struct
timeval into ticks by tvtohz().  This routine rounds up to the next
tick and then adds 1 to the result (in both -stable and -current).
The `+1' would seem to be incorrect - even if you want to allow for
the current tick, a more reasonable estimate would be 0.5, not 1.

Based on a quick check, both Solaris 2.5 and Digital Unix (aka Tru64)
4.0D don't include this one tick over-estimate.

I believe one (only) of the following two patches should be applied:

Index: kern_clock.c
===================================================================
RCS file: /home/CVSROOT/src/sys/kern/kern_clock.c,v
retrieving revision 1.104
diff -u -r1.104 kern_clock.c
--- kern_clock.c	1999/12/08 10:02:12	1.104
+++ kern_clock.c	2000/01/24 21:51:27
@@ -271,9 +271,8 @@
 	 * If the number of usecs in the whole seconds part of the time
 	 * difference fits in a long, then the total number of usecs will
 	 * fit in an unsigned long.  Compute the total and convert it to
-	 * ticks, rounding up and adding 1 to allow for the current tick
-	 * to expire.  Rounding also depends on unsigned long arithmetic
-	 * to avoid overflow.
+	 * ticks, rounding up.  Rounding also depends on unsigned long
+	 * arithmetic to avoid overflow.
 	 *
 	 * Otherwise, if the number of ticks in the whole seconds part of
 	 * the time difference fits in a long, then convert the parts to
@@ -305,10 +304,10 @@
 		ticks = 1;
 	} else if (sec <= LONG_MAX / 1000000)
 		ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
-			/ tick + 1;
+			/ tick;
 	else if (sec <= LONG_MAX / hz)
 		ticks = sec * hz
-			+ ((unsigned long)usec + (tick - 1)) / tick + 1;
+			+ ((unsigned long)usec + (tick - 1)) / tick;
 	else
 		ticks = LONG_MAX;
 	if (ticks > INT_MAX)
Index: sys_generic.c
===================================================================
RCS file: /home/CVSROOT/src/sys/kern/sys_generic.c,v
retrieving revision 1.54
diff -u -r1.54 sys_generic.c
--- sys_generic.c	2000/01/14 02:53:25	1.54
+++ sys_generic.c	2000/01/24 21:50:26
@@ -687,7 +687,10 @@
 		ttv = atv;
 		timevalsub(&ttv, &rtv);
 		timo = ttv.tv_sec > 24 * 60 * 60 ?
-		    24 * 60 * 60 * hz : tvtohz(&ttv);
+		    24 * 60 * 60 * hz + 1 : tvtohz(&ttv);
+		/* compensate for over-estimate in tvtohz() */
+		if (timo > 1)
+		    timo--
 	}
 	s = splhigh();
 	if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
@@ -818,7 +821,10 @@
 		ttv = atv;
 		timevalsub(&ttv, &rtv);
 		timo = ttv.tv_sec > 24 * 60 * 60 ?
-		    24 * 60 * 60 * hz : tvtohz(&ttv);
+		    24 * 60 * 60 * hz + 1 : tvtohz(&ttv);
+		/* compensate for over-estimate in tvtohz() */
+		if (timo > 1)
+		    timo--
 	} 
 	s = splhigh(); 
 	if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {

Peter


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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00Jan25.085841est.115243>