secondary cache feature in vm.
[minix.git] / lib / libsys / timing.c
blob89c036294704e70db4e322ac6a4b405635e60bc2
2 #include <minix/sysutil.h>
3 #include <minix/syslib.h>
4 #include <minix/config.h>
5 #include <minix/const.h>
7 #define HIGHCOUNT 0
8 #define LOWCOUNT 1
10 #define START 0
11 #define END 1
13 void util_timer_start(util_timingdata_t *timingdata, char *name)
15 size_t i;
17 if(timingdata->names[0] == '\0') {
18 for(i = 0; i < sizeof(timingdata->names) && *name; i++)
19 timingdata->names[i] = *name++;
20 timingdata->names[sizeof(timingdata->names)-1] = '\0';
23 if (timingdata->starttimes[HIGHCOUNT]) {
24 panic("restart timer?");
25 return;
28 read_tsc(&timingdata->starttimes[HIGHCOUNT],
29 &timingdata->starttimes[LOWCOUNT]);
32 void util_timer_end(util_timingdata_t *timingdata)
34 unsigned long h, l, d = 0;
35 int bin;
37 read_tsc(&h, &l);
38 if (!timingdata->starttimes[HIGHCOUNT]) {
39 panic("timer stopped but not started");
40 return;
42 if (timingdata->starttimes[HIGHCOUNT] == h) {
43 d = (l - timingdata->starttimes[LOWCOUNT]);
44 } else if (timingdata->starttimes[HIGHCOUNT] == h-1 &&
45 timingdata->starttimes[LOWCOUNT] > l) {
46 d = ((ULONG_MAX - timingdata->starttimes[LOWCOUNT]) + l);
47 } else {
48 timingdata->misses++;
49 return;
51 timingdata->starttimes[HIGHCOUNT] = 0;
52 if (!timingdata->lock_timings_range[START] ||
53 d < timingdata->lock_timings_range[START] ||
54 d > timingdata->lock_timings_range[END]) {
55 int t;
56 if (!timingdata->lock_timings_range[START] ||
57 d < timingdata->lock_timings_range[START])
58 timingdata->lock_timings_range[START] = d;
59 if (!timingdata->lock_timings_range[END] ||
60 d > timingdata->lock_timings_range[END])
61 timingdata->lock_timings_range[END] = d;
62 for(t = 0; t < TIMING_POINTS; t++)
63 timingdata->lock_timings[t] = 0;
64 timingdata->binsize =
65 (timingdata->lock_timings_range[END] -
66 timingdata->lock_timings_range[START])/(TIMING_POINTS+1);
67 if (timingdata->binsize < 1)
68 timingdata->binsize = 1;
69 timingdata->resets++;
71 bin = (d-timingdata->lock_timings_range[START]) /
72 timingdata->binsize;
73 if (bin < 0 || bin >= TIMING_POINTS) {
74 /* not serious, but can't happen, so shouldn't */
75 panic("bin out of range: %d", bin);
76 } else {
77 timingdata->lock_timings[bin]++;
78 timingdata->measurements++;
81 return;