Rev 388 | Rev 786 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
235 | 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 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2001 Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | */ |
||
37 | |||
38 | #include "rmstar.h" |
||
39 | #include <ll/stdio.h> |
||
40 | #include <ll/string.h> |
||
41 | #include <kernel/model.h> |
||
42 | #include <kernel/descr.h> |
||
43 | #include <kernel/var.h> |
||
44 | #include <kernel/func.h> |
||
45 | |||
46 | #define RMSTAR_CHANGE_LEVEL 1 |
||
47 | |||
48 | /* for iqueues */ |
||
49 | /* #include "iqueue.h" Now iqueues are the only queue type into the kernel */ |
||
50 | |||
51 | /* for BUDGET_TASK_MODEL */ |
||
241 | giacomo | 52 | #include "fsf_server.h" |
235 | giacomo | 53 | |
54 | /* |
||
55 | * DEBUG stuffs begin |
||
56 | */ |
||
57 | |||
58 | //#define RMSTAR_DEBUG |
||
59 | |||
60 | #ifdef RMSTAR_DEBUG |
||
61 | |||
62 | static __inline__ fake_printf(char *fmt, ...) {} |
||
63 | |||
64 | #define rmstar_printf fake_printf |
||
65 | #define rmstar_printf2 fake_printf |
||
66 | #define rmstar_printf3 fake_printf |
||
67 | |||
68 | //#define rmstar_printf kern_printf |
||
69 | //#define rmstar_printf2 kern_printf |
||
70 | //#define rmstar_printf3 kern_printf |
||
71 | #endif |
||
72 | |||
73 | /* |
||
74 | * DEBUG stuffs end |
||
75 | */ |
||
76 | |||
77 | /* Status used in the level */ |
||
78 | #define RMSTAR_READY MODULE_STATUS_BASE /* - Ready status */ |
||
79 | #define RMSTAR_IDLE MODULE_STATUS_BASE+4 /* to wait the deadline */ |
||
80 | |||
81 | /* flags */ |
||
82 | #define RMSTAR_FLAG_NORAISEEXC 2 |
||
394 | trimarchi | 83 | #define RMSTAR_FLAG_SPORADIC 1 |
235 | giacomo | 84 | |
85 | /* the level redefinition for the Earliest Deadline First level */ |
||
86 | typedef struct { |
||
87 | level_des l; /* the standard level descriptor */ |
||
88 | |||
89 | TIME period[MAX_PROC]; /* The task periods; the deadlines are |
||
90 | stored in the priority field */ |
||
91 | int deadline_timer[MAX_PROC]; |
||
92 | /* The task deadline timers */ |
||
93 | |||
94 | struct timespec deadline_timespec[MAX_PROC]; |
||
95 | |||
96 | int dline_miss[MAX_PROC]; /* Deadline miss counter */ |
||
97 | int wcet_miss[MAX_PROC]; /* Wcet miss counter */ |
||
98 | |||
99 | int nact[MAX_PROC]; /* Wcet miss counter */ |
||
100 | |||
101 | int flag[MAX_PROC]; |
||
102 | /* used to manage the JOB_TASK_MODEL and the |
||
103 | periodicity */ |
||
104 | |||
105 | IQUEUE ready; /* the ready queue */ |
||
106 | |||
107 | PID activated; /* the task that has been inserted into the |
||
108 | master module */ |
||
109 | |||
110 | int budget[MAX_PROC]; |
||
111 | |||
112 | int scheduling_level; |
||
113 | |||
394 | trimarchi | 114 | int cap_lev; |
115 | |||
116 | struct timespec cap_lasttime; |
||
117 | |||
235 | giacomo | 118 | } RMSTAR_level_des; |
119 | |||
394 | trimarchi | 120 | static void capacity_handler(void *l) |
121 | { |
||
122 | RMSTAR_level_des *lev = l; |
||
123 | lev->cap_lev = NIL; |
||
124 | event_need_reschedule(); |
||
125 | } |
||
126 | |||
235 | giacomo | 127 | static void RMSTAR_check_preemption(RMSTAR_level_des *lev) |
128 | { |
||
129 | PID first; |
||
130 | |||
131 | #ifdef RMSTAR_DEBUG |
||
132 | rmstar_printf("(E:chk)"); |
||
133 | #endif |
||
134 | |||
135 | if ((first = iq_query_first(&lev->ready)) != lev->activated) { |
||
136 | if (lev->activated != NIL) |
||
137 | level_table[ lev->scheduling_level ]-> |
||
138 | private_extract(lev->scheduling_level, lev->activated); |
||
139 | |||
140 | lev->activated = first; |
||
141 | |||
142 | if (first != NIL) { |
||
143 | BUDGET_TASK_MODEL b; |
||
144 | budget_task_default_model(b, lev->budget[first]); |
||
145 | |||
146 | level_table[ lev->scheduling_level ]-> |
||
147 | private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | static void RMSTAR_timer_deadline(void *par); |
||
153 | |||
154 | static void RMSTAR_internal_activate(RMSTAR_level_des *lev, PID p, |
||
155 | struct timespec *t) |
||
156 | { |
||
157 | #ifdef RMSTAR_DEBUG |
||
158 | rmstar_printf("(E:iact)"); |
||
159 | #endif |
||
160 | |||
161 | ADDUSEC2TIMESPEC(lev->period[p], t); |
||
162 | |||
163 | *iq_query_timespec(p, &lev->ready) = *t; |
||
164 | lev->deadline_timespec[p] = *t; |
||
165 | |||
166 | /* Insert task in the correct position */ |
||
167 | proc_table[p].status = RMSTAR_READY; |
||
168 | iq_priority_insert(p,&lev->ready); |
||
169 | |||
394 | trimarchi | 170 | proc_table[p].control &= ~CONTROL_CAP; |
235 | giacomo | 171 | |
172 | /* check for preemption */ |
||
173 | RMSTAR_check_preemption(lev); |
||
174 | } |
||
175 | |||
176 | static void RMSTAR_timer_deadline(void *par) |
||
177 | { |
||
178 | PID p = (PID) par; |
||
179 | RMSTAR_level_des *lev; |
||
180 | |||
181 | #ifdef RMSTAR_DEBUG |
||
182 | // rmstar_printf("(E:tdl "); |
||
183 | #endif |
||
184 | |||
185 | lev = (RMSTAR_level_des *)level_table[proc_table[p].task_level]; |
||
186 | |||
187 | switch (proc_table[p].status) { |
||
188 | case RMSTAR_IDLE: |
||
189 | #ifdef RMSTAR_DEBUG |
||
190 | // rmstar_printf2("I%d",p); |
||
191 | #endif |
||
192 | /* set the request time */ |
||
394 | trimarchi | 193 | if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC)) |
194 | RMSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready)); |
||
235 | giacomo | 195 | |
196 | event_need_reschedule(); |
||
197 | break; |
||
198 | |||
199 | default: |
||
200 | #ifdef RMSTAR_DEBUG |
||
201 | // rmstar_printf2("D%d",p); |
||
202 | #endif |
||
203 | /* else, a deadline miss occurred!!! */ |
||
204 | lev->dline_miss[p]++; |
||
394 | trimarchi | 205 | if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC)) { |
206 | lev->nact[p]++; |
||
207 | ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]); |
||
208 | } |
||
235 | giacomo | 209 | } |
210 | |||
211 | /* Set the deadline timer */ |
||
394 | trimarchi | 212 | if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC)) |
213 | lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
||
214 | RMSTAR_timer_deadline, |
||
215 | (void *)p); |
||
235 | giacomo | 216 | |
217 | #ifdef RMSTAR_DEBUG |
||
218 | // rmstar_printf(")"); |
||
219 | #endif |
||
220 | } |
||
221 | |||
222 | static void RMSTAR_timer_guest_deadline(void *par) |
||
223 | { |
||
224 | PID p = (PID) par; |
||
225 | |||
226 | #ifdef RMSTAR_DEBUG |
||
227 | rmstar_printf("(E:gdl)"); |
||
228 | #endif |
||
229 | |||
230 | kern_raise(XDEADLINE_MISS,p); |
||
231 | } |
||
232 | |||
394 | trimarchi | 233 | static void RMSTAR_account_capacity(RMSTAR_level_des *lev, PID p) |
234 | { |
||
235 | struct timespec ty; |
||
236 | TIME tx; |
||
237 | |||
238 | SUBTIMESPEC(&schedule_time, &lev->cap_lasttime, &ty); |
||
239 | tx = TIMESPEC2USEC(&ty); |
||
240 | |||
241 | proc_table[p].avail_time -= tx; |
||
242 | } |
||
243 | |||
244 | |||
235 | giacomo | 245 | static int RMSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
246 | { |
||
247 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
394 | trimarchi | 248 | |
235 | giacomo | 249 | /* if the RMSTAR_task_create is called, then the pclass must be a |
250 | valid pclass. */ |
||
251 | HARD_TASK_MODEL *h; |
||
394 | trimarchi | 252 | |
235 | giacomo | 253 | if (m->pclass != HARD_PCLASS) return -1; |
254 | if (m->level != 0 && m->level != l) return -1; |
||
255 | h = (HARD_TASK_MODEL *)m; |
||
394 | trimarchi | 256 | if (!h->wcet || !h->mit) return -1; |
235 | giacomo | 257 | /* now we know that m is a valid model */ |
258 | |||
394 | trimarchi | 259 | if (h->periodicity == APERIODIC) |
260 | lev->flag[p] |= RMSTAR_FLAG_SPORADIC; |
||
261 | |||
235 | giacomo | 262 | #ifdef RMSTAR_DEBUG |
263 | rmstar_printf("(E:tcr)"); |
||
264 | #endif |
||
265 | |||
266 | lev->period[p] = h->mit; |
||
267 | *iq_query_priority(p, &lev->ready) = h->mit; |
||
268 | |||
269 | lev->flag[p] = 0; |
||
270 | lev->deadline_timer[p] = -1; |
||
271 | lev->dline_miss[p] = 0; |
||
272 | lev->wcet_miss[p] = 0; |
||
273 | lev->nact[p] = 0; |
||
274 | |||
275 | /* Enable wcet check */ |
||
276 | proc_table[p].avail_time = h->wcet; |
||
277 | proc_table[p].wcet = h->wcet; |
||
394 | trimarchi | 278 | //proc_table[p].control |= CONTROL_CAP; |
235 | giacomo | 279 | |
280 | return 0; /* OK, also if the task cannot be guaranteed... */ |
||
281 | } |
||
282 | |||
283 | static void RMSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
||
284 | { |
||
285 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
394 | trimarchi | 286 | struct timespec ty; |
235 | giacomo | 287 | |
288 | #ifdef RMSTAR_DEBUG |
||
289 | rmstar_printf("(E:dis)"); |
||
290 | |||
291 | rmstar_printf3("(%d %d)", |
||
292 | iq_query_timespec(p, &lev->ready)->tv_nsec/1000000, |
||
293 | schedule_time.tv_nsec/1000000); |
||
294 | #endif |
||
295 | |||
394 | trimarchi | 296 | if (!nostop || proc_table[exec].task_level==l) { |
297 | TIMESPEC_ASSIGN(&ty, &schedule_time); |
||
298 | TIMESPEC_ASSIGN(&lev->cap_lasttime, &schedule_time); |
||
299 | |||
300 | /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume |
||
301 | * * capacity on exe task always */ |
||
302 | ADDUSEC2TIMESPEC(proc_table[exec].avail_time ,&ty); |
||
303 | lev->cap_lev = kern_event_post(&ty,capacity_handler, lev); |
||
304 | level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop); |
||
305 | } |
||
306 | else |
||
307 | level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop); |
||
308 | |||
235 | giacomo | 309 | } |
310 | |||
311 | static void RMSTAR_public_epilogue(LEVEL l, PID p) |
||
312 | { |
||
313 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
314 | |||
315 | #ifdef RMSTAR_DEBUG |
||
316 | rmstar_printf("(E:epi "); |
||
317 | #endif |
||
318 | |||
394 | trimarchi | 319 | if (lev->cap_lev!=NIL) { |
320 | kern_event_delete(lev->cap_lev); |
||
321 | lev->cap_lev=NIL; |
||
322 | } |
||
323 | |||
324 | |||
325 | if ( proc_table[exec].task_level==l ) { |
||
326 | |||
327 | RMSTAR_account_capacity(lev,exec); |
||
328 | |||
329 | /* check if the wcet is finished... */ |
||
330 | if (proc_table[p].avail_time) { |
||
331 | /* wcet finished: disable wcet event and count wcet miss */ |
||
235 | giacomo | 332 | #ifdef RMSTAR_DEBUG |
394 | trimarchi | 333 | rmstar_printf2("W%d",p); |
235 | giacomo | 334 | #endif |
394 | trimarchi | 335 | //proc_table[p].control &= ~CONTROL_CAP; |
336 | lev->wcet_miss[p]++; |
||
337 | } |
||
235 | giacomo | 338 | #ifdef RMSTAR_DEBUG |
394 | trimarchi | 339 | rmstar_printf(")"); |
235 | giacomo | 340 | #endif |
394 | trimarchi | 341 | |
342 | level_table[ lev->scheduling_level ]-> |
||
343 | private_epilogue(lev->scheduling_level,p); |
||
344 | |||
345 | proc_table[p].status = RMSTAR_READY; |
||
346 | } else |
||
347 | level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p); |
||
235 | giacomo | 348 | } |
349 | |||
350 | static void RMSTAR_public_activate(LEVEL l, PID p) |
||
351 | { |
||
352 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
353 | struct timespec t; |
||
354 | |||
355 | #ifdef RMSTAR_DEBUG |
||
356 | rmstar_printf("(E:act)"); |
||
357 | #endif |
||
394 | trimarchi | 358 | /* Test if we are trying to activate a non sleeping task */ |
359 | /* save activation (only if needed... */ |
||
235 | giacomo | 360 | |
394 | trimarchi | 361 | if (proc_table[p].status != SLEEP) { |
362 | /* a periodic task cannot be activated when it is already active */ |
||
363 | /* but aperiodic task can be reactivate before */ |
||
364 | if (lev->flag[p] & RMSTAR_FLAG_SPORADIC) { |
||
365 | if (proc_table[p].status != RMSTAR_IDLE) { |
||
366 | lev->nact[p]++; |
||
367 | return; |
||
368 | } |
||
369 | } else { |
||
370 | kern_raise(XACTIVATION,p); |
||
371 | } |
||
372 | } |
||
373 | |||
235 | giacomo | 374 | /* Test if we are trying to activate a non sleeping task */ |
375 | /* save activation (only if needed... */ |
||
376 | |||
377 | kern_gettime(&t); |
||
378 | |||
379 | RMSTAR_internal_activate(lev,p, &t); |
||
380 | |||
381 | /* Set the deadline timer */ |
||
382 | lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
||
383 | RMSTAR_timer_deadline, |
||
384 | (void *)p); |
||
385 | |||
386 | } |
||
387 | |||
388 | static void RMSTAR_public_unblock(LEVEL l, PID p) |
||
389 | { |
||
390 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
391 | |||
392 | #ifdef RMSTAR_DEBUG |
||
393 | rmstar_printf("(E:ins)"); |
||
394 | #endif |
||
395 | |||
396 | /* Insert task in the correct position */ |
||
397 | proc_table[p].status = RMSTAR_READY; |
||
398 | iq_priority_insert(p,&lev->ready); |
||
399 | |||
400 | /* and check for preemption! */ |
||
401 | RMSTAR_check_preemption(lev); |
||
402 | } |
||
403 | |||
404 | static void RMSTAR_public_block(LEVEL l, PID p) |
||
405 | { |
||
406 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
407 | |||
408 | #ifdef RMSTAR_DEBUG |
||
409 | rmstar_printf("(E:ext)"); |
||
410 | #endif |
||
411 | |||
412 | /* the task is blocked on a synchronization primitive. we have to |
||
413 | remove it from the master module -and- from the local queue! */ |
||
414 | iq_extract(p,&lev->ready); |
||
415 | |||
416 | /* and finally, a preemption check! (it will also call guest_end) */ |
||
417 | RMSTAR_check_preemption(lev); |
||
418 | } |
||
419 | |||
420 | static int RMSTAR_public_message(LEVEL l, PID p, void *m) |
||
421 | { |
||
422 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
423 | struct timespec temp; |
||
424 | |||
425 | #ifdef RMSTAR_DEBUG |
||
426 | rmstar_printf("(E:ecy "); |
||
427 | #endif |
||
428 | |||
429 | switch ((long)(m)) |
||
430 | { |
||
431 | |||
432 | /* Task EndCycle */ |
||
433 | case (long)(NULL): |
||
434 | |||
435 | /* we call guest_end directly here because the same task may |
||
436 | be reinserted in the queue before calling the preemption check! */ |
||
437 | level_table[ lev->scheduling_level ]-> |
||
438 | private_extract(lev->scheduling_level,p); lev->activated = NIL; |
||
439 | |||
440 | iq_extract(p,&lev->ready); |
||
441 | |||
442 | /* we reset the capacity counters... */ |
||
443 | proc_table[p].avail_time = proc_table[p].wcet; |
||
444 | |||
445 | if (lev->nact[p] > 0) { |
||
446 | #ifdef RMSTAR_DEBUG |
||
447 | rmstar_printf2("E%d",p); |
||
448 | #endif |
||
449 | |||
450 | /* Pending activation: reactivate the thread!!! */ |
||
451 | lev->nact[p]--; |
||
452 | |||
453 | /* see also RMSTAR_timer_deadline */ |
||
454 | kern_gettime(&temp); |
||
455 | |||
456 | RMSTAR_internal_activate(lev,p,&temp); |
||
457 | |||
458 | /* check if the deadline has already expired */ |
||
459 | temp = *iq_query_timespec(p, &lev->ready); |
||
460 | if (TIMESPEC_A_LT_B(&temp, &schedule_time)) { |
||
461 | /* count the deadline miss */ |
||
462 | lev->dline_miss[p]++; |
||
463 | kern_event_delete(lev->deadline_timer[p]); |
||
464 | } |
||
465 | |||
466 | } |
||
467 | else { |
||
468 | #ifdef RMSTAR_DEBUG |
||
469 | rmstar_printf("e%d",p); |
||
470 | #endif |
||
394 | trimarchi | 471 | if (lev->flag[p] & RMSTAR_FLAG_SPORADIC && lev->deadline_timer[p] != NIL) |
472 | kern_event_delete(lev->deadline_timer[p]); |
||
473 | |||
235 | giacomo | 474 | /* the task has terminated his job before it consume the wcet. All OK! */ |
475 | proc_table[p].status = RMSTAR_IDLE; |
||
476 | |||
477 | /* and finally, a preemption check! */ |
||
478 | RMSTAR_check_preemption(lev); |
||
479 | |||
480 | /* when the deadline timer fire, it recognize the situation and set |
||
481 | correctly all the stuffs (like reactivation, etc... ) */ |
||
482 | } |
||
483 | #ifdef RMSTAR_DEBUG |
||
484 | rmstar_printf(")"); |
||
485 | #endif |
||
486 | |||
487 | jet_update_endcycle(); /* Update the Jet data... */ |
||
488 | break; |
||
489 | default: |
||
490 | |||
491 | break; |
||
492 | |||
493 | } |
||
494 | return 0; |
||
495 | } |
||
496 | |||
497 | static void RMSTAR_public_end(LEVEL l, PID p) |
||
498 | { |
||
499 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
500 | |||
501 | #ifdef RMSTAR_DEBUG |
||
502 | rmstar_printf("(E:end)"); |
||
503 | #endif |
||
504 | |||
505 | iq_extract(p,&lev->ready); |
||
506 | |||
507 | /* we finally put the task in the ready queue */ |
||
508 | proc_table[p].status = FREE; |
||
509 | |||
510 | iq_insertfirst(p,&freedesc); |
||
511 | |||
512 | if (lev->deadline_timer[p] != -1) { |
||
513 | kern_event_delete(lev->deadline_timer[p]); |
||
514 | } |
||
515 | |||
516 | /* and finally, a preemption check! (it will also call guest_end) */ |
||
517 | RMSTAR_check_preemption(lev); |
||
518 | } |
||
519 | |||
520 | |||
521 | /* Guest Functions |
||
522 | These functions manages a JOB_TASK_MODEL, that is used to put |
||
523 | a guest task in the RMSTAR ready queue. */ |
||
524 | |||
525 | static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m) |
||
526 | { |
||
527 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
528 | JOB_TASK_MODEL *job; |
||
529 | |||
530 | if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) { |
||
531 | kern_raise(XINVALID_TASK, p); |
||
532 | return; |
||
533 | } |
||
534 | |||
535 | job = (JOB_TASK_MODEL *)m; |
||
536 | |||
537 | *iq_query_timespec(p, &lev->ready) = job->deadline; |
||
538 | |||
539 | lev->deadline_timer[p] = -1; |
||
540 | lev->dline_miss[p] = 0; |
||
541 | lev->wcet_miss[p] = 0; |
||
542 | lev->nact[p] = 0; |
||
543 | |||
544 | if (job->noraiseexc) |
||
545 | lev->flag[p] = RMSTAR_FLAG_NORAISEEXC; |
||
546 | else { |
||
547 | lev->flag[p] = 0; |
||
548 | lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready), |
||
549 | RMSTAR_timer_guest_deadline, |
||
550 | (void *)p); |
||
551 | } |
||
552 | |||
553 | lev->period[p] = job->period; |
||
554 | *iq_query_priority(p, &lev->ready) = job->period; |
||
555 | |||
556 | /* there is no bandwidth guarantee at this level, it is performed |
||
557 | by the level that inserts guest tasks... */ |
||
558 | |||
559 | /* Insert task in the correct position */ |
||
560 | iq_priority_insert(p,&lev->ready); |
||
561 | proc_table[p].status = RMSTAR_READY; |
||
562 | |||
563 | /* check for preemption */ |
||
564 | RMSTAR_check_preemption(lev); |
||
565 | } |
||
566 | |||
567 | |||
568 | static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop) |
||
569 | { |
||
570 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
571 | |||
572 | level_table[ lev->scheduling_level ]-> |
||
573 | private_dispatch(lev->scheduling_level,p,nostop); |
||
574 | } |
||
575 | |||
576 | static void RMSTAR_private_epilogue(LEVEL l, PID p) |
||
577 | { |
||
578 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
579 | |||
580 | /* the task has been preempted. it returns into the ready queue... */ |
||
581 | level_table[ lev->scheduling_level ]-> |
||
582 | private_epilogue(lev->scheduling_level,p); |
||
583 | |||
584 | proc_table[p].status = RMSTAR_READY; |
||
585 | } |
||
586 | |||
587 | static void RMSTAR_private_extract(LEVEL l, PID p) |
||
588 | { |
||
589 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
590 | |||
591 | #ifdef RMSTAR_DEBUG |
||
592 | //kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
||
593 | #endif |
||
594 | |||
595 | iq_extract(p, &lev->ready); |
||
596 | |||
597 | /* we remove the deadline timer, because the slice is finished */ |
||
598 | if (lev->deadline_timer[p] != NIL) { |
||
599 | #ifdef RMSTAR_DEBUG |
||
600 | // kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
||
601 | #endif |
||
602 | kern_event_delete(lev->deadline_timer[p]); |
||
603 | lev->deadline_timer[p] = NIL; |
||
604 | } |
||
605 | |||
606 | /* and finally, a preemption check! (it will also call guest_end() */ |
||
607 | RMSTAR_check_preemption(lev); |
||
608 | } |
||
609 | |||
610 | /* Registration functions */ |
||
611 | |||
612 | /* Registration function: |
||
613 | int flags the init flags ... see RMSTAR.h */ |
||
614 | LEVEL RMSTAR_register_level(int master) |
||
615 | { |
||
616 | LEVEL l; /* the level that we register */ |
||
617 | RMSTAR_level_des *lev; /* for readableness only */ |
||
618 | PID i; /* a counter */ |
||
619 | |||
620 | #ifdef RMSTAR_DEBUG |
||
621 | printk("RMSTAR_register_level\n"); |
||
622 | #endif |
||
623 | |||
624 | /* request an entry in the level_table */ |
||
625 | l = level_alloc_descriptor(sizeof(RMSTAR_level_des)); |
||
626 | |||
627 | lev = (RMSTAR_level_des *)level_table[l]; |
||
628 | |||
629 | /* fill the standard descriptor */ |
||
630 | lev->l.private_insert = RMSTAR_private_insert; |
||
631 | lev->l.private_extract = RMSTAR_private_extract; |
||
632 | lev->l.private_dispatch = RMSTAR_private_dispatch; |
||
633 | lev->l.private_epilogue = RMSTAR_private_epilogue; |
||
634 | |||
635 | lev->l.public_guarantee = NULL; |
||
636 | lev->l.public_create = RMSTAR_public_create; |
||
637 | lev->l.public_end = RMSTAR_public_end; |
||
638 | lev->l.public_dispatch = RMSTAR_public_dispatch; |
||
639 | lev->l.public_epilogue = RMSTAR_public_epilogue; |
||
640 | lev->l.public_activate = RMSTAR_public_activate; |
||
641 | lev->l.public_unblock = RMSTAR_public_unblock; |
||
642 | lev->l.public_block = RMSTAR_public_block; |
||
643 | lev->l.public_message = RMSTAR_public_message; |
||
644 | |||
645 | /* fill the RMSTAR descriptor part */ |
||
646 | for(i=0; i<MAX_PROC; i++) { |
||
647 | lev->period[i] = 0; |
||
648 | lev->deadline_timer[i] = -1; |
||
649 | lev->flag[i] = 0; |
||
650 | lev->dline_miss[i] = 0; |
||
651 | lev->wcet_miss[i] = 0; |
||
652 | lev->nact[i] = 0; |
||
653 | lev->budget[i] = NIL; |
||
654 | } |
||
655 | |||
656 | iq_init(&lev->ready, NULL, 0); |
||
657 | lev->activated = NIL; |
||
658 | |||
659 | lev->scheduling_level = master; |
||
660 | |||
394 | trimarchi | 661 | lev->cap_lev = NIL; |
662 | NULL_TIMESPEC(&lev->cap_lasttime); |
||
663 | |||
235 | giacomo | 664 | return l; |
665 | } |
||
666 | |||
667 | int RMSTAR_get_dline_miss(PID p) |
||
668 | { |
||
669 | LEVEL l = proc_table[p].task_level; |
||
670 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
671 | |||
672 | return lev->dline_miss[p]; |
||
673 | } |
||
674 | |||
675 | int RMSTAR_get_wcet_miss(PID p) |
||
676 | { |
||
677 | LEVEL l = proc_table[p].task_level; |
||
678 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
679 | |||
680 | return lev->wcet_miss[p]; |
||
681 | } |
||
682 | |||
683 | int RMSTAR_get_nact(PID p) |
||
684 | { |
||
685 | LEVEL l = proc_table[p].task_level; |
||
686 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
687 | |||
688 | return lev->nact[p]; |
||
689 | } |
||
690 | |||
691 | int RMSTAR_reset_dline_miss(PID p) |
||
692 | { |
||
693 | LEVEL l = proc_table[p].task_level; |
||
694 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
695 | |||
696 | lev->dline_miss[p] = 0; |
||
697 | return 0; |
||
698 | } |
||
699 | |||
700 | int RMSTAR_reset_wcet_miss(PID p) |
||
701 | { |
||
702 | LEVEL l = proc_table[p].task_level; |
||
703 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
704 | |||
705 | lev->wcet_miss[p] = 0; |
||
706 | return 0; |
||
707 | } |
||
708 | |||
709 | |||
710 | int RMSTAR_setbudget(LEVEL l, PID p, int budget) |
||
711 | { |
||
712 | |||
713 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
714 | |||
715 | lev->budget[p] = budget; |
||
716 | |||
717 | return 0; |
||
718 | |||
719 | } |
||
720 | |||
721 | int RMSTAR_getbudget(LEVEL l, PID p) |
||
722 | { |
||
723 | |||
724 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
725 | |||
726 | return lev->budget[p]; |
||
727 | |||
728 | } |
||
729 | |||
730 | int RMSTAR_budget_has_thread(LEVEL l, int budget) |
||
731 | { |
||
732 | |||
733 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
734 | int i; |
||
735 | |||
736 | for(i = 0; i< MAX_PROC; i++) |
||
737 | if (lev->budget[i] == budget) return 1; |
||
738 | |||
739 | return 0; |
||
740 | |||
741 | } |