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 | |
| parent | 606b0374383e93338cf057ac87d08c6173786e3d (diff) | |
DGL testing.wip-nested-locking
| -rw-r--r-- | bin/dgl_test.c | 157 | ||||
| -rw-r--r-- | bin/dglspin.c | 56 | ||||
| -rw-r--r-- | src/syscalls.c | 1 |
3 files changed, 45 insertions, 169 deletions
diff --git a/bin/dgl_test.c b/bin/dgl_test.c deleted file mode 100644 index 22a13ae..0000000 --- a/bin/dgl_test.c +++ /dev/null | |||
| @@ -1,157 +0,0 @@ | |||
| 1 | /* based_task.c -- A basic real-time task skeleton. | ||
| 2 | * | ||
| 3 | * This (by itself useless) task demos how to setup a | ||
| 4 | * single-threaded LITMUS^RT real-time task. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* First, we include standard headers. | ||
| 8 | * Generally speaking, a LITMUS^RT real-time task can perform any | ||
| 9 | * system call, etc., but no real-time guarantees can be made if a | ||
| 10 | * system call blocks. To be on the safe side, only use I/O for debugging | ||
| 11 | * purposes and from non-real-time sections. | ||
| 12 | */ | ||
| 13 | #include <stdio.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <fcntl.h> | ||
| 16 | |||
| 17 | /* Second, we include the LITMUS^RT user space library header. | ||
| 18 | * This header, part of liblitmus, provides the user space API of | ||
| 19 | * LITMUS^RT. | ||
| 20 | */ | ||
| 21 | #include "litmus.h" | ||
| 22 | |||
| 23 | /* Next, we define period and execution cost to be constant. | ||
| 24 | * These are only constants for convenience in this example, they can be | ||
| 25 | * determined at run time, e.g., from command line parameters. | ||
| 26 | */ | ||
| 27 | #define PERIOD 100 | ||
| 28 | #define EXEC_COST 10 | ||
| 29 | |||
| 30 | /* Catch errors. | ||
| 31 | */ | ||
| 32 | #define CALL( exp ) do { \ | ||
| 33 | int ret; \ | ||
| 34 | ret = exp; \ | ||
| 35 | if (ret != 0) \ | ||
| 36 | fprintf(stderr, "%s failed: %m\n", #exp);\ | ||
| 37 | else \ | ||
| 38 | fprintf(stderr, "%s ok.\n", #exp); \ | ||
| 39 | } while (0) | ||
| 40 | |||
| 41 | |||
| 42 | /* Declare the periodically invoked job. | ||
| 43 | * Returns 1 -> task should exit. | ||
| 44 | * 0 -> task should continue. | ||
| 45 | */ | ||
| 46 | int job(void); | ||
| 47 | |||
| 48 | /* typically, main() does a couple of things: | ||
| 49 | * 1) parse command line parameters, etc. | ||
| 50 | * 2) Setup work environment. | ||
| 51 | * 3) Setup real-time parameters. | ||
| 52 | * 4) Transition to real-time mode. | ||
| 53 | * 5) Invoke periodic or sporadic jobs. | ||
| 54 | * 6) Transition to background mode. | ||
| 55 | * 7) Clean up and exit. | ||
| 56 | * | ||
| 57 | * The following main() function provides the basic skeleton of a single-threaded | ||
| 58 | * LITMUS^RT real-time task. In a real program, all the return values should be | ||
| 59 | * checked for errors. | ||
| 60 | */ | ||
| 61 | int main(int argc, char** argv) | ||
| 62 | { | ||
| 63 | //int do_exit; | ||
| 64 | int fd, od_org, od_new; | ||
| 65 | int* resource; | ||
| 66 | int mask; | ||
| 67 | |||
| 68 | /* The task is in background mode upon startup. */ | ||
| 69 | |||
| 70 | |||
| 71 | /***** | ||
| 72 | * 1) Command line paramter parsing would be done here. | ||
| 73 | */ | ||
| 74 | |||
| 75 | /***** | ||
| 76 | * 2) Work environment (e.g., global data structures, file data, etc.) would | ||
| 77 | * be setup here. | ||
| 78 | */ | ||
| 79 | |||
| 80 | CALL(fd = open(".dgl_locks", O_RDONLY | O_CREAT) ); | ||
| 81 | resource = (int*)malloc(sizeof(int)); | ||
| 82 | *resource = -1; | ||
| 83 | |||
| 84 | /***** | ||
| 85 | * 3) Setup real-time parameters. | ||
| 86 | * In this example, we create a sporadic task that does not specify a | ||
| 87 | * target partition (and thus is intended to run under global scheduling). | ||
| 88 | * If this were to execute under a partitioned scheduler, it would be assigned | ||
| 89 | * to the first partition (since partitioning is performed offline). | ||
| 90 | */ | ||
| 91 | |||
| 92 | CALL( init_litmus() ); | ||
| 93 | //CALL( sporadic_global(EXEC_COST, PERIOD) ); | ||
| 94 | CALL( sporadic_partitioned(EXEC_COST, PERIOD, 0) ); | ||
| 95 | |||
| 96 | /* To specify a partition, use sporadic_partitioned(). | ||
| 97 | * Example: | ||
| 98 | * | ||
| 99 | * sporadic_partitioned(EXEC_COST, PERIOD, CPU); | ||
| 100 | * | ||
| 101 | * where CPU ranges from 0 to "Number of CPUs" - 1. | ||
| 102 | */ | ||
| 103 | |||
| 104 | /***** | ||
| 105 | * 4) Transition to real-time mode. | ||
| 106 | */ | ||
| 107 | CALL( task_mode(LITMUS_RT_TASK) ); | ||
| 108 | |||
| 109 | /* The task is now executing as a real-time task if the call didn't fail. | ||
| 110 | */ | ||
| 111 | |||
| 112 | CALL(od_org = open_new_dgl_sem(fd, 0) ); | ||
| 113 | CALL(od_new = attach_dgl_sem(fd, 1, od_org) ); | ||
| 114 | |||
| 115 | mask = (1<<od_org) & (1<<od_new); | ||
| 116 | |||
| 117 | |||
| 118 | //CALL( dynamic_group_lock(0) ); | ||
| 119 | dynamic_group_lock(mask); | ||
| 120 | |||
| 121 | /***** | ||
| 122 | * 5) Invoke real-time jobs. | ||
| 123 | */ | ||
| 124 | //do { | ||
| 125 | // /* Wait until the next job is released. */ | ||
| 126 | // sleep_next_period(); | ||
| 127 | // /* Invoke job. */ | ||
| 128 | // do_exit = job(); | ||
| 129 | //} while (!do_exit); | ||
| 130 | |||
| 131 | //do_exit=0; | ||
| 132 | //do_exit++; | ||
| 133 | //od++; | ||
| 134 | |||
| 135 | |||
| 136 | /***** | ||
| 137 | * 6) Transition to background mode. | ||
| 138 | */ | ||
| 139 | //CALL( task_mode(BACKGROUND_TASK) ); | ||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | /***** | ||
| 144 | * 7) Clean up, maybe print results and stats, and exit. | ||
| 145 | */ | ||
| 146 | return 0; | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | //int job(void) | ||
| 151 | //{ | ||
| 152 | // /* Do real-time calculation. */ | ||
| 153 | // | ||
| 154 | // | ||
| 155 | // /* Don't exit. */ | ||
| 156 | // return 0; | ||
| 157 | //} | ||
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 | ||
diff --git a/src/syscalls.c b/src/syscalls.c index 2c38a04..c9f4d2b 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
| @@ -55,7 +55,6 @@ int litmus_unlock(int od) | |||
| 55 | 55 | ||
| 56 | int dynamic_group_lock(int mask) | 56 | int dynamic_group_lock(int mask) |
| 57 | { | 57 | { |
| 58 | printf("Calling dynamic group lock!!!"); | ||
| 59 | return syscall(__NR_dynamic_group_lock, mask); | 58 | return syscall(__NR_dynamic_group_lock, mask); |
| 60 | } | 59 | } |
| 61 | 60 | ||
