minix/lib/libsys/timing.c
Ben Gras 35a108b911 panic() cleanup.
this change
   - makes panic() variadic, doing full printf() formatting -
     no more NO_NUM, and no more separate printf() statements
     needed to print extra info (or something in hex) before panicing
   - unifies panic() - same panic() name and usage for everyone -
     vm, kernel and rest have different names/syntax currently
     in order to implement their own luxuries, but no longer
   - throws out the 1st argument, to make source less noisy.
     the panic() in syslib retrieves the server name from the kernel
     so it should be clear enough who is panicing; e.g.
         panic("sigaction failed: %d", errno);
     looks like:
         at_wini(73130): panic: sigaction failed: 0
         syslib:panic.c: stacktrace: 0x74dc 0x2025 0x100a
   - throws out report() - printf() is more convenient and powerful
   - harmonizes/fixes the use of panic() - there were a few places
     that used printf-style formatting (didn't work) and newlines
     (messes up the formatting) in panic()
   - throws out a few per-server panic() functions
   - cleans up a tie-in of tty with panic()

merging printf() and panic() statements to be done incrementally.
2010-03-05 15:05:11 +00:00

84 lines
2.1 KiB
C

#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("restart timer?");
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("timer stopped but not started");
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("bin out of range: %d", bin);
} else {
timingdata->lock_timings[bin]++;
timingdata->measurements++;
}
return;
}