diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2009-03-02 16:20:55 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2009-03-02 16:20:55 -0500 |
commit | 3c5dae7026bc20c0ba7e6d50cce7260b14fc50ab (patch) | |
tree | fa5ea945a518daf12ee9691a288af96f4c980365 /bin/null_call.c | |
parent | 1d7d6d00b84f46016ec98c260f22d5e06036b473 (diff) |
add system call overhead measurement program
Run this tool (and a background workload) to measure system call
overheads.
Diffstat (limited to 'bin/null_call.c')
-rw-r--r-- | bin/null_call.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/null_call.c b/bin/null_call.c new file mode 100644 index 0000000..94ba866 --- /dev/null +++ b/bin/null_call.c | |||
@@ -0,0 +1,62 @@ | |||
1 | #include <sys/time.h> | ||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <time.h> | ||
5 | #include <math.h> | ||
6 | |||
7 | #include "litmus.h" | ||
8 | #include "cycles.h" | ||
9 | |||
10 | static void time_null_call(void) | ||
11 | { | ||
12 | cycles_t t0, t1, t2; | ||
13 | int ret; | ||
14 | |||
15 | t0 = get_cycles(); | ||
16 | ret = null_call(&t1); | ||
17 | t2 = get_cycles(); | ||
18 | if (ret != 0) | ||
19 | perror("null_call"); | ||
20 | printf("%10" CYCLES_FMT ", " | ||
21 | "%10" CYCLES_FMT ", " | ||
22 | "%10" CYCLES_FMT ", " | ||
23 | "%10" CYCLES_FMT ", " | ||
24 | "%10" CYCLES_FMT ", " | ||
25 | "%10" CYCLES_FMT "\n", | ||
26 | t0, t1, t2, t1 - t0, t2 - t1, t2 - t0); | ||
27 | } | ||
28 | |||
29 | static struct timespec sec2timespec(double seconds) | ||
30 | { | ||
31 | struct timespec tspec; | ||
32 | double full_secs = floor(seconds); | ||
33 | tspec.tv_sec = (time_t) full_secs; | ||
34 | tspec.tv_nsec = (long) ((seconds - full_secs) * 1000000000L); | ||
35 | return tspec; | ||
36 | } | ||
37 | |||
38 | int main(int argc, char **argv) | ||
39 | { | ||
40 | double delay; | ||
41 | struct timespec sleep_time; | ||
42 | |||
43 | if (argc == 2) { | ||
44 | delay = atof(argv[1]); | ||
45 | sleep_time = sec2timespec(delay); | ||
46 | if (delay <= 0.0) | ||
47 | fprintf(stderr, "Invalid time spec: %s\n", argv[1]); | ||
48 | fprintf(stderr, "Measuring syscall overhead every " | ||
49 | "%lus and %luns.\n", | ||
50 | (unsigned long) sleep_time.tv_sec, | ||
51 | (unsigned long) sleep_time.tv_nsec); | ||
52 | do { | ||
53 | time_null_call(); | ||
54 | } while (nanosleep(&sleep_time, NULL) == 0); | ||
55 | } else { | ||
56 | fprintf(stderr, "Press enter key to measure...\n"); | ||
57 | while (getchar() != EOF) { | ||
58 | time_null_call(); | ||
59 | } | ||
60 | } | ||
61 | return 0; | ||
62 | } | ||