2 #include <minix/sysutil.h>
3 #include <minix/syslib.h>
4 #include <minix/config.h>
5 #include <minix/const.h>
13 void util_timer_start(util_timingdata_t
*timingdata
, char *name
)
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?");
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;
38 if (!timingdata
->starttimes
[HIGHCOUNT
]) {
39 panic("timer stopped but not started");
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
);
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
]) {
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;
65 (timingdata
->lock_timings_range
[END
] -
66 timingdata
->lock_timings_range
[START
])/(TIMING_POINTS
+1);
67 if (timingdata
->binsize
< 1)
68 timingdata
->binsize
= 1;
71 bin
= (d
-timingdata
->lock_timings_range
[START
]) /
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
);
77 timingdata
->lock_timings
[bin
]++;
78 timingdata
->measurements
++;