Port-sandpoint archive

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

Microtime bug



Hi,

We had problems with microtime (9) not returning increasing time from one call to another. The patch below solved that problem so maybe it should be commited. (The patch contains code extracted from current macppc clock.c, the only change is where lasttb is updated).

Another question (not specific to sandpoint): why does microtime use "time" and not "mono_time"? From the description in the man-page mono_time sounds like a better choice (and if mono_time was used the BUGS-section of that man-page could be omitted).

Yet another question (also not specific to sandpoint): why does clock_getres (kern/kern_time.c) return 1000000000 / hz? Shouldn't it return 1000 since clock_gettime calls microtime, or call some HD function to get the true resolution?


/Erik

--- clock.c.orig        Tue Jun 19 10:34:51 2001
+++ clock.c     Mon Mar 25 15:52:32 2002
@@ -40,7 +40,7 @@
#include <machine/pio.h>

/*
- * Initially we assume a processor with a bus frequency of 12.5 MHz.
+ * ticks_per_sec and ns_per_tick is set in machdep.c.
 */
u_long ticks_per_sec;
u_long ns_per_tick;
@@ -71,17 +71,11 @@
        * Based on the actual time delay since the last decrementer reload,
        * we arrange for earlier interrupt next time.
        */
-       asm ("mftb %0; mfdec %1" : "=r"(tb), "=r"(tick));
+       asm ("mfdec %0" : "=r"(tick));
       for (nticks = 0; tick < 0; nticks++)
               tick += ticks_per_intr;
       asm volatile ("mtdec %0" :: "r"(tick));

-       /*
-        * lasttb is used during microtime. Set it to the virtual
-        * start of this tick interval.
-        */
-       lasttb = tb + tick - ticks_per_intr;
-
       intrcnt[CNT_CLOCK]++;

       pri = splclock();
@@ -90,6 +84,13 @@
       else {
               nticks += tickspending;
               tickspending = 0;
+
+               /*
+                * lasttb is used during microtime. Set it to the virtual
+                * start of this tick interval.
+                */
+               asm ("mftb %0" : "=r"(tb));
+               lasttb = tb + tick - ticks_per_intr;

               /*
                * Reenable interrupts





Home | Main Index | Thread Index | Old Index