2 * This program can be used to calibrate the clock reading jitter of a
3 * particular CPU and operating system. It first tickles every element
4 * of an array, in order to force pages into memory, then repeatedly calls
5 * gettimeofday() and, finally, writes out the time values for later
6 * analysis. From this you can determine the jitter and if the clock ever
21 struct timeval ts, tr;
23 long temp, j, i, gtod[NBUF];
25 gettimeofday(&ts, &tzp);
28 * Force pages into memory
30 for (i = 0; i < NBUF; i ++)
34 * Construct gtod array
36 for (i = 0; i < NBUF; i ++) {
37 gettimeofday(&tr, &tzp);
38 gtod[i] = (tr.tv_sec - ts.tv_sec) * 1000000 + tr.tv_usec;
42 * Write out gtod array for later processing with S
44 for (i = 0; i < NBUF - 2; i++) {
46 printf("%lu\n", gtod[i]);
48 gtod[i] = gtod[i + 1] - gtod[i];
49 printf("%lu\n", gtod[i]);
53 * Sort the gtod array and display deciles
55 for (i = 0; i < NBUF - 2; i++) {
56 for (j = 0; j <= i; j++) {
57 if (gtod[j] > gtod[i]) {
64 fprintf(stderr, "First rank\n");
65 for (i = 0; i < 10; i++)
66 fprintf(stderr, "%10ld%10ld\n", i, gtod[i]);
67 fprintf(stderr, "Last rank\n");
68 for (i = NBUF - 12; i < NBUF - 2; i++)
69 fprintf(stderr, "%10ld%10ld\n", i, gtod[i]);