diff options
author | Bryan Ward <bcw@cs.unc.edu> | 2013-04-18 16:34:51 -0400 |
---|---|---|
committer | root <root@ubuntu-qemu.(none)> | 2013-04-18 16:34:51 -0400 |
commit | c5e6af664ca88d08fa0fb2cfc910b125d4c47b73 (patch) | |
tree | 1f2cf49b88bf1c330d7db1018f569193a9b25989 /bin/dglspin.c | |
parent | 606b0374383e93338cf057ac87d08c6173786e3d (diff) |
DGL testing.wip-nested-locking
Diffstat (limited to 'bin/dglspin.c')
-rw-r--r-- | bin/dglspin.c | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/bin/dglspin.c b/bin/dglspin.c index 805fd85..5999662 100644 --- a/bin/dglspin.c +++ b/bin/dglspin.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <time.h> | 6 | #include <time.h> |
7 | #include <assert.h> | 7 | #include <assert.h> |
8 | #include <fcntl.h> | 8 | #include <fcntl.h> |
9 | #include <strings.h> | ||
9 | 10 | ||
10 | 11 | ||
11 | #include "litmus.h" | 12 | #include "litmus.h" |
@@ -110,16 +111,31 @@ static int loop_once(void) | |||
110 | static int loop_for(double exec_time, double emergency_exit, int mask) | 111 | static int loop_for(double exec_time, double emergency_exit, int mask) |
111 | { | 112 | { |
112 | double last_loop = 0, loop_start; | 113 | double last_loop = 0, loop_start; |
113 | int tmp = 0; | 114 | int tmp = 0, locks = 1, locked=0, phase=0; |
114 | 115 | ||
115 | double start = cputime(); | 116 | double start = cputime(); |
116 | double now = cputime(); | 117 | double now = cputime(); |
117 | 118 | ||
118 | while (now + last_loop < start + exec_time) { | 119 | while (now + last_loop < start + exec_time) { |
119 | loop_start = now; | 120 | |
120 | dynamic_group_lock(mask); | 121 | loop_start = now; |
121 | tmp += loop_once(); | 122 | |
122 | dynamic_group_unlock(mask); | 123 | if(now + last_loop > start + phase * (exec_time / (2*locks))){ |
124 | if(locked){ | ||
125 | locked = 0; | ||
126 | printf("unlock\n"); | ||
127 | dynamic_group_unlock(mask); | ||
128 | } | ||
129 | else{ | ||
130 | dynamic_group_lock(mask); | ||
131 | printf("lock\n"); | ||
132 | locked = 1; | ||
133 | } | ||
134 | phase += 1; | ||
135 | } | ||
136 | |||
137 | tmp += loop_once(); | ||
138 | |||
123 | now = cputime(); | 139 | now = cputime(); |
124 | last_loop = now - loop_start; | 140 | last_loop = now - loop_start; |
125 | if (emergency_exit && wctime() > emergency_exit) { | 141 | if (emergency_exit && wctime() > emergency_exit) { |
@@ -131,6 +147,10 @@ static int loop_for(double exec_time, double emergency_exit, int mask) | |||
131 | } | 147 | } |
132 | } | 148 | } |
133 | 149 | ||
150 | if(locked){ | ||
151 | dynamic_group_unlock(mask); | ||
152 | } | ||
153 | |||
134 | return tmp; | 154 | return tmp; |
135 | } | 155 | } |
136 | 156 | ||
@@ -164,7 +184,8 @@ static int job(double exec_time, double program_end, int mask) | |||
164 | } | 184 | } |
165 | } | 185 | } |
166 | 186 | ||
167 | #define OPTSTR "p:c:wlveo:f:s:q:" | 187 | #define OPTSTR "p:c:wlveo:f:s:q:r:" |
188 | #define MAX_RESOURCES 10 | ||
168 | 189 | ||
169 | int main(int argc, char** argv) | 190 | int main(int argc, char** argv) |
170 | { | 191 | { |
@@ -187,7 +208,10 @@ int main(int argc, char** argv) | |||
187 | task_class_t class = RT_CLASS_HARD; | 208 | task_class_t class = RT_CLASS_HARD; |
188 | int cur_job, num_jobs; | 209 | int cur_job, num_jobs; |
189 | 210 | ||
190 | int fd, od_org, od_new, mask; | 211 | int fd, i; |
212 | int mask = 0; | ||
213 | char* resources; | ||
214 | int ods[MAX_RESOURCES]; | ||
191 | 215 | ||
192 | progname = argv[0]; | 216 | progname = argv[0]; |
193 | 217 | ||
@@ -225,6 +249,9 @@ int main(int argc, char** argv) | |||
225 | case 's': | 249 | case 's': |
226 | scale = atof(optarg); | 250 | scale = atof(optarg); |
227 | break; | 251 | break; |
252 | case 'r': | ||
253 | resources = optarg; | ||
254 | break; | ||
228 | case ':': | 255 | case ':': |
229 | usage("Argument missing."); | 256 | usage("Argument missing."); |
230 | break; | 257 | break; |
@@ -306,9 +333,16 @@ int main(int argc, char** argv) | |||
306 | bail_out("wait_for_ts_release()"); | 333 | bail_out("wait_for_ts_release()"); |
307 | } | 334 | } |
308 | 335 | ||
309 | od_org = open_new_dgl_sem(fd, 0); | 336 | for(i = 0; i < MAX_RESOURCES; i++){ |
310 | od_new = attach_dgl_sem(fd, 1, od_org); | 337 | if(i==0) |
311 | mask = (1<<od_org) & (1<<od_new); | 338 | ods[i] = open_new_dgl_sem(fd, i); |
339 | else | ||
340 | ods[i] = attach_dgl_sem(fd, i, ods[0]); | ||
341 | |||
342 | if(resources[i]=='1'){ | ||
343 | mask |= (1 << ods[i]); | ||
344 | } | ||
345 | } | ||
312 | 346 | ||
313 | start = wctime(); | 347 | start = wctime(); |
314 | 348 | ||
@@ -320,7 +354,7 @@ int main(int argc, char** argv) | |||
320 | start + duration, mask); | 354 | start + duration, mask); |
321 | } | 355 | } |
322 | } else { | 356 | } else { |
323 | /* conver to seconds and scale */ | 357 | /* convert to seconds and scale */ |
324 | while (job(wcet_ms * 0.001 * scale, start + duration, mask)); | 358 | while (job(wcet_ms * 0.001 * scale, start + duration, mask)); |
325 | } | 359 | } |
326 | 360 | ||