1 /* $NetBSD: hist.c,v 1.2 2003/12/04 16:23:38 drochner Exp $ */
4 * This program can be used to calibrate the clock reading jitter of a
5 * particular CPU and operating system. It first tickles every element
6 * of an array, in order to force pages into memory, then repeatedly calls
7 * gettimeofday() and, finally, writes out the time values for later
8 * analysis. From this you can determine the jitter and if the clock ever
16 #include "ntp_types.h"
21 #define NBUF 100001 /* size of basic histogram */
22 #define NSRT 20000 /* size of overflow histogram */
23 #define NCNT (600 * 1000000) /* sample interval (us) */
25 int col
P((long *, long *));
33 struct timeval ts
, tr
, tp
;
36 long t
, u
, v
, w
, gtod
[NBUF
], ovfl
[NSRT
];
39 * Force pages into memory
41 for (i
= 0; i
< NBUF
; i
++)
43 for (i
= 0; i
< NSRT
; i
++)
50 gettimeofday(&ts
, &tzp
);
51 t
= ts
.tv_sec
* 1000000 + ts
.tv_usec
;
54 gettimeofday(&tr
, &tzp
);
55 u
= tr
.tv_sec
* 1000000 + tr
.tv_usec
;
61 printf("error <= 0 %ld %d %d, %d %d\n", w, ts.tv_sec,
62 ts.tv_usec, tr.tv_sec, tr.tv_usec);
64 } else if (w
> NBUF
- 1) {
78 for (i
= 0; i
< NBUF
- 1; i
++) {
80 printf("%ld %ld\n", i
, gtod
[i
]);
85 #ifdef QSORT_USES_VOID_P
90 ovfl
, (size_t)n
, sizeof(long), col
);
93 for (i
= 0; i
< n
; i
++) {
96 printf("%ld %ld\n", w
, j
);
103 printf("%ld %ld\n", w
, j
);