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