diff options
| -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 | |||
