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>
14 void util_timer_start(util_timingdata_t
*timingdata
, char *name
)
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?");
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;
38 read_tsc((u32_t
*) &h
, (u32_t
*) &l
);
39 if (!timingdata
->starttimes
[HIGHCOUNT
]) {
40 panic("timer stopped but not started");
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
);
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
]) {
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;
66 (timingdata
->lock_timings_range
[END
] -
67 timingdata
->lock_timings_range
[START
])/(TIMING_POINTS
+1);
68 if (timingdata
->binsize
< 1)
69 timingdata
->binsize
= 1;
72 bin
= (d
-timingdata
->lock_timings_range
[START
]) /
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
);
78 timingdata
->lock_timings
[bin
]++;
79 timingdata
->measurements
++;