diff options
-rw-r--r-- | include/litmus.h | 9 | ||||
-rw-r--r-- | src/litmus.c | 19 |
2 files changed, 24 insertions, 4 deletions
diff --git a/include/litmus.h b/include/litmus.h index a5d3e2e..7ee13dc 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -9,18 +9,21 @@ typedef int pid_t; /* PID of a task */ | |||
9 | /* obtain the PID of a thread */ | 9 | /* obtain the PID of a thread */ |
10 | pid_t gettid(void); | 10 | pid_t gettid(void); |
11 | 11 | ||
12 | /* migrate to partition */ | ||
13 | int be_migrate_to(int target_cpu); | ||
14 | |||
12 | int set_rt_task_param(pid_t pid, struct rt_task* param); | 15 | int set_rt_task_param(pid_t pid, struct rt_task* param); |
13 | int get_rt_task_param(pid_t pid, struct rt_task* param); | 16 | int get_rt_task_param(pid_t pid, struct rt_task* param); |
14 | 17 | ||
15 | /* setup helper */ | 18 | /* setup helper */ |
16 | /* times are givin in ms */ | 19 | /* times are givin in ms */ |
17 | int sporadic_task(lt_t e, lt_t p, lt_t phase, | 20 | int sporadic_task(lt_t e, lt_t p, lt_t phase, |
18 | int partition, task_class_t cls); | 21 | int partition, task_class_t cls, int set_cpu_set); |
19 | 22 | ||
20 | #define sporadic_global(e, p) \ | 23 | #define sporadic_global(e, p) \ |
21 | sporadic_task(e, p, 0, 0, RT_CLASS_SOFT) | 24 | sporadic_task(e, p, 0, 0, RT_CLASS_SOFT, 0) |
22 | #define sporadic_partitioned(e, p, cpu) \ | 25 | #define sporadic_partitioned(e, p, cpu) \ |
23 | sporadic_task(e, p, 0, cpu, RT_CLASS_SOFT) | 26 | sporadic_task(e, p, 0, cpu, RT_CLASS_SOFT, 1) |
24 | 27 | ||
25 | /* file descriptor attached shared objects support */ | 28 | /* file descriptor attached shared objects support */ |
26 | typedef enum { | 29 | typedef enum { |
diff --git a/src/litmus.c b/src/litmus.c index 4fe6572..8f03f4c 100644 --- a/src/litmus.c +++ b/src/litmus.c | |||
@@ -5,6 +5,8 @@ | |||
5 | #include <signal.h> | 5 | #include <signal.h> |
6 | #include <sys/mman.h> | 6 | #include <sys/mman.h> |
7 | 7 | ||
8 | #include <sched.h> /* for cpu sets */ | ||
9 | |||
8 | #include "litmus.h" | 10 | #include "litmus.h" |
9 | #include "internal.h" | 11 | #include "internal.h" |
10 | 12 | ||
@@ -29,15 +31,30 @@ task_class_t str2class(const char* str) | |||
29 | 31 | ||
30 | #define NS_PER_MS 1000000 | 32 | #define NS_PER_MS 1000000 |
31 | 33 | ||
34 | /* only for best-effort execution: migrate to target_cpu */ | ||
35 | int be_migrate_to(int target_cpu) | ||
36 | { | ||
37 | cpu_set_t cpu_set; | ||
38 | |||
39 | CPU_ZERO(&cpu_set); | ||
40 | CPU_SET(target_cpu, &cpu_set); | ||
41 | return sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set); | ||
42 | } | ||
43 | |||
32 | int sporadic_task(lt_t e, lt_t p, lt_t phase, | 44 | int sporadic_task(lt_t e, lt_t p, lt_t phase, |
33 | int cpu, task_class_t cls) | 45 | int cpu, task_class_t cls, int set_cpu_set) |
34 | { | 46 | { |
35 | struct rt_task param; | 47 | struct rt_task param; |
48 | int ret; | ||
36 | param.exec_cost = e * NS_PER_MS; | 49 | param.exec_cost = e * NS_PER_MS; |
37 | param.period = p * NS_PER_MS; | 50 | param.period = p * NS_PER_MS; |
38 | param.cpu = cpu; | 51 | param.cpu = cpu; |
39 | param.cls = cls; | 52 | param.cls = cls; |
40 | param.phase = phase; | 53 | param.phase = phase; |
54 | if (set_cpu_set) { | ||
55 | ret = be_migrate_to(cpu); | ||
56 | check("migrate to cpu"); | ||
57 | } | ||
41 | return set_rt_task_param(gettid(), ¶m); | 58 | return set_rt_task_param(gettid(), ¶m); |
42 | } | 59 | } |
43 | 60 | ||