diff options
| author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-07-17 17:22:36 -0400 |
|---|---|---|
| committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-07-17 17:22:52 -0400 |
| commit | bdd1bf3d4f17e820e309f02ab1bdb726952e6ca8 (patch) | |
| tree | 5f2aaf77f220c13710cdd9de16ecc141619af846 | |
| parent | 1f8c4dd0e5932367344638fb3fcd6ea26390fb7c (diff) | |
Revisions based on review comments.wip-arbit-deadline
| -rw-r--r-- | bin/base_mt_task.c | 29 | ||||
| -rw-r--r-- | bin/base_task.c | 32 | ||||
| -rw-r--r-- | bin/rtspin.c | 2 | ||||
| -rw-r--r-- | include/litmus.h | 27 | ||||
| -rw-r--r-- | src/litmus.c | 9 | ||||
| -rw-r--r-- | tests/core_api.c | 3 | ||||
| -rw-r--r-- | tests/fdso.c | 2 | ||||
| -rw-r--r-- | tests/locks.c | 4 |
8 files changed, 64 insertions, 44 deletions
diff --git a/bin/base_mt_task.c b/bin/base_mt_task.c index 802ef0b..78446e3 100644 --- a/bin/base_mt_task.c +++ b/bin/base_mt_task.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #include <stdio.h> | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
| 14 | #include <string.h> | ||
| 14 | 15 | ||
| 15 | /* Include gettid() */ | 16 | /* Include gettid() */ |
| 16 | #include <sys/types.h> | 17 | #include <sys/types.h> |
| @@ -21,9 +22,11 @@ | |||
| 21 | /* Include the LITMUS^RT API.*/ | 22 | /* Include the LITMUS^RT API.*/ |
| 22 | #include "litmus.h" | 23 | #include "litmus.h" |
| 23 | 24 | ||
| 24 | #define PERIOD 100 | 25 | #define PERIOD 100 |
| 25 | #define REL_DEADLINE 100 | 26 | #define RELATIVE_DEADLINE 100 |
| 26 | #define EXEC_COST 10 | 27 | #define EXEC_COST 10 |
| 28 | |||
| 29 | #define NS_PER_MS 1e6 | ||
| 27 | 30 | ||
| 28 | /* Let's create 10 threads in the example, | 31 | /* Let's create 10 threads in the example, |
| 29 | * for a total utilization of 1. | 32 | * for a total utilization of 1. |
| @@ -123,6 +126,15 @@ void* rt_thread(void *tcontext) | |||
| 123 | { | 126 | { |
| 124 | int do_exit; | 127 | int do_exit; |
| 125 | struct thread_context *ctx = (struct thread_context *) tcontext; | 128 | struct thread_context *ctx = (struct thread_context *) tcontext; |
| 129 | struct rt_task param; | ||
| 130 | |||
| 131 | /* Set up task parameters */ | ||
| 132 | memset(¶m, 0, sizeof(param)); | ||
| 133 | param.exec_cost = EXEC_COST * NS_PER_MS; | ||
| 134 | param.period = PERIOD * NS_PER_MS; | ||
| 135 | param.relative_deadline = RELATIVE_DEADLINE * NS_PER_MS; | ||
| 136 | param.cls = RT_CLASS_SOFT; | ||
| 137 | param.budget_policy = NO_ENFORCEMENT; | ||
| 126 | 138 | ||
| 127 | /* Make presence visible. */ | 139 | /* Make presence visible. */ |
| 128 | printf("RT Thread %d active.\n", ctx->id); | 140 | printf("RT Thread %d active.\n", ctx->id); |
| @@ -131,7 +143,16 @@ void* rt_thread(void *tcontext) | |||
| 131 | * 1) Initialize real-time settings. | 143 | * 1) Initialize real-time settings. |
| 132 | */ | 144 | */ |
| 133 | CALL( init_rt_thread() ); | 145 | CALL( init_rt_thread() ); |
| 134 | CALL( sporadic_global(EXEC_COST, PERIOD, REL_DEADLINE) ); | 146 | |
| 147 | /* To specify a partition, do | ||
| 148 | * | ||
| 149 | * param.cpu = CPU; | ||
| 150 | * be_migrate_to(CPU); | ||
| 151 | * | ||
| 152 | * where CPU ranges from 0 to "Number of CPUs" - 1 before calling | ||
| 153 | * set_rt_task_param(). | ||
| 154 | */ | ||
| 155 | CALL( set_rt_task_param(gettid(), ¶m) ); | ||
| 135 | 156 | ||
| 136 | /***** | 157 | /***** |
| 137 | * 2) Transition to real-time mode. | 158 | * 2) Transition to real-time mode. |
diff --git a/bin/base_task.c b/bin/base_task.c index b2408ac..8baf3c8 100644 --- a/bin/base_task.c +++ b/bin/base_task.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | */ | 12 | */ |
| 13 | #include <stdio.h> | 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
| 15 | #include <string.h> | ||
| 15 | 16 | ||
| 16 | /* Second, we include the LITMUS^RT user space library header. | 17 | /* Second, we include the LITMUS^RT user space library header. |
| 17 | * This header, part of liblitmus, provides the user space API of | 18 | * This header, part of liblitmus, provides the user space API of |
| @@ -22,10 +23,14 @@ | |||
| 22 | /* Next, we define period and execution cost to be constant. | 23 | /* Next, we define period and execution cost to be constant. |
| 23 | * These are only constants for convenience in this example, they can be | 24 | * These are only constants for convenience in this example, they can be |
| 24 | * determined at run time, e.g., from command line parameters. | 25 | * determined at run time, e.g., from command line parameters. |
| 26 | * | ||
| 27 | * These are in milliseconds. | ||
| 25 | */ | 28 | */ |
| 26 | #define PERIOD 100 | 29 | #define PERIOD 100 |
| 27 | #define REL_DEADLINE 100 | 30 | #define RELATIVE_DEADLINE 100 |
| 28 | #define EXEC_COST 10 | 31 | #define EXEC_COST 10 |
| 32 | |||
| 33 | #define NS_PER_MS 1e6 | ||
| 29 | 34 | ||
| 30 | /* Catch errors. | 35 | /* Catch errors. |
| 31 | */ | 36 | */ |
| @@ -61,6 +66,15 @@ int job(void); | |||
| 61 | int main(int argc, char** argv) | 66 | int main(int argc, char** argv) |
| 62 | { | 67 | { |
| 63 | int do_exit; | 68 | int do_exit; |
| 69 | struct rt_task param; | ||
| 70 | |||
| 71 | /* Setup task parameters */ | ||
| 72 | memset(¶m, 0, sizeof(param)); | ||
| 73 | param.exec_cost = EXEC_COST * NS_PER_MS; | ||
| 74 | param.period = PERIOD * NS_PER_MS; | ||
| 75 | param.relative_deadline = RELATIVE_DEADLINE * NS_PER_MS; | ||
| 76 | param.cls = RT_CLASS_SOFT; | ||
| 77 | param.budget_policy = NO_ENFORCEMENT; | ||
| 64 | 78 | ||
| 65 | /* The task is in background mode upon startup. */ | 79 | /* The task is in background mode upon startup. */ |
| 66 | 80 | ||
| @@ -86,16 +100,16 @@ int main(int argc, char** argv) | |||
| 86 | * to the first partition (since partitioning is performed offline). | 100 | * to the first partition (since partitioning is performed offline). |
| 87 | */ | 101 | */ |
| 88 | CALL( init_litmus() ); | 102 | CALL( init_litmus() ); |
| 89 | CALL( sporadic_global(EXEC_COST, PERIOD, REL_DEADLINE) ); | ||
| 90 | 103 | ||
| 91 | /* To specify a partition, use sporadic_partitioned(). | 104 | /* To specify a partition, do |
| 92 | * Example: | ||
| 93 | * | 105 | * |
| 94 | * sporadic_partitioned(EXEC_COST, PERIOD, CPU); | 106 | * param.cpu = CPU; |
| 107 | * be_migrate_to(CPU); | ||
| 95 | * | 108 | * |
| 96 | * where CPU ranges from 0 to "Number of CPUs" - 1. | 109 | * where CPU ranges from 0 to "Number of CPUs" - 1 before calling |
| 110 | * set_rt_task_param(). | ||
| 97 | */ | 111 | */ |
| 98 | 112 | CALL( set_rt_task_param(gettid(), ¶m) ); | |
| 99 | 113 | ||
| 100 | 114 | ||
| 101 | /***** | 115 | /***** |
diff --git a/bin/rtspin.c b/bin/rtspin.c index 48b8379..ae76941 100644 --- a/bin/rtspin.c +++ b/bin/rtspin.c | |||
| @@ -274,7 +274,7 @@ int main(int argc, char** argv) | |||
| 274 | bail_out("could not migrate to target partition"); | 274 | bail_out("could not migrate to target partition"); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | ret = sporadic_task_ns(wcet, period, 0, 0, cpu, class, | 277 | ret = sporadic_task_ns(wcet, period, 0, cpu, class, |
| 278 | want_enforcement ? PRECISE_ENFORCEMENT | 278 | want_enforcement ? PRECISE_ENFORCEMENT |
| 279 | : NO_ENFORCEMENT, | 279 | : NO_ENFORCEMENT, |
| 280 | migrate); | 280 | migrate); |
diff --git a/include/litmus.h b/include/litmus.h index 2c33f0c..4c85d28 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
| @@ -31,36 +31,21 @@ int get_rt_task_param(pid_t pid, struct rt_task* param); | |||
| 31 | 31 | ||
| 32 | /* times are given in ms */ | 32 | /* times are given in ms */ |
| 33 | int sporadic_task( | 33 | int sporadic_task( |
| 34 | lt_t e, lt_t p, lt_t d, lt_t phase, | 34 | lt_t e, lt_t p, lt_t phase, |
| 35 | int partition, task_class_t cls, | 35 | int partition, task_class_t cls, |
| 36 | budget_policy_t budget_policy, int set_cpu_set); | 36 | budget_policy_t budget_policy, int set_cpu_set); |
| 37 | 37 | ||
| 38 | /* times are given in ns */ | 38 | /* times are given in ns */ |
| 39 | int sporadic_task_ns( | 39 | int sporadic_task_ns( |
| 40 | lt_t e, lt_t p, lt_t d, lt_t phase, | 40 | lt_t e, lt_t p, lt_t phase, |
| 41 | int cpu, task_class_t cls, | 41 | int cpu, task_class_t cls, |
| 42 | budget_policy_t budget_policy, int set_cpu_set); | 42 | budget_policy_t budget_policy, int set_cpu_set); |
| 43 | 43 | ||
| 44 | /* implicit deadline macros */ | ||
| 45 | #define sporadic_implicit_task(e, p, phase, \ | ||
| 46 | partition, cls, \ | ||
| 47 | budget_policy, set_cpu_set) \ | ||
| 48 | sporadic_task(e, p, 0, phase, partition, cls, budget_policy, set_cpu_set) | ||
| 49 | #define sporadic_implicit_task_ns(e, p, phase, \ | ||
| 50 | partition, cls, \ | ||
| 51 | budget_policy, set_cpu_set) \ | ||
| 52 | sporadic_task_ns(e, p, 0, phase, partition, cls, budget_policy, set_cpu_set) | ||
| 53 | |||
| 54 | |||
| 55 | /* budget enforcement off by default in these macros */ | 44 | /* budget enforcement off by default in these macros */ |
| 56 | #define sporadic_global(e, p, d) \ | 45 | #define sporadic_global(e, p) \ |
| 57 | sporadic_task(e, p, d, 0, 0, RT_CLASS_SOFT, NO_ENFORCEMENT, 0) | 46 | sporadic_task(e, p, 0, 0, RT_CLASS_SOFT, NO_ENFORCEMENT, 0) |
| 58 | #define sporadic_partitioned(e, p, d, cpu) \ | 47 | #define sporadic_partitioned(e, p, cpu) \ |
| 59 | sporadic_task(e, p, d, 0, cpu, RT_CLASS_SOFT, NO_ENFORCEMENT, 1) | 48 | sporadic_task(e, p, 0, cpu, RT_CLASS_SOFT, NO_ENFORCEMENT, 1) |
| 60 | #define sporadic_implicit_global(e, p) \ | ||
| 61 | sporadic_implicit_task(e, p, 0, 0, RT_CLASS_SOFT, NO_ENFORCEMENT, 0) | ||
| 62 | #define sporadic_implicit_partitioned(e, p, cpu) \ | ||
| 63 | sporadic_implicit_task(e, p, 0, cpu, RT_CLASS_SOFT, NO_ENFORCEMENT, 1) | ||
| 64 | 49 | ||
| 65 | /* file descriptor attached shared objects support */ | 50 | /* file descriptor attached shared objects support */ |
| 66 | typedef enum { | 51 | typedef enum { |
diff --git a/src/litmus.c b/src/litmus.c index 907317a..d78a9eb 100644 --- a/src/litmus.c +++ b/src/litmus.c | |||
| @@ -41,16 +41,15 @@ int be_migrate_to(int target_cpu) | |||
| 41 | return sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set); | 41 | return sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | int sporadic_task(lt_t e, lt_t p, lt_t d, lt_t phase, | 44 | int sporadic_task(lt_t e, lt_t p, lt_t phase, |
| 45 | int cpu, task_class_t cls, | 45 | int cpu, task_class_t cls, |
| 46 | budget_policy_t budget_policy, int set_cpu_set) | 46 | budget_policy_t budget_policy, int set_cpu_set) |
| 47 | { | 47 | { |
| 48 | return sporadic_task_ns(e * NS_PER_MS, p * NS_PER_MS, | 48 | return sporadic_task_ns(e * NS_PER_MS, p * NS_PER_MS, phase * NS_PER_MS, |
| 49 | d * NS_PER_MS, phase * NS_PER_MS, | ||
| 50 | cpu, cls, budget_policy, set_cpu_set); | 49 | cpu, cls, budget_policy, set_cpu_set); |
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | int sporadic_task_ns(lt_t e, lt_t p, lt_t d, lt_t phase, | 52 | int sporadic_task_ns(lt_t e, lt_t p, lt_t phase, |
| 54 | int cpu, task_class_t cls, | 53 | int cpu, task_class_t cls, |
| 55 | budget_policy_t budget_policy, int set_cpu_set) | 54 | budget_policy_t budget_policy, int set_cpu_set) |
| 56 | { | 55 | { |
| @@ -64,7 +63,7 @@ int sporadic_task_ns(lt_t e, lt_t p, lt_t d, lt_t phase, | |||
| 64 | 63 | ||
| 65 | param.exec_cost = e; | 64 | param.exec_cost = e; |
| 66 | param.period = p; | 65 | param.period = p; |
| 67 | param.rdeadline = (d == 0) ? p : d; /* implicit deadline if d == 0 */ | 66 | param.relative_deadline = p; /* implicit deadline */ |
| 68 | param.cpu = cpu; | 67 | param.cpu = cpu; |
| 69 | param.cls = cls; | 68 | param.cls = cls; |
| 70 | param.phase = phase; | 69 | param.phase = phase; |
diff --git a/tests/core_api.c b/tests/core_api.c index 61463fc..425bb99 100644 --- a/tests/core_api.c +++ b/tests/core_api.c | |||
| @@ -20,6 +20,7 @@ TESTCASE(set_rt_task_param_invalid_params, ALL, | |||
| 20 | struct rt_task params; | 20 | struct rt_task params; |
| 21 | params.cpu = 0; | 21 | params.cpu = 0; |
| 22 | params.period = 100; | 22 | params.period = 100; |
| 23 | params.relative_deadline = params.period; | ||
| 23 | params.phase = 0; | 24 | params.phase = 0; |
| 24 | params.cls = RT_CLASS_HARD; | 25 | params.cls = RT_CLASS_HARD; |
| 25 | params.budget_policy = NO_ENFORCEMENT; | 26 | params.budget_policy = NO_ENFORCEMENT; |
| @@ -61,7 +62,7 @@ TESTCASE(rt_fork_non_rt, LITMUS, | |||
| 61 | unsigned int pid, job_no; | 62 | unsigned int pid, job_no; |
| 62 | int status; | 63 | int status; |
| 63 | 64 | ||
| 64 | SYSCALL( sporadic_implicit_partitioned(10, 100, 0) ); | 65 | SYSCALL( sporadic_partitioned(10, 100, 0) ); |
| 65 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | 66 | SYSCALL( task_mode(LITMUS_RT_TASK) ); |
| 66 | 67 | ||
| 67 | pid = fork(); | 68 | pid = fork(); |
diff --git a/tests/fdso.c b/tests/fdso.c index 15c643f..8a2a0d0 100644 --- a/tests/fdso.c +++ b/tests/fdso.c | |||
| @@ -66,7 +66,7 @@ TESTCASE(not_inherit_od, GSN_EDF | PSN_EDF, | |||
| 66 | ASSERT( pid != -1 ); | 66 | ASSERT( pid != -1 ); |
| 67 | 67 | ||
| 68 | /* must be an RT task to lock at all */ | 68 | /* must be an RT task to lock at all */ |
| 69 | SYSCALL( sporadic_implicit_partitioned(10, 100, 0) ); | 69 | SYSCALL( sporadic_partitioned(10, 100, 0) ); |
| 70 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | 70 | SYSCALL( task_mode(LITMUS_RT_TASK) ); |
| 71 | 71 | ||
| 72 | if (pid == 0) { | 72 | if (pid == 0) { |
diff --git a/tests/locks.c b/tests/locks.c index 4d9934f..65b932a 100644 --- a/tests/locks.c +++ b/tests/locks.c | |||
| @@ -53,7 +53,7 @@ TESTCASE(lock_srp, PSN_EDF, | |||
| 53 | 53 | ||
| 54 | SYSCALL( fd = open(".srp_locks", O_RDONLY | O_CREAT) ); | 54 | SYSCALL( fd = open(".srp_locks", O_RDONLY | O_CREAT) ); |
| 55 | 55 | ||
| 56 | SYSCALL( sporadic_implicit_partitioned(10, 100, 0) ); | 56 | SYSCALL( sporadic_partitioned(10, 100, 0) ); |
| 57 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | 57 | SYSCALL( task_mode(LITMUS_RT_TASK) ); |
| 58 | 58 | ||
| 59 | SYSCALL( od = open_srp_sem(fd, 0) ); | 59 | SYSCALL( od = open_srp_sem(fd, 0) ); |
| @@ -85,7 +85,7 @@ TESTCASE(lock_fmlp, PSN_EDF | GSN_EDF, | |||
| 85 | 85 | ||
| 86 | SYSCALL( fd = open(".fmlp_locks", O_RDONLY | O_CREAT) ); | 86 | SYSCALL( fd = open(".fmlp_locks", O_RDONLY | O_CREAT) ); |
| 87 | 87 | ||
| 88 | SYSCALL( sporadic_implicit_partitioned(10, 100, 0) ); | 88 | SYSCALL( sporadic_partitioned(10, 100, 0) ); |
| 89 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | 89 | SYSCALL( task_mode(LITMUS_RT_TASK) ); |
| 90 | 90 | ||
| 91 | SYSCALL( od = open_fmlp_sem(fd, 0) ); | 91 | SYSCALL( od = open_fmlp_sem(fd, 0) ); |
