1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "litmus.h"
#include "cycles.h"
static void time_null_call(void)
{
cycles_t t0, t1, t2;
int ret;
t0 = get_cycles();
ret = null_call(&t1);
t2 = get_cycles();
if (ret != 0)
perror("null_call");
printf("%10" CYCLES_FMT ", "
"%10" CYCLES_FMT ", "
"%10" CYCLES_FMT ", "
"%10" CYCLES_FMT ", "
"%10" CYCLES_FMT ", "
"%10" CYCLES_FMT "\n",
t0, t1, t2, t1 - t0, t2 - t1, t2 - t0);
}
static struct timespec sec2timespec(double seconds)
{
struct timespec tspec;
double full_secs = floor(seconds);
tspec.tv_sec = (time_t) full_secs;
tspec.tv_nsec = (long) ((seconds - full_secs) * 1000000000L);
return tspec;
}
int main(int argc, char **argv)
{
double delay;
struct timespec sleep_time;
if (argc == 2) {
delay = atof(argv[1]);
sleep_time = sec2timespec(delay);
if (delay <= 0.0)
fprintf(stderr, "Invalid time spec: %s\n", argv[1]);
fprintf(stderr, "Measuring syscall overhead every "
"%lus and %luns.\n",
(unsigned long) sleep_time.tv_sec,
(unsigned long) sleep_time.tv_nsec);
do {
time_null_call();
} while (nanosleep(&sleep_time, NULL) == 0);
} else {
fprintf(stderr, "Press enter key to measure...\n");
while (getchar() != EOF) {
time_null_call();
}
}
return 0;
}
|