2009-01-09 17:39:31 +01:00
|
|
|
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
2011-06-23 19:25:36 +02:00
|
|
|
#include <minix/minlib.h>
|
2009-01-09 17:39:31 +01:00
|
|
|
|
|
|
|
#define HIGHCOUNT 0
|
|
|
|
#define LOWCOUNT 1
|
|
|
|
|
|
|
|
#define START 0
|
|
|
|
#define END 1
|
|
|
|
|
|
|
|
void util_timer_start(util_timingdata_t *timingdata, char *name)
|
|
|
|
{
|
2010-03-10 14:19:27 +01:00
|
|
|
size_t i;
|
2009-01-09 17:39:31 +01:00
|
|
|
|
|
|
|
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]) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("restart timer?");
|
2009-01-09 17:39:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
read_tsc((u32_t *) &timingdata->starttimes[HIGHCOUNT],
|
|
|
|
(u32_t *) &timingdata->starttimes[LOWCOUNT]);
|
2009-01-09 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void util_timer_end(util_timingdata_t *timingdata)
|
|
|
|
{
|
2010-03-10 14:19:27 +01:00
|
|
|
unsigned long h, l, d = 0;
|
2009-01-09 17:39:31 +01:00
|
|
|
int bin;
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
read_tsc((u32_t *) &h, (u32_t *) &l);
|
2009-01-09 17:39:31 +01:00
|
|
|
if (!timingdata->starttimes[HIGHCOUNT]) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("timer stopped but not started");
|
2009-01-09 17:39:31 +01:00
|
|
|
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 */
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("bin out of range: %d", bin);
|
2009-01-09 17:39:31 +01:00
|
|
|
} else {
|
|
|
|
timingdata->lock_timings[bin]++;
|
|
|
|
timingdata->measurements++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|