From owner-freebsd-bugs Mon Aug 19 16:40:17 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0ECD637B400 for ; Mon, 19 Aug 2002 16:40:09 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 87A2B43E6A for ; Mon, 19 Aug 2002 16:40:08 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7JNe8JU002766 for ; Mon, 19 Aug 2002 16:40:08 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7JNe7CB002764; Mon, 19 Aug 2002 16:40:07 -0700 (PDT) Date: Mon, 19 Aug 2002 16:40:07 -0700 (PDT) Message-Id: <200208192340.g7JNe7CB002764@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Bruce Evans Subject: Re: kern/41781: clock_getres returns tv_nsec=0 when TSC is 1Ghz or faster Reply-To: Bruce Evans Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR kern/41781; it has been noted by GNATS. From: Bruce Evans To: Kevin Martin 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