1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "litmus.h"
#include "internal.h"
static void tperrorx(char* msg)
{
fprintf(stderr,
"Task %d: %s: %m",
getpid(), msg);
exit(-1);
}
/* common launch routine */
int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup,
void* setup_arg)
{
int ret;
int rt_task = fork();
if (rt_task == 0) {
/* we are the real-time task
* launch task and die when it is done
*/
rt_task = getpid();
ret = setup(rt_task, setup_arg);
if (ret < 0)
tperrorx("could not setup task parameters");
ret = task_mode(LITMUS_RT_TASK);
if (ret < 0)
tperrorx("could not become real-time task");
exit(rt_prog(rt_arg));
}
return rt_task;
}
struct create_rt_param {
int cpu;
int wcet;
int period;
task_class_t class;
};
int setup_create_rt(int pid, struct create_rt_param* arg)
{
rt_param_t params;
params.period = arg->period;
params.exec_cost = arg->wcet;
params.cpu = arg->cpu;
params.cls = arg->class;
return set_rt_task_param(pid, ¶ms);
}
int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period,
task_class_t class)
{
struct create_rt_param params;
params.cpu = cpu;
params.period = period;
params.wcet = wcet;
params.class = class;
return __launch_rt_task(rt_prog, arg,
(rt_setup_fn_t) setup_create_rt, ¶ms);
}
int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) {
return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD);
}
|