diff options
-rw-r--r-- | SConstruct | 7 | ||||
-rw-r--r-- | bin/null_call.c | 62 |
2 files changed, 69 insertions, 0 deletions
@@ -73,6 +73,7 @@ st = env.Clone( | |||
73 | LIBPATH = '.' | 73 | LIBPATH = '.' |
74 | ) | 74 | ) |
75 | 75 | ||
76 | |||
76 | # link with liblitmus | 77 | # link with liblitmus |
77 | rt = env.Clone( | 78 | rt = env.Clone( |
78 | LIBS = 'litmus', | 79 | LIBS = 'litmus', |
@@ -80,6 +81,11 @@ rt = env.Clone( | |||
80 | ) | 81 | ) |
81 | rt.Append(LINKFLAGS = '-static') | 82 | rt.Append(LINKFLAGS = '-static') |
82 | 83 | ||
84 | |||
85 | # link with math lib | ||
86 | rtm = rt.Clone() | ||
87 | rtm.Append(LIBS = ['m']) | ||
88 | |||
83 | # multithreaded real-time tasks | 89 | # multithreaded real-time tasks |
84 | mtrt = rt.Clone() | 90 | mtrt = rt.Clone() |
85 | mtrt.Append(LINKFLAGS = '-pthread') | 91 | mtrt.Append(LINKFLAGS = '-pthread') |
@@ -107,4 +113,5 @@ rt.Program('np_test', 'bin/np_test.c') | |||
107 | rt.Program('rt_launch', ['bin/rt_launch.c', 'bin/common.c']) | 113 | rt.Program('rt_launch', ['bin/rt_launch.c', 'bin/common.c']) |
108 | rt.Program('rtspin', ['bin/rtspin.c', 'bin/common.c']) | 114 | rt.Program('rtspin', ['bin/rtspin.c', 'bin/common.c']) |
109 | rt.Program('release_ts', 'bin/release_ts.c') | 115 | rt.Program('release_ts', 'bin/release_ts.c') |
116 | rtm.Program('measure_syscall', 'bin/null_call.c') | ||
110 | st.Program('showst', 'bin/showst.c') | 117 | st.Program('showst', 'bin/showst.c') |
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 | } | ||