Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/powerpc/ibm4xx A more accurate microtime() implemen...



details:   https://anonhg.NetBSD.org/src/rev/823e41c8651c
branches:  trunk
changeset: 573067:823e41c8651c
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed Jan 19 00:26:54 2005 +0000

description:
A more accurate microtime() implementation.  Avoids precision
errors when the clock frequency doesn't divide nicely in to 10^9.

diffstat:

 sys/arch/powerpc/ibm4xx/clock.c |  12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r f4ddc3cba3ee -r 823e41c8651c sys/arch/powerpc/ibm4xx/clock.c
--- a/sys/arch/powerpc/ibm4xx/clock.c   Wed Jan 19 00:23:44 2005 +0000
+++ b/sys/arch/powerpc/ibm4xx/clock.c   Wed Jan 19 00:26:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.10 2004/09/02 08:22:58 scw Exp $   */
+/*     $NetBSD: clock.c,v 1.11 2005/01/19 00:26:54 simonb Exp $        */
 /*      $OpenBSD: clock.c,v 1.3 1997/10/13 13:42:53 pefo Exp $  */
 
 /*
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.10 2004/09/02 08:22:58 scw Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.11 2005/01/19 00:26:54 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -166,16 +166,18 @@
        int msr;
 
        asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr) :);
+
        tb = mftbl();
-       ticks = (tb - lasttb) * ns_per_tick;
+       ticks = ((tb - lasttb) * 1000000ULL) / ticks_per_sec;
+
        *tvp = time;
-       asm volatile ("mtmsr %0" :: "r"(msr));
-       ticks /= 1000;
        tvp->tv_usec += ticks;
        while (tvp->tv_usec >= 1000000) {
                tvp->tv_usec -= 1000000;
                tvp->tv_sec++;
        }
+
+       asm volatile ("mtmsr %0" :: "r"(msr));
 }
 
 /*



Home | Main Index | Thread Index | Old Index