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