Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Aug 2002 16:40:07 -0700 (PDT)
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/41781: clock_getres returns tv_nsec=0 when TSC is 1Ghz or faster
Message-ID:  <200208192340.g7JNe7CB002764@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/41781; it has been noted by GNATS.

From: Bruce Evans <bde@zeta.org.au>
To: Kevin Martin <sigma@pair.com>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/41781: clock_getres returns tv_nsec=0 when TSC is 1Ghz or
 faster
Date: Tue, 20 Aug 2002 09:41:31 +1000 (EST)

 On Mon, 19 Aug 2002, Kevin Martin wrote:
 
 > >Description:
 > When the the TSC timer is 1Ghz or faster:
 > Timecounter "TSC"  frequency 1002275326 Hz
 > kern/kern_time.c handles clock_getres by dividing this value into
 > 1000000000L.  The integer result is unfortunately zero.  Programs
 > which expect a useful result are disappointed.  For example, PGP uses
 > this value and divides by it, promptly dumping core.
 
 I just wrote the following untested fix for this.
 
 %%%
 Index: kern_time.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/kern/kern_time.c,v
 retrieving revision 1.84
 diff -u -2 -r1.84 kern_time.c
 --- kern_time.c	18 Aug 2002 21:24:22 -0000	1.84
 +++ kern_time.c	19 Aug 2002 20:45:17 -0000
 @@ -215,5 +209,10 @@
  	if (SCARG(uap, tp)) {
  		ts.tv_sec = 0;
 -		ts.tv_nsec = 1000000000 / tc_getfrequency();
 +		/*
 +		 * Round up the result of the division cheaply by adding 1.
 +		 * Rounding up is especially important if rounding down
 +		 * would give 0.  Perfect rounding is unimportant.
 +		 */
 +		ts.tv_nsec = 1000000000 / tc_getfrequency() + 1;
  		error = copyout(&ts, SCARG(uap, tp), sizeof(ts));
  	}
 %%%
 
 > >Fix:
 > I believe the best solution is to return a minimum value of one
 > nanosecond, since the worst you've done is tell the calling program
 > that the timer is less precise than it is.  Does POSIX have anything
 > to say?  I don't know.
 
 It doesn't say anything relevant, at least in POSIX.1-200x-draft7.  It
 says that clock_getres() gives the actual resolution, but this is
 clearly unimplementable if the actual resolution is less than one
 nanosecond or even if it is not an integral number of nanoseconds.
 
 Bruce
 

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




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