Rev 673 | Rev 676 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * Mauro Marinoni |
||
11 | * Anton Cervin |
||
12 | * |
||
13 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
14 | * |
||
15 | * http://www.sssup.it |
||
16 | * http://retis.sssup.it |
||
17 | * http://shark.sssup.it |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
37 | #include <kernel/model.h> |
||
38 | #include <kernel/descr.h> |
||
39 | #include <kernel/var.h> |
||
40 | #include <kernel/func.h> |
||
41 | |||
42 | #include <stdlib.h> |
||
43 | |||
44 | #include <modules/elastic.h> |
||
45 | |||
46 | #include <tracer.h> |
||
47 | |||
673 | giacomo | 48 | #define ELASTIC_EMPTY_SLOT 0 |
49 | #define ELASTIC_PRESENT 1 |
||
50 | #define ELASTIC_SAVE_ARRIVALS 2 |
||
671 | giacomo | 51 | |
52 | typedef struct { |
||
53 | |||
54 | struct timespec dline; |
||
55 | |||
56 | TIME Tmin; |
||
57 | TIME Tmax; |
||
58 | |||
59 | TIME period; |
||
60 | TIME wcet; |
||
673 | giacomo | 61 | |
62 | bandwidth_t Up; |
||
671 | giacomo | 63 | |
64 | int kelastic; |
||
65 | int beta; |
||
66 | |||
67 | int nact; |
||
68 | |||
69 | int flags; |
||
70 | |||
71 | } ELASTIC_task_descr; |
||
72 | |||
73 | typedef struct { |
||
74 | level_des l; /*+ the standard level descriptor +*/ |
||
75 | |||
76 | bandwidth_t U; /*+ the used bandwidth by the server +*/ |
||
77 | |||
78 | ELASTIC_task_descr *elist; |
||
79 | |||
80 | LEVEL scheduling_level; |
||
81 | |||
82 | LEVEL current_level; |
||
83 | |||
84 | int flags; |
||
85 | |||
86 | } ELASTIC_level_des; |
||
87 | |||
673 | giacomo | 88 | static int ELASTIC_recompute() { |
89 | |||
90 | return 0; |
||
91 | |||
92 | } |
||
93 | |||
94 | static int ELASTIC_check_guarantie() { |
||
95 | |||
96 | return 0; |
||
97 | |||
98 | } |
||
99 | |||
671 | giacomo | 100 | static void ELASTIC_activation(ELASTIC_level_des *lev, |
101 | PID p, |
||
102 | struct timespec *acttime) |
||
103 | { |
||
104 | JOB_TASK_MODEL job; |
||
674 | giacomo | 105 | |
106 | /* Job deadline */ |
||
107 | TIMESPEC_ASSIGN(&(lev->elist[p].dline),acttime); |
||
108 | ADDUSEC2TIMESPEC(lev->elist[p].period,&(lev->elist[p].dline)); |
||
109 | |||
110 | /* Job insertion */ |
||
111 | job_task_default_model(job, lev->elist[p].dline); |
||
671 | giacomo | 112 | level_table[ lev->scheduling_level ]-> |
113 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
||
114 | |||
674 | giacomo | 115 | } |
671 | giacomo | 116 | |
674 | giacomo | 117 | static void ELASTIC_timer_act(void *arg) { |
118 | |||
119 | PID p = (PID)(arg); |
||
120 | ELASTIC_level_des *lev; |
||
121 | struct timespec acttime; |
||
122 | |||
123 | kern_gettime(&acttime); |
||
124 | |||
125 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
126 | |||
127 | ELASTIC_activation(lev, p, &acttime); |
||
671 | giacomo | 128 | } |
129 | |||
130 | /* The on-line guarantee is enabled only if the appropriate flag is set... */ |
||
131 | static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
||
132 | { |
||
133 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
134 | |||
673 | giacomo | 135 | return 0; |
136 | |||
671 | giacomo | 137 | } |
138 | |||
139 | static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
140 | { |
||
141 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
142 | ELASTIC_TASK_MODEL *elastic; |
||
143 | |||
144 | if (m->pclass != ELASTIC_PCLASS) return -1; |
||
145 | if (m->level != 0 && m->level != l) return -1; |
||
146 | elastic = (ELASTIC_TASK_MODEL *)m; |
||
147 | |||
673 | giacomo | 148 | if (elastic->wcet == 0) return -1; |
149 | if (elastic->Tmin > elastic->Tmax) return -1; |
||
150 | if (elastic->Tmax == 0) return -1; |
||
151 | |||
152 | lev->elist[p].flags |= ELASTIC_PRESENT; |
||
153 | |||
154 | NULL_TIMESPEC(&(lev->elist[p].dline)); |
||
155 | lev->elist[p].Tmin = elastic->Tmin; |
||
156 | lev->elist[p].Tmax = elastic->Tmax; |
||
157 | lev->elist[p].wcet = elastic->wcet; |
||
158 | lev->elist[p].kelastic = elastic->kelastic; |
||
159 | lev->elist[p].beta = elastic->beta; |
||
160 | |||
161 | if (lev->flags & ELASTIC_ENABLE_GUARANTEE) |
||
162 | if (ELASTIC_check_guarantie() != 0) { |
||
163 | lev->elist[p].flags = ELASTIC_EMPTY_SLOT; |
||
164 | return -1; |
||
165 | } |
||
166 | |||
167 | ELASTIC_recompute(); |
||
168 | |||
169 | if (lev->elist[p].period == 0) { |
||
170 | lev->elist[p].flags = ELASTIC_EMPTY_SLOT; |
||
171 | return -1; |
||
172 | } |
||
173 | |||
674 | giacomo | 174 | proc_table[p].avail_time = elastic->wcet; |
673 | giacomo | 175 | proc_table[p].wcet = elastic->wcet; |
674 | giacomo | 176 | proc_table[p].control |= CONTROL_CAP; |
673 | giacomo | 177 | |
178 | if (elastic->arrivals == SAVE_ARRIVALS) |
||
179 | lev->elist[p].flags |= ELASTIC_SAVE_ARRIVALS; |
||
180 | |||
671 | giacomo | 181 | return 0; /* OK, also if the task cannot be guaranteed... */ |
182 | |||
183 | } |
||
184 | |||
185 | static void ELASTIC_public_detach(LEVEL l, PID p) |
||
186 | { |
||
187 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
188 | |||
189 | } |
||
190 | |||
191 | static int ELASTIC_public_eligible(LEVEL l, PID p) |
||
192 | { |
||
193 | |||
194 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
195 | JOB_TASK_MODEL job; |
||
196 | |||
197 | return 0; |
||
198 | |||
199 | } |
||
200 | |||
201 | static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop) |
||
202 | { |
||
203 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
674 | giacomo | 204 | |
671 | giacomo | 205 | level_table[ lev->scheduling_level ]-> |
206 | private_dispatch(lev->scheduling_level,p,nostop); |
||
674 | giacomo | 207 | |
671 | giacomo | 208 | } |
209 | |||
210 | static void ELASTIC_public_epilogue(LEVEL l, PID p) |
||
211 | { |
||
212 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
213 | JOB_TASK_MODEL job; |
||
214 | |||
674 | giacomo | 215 | /* check if the wcet is finished... */ |
216 | if (proc_table[p].avail_time <= 0) { |
||
217 | |||
218 | TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,(unsigned short int)proc_table[p].context,0); |
||
219 | kern_raise(XWCET_VIOLATION,p); |
||
220 | |||
221 | } |
||
222 | |||
223 | level_table[ lev->scheduling_level ]-> |
||
224 | private_epilogue(lev->scheduling_level,p); |
||
225 | |||
671 | giacomo | 226 | } |
227 | |||
228 | static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t) |
||
229 | { |
||
230 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
231 | |||
674 | giacomo | 232 | #ifdef ELASTIC_DEBUG |
233 | printk("(ELASTIC:Act:%d)", p); |
||
234 | #endif |
||
235 | |||
236 | /* check if we are not in the SLEEP state */ |
||
237 | if (proc_table[p].status != SLEEP) { |
||
238 | |||
239 | if (lev->flags & ELASTIC_SAVE_ARRIVALS) { |
||
240 | |||
241 | /* skip the sporadic job, but increase a counter */ |
||
242 | #ifdef ELASTIC_DEBUG |
||
243 | printk("(ELASTIC:SaveAct:%d)", p); |
||
244 | #endif |
||
245 | |||
246 | lev->elist[p].nact++; |
||
247 | |||
248 | } |
||
249 | |||
250 | return; |
||
251 | |||
252 | } |
||
253 | |||
254 | ELASTIC_activation(lev,p,t); |
||
255 | |||
256 | /* Next activation */ |
||
257 | kern_event_post(&(lev->elist[p].dline), ELASTIC_timer_act, (void *)(p)); |
||
258 | |||
671 | giacomo | 259 | } |
260 | |||
261 | static void ELASTIC_public_unblock(LEVEL l, PID p) |
||
262 | { |
||
263 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
264 | struct timespec acttime; |
||
265 | |||
266 | kern_gettime(&acttime); |
||
267 | |||
268 | ELASTIC_activation(lev,p,&acttime); |
||
269 | |||
270 | } |
||
271 | |||
272 | static void ELASTIC_public_block(LEVEL l, PID p) |
||
273 | { |
||
274 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
275 | |||
276 | level_table[ lev->scheduling_level ]-> |
||
277 | private_extract(lev->scheduling_level,p); |
||
278 | |||
279 | } |
||
280 | |||
281 | static int ELASTIC_public_message(LEVEL l, PID p, void *m) |
||
282 | { |
||
283 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
284 | |||
285 | switch((long)(m)) { |
||
286 | |||
287 | case (long)(NULL): |
||
288 | |||
289 | jet_update_endcycle(); /* Update the Jet data... */ |
||
290 | TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
291 | |||
292 | break; |
||
293 | |||
294 | case 1: |
||
295 | |||
296 | TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
297 | |||
298 | break; |
||
299 | |||
300 | } |
||
301 | |||
302 | return 0; |
||
303 | |||
304 | } |
||
305 | |||
306 | static void ELASTIC_public_end(LEVEL l, PID p) |
||
307 | { |
||
308 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
309 | |||
310 | level_table[ lev->scheduling_level ]-> |
||
311 | private_extract(lev->scheduling_level,p); |
||
312 | |||
313 | } |
||
314 | |||
315 | /*+ Registration function +*/ |
||
316 | LEVEL ELASTIC_register_level(int flags, LEVEL master) |
||
317 | { |
||
318 | LEVEL l; /* the level that we register */ |
||
319 | ELASTIC_level_des *lev; /* for readableness only */ |
||
320 | PID i; |
||
321 | |||
322 | printk("ELASTIC_register_level\n"); |
||
323 | |||
324 | /* request an entry in the level_table */ |
||
325 | l = level_alloc_descriptor(sizeof(ELASTIC_level_des)); |
||
326 | |||
327 | lev = (ELASTIC_level_des *)level_table[l]; |
||
328 | |||
329 | /* fill the standard descriptor */ |
||
330 | if (flags & ELASTIC_ENABLE_GUARANTEE) |
||
331 | lev->l.public_guarantee = ELASTIC_public_guarantee; |
||
332 | else |
||
333 | lev->l.public_guarantee = NULL; |
||
334 | lev->l.public_create = ELASTIC_public_create; |
||
335 | lev->l.public_detach = ELASTIC_public_detach; |
||
336 | lev->l.public_end = ELASTIC_public_end; |
||
337 | lev->l.public_eligible = ELASTIC_public_eligible; |
||
338 | lev->l.public_dispatch = ELASTIC_public_dispatch; |
||
339 | lev->l.public_epilogue = ELASTIC_public_epilogue; |
||
340 | lev->l.public_activate = ELASTIC_public_activate; |
||
341 | lev->l.public_unblock = ELASTIC_public_unblock; |
||
342 | lev->l.public_block = ELASTIC_public_block; |
||
343 | lev->l.public_message = ELASTIC_public_message; |
||
344 | |||
345 | lev->elist = malloc(MAX_PROC * sizeof(ELASTIC_task_descr)); |
||
346 | if (lev->elist == NULL) { |
||
347 | printk("ELASTIC: Error allocating elastic task decriptor table\n"); |
||
348 | sys_end(); |
||
349 | } |
||
350 | |||
351 | /* fill the CBS descriptor part */ |
||
352 | for (i=0; i<MAX_PROC; i++) { |
||
353 | NULL_TIMESPEC(&(lev->elist[i].dline)); |
||
354 | lev->elist[i].Tmin = 0; |
||
355 | lev->elist[i].Tmax = 0; |
||
356 | lev->elist[i].period = 0; |
||
357 | lev->elist[i].wcet = 0; |
||
358 | lev->elist[i].kelastic = 0; |
||
359 | lev->elist[i].beta = 0; |
||
360 | lev->elist[i].nact = 0; |
||
361 | lev->elist[i].flags = ELASTIC_EMPTY_SLOT; |
||
362 | } |
||
363 | |||
364 | lev->U = 0; |
||
365 | |||
366 | lev->scheduling_level = master; |
||
367 | |||
368 | lev->current_level = l; |
||
369 | |||
370 | lev->flags = flags; |
||
371 | |||
372 | return l; |
||
373 | } |
||
374 |