diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-22 17:24:40 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-22 17:24:40 -0500 |
commit | 42967d0d27f71711823567e3969574535c903dba (patch) | |
tree | 5b521ce75a0cad18317eeb056146689478b64afb /src | |
parent | e0a05caf790c5493b83ff6a060175a24b3317258 (diff) |
core: change real-time task creation to new transitioning method
The old clone based hack will be removed soon.
Diffstat (limited to 'src')
-rw-r--r-- | src/litmus.c | 84 |
1 files changed, 18 insertions, 66 deletions
diff --git a/src/litmus.c b/src/litmus.c index 89d0f86..426e9e2 100644 --- a/src/litmus.c +++ b/src/litmus.c | |||
@@ -49,44 +49,6 @@ type name(type1 arg1,type2 arg2, type3 arg3, type4 arg4) \ | |||
49 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ | 49 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ |
50 | } | 50 | } |
51 | 51 | ||
52 | |||
53 | /* clear the TID in the child */ | ||
54 | #define CLONE_CHILD_CLEARTID 0x00200000 | ||
55 | /* set the TID in the child */ | ||
56 | #define CLONE_CHILD_SETTID 0x01000000 | ||
57 | /* don't let the child run before we have completed setup */ | ||
58 | #define CLONE_STOPPED 0x02000000 | ||
59 | /* litmus clone flag */ | ||
60 | #define CLONE_REALTIME 0x10000000 | ||
61 | |||
62 | /* CLONE_REALTIME is necessary because CLONE_STOPPED will put a SIGSTOP in | ||
63 | * the pending signal queue. Thus the first thing a newly created task will | ||
64 | * do after it is released is to stop, which is not what we want | ||
65 | * | ||
66 | * CLONE_REALTIME just sets the status to TASK_STOPPED without queueing a | ||
67 | * signal. | ||
68 | */ | ||
69 | |||
70 | |||
71 | /* this is essentially a fork with CLONE_STOPPED */ | ||
72 | /* #define CLONE_LITMUS CLONE_STOPPED | CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID */ | ||
73 | #define CLONE_LITMUS CLONE_REALTIME | CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID | ||
74 | |||
75 | /* we need to override libc because it wants to be clever | ||
76 | * and rejects our call without presenting it even to the kernel | ||
77 | */ | ||
78 | #define __NR_raw_clone 120 | ||
79 | |||
80 | |||
81 | _syscall2(int, raw_clone, unsigned long, flags, unsigned long, child_stack) | ||
82 | |||
83 | int fork_rt(void) | ||
84 | { | ||
85 | int rt_task = raw_clone(CLONE_LITMUS, 0); | ||
86 | return rt_task; | ||
87 | } | ||
88 | |||
89 | |||
90 | const char* get_scheduler_name(spolicy scheduler) | 52 | const char* get_scheduler_name(spolicy scheduler) |
91 | { | 53 | { |
92 | const char* name; | 54 | const char* name; |
@@ -123,46 +85,36 @@ const char* get_scheduler_name(spolicy scheduler) | |||
123 | return name; | 85 | return name; |
124 | } | 86 | } |
125 | 87 | ||
88 | static void tperrorx(char* msg) | ||
89 | { | ||
90 | fprintf(stderr, | ||
91 | "Task %d: %s: %m", | ||
92 | getpid(), msg); | ||
93 | exit(-1); | ||
94 | } | ||
126 | 95 | ||
127 | /* common launch routine */ | 96 | /* common launch routine */ |
128 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | 97 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, |
129 | void* setup_arg) | 98 | void* setup_arg) |
130 | { | 99 | { |
131 | int ret; | 100 | int ret; |
132 | int rt_task = fork_rt(); | 101 | int rt_task = fork(); |
133 | |||
134 | if (rt_task < 0) | ||
135 | return rt_task; | ||
136 | 102 | ||
137 | if (rt_task > 0) { | 103 | if (rt_task == 0) { |
138 | /* we are the controller task */ | ||
139 | ret = setup(rt_task, setup_arg); | ||
140 | if (ret < 0) { | ||
141 | /* we have a problem: we created the task but | ||
142 | * for some stupid reason we cannot set the real-time | ||
143 | * parameters. We must clean up the stopped task. | ||
144 | */ | ||
145 | kill(rt_task, SIGKILL); | ||
146 | /* syscall will have set errno, we don't have to do | ||
147 | * anything | ||
148 | */ | ||
149 | return -1; | ||
150 | } | ||
151 | ret = prepare_rt_task(rt_task); | ||
152 | if (ret < 0) { | ||
153 | /* same problem as above*/ | ||
154 | kill(rt_task, SIGKILL); | ||
155 | rt_task = -1; | ||
156 | } | ||
157 | return rt_task; | ||
158 | } | ||
159 | else { | ||
160 | /* we are the real-time task | 104 | /* we are the real-time task |
161 | * launch task and die when it is done | 105 | * launch task and die when it is done |
162 | */ | 106 | */ |
163 | 107 | rt_task = getpid(); | |
108 | ret = setup(rt_task, setup_arg); | ||
109 | if (ret < 0) | ||
110 | tperrorx("could not setup task parameters"); | ||
111 | ret = task_mode(LITMUS_RT_TASK); | ||
112 | if (ret < 0) | ||
113 | tperrorx("could not become real-time task"); | ||
164 | exit(rt_prog(rt_arg)); | 114 | exit(rt_prog(rt_arg)); |
165 | } | 115 | } |
116 | |||
117 | return rt_task; | ||
166 | } | 118 | } |
167 | 119 | ||
168 | struct create_rt_param { | 120 | struct create_rt_param { |