VM: simplify slab allocator
[minix.git] / lib / libsys / timing.c
blob51acc7b08649ad150ef2a9e6045bd28765d1138a
2 #include <minix/sysutil.h>
3 #include <minix/syslib.h>
4 #include <minix/config.h>
5 #include <minix/const.h>
6 #include <minix/minlib.h>
8 #define HIGHCOUNT 0
9 #define LOWCOUNT 1
11 #define START 0
12 #define END 1
14 void util_timer_start(util_timingdata_t *timingdata, char *name)
16 size_t i;
18 if(timingdata->names[0] == '\0') {
19 for(i = 0; i < sizeof(timingdata->names) && *name; i++)
20 timingdata->names[i] = *name++;
21 timingdata->names[sizeof(timingdata->names)-1] = '\0';
24 if (timingdata->starttimes[HIGHCOUNT]) {
25 panic("restart timer?");
26 return;
29 read_tsc((u32_t *) &timingdata->starttimes[HIGHCOUNT],
30 (u32_t *) &timingdata->starttimes[LOWCOUNT]);
33 void util_timer_end(util_timingdata_t *timingdata)
35 unsigned long h, l, d = 0;
36 int bin;
38 read_tsc((u32_t *) &h, (u32_t *) &l);
39 if (!timingdata->starttimes[HIGHCOUNT]) {
40 panic("timer stopped but not started");
41 return;
43 if (timingdata->starttimes[HIGHCOUNT] == h) {
44 d = (l - timingdata->starttimes[LOWCOUNT]);
45 } else if (timingdata->starttimes[HIGHCOUNT] == h-1 &&
46 timingdata->starttimes[LOWCOUNT] > l) {
47 d = ((ULONG_MAX - timingdata->starttimes[LOWCOUNT]) + l);
48 } else {
49 timingdata->misses++;
50 return;
52 timingdata->starttimes[HIGHCOUNT] = 0;
53 if (!timingdata->lock_timings_range[START] ||
54 d < timingdata->lock_timings_range[START] ||
55 d > timingdata->lock_timings_range[END]) {
56 int t;
57 if (!timingdata->lock_timings_range[START] ||
58 d < timingdata->lock_timings_range[START])
59 timingdata->lock_timings_range[START] = d;
60 if (!timingdata->lock_timings_range[END] ||
61 d > timingdata->lock_timings_range[END])
62 timingdata->lock_timings_range[END] = d;
63 for(t = 0; t < TIMING_POINTS; t++)
64 timingdata->lock_timings[t] = 0;
65 timingdata->binsize =
66 (timingdata->lock_timings_range[END] -
67 timingdata->lock_timings_range[START])/(TIMING_POINTS+1);
68 if (timingdata->binsize < 1)
69 timingdata->binsize = 1;
70 timingdata->resets++;
72 bin = (d-timingdata->lock_timings_range[START]) /
73 timingdata->binsize;
74 if (bin < 0 || bin >= TIMING_POINTS) {
75 /* not serious, but can't happen, so shouldn't */
76 panic("bin out of range: %d", bin);
77 } else {
78 timingdata->lock_timings[bin]++;
79 timingdata->measurements++;
82 return;