aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rtspin.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/rtspin.c')
-rw-r--r--bin/rtspin.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/bin/rtspin.c b/bin/rtspin.c
index 56f5549..7829942 100644
--- a/bin/rtspin.c
+++ b/bin/rtspin.c
@@ -10,6 +10,16 @@
10#include "common.h" 10#include "common.h"
11 11
12 12
13static double cputime()
14{
15 struct timespec ts;
16 int err;
17 err = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
18 if (err != 0)
19 perror("clock_gettime");
20 return (ts.tv_sec + 1E-9 * ts.tv_nsec);
21}
22
13static double wctime() 23static double wctime()
14{ 24{
15 struct timeval tv; 25 struct timeval tv;
@@ -40,11 +50,20 @@ static int loop_once(void)
40static int loop_for(double exec_time) 50static int loop_for(double exec_time)
41{ 51{
42 double t = 0; 52 double t = 0;
43 int tmp = 0; 53 int tmp = 0;
44 while (t + loop_length < exec_time) { 54/* while (t + loop_length < exec_time) {
55 tmp += loop_once();
56 t += loop_length;
57 }
58*/
59 double start = cputime();
60 double now = cputime();
61 while (now + loop_length < start + exec_time) {
45 tmp += loop_once(); 62 tmp += loop_once();
46 t += loop_length; 63 t += loop_length;
64 now = cputime();
47 } 65 }
66
48 return tmp; 67 return tmp;
49} 68}
50 69
@@ -106,7 +125,7 @@ static int job(double exec_time)
106 return 0; 125 return 0;
107} 126}
108 127
109#define OPTSTR "p:c:wl" 128#define OPTSTR "p:c:wld:"
110 129
111int main(int argc, char** argv) 130int main(int argc, char** argv)
112{ 131{
@@ -118,6 +137,7 @@ int main(int argc, char** argv)
118 int opt; 137 int opt;
119 int wait = 0; 138 int wait = 0;
120 int test_loop = 0; 139 int test_loop = 0;
140 int skip_config = 0;
121 double duration, start; 141 double duration, start;
122 task_class_t class = RT_CLASS_HARD; 142 task_class_t class = RT_CLASS_HARD;
123 143
@@ -138,6 +158,10 @@ int main(int argc, char** argv)
138 case 'l': 158 case 'l':
139 test_loop = 1; 159 test_loop = 1;
140 break; 160 break;
161 case 'd':
162 loop_length = atof(optarg) / 1000000;
163 skip_config = 1;
164 break;
141 case ':': 165 case ':':
142 usage("Argument missing."); 166 usage("Argument missing.");
143 break; 167 break;
@@ -148,8 +172,9 @@ int main(int argc, char** argv)
148 } 172 }
149 } 173 }
150 174
151 175
152 configure_loop(); 176 if (!skip_config)
177 configure_loop();
153 178
154 if (test_loop) { 179 if (test_loop) {
155 debug_delay_loop(); 180 debug_delay_loop();