.. | .. |
---|
10 | 10 | #include <sched.h> |
---|
11 | 11 | #include <errno.h> |
---|
12 | 12 | #include <string.h> |
---|
| 13 | +#include <time.h> |
---|
13 | 14 | #include "../kselftest.h" |
---|
| 15 | + |
---|
| 16 | +#define MSEC_PER_SEC 1000L |
---|
| 17 | +#define NSEC_PER_MSEC 1000000L |
---|
14 | 18 | |
---|
15 | 19 | void usage(char *name) { |
---|
16 | 20 | printf ("Usage: %s cpunum\n", name); |
---|
.. | .. |
---|
22 | 26 | long long tsc, old_tsc, new_tsc; |
---|
23 | 27 | long long aperf, old_aperf, new_aperf; |
---|
24 | 28 | long long mperf, old_mperf, new_mperf; |
---|
25 | | - struct timeb before, after; |
---|
| 29 | + struct timespec before, after; |
---|
26 | 30 | long long int start, finish, total; |
---|
27 | 31 | cpu_set_t cpuset; |
---|
28 | 32 | |
---|
.. | .. |
---|
55 | 59 | return 1; |
---|
56 | 60 | } |
---|
57 | 61 | |
---|
58 | | - ftime(&before); |
---|
| 62 | + if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) { |
---|
| 63 | + perror("clock_gettime"); |
---|
| 64 | + return 1; |
---|
| 65 | + } |
---|
59 | 66 | pread(fd, &old_tsc, sizeof(old_tsc), 0x10); |
---|
60 | 67 | pread(fd, &old_aperf, sizeof(old_mperf), 0xe7); |
---|
61 | 68 | pread(fd, &old_mperf, sizeof(old_aperf), 0xe8); |
---|
.. | .. |
---|
64 | 71 | sqrt(i); |
---|
65 | 72 | } |
---|
66 | 73 | |
---|
67 | | - ftime(&after); |
---|
| 74 | + if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) { |
---|
| 75 | + perror("clock_gettime"); |
---|
| 76 | + return 1; |
---|
| 77 | + } |
---|
68 | 78 | pread(fd, &new_tsc, sizeof(new_tsc), 0x10); |
---|
69 | 79 | pread(fd, &new_aperf, sizeof(new_mperf), 0xe7); |
---|
70 | 80 | pread(fd, &new_mperf, sizeof(new_aperf), 0xe8); |
---|
.. | .. |
---|
73 | 83 | aperf = new_aperf-old_aperf; |
---|
74 | 84 | mperf = new_mperf-old_mperf; |
---|
75 | 85 | |
---|
76 | | - start = before.time*1000 + before.millitm; |
---|
77 | | - finish = after.time*1000 + after.millitm; |
---|
| 86 | + start = before.tv_sec*MSEC_PER_SEC + before.tv_nsec/NSEC_PER_MSEC; |
---|
| 87 | + finish = after.tv_sec*MSEC_PER_SEC + after.tv_nsec/NSEC_PER_MSEC; |
---|
78 | 88 | total = finish - start; |
---|
79 | 89 | |
---|
80 | | - printf("runTime: %4.2f\n", 1.0*total/1000); |
---|
| 90 | + printf("runTime: %4.2f\n", 1.0*total/MSEC_PER_SEC); |
---|
81 | 91 | printf("freq: %7.0f\n", tsc / (1.0*aperf / (1.0 * mperf)) / total); |
---|
82 | 92 | return 0; |
---|
83 | 93 | } |
---|