diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | include/internal.h | 6 | ||||
| -rw-r--r-- | include/litmus.h | 6 | ||||
| -rw-r--r-- | src/syscalls.c | 10 | ||||
| -rw-r--r-- | src/task.c | 43 |
5 files changed, 50 insertions, 19 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | KERNEL_DIR = ../litmus | 1 | KERNEL_DIR = ../q08 |
| 2 | 2 | ||
| 3 | INC=-Iinclude/ -I${KERNEL_DIR}/include/ | 3 | INC=-Iinclude/ -I${KERNEL_DIR}/include/ |
| 4 | 4 | ||
| @@ -43,7 +43,7 @@ rt_launch: liblitmus.a litmus.h rt_launch.o | |||
| 43 | stdump: liblitmus.a litmus.h sched_trace.h stdump.o | 43 | stdump: liblitmus.a litmus.h sched_trace.h stdump.o |
| 44 | cc -o stdump stdump.o ${LIBS} | 44 | cc -o stdump stdump.o ${LIBS} |
| 45 | 45 | ||
| 46 | liblitmus.a: ${LIB_OBJ} litmus.h | 46 | liblitmus.a: ${LIB_OBJ} litmus.h |
| 47 | ${AR} rcs liblitmus.a ${LIB_OBJ} | 47 | ${AR} rcs liblitmus.a ${LIB_OBJ} |
| 48 | 48 | ||
| 49 | check: | 49 | check: |
diff --git a/include/internal.h b/include/internal.h index 25e1573..761c434 100644 --- a/include/internal.h +++ b/include/internal.h | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | /* prepare a real-time task */ | 6 | /* prepare a real-time task */ |
| 7 | typedef int (*rt_setup_fn_t)(int pid, void* arg); | 7 | typedef int (*rt_setup_fn_t)(int pid, void* arg); |
| 8 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, | 8 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, |
| 9 | rt_setup_fn_t setup, void* setup_arg); | 9 | rt_setup_fn_t setup, void* setup_arg); |
| 10 | 10 | ||
| 11 | #define check(str) \ | 11 | #define check(str) \ |
| @@ -19,3 +19,7 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | #endif | 21 | #endif |
| 22 | |||
| 23 | |||
| 24 | int sched_setscheduler(pid_t pid, int policy, int* prioriy); | ||
| 25 | int sched_getscheduler(pid_t pid); | ||
diff --git a/include/litmus.h b/include/litmus.h index b10abff..6699213 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #ifndef LITMUS_H | 1 | #ifndef LITMUS_H |
| 2 | #define LITMUS_H | 2 | #define LITMUS_H |
| 3 | 3 | ||
| 4 | #include <linux/rt_param.h> | 4 | #include <litmus/rt_param.h> |
| 5 | #include <sys/types.h> | 5 | #include <sys/types.h> |
| 6 | 6 | ||
| 7 | typedef int pid_t; /* PID of a task */ | 7 | typedef int pid_t; /* PID of a task */ |
| @@ -14,7 +14,7 @@ int get_rt_task_param(pid_t pid, struct rt_task* param); | |||
| 14 | 14 | ||
| 15 | /* setup helper */ | 15 | /* setup helper */ |
| 16 | /* times are givin in ms */ | 16 | /* times are givin in ms */ |
| 17 | int sporadic_task(unsigned long exec_cost, unsigned long period, | 17 | int sporadic_task(unsigned long exec_cost, unsigned long period, |
| 18 | int partition, task_class_t cls); | 18 | int partition, task_class_t cls); |
| 19 | 19 | ||
| 20 | #define sporadic_global(e, p) \ | 20 | #define sporadic_global(e, p) \ |
| @@ -57,7 +57,7 @@ void exit_litmus(void); | |||
| 57 | typedef int (*rt_fn_t)(void*); | 57 | typedef int (*rt_fn_t)(void*); |
| 58 | 58 | ||
| 59 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period); | 59 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period); |
| 60 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, | 60 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, |
| 61 | int period, task_class_t cls); | 61 | int period, task_class_t cls); |
| 62 | 62 | ||
| 63 | /* per-task modes */ | 63 | /* per-task modes */ |
diff --git a/src/syscalls.c b/src/syscalls.c index 40f5f7f..1ad709b 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* To get syscall() we need to define _GNU_SOURCE | 1 | /* To get syscall() we need to define _GNU_SOURCE |
| 2 | * in modern glibc versions. | 2 | * in modern glibc versions. |
| 3 | */ | 3 | */ |
| 4 | #define _GNU_SOURCE | 4 | #define _GNU_SOURCE |
| @@ -87,8 +87,12 @@ int wait_for_job_release(unsigned int job_no) | |||
| 87 | return syscall(__NR_wait_for_job_release, job_no); | 87 | return syscall(__NR_wait_for_job_release, job_no); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | int task_mode(int target_mode) | 90 | int sched_setscheduler(pid_t pid, int policy, int* priority) |
| 91 | { | 91 | { |
| 92 | return syscall(__NR_task_mode, target_mode); | 92 | return syscall(__NR_sched_setscheduler, pid, policy, priority); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | int sched_getscheduler(pid_t pid) | ||
| 96 | { | ||
| 97 | return syscall(__NR_sched_getscheduler, pid); | ||
| 98 | } | ||
| @@ -1,30 +1,31 @@ | |||
| 1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <unistd.h> | 3 | #include <unistd.h> |
| 4 | #include <errno.h> | ||
| 4 | 5 | ||
| 5 | #include "litmus.h" | 6 | #include "litmus.h" |
| 6 | #include "internal.h" | 7 | #include "internal.h" |
| 7 | 8 | ||
| 8 | static void tperrorx(char* msg) | 9 | static void tperrorx(char* msg) |
| 9 | { | 10 | { |
| 10 | fprintf(stderr, | 11 | fprintf(stderr, |
| 11 | "Task %d: %s: %m", | 12 | "Task %d: %s: %m", |
| 12 | getpid(), msg); | 13 | gettid(), msg); |
| 13 | exit(-1); | 14 | exit(-1); |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | /* common launch routine */ | 17 | /* common launch routine */ |
| 17 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | 18 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, |
| 18 | void* setup_arg) | 19 | void* setup_arg) |
| 19 | { | 20 | { |
| 20 | int ret; | 21 | int ret; |
| 21 | int rt_task = fork(); | 22 | int rt_task = fork(); |
| 22 | 23 | ||
| 23 | if (rt_task == 0) { | 24 | if (rt_task == 0) { |
| 24 | /* we are the real-time task | 25 | /* we are the real-time task |
| 25 | * launch task and die when it is done | 26 | * launch task and die when it is done |
| 26 | */ | 27 | */ |
| 27 | rt_task = getpid(); | 28 | rt_task = gettid(); |
| 28 | ret = setup(rt_task, setup_arg); | 29 | ret = setup(rt_task, setup_arg); |
| 29 | if (ret < 0) | 30 | if (ret < 0) |
| 30 | tperrorx("could not setup task parameters"); | 31 | tperrorx("could not setup task parameters"); |
| @@ -38,14 +39,14 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | |||
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, | 41 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, |
| 41 | task_class_t class) | 42 | task_class_t class) |
| 42 | { | 43 | { |
| 43 | struct rt_task params; | 44 | struct rt_task params; |
| 44 | params.cpu = cpu; | 45 | params.cpu = cpu; |
| 45 | params.period = period; | 46 | params.period = period; |
| 46 | params.exec_cost = wcet; | 47 | params.exec_cost = wcet; |
| 47 | params.cls = class; | 48 | params.cls = class; |
| 48 | return __launch_rt_task(rt_prog, arg, | 49 | return __launch_rt_task(rt_prog, arg, |
| 49 | (rt_setup_fn_t) set_rt_task_param, ¶ms); | 50 | (rt_setup_fn_t) set_rt_task_param, ¶ms); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| @@ -53,3 +54,25 @@ int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) { | |||
| 53 | return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD); | 54 | return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD); |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 57 | |||
| 58 | #define SCHED_NORMAL 0 | ||
| 59 | #define SCHED_LITMUS 6 | ||
| 60 | |||
| 61 | int task_mode(int mode) | ||
| 62 | { | ||
| 63 | int prio = 0; | ||
| 64 | int me = gettid(); | ||
| 65 | int policy = sched_getscheduler(gettid()); | ||
| 66 | int old_mode = policy == SCHED_LITMUS ? LITMUS_RT_TASK : BACKGROUND_TASK; | ||
| 67 | |||
| 68 | if (old_mode == LITMUS_RT_TASK && mode == BACKGROUND_TASK) { | ||
| 69 | /* transition to normal task */ | ||
| 70 | return sched_setscheduler(me, SCHED_NORMAL, &prio); | ||
| 71 | } else if (old_mode == BACKGROUND_TASK && mode == LITMUS_RT_TASK) { | ||
| 72 | /* transition to RT task */ | ||
| 73 | return sched_setscheduler(me, SCHED_LITMUS, &prio); | ||
| 74 | } else { | ||
| 75 | errno = -EINVAL; | ||
| 76 | return -1; | ||
| 77 | } | ||
| 78 | } | ||
