source: trunk/third/xntp/util/jitter.c @ 10832

Revision 10832, 1.5 KB checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10831, which included commits to RCS files with non-trunk default branches.
Line 
1/*
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
7 * runs backwards.
8 */
9#include <sys/time.h>
10#include <stdio.h>
11
12#define NBUF 20002
13
14void
15main()
16{
17        struct timeval ts, tr;
18        struct timezone tzp;
19        long temp, j, i, gtod[NBUF];
20
21        gettimeofday(&ts, &tzp);
22
23        /*
24         * Force pages into memory
25         */
26        for (i = 0; i < NBUF; i ++)
27                gtod[i] = 0;
28
29        /*
30         * Construct gtod array
31         */
32        for (i = 0; i < NBUF; i ++) {
33                gettimeofday(&tr, &tzp);
34                gtod[i] = (tr.tv_sec - ts.tv_sec) * 1000000 + tr.tv_usec;
35        }
36
37        /*
38         * Write out gtod array for later processing with S
39         */
40        for (i = 0; i < NBUF - 2; i++) {
41/*
42                printf("%lu\n", gtod[i]);
43*/
44                gtod[i] = gtod[i + 1] - gtod[i];
45                printf("%lu\n", gtod[i]);
46        }
47
48        /*
49         * Sort the gtod array and display deciles
50         */
51        for (i = 0; i < NBUF - 2; i++) {
52                for (j = 0; j <= i; j++) {
53                        if (gtod[j] > gtod[i]) {
54                                temp = gtod[j];
55                                gtod[j] = gtod[i];
56                                gtod[i] = temp;
57                        }
58                }
59        }
60        fprintf(stderr, "First rank\n");
61        for (i = 0; i < 10; i++)
62                fprintf(stderr, "%10ld%10ld\n", i, gtod[i]);
63        fprintf(stderr, "Last rank\n");
64        for (i = NBUF - 12; i < NBUF - 2; i++)
65                fprintf(stderr, "%10ld%10ld\n", i, gtod[i]);
66}
Note: See TracBrowser for help on using the repository browser.