]> Zhao Yanbai Git Server - minix.git/commitdiff
timing library from kernel into library
authorBen Gras <ben@minix3.org>
Fri, 9 Jan 2009 16:39:31 +0000 (16:39 +0000)
committerBen Gras <ben@minix3.org>
Fri, 9 Jan 2009 16:39:31 +0000 (16:39 +0000)
lib/sysutil/Makefile.in
lib/sysutil/timing.c [new file with mode: 0644]

index 3cd2866ce42752f5ef26d4c822df63b2329ae531..4f348804fc547a6c085069ccbbd5d4432deb8b47 100644 (file)
@@ -25,6 +25,7 @@ libsys_FILES=" \
        ser_putc.c \
        stacktrace.c \
        sys_hz.c \
+       timing.c \
        profile_extern.c \
        profile.c"
 
diff --git a/lib/sysutil/timing.c b/lib/sysutil/timing.c
new file mode 100644 (file)
index 0000000..4842dc0
--- /dev/null
@@ -0,0 +1,83 @@
+
+#include <minix/sysutil.h>
+#include <minix/syslib.h>
+#include <minix/config.h>
+#include <minix/const.h>
+
+#define HIGHCOUNT      0
+#define LOWCOUNT       1
+
+#define START          0
+#define END            1
+
+void util_timer_start(util_timingdata_t *timingdata, char *name)
+{
+       unsigned long h, l;
+       int i;
+
+       if(timingdata->names[0] == '\0') {
+               for(i = 0; i < sizeof(timingdata->names) && *name; i++)
+                       timingdata->names[i] = *name++;
+               timingdata->names[sizeof(timingdata->names)-1] = '\0';
+       }
+
+       if (timingdata->starttimes[HIGHCOUNT]) {
+               panic(__FILE__, "restart timer?", NO_NUM);
+               return;
+       }
+
+       read_tsc(&timingdata->starttimes[HIGHCOUNT],
+               &timingdata->starttimes[LOWCOUNT]);
+}
+
+void util_timer_end(util_timingdata_t *timingdata)
+{
+       unsigned long h, l, d = 0, binsize;
+       int bin;
+
+       read_tsc(&h, &l);
+       if (!timingdata->starttimes[HIGHCOUNT]) {
+               panic(__FILE__, "timer stopped but not started", NO_NUM);
+               return;
+       }
+       if (timingdata->starttimes[HIGHCOUNT] == h) {
+               d = (l - timingdata->starttimes[LOWCOUNT]);
+       } else if (timingdata->starttimes[HIGHCOUNT] == h-1 &&
+               timingdata->starttimes[LOWCOUNT] > l) {
+               d = ((ULONG_MAX - timingdata->starttimes[LOWCOUNT]) + l);
+       } else {
+               timingdata->misses++;
+               return;
+       }
+       timingdata->starttimes[HIGHCOUNT] = 0;
+       if (!timingdata->lock_timings_range[START] ||
+               d < timingdata->lock_timings_range[START] ||
+               d > timingdata->lock_timings_range[END]) {
+               int t;
+               if (!timingdata->lock_timings_range[START] ||
+                       d < timingdata->lock_timings_range[START])
+                       timingdata->lock_timings_range[START] = d;
+               if (!timingdata->lock_timings_range[END] ||
+                       d > timingdata->lock_timings_range[END])
+                       timingdata->lock_timings_range[END] = d;
+               for(t = 0; t < TIMING_POINTS; t++)
+                       timingdata->lock_timings[t] = 0;
+               timingdata->binsize =
+                (timingdata->lock_timings_range[END] -
+                timingdata->lock_timings_range[START])/(TIMING_POINTS+1);
+               if (timingdata->binsize < 1)
+                 timingdata->binsize = 1;
+               timingdata->resets++;
+       }
+       bin = (d-timingdata->lock_timings_range[START]) /
+               timingdata->binsize;
+       if (bin < 0 || bin >= TIMING_POINTS) {
+               /* not serious, but can't happen, so shouldn't */
+               panic(__FILE__, "bin out of range", bin);
+       } else {
+               timingdata->lock_timings[bin]++;
+               timingdata->measurements++;
+       }
+
+       return;
+}