Rev 1116 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1089 | pj | 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 | ------------ |
||
1123 | pj | 21 | CVS : $Id: rmstar.c,v 1.4 2003-01-07 17:10:17 pj Exp $ |
1089 | pj | 22 | |
23 | File: $File$ |
||
1123 | pj | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2003-01-07 17:10:17 $ |
||
1089 | pj | 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 | /* for iqueues */ |
||
1116 | pj | 58 | /* #include "iqueue.h" Now iqueues are the only queue type into the kernel */ |
1089 | pj | 59 | |
60 | /* for BUDGET_TASK_MODEL */ |
||
61 | #include "cbsstar.h" |
||
62 | |||
63 | /* |
||
64 | * DEBUG stuffs begin |
||
65 | */ |
||
66 | |||
67 | //#define RMSTAR_DEBUG |
||
68 | |||
1123 | pj | 69 | #ifdef RMSTAR_DEBUG |
1089 | pj | 70 | |
71 | static __inline__ fake_printf(char *fmt, ...) {} |
||
72 | |||
73 | #define rmstar_printf fake_printf |
||
74 | #define rmstar_printf2 fake_printf |
||
75 | #define rmstar_printf3 fake_printf |
||
76 | |||
77 | //#define rmstar_printf kern_printf |
||
78 | //#define rmstar_printf2 kern_printf |
||
79 | //#define rmstar_printf3 kern_printf |
||
80 | #endif |
||
81 | |||
82 | /* |
||
83 | * DEBUG stuffs end |
||
84 | */ |
||
85 | |||
86 | /* Status used in the level */ |
||
87 | #define RMSTAR_READY MODULE_STATUS_BASE /* - Ready status */ |
||
88 | #define RMSTAR_IDLE MODULE_STATUS_BASE+4 /* to wait the deadline */ |
||
89 | |||
90 | /* flags */ |
||
91 | #define RMSTAR_FLAG_NORAISEEXC 2 |
||
92 | |||
93 | /* the level redefinition for the Earliest Deadline First level */ |
||
94 | typedef struct { |
||
95 | level_des l; /* the standard level descriptor */ |
||
96 | |||
97 | TIME period[MAX_PROC]; /* The task periods; the deadlines are |
||
98 | stored in the priority field */ |
||
99 | int deadline_timer[MAX_PROC]; |
||
100 | /* The task deadline timers */ |
||
101 | |||
102 | struct timespec deadline_timespec[MAX_PROC]; |
||
103 | |||
104 | int dline_miss[MAX_PROC]; /* Deadline miss counter */ |
||
105 | int wcet_miss[MAX_PROC]; /* Wcet miss counter */ |
||
106 | |||
107 | int nact[MAX_PROC]; /* Wcet miss counter */ |
||
108 | |||
109 | int flag[MAX_PROC]; |
||
110 | /* used to manage the JOB_TASK_MODEL and the |
||
111 | periodicity */ |
||
112 | |||
113 | IQUEUE ready; /* the ready queue */ |
||
114 | |||
115 | PID activated; /* the task that has been inserted into the |
||
116 | master module */ |
||
117 | |||
118 | int budget; |
||
119 | |||
120 | int scheduling_level; |
||
121 | } RMSTAR_level_des; |
||
122 | |||
123 | static void RMSTAR_check_preemption(RMSTAR_level_des *lev) |
||
124 | { |
||
125 | PID first; |
||
126 | |||
127 | #ifdef RMSTAR_DEBUG |
||
128 | rmstar_printf("(E:chk)"); |
||
129 | #endif |
||
130 | |||
1116 | pj | 131 | if ((first = iq_query_first(&lev->ready)) != lev->activated) { |
1089 | pj | 132 | if (lev->activated != NIL) |
133 | level_table[ lev->scheduling_level ]-> |
||
1123 | pj | 134 | private_extract(lev->scheduling_level, lev->activated); |
1089 | pj | 135 | |
136 | lev->activated = first; |
||
137 | |||
138 | if (first != NIL) { |
||
139 | BUDGET_TASK_MODEL b; |
||
140 | budget_task_default_model(b, lev->budget); |
||
141 | |||
142 | level_table[ lev->scheduling_level ]-> |
||
1123 | pj | 143 | private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b); |
1089 | pj | 144 | } |
145 | } |
||
146 | } |
||
147 | |||
148 | static void RMSTAR_timer_deadline(void *par); |
||
149 | |||
1123 | pj | 150 | static void RMSTAR_internal_activate(RMSTAR_level_des *lev, PID p, |
151 | struct timespec *t) |
||
1089 | pj | 152 | { |
153 | #ifdef RMSTAR_DEBUG |
||
154 | rmstar_printf("(E:iact)"); |
||
155 | #endif |
||
156 | |||
1123 | pj | 157 | ADDUSEC2TIMESPEC(lev->period[p], t); |
1089 | pj | 158 | |
1123 | pj | 159 | *iq_query_timespec(p, &lev->ready) = *t; |
160 | lev->deadline_timespec[p] = *t; |
||
1089 | pj | 161 | |
162 | /* Insert task in the correct position */ |
||
163 | proc_table[p].status = RMSTAR_READY; |
||
164 | iq_priority_insert(p,&lev->ready); |
||
165 | |||
166 | /* needed because when there is a wcet miss I disable CONTROL_CAP */ |
||
167 | proc_table[p].control |= CONTROL_CAP; |
||
168 | |||
169 | /* check for preemption */ |
||
170 | RMSTAR_check_preemption(lev); |
||
171 | } |
||
172 | |||
173 | static void RMSTAR_timer_deadline(void *par) |
||
174 | { |
||
175 | PID p = (PID) par; |
||
176 | RMSTAR_level_des *lev; |
||
177 | |||
178 | #ifdef RMSTAR_DEBUG |
||
179 | // rmstar_printf("(E:tdl "); |
||
180 | #endif |
||
181 | |||
182 | lev = (RMSTAR_level_des *)level_table[proc_table[p].task_level]; |
||
183 | |||
184 | switch (proc_table[p].status) { |
||
185 | case RMSTAR_IDLE: |
||
186 | #ifdef RMSTAR_DEBUG |
||
187 | // rmstar_printf2("I%d",p); |
||
188 | #endif |
||
189 | /* set the request time */ |
||
1123 | pj | 190 | RMSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready)); |
1089 | pj | 191 | |
192 | event_need_reschedule(); |
||
193 | break; |
||
194 | |||
195 | default: |
||
196 | #ifdef RMSTAR_DEBUG |
||
197 | // rmstar_printf2("D%d",p); |
||
198 | #endif |
||
199 | /* else, a deadline miss occurred!!! */ |
||
200 | lev->dline_miss[p]++; |
||
201 | |||
202 | /* the task is into another state */ |
||
203 | lev->nact[p]++; |
||
204 | |||
205 | /* Set the deadline timer */ |
||
206 | ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]); |
||
207 | } |
||
208 | |||
209 | /* Set the deadline timer */ |
||
210 | lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
||
211 | RMSTAR_timer_deadline, |
||
212 | (void *)p); |
||
213 | |||
214 | #ifdef RMSTAR_DEBUG |
||
215 | // rmstar_printf(")"); |
||
216 | #endif |
||
217 | } |
||
218 | |||
219 | static void RMSTAR_timer_guest_deadline(void *par) |
||
220 | { |
||
221 | PID p = (PID) par; |
||
222 | |||
223 | #ifdef RMSTAR_DEBUG |
||
224 | rmstar_printf("(E:gdl)"); |
||
225 | #endif |
||
226 | |||
227 | kern_raise(XDEADLINE_MISS,p); |
||
228 | } |
||
229 | |||
1123 | pj | 230 | static int RMSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
1089 | pj | 231 | { |
232 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
233 | |||
234 | /* if the RMSTAR_task_create is called, then the pclass must be a |
||
235 | valid pclass. */ |
||
1123 | pj | 236 | HARD_TASK_MODEL *h; |
1089 | pj | 237 | |
1123 | pj | 238 | if (m->pclass != HARD_PCLASS) return -1; |
239 | if (m->level != 0 && m->level != l) return -1; |
||
240 | h = (HARD_TASK_MODEL *)m; |
||
241 | if (!h->wcet || !h->mit || h->periodicity != PERIODIC) return -1; |
||
242 | /* now we know that m is a valid model */ |
||
243 | |||
1089 | pj | 244 | #ifdef RMSTAR_DEBUG |
245 | rmstar_printf("(E:tcr)"); |
||
246 | #endif |
||
247 | |||
248 | lev->period[p] = h->mit; |
||
249 | *iq_query_priority(p, &lev->ready) = h->mit; |
||
250 | |||
251 | lev->flag[p] = 0; |
||
252 | lev->deadline_timer[p] = -1; |
||
253 | lev->dline_miss[p] = 0; |
||
254 | lev->wcet_miss[p] = 0; |
||
255 | lev->nact[p] = 0; |
||
256 | |||
257 | /* Enable wcet check */ |
||
258 | proc_table[p].avail_time = h->wcet; |
||
259 | proc_table[p].wcet = h->wcet; |
||
260 | proc_table[p].control |= CONTROL_CAP; |
||
261 | |||
262 | return 0; /* OK, also if the task cannot be guaranteed... */ |
||
263 | } |
||
264 | |||
1123 | pj | 265 | static void RMSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
1089 | pj | 266 | { |
267 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
268 | |||
269 | #ifdef RMSTAR_DEBUG |
||
270 | rmstar_printf("(E:dis)"); |
||
271 | |||
272 | rmstar_printf3("(%d %d)", |
||
273 | iq_query_timespec(p, &lev->ready)->tv_nsec/1000000, |
||
274 | schedule_time.tv_nsec/1000000); |
||
275 | #endif |
||
276 | |||
277 | level_table[ lev->scheduling_level ]-> |
||
1123 | pj | 278 | private_dispatch(lev->scheduling_level,p,nostop); |
1089 | pj | 279 | } |
280 | |||
1123 | pj | 281 | static void RMSTAR_public_epilogue(LEVEL l, PID p) |
1089 | pj | 282 | { |
283 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
284 | |||
285 | #ifdef RMSTAR_DEBUG |
||
286 | rmstar_printf("(E:epi "); |
||
287 | #endif |
||
288 | |||
289 | /* check if the wcet is finished... */ |
||
290 | if (proc_table[p].avail_time <= 0 && proc_table[p].control&CONTROL_CAP) { |
||
291 | /* wcet finished: disable wcet event and count wcet miss */ |
||
292 | #ifdef RMSTAR_DEBUG |
||
293 | rmstar_printf2("W%d",p); |
||
294 | #endif |
||
295 | proc_table[p].control &= ~CONTROL_CAP; |
||
296 | lev->wcet_miss[p]++; |
||
297 | } |
||
298 | #ifdef RMSTAR_DEBUG |
||
299 | rmstar_printf(")"); |
||
300 | #endif |
||
301 | |||
302 | level_table[ lev->scheduling_level ]-> |
||
1123 | pj | 303 | private_epilogue(lev->scheduling_level,p); |
1089 | pj | 304 | |
305 | proc_table[p].status = RMSTAR_READY; |
||
306 | } |
||
307 | |||
1123 | pj | 308 | static void RMSTAR_public_activate(LEVEL l, PID p) |
1089 | pj | 309 | { |
310 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 311 | struct timespec t; |
1089 | pj | 312 | |
313 | #ifdef RMSTAR_DEBUG |
||
314 | rmstar_printf("(E:act)"); |
||
315 | #endif |
||
316 | |||
317 | /* Test if we are trying to activate a non sleeping task */ |
||
318 | /* save activation (only if needed... */ |
||
319 | if (proc_table[p].status != SLEEP) { |
||
320 | /* a periodic task cannot be activated when it is already active */ |
||
321 | kern_raise(XACTIVATION,p); |
||
322 | return; |
||
323 | } |
||
324 | |||
1123 | pj | 325 | kern_gettime(&t); |
1089 | pj | 326 | |
1123 | pj | 327 | RMSTAR_internal_activate(lev,p, &t); |
1089 | pj | 328 | |
329 | /* Set the deadline timer */ |
||
330 | lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
||
331 | RMSTAR_timer_deadline, |
||
332 | (void *)p); |
||
333 | |||
334 | } |
||
335 | |||
1123 | pj | 336 | static void RMSTAR_public_unblock(LEVEL l, PID p) |
1089 | pj | 337 | { |
338 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
339 | |||
340 | #ifdef RMSTAR_DEBUG |
||
341 | rmstar_printf("(E:ins)"); |
||
342 | #endif |
||
343 | |||
344 | /* Insert task in the correct position */ |
||
345 | proc_table[p].status = RMSTAR_READY; |
||
346 | iq_priority_insert(p,&lev->ready); |
||
347 | |||
348 | /* and check for preemption! */ |
||
349 | RMSTAR_check_preemption(lev); |
||
350 | } |
||
351 | |||
1123 | pj | 352 | static void RMSTAR_public_block(LEVEL l, PID p) |
1089 | pj | 353 | { |
354 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
355 | |||
356 | #ifdef RMSTAR_DEBUG |
||
357 | rmstar_printf("(E:ext)"); |
||
358 | #endif |
||
359 | |||
360 | /* the task is blocked on a synchronization primitive. we have to |
||
361 | remove it from the master module -and- from the local queue! */ |
||
362 | iq_extract(p,&lev->ready); |
||
363 | |||
364 | /* and finally, a preemption check! (it will also call guest_end) */ |
||
365 | RMSTAR_check_preemption(lev); |
||
366 | } |
||
367 | |||
1123 | pj | 368 | static int RMSTAR_public_message(LEVEL l, PID p, void *m) |
1089 | pj | 369 | { |
370 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
371 | struct timespec temp; |
||
372 | |||
373 | #ifdef RMSTAR_DEBUG |
||
374 | rmstar_printf("(E:ecy "); |
||
375 | #endif |
||
376 | |||
377 | /* we call guest_end directly here because the same task may |
||
378 | be reinserted in the queue before calling the preemption check! */ |
||
379 | level_table[ lev->scheduling_level ]-> |
||
1123 | pj | 380 | private_extract(lev->scheduling_level,p); lev->activated = NIL; |
1089 | pj | 381 | |
382 | iq_extract(p,&lev->ready); |
||
383 | |||
384 | /* we reset the capacity counters... */ |
||
385 | proc_table[p].avail_time = proc_table[p].wcet; |
||
386 | |||
387 | if (lev->nact[p] > 0) { |
||
388 | #ifdef RMSTAR_DEBUG |
||
389 | rmstar_printf2("E%d",p); |
||
390 | #endif |
||
391 | |||
392 | /* Pending activation: reactivate the thread!!! */ |
||
393 | lev->nact[p]--; |
||
394 | |||
395 | /* see also RMSTAR_timer_deadline */ |
||
1123 | pj | 396 | kern_gettime(&temp); |
1089 | pj | 397 | |
1123 | pj | 398 | RMSTAR_internal_activate(lev,p,&temp); |
1089 | pj | 399 | |
400 | /* check if the deadline has already expired */ |
||
401 | temp = *iq_query_timespec(p, &lev->ready); |
||
402 | if (TIMESPEC_A_LT_B(&temp, &schedule_time)) { |
||
403 | /* count the deadline miss */ |
||
404 | lev->dline_miss[p]++; |
||
1123 | pj | 405 | kern_event_delete(lev->deadline_timer[p]); |
1089 | pj | 406 | } |
407 | |||
408 | } |
||
409 | else { |
||
410 | #ifdef RMSTAR_DEBUG |
||
411 | rmstar_printf("e%d",p); |
||
412 | #endif |
||
413 | |||
414 | /* the task has terminated his job before it consume the wcet. All OK! */ |
||
415 | proc_table[p].status = RMSTAR_IDLE; |
||
416 | |||
417 | /* and finally, a preemption check! */ |
||
418 | RMSTAR_check_preemption(lev); |
||
419 | |||
420 | /* when the deadline timer fire, it recognize the situation and set |
||
1123 | pj | 421 | correctly all the stuffs (like reactivation, etc... ) */ |
1089 | pj | 422 | } |
423 | #ifdef RMSTAR_DEBUG |
||
424 | rmstar_printf(")"); |
||
425 | #endif |
||
1123 | pj | 426 | |
427 | jet_update_endcycle(); /* Update the Jet data... */ |
||
428 | trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
||
429 | |||
430 | return 0; |
||
1089 | pj | 431 | } |
432 | |||
1123 | pj | 433 | static void RMSTAR_public_end(LEVEL l, PID p) |
1089 | pj | 434 | { |
435 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
436 | |||
437 | #ifdef RMSTAR_DEBUG |
||
438 | rmstar_printf("(E:end)"); |
||
439 | #endif |
||
440 | |||
441 | iq_extract(p,&lev->ready); |
||
442 | |||
443 | /* we finally put the task in the ready queue */ |
||
444 | proc_table[p].status = FREE; |
||
445 | |||
1116 | pj | 446 | iq_insertfirst(p,&freedesc); |
1089 | pj | 447 | |
448 | if (lev->deadline_timer[p] != -1) { |
||
1123 | pj | 449 | kern_event_delete(lev->deadline_timer[p]); |
1089 | pj | 450 | } |
451 | |||
452 | /* and finally, a preemption check! (it will also call guest_end) */ |
||
453 | RMSTAR_check_preemption(lev); |
||
454 | } |
||
455 | |||
456 | |||
457 | /* Guest Functions |
||
458 | These functions manages a JOB_TASK_MODEL, that is used to put |
||
459 | a guest task in the RMSTAR ready queue. */ |
||
460 | |||
1123 | pj | 461 | static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m) |
1089 | pj | 462 | { |
463 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 464 | JOB_TASK_MODEL *job; |
1089 | pj | 465 | |
1123 | pj | 466 | if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) { |
467 | kern_raise(XINVALID_TASK, p); |
||
468 | return; |
||
469 | } |
||
1089 | pj | 470 | |
1123 | pj | 471 | job = (JOB_TASK_MODEL *)m; |
472 | |||
1089 | pj | 473 | *iq_query_timespec(p, &lev->ready) = job->deadline; |
474 | |||
475 | lev->deadline_timer[p] = -1; |
||
476 | lev->dline_miss[p] = 0; |
||
477 | lev->wcet_miss[p] = 0; |
||
478 | lev->nact[p] = 0; |
||
479 | |||
480 | if (job->noraiseexc) |
||
481 | lev->flag[p] = RMSTAR_FLAG_NORAISEEXC; |
||
1123 | pj | 482 | else { |
1089 | pj | 483 | lev->flag[p] = 0; |
1123 | pj | 484 | lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready), |
485 | RMSTAR_timer_guest_deadline, |
||
486 | (void *)p); |
||
487 | } |
||
1089 | pj | 488 | |
489 | lev->period[p] = job->period; |
||
490 | *iq_query_priority(p, &lev->ready) = job->period; |
||
491 | |||
492 | /* there is no bandwidth guarantee at this level, it is performed |
||
493 | by the level that inserts guest tasks... */ |
||
494 | |||
495 | /* Insert task in the correct position */ |
||
496 | iq_priority_insert(p,&lev->ready); |
||
497 | proc_table[p].status = RMSTAR_READY; |
||
498 | |||
499 | /* check for preemption */ |
||
500 | RMSTAR_check_preemption(lev); |
||
501 | } |
||
502 | |||
1123 | pj | 503 | static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop) |
1089 | pj | 504 | { |
505 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
506 | |||
1123 | pj | 507 | level_table[ lev->scheduling_level ]-> |
508 | private_dispatch(lev->scheduling_level,p,nostop); |
||
1089 | pj | 509 | } |
510 | |||
1123 | pj | 511 | static void RMSTAR_private_epilogue(LEVEL l, PID p) |
1089 | pj | 512 | { |
513 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
514 | |||
1123 | pj | 515 | /* the task has been preempted. it returns into the ready queue... */ |
516 | level_table[ lev->scheduling_level ]-> |
||
517 | private_epilogue(lev->scheduling_level,p); |
||
1089 | pj | 518 | |
1123 | pj | 519 | proc_table[p].status = RMSTAR_READY; |
1089 | pj | 520 | } |
521 | |||
1123 | pj | 522 | static void RMSTAR_private_extract(LEVEL l, PID p) |
1089 | pj | 523 | { |
524 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
525 | |||
526 | #ifdef RMSTAR_DEBUG |
||
527 | //kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
||
528 | #endif |
||
529 | |||
530 | iq_extract(p, &lev->ready); |
||
531 | |||
532 | /* we remove the deadline timer, because the slice is finished */ |
||
533 | if (lev->deadline_timer[p] != NIL) { |
||
534 | #ifdef RMSTAR_DEBUG |
||
535 | // kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
||
536 | #endif |
||
1123 | pj | 537 | kern_event_delete(lev->deadline_timer[p]); |
1089 | pj | 538 | lev->deadline_timer[p] = NIL; |
539 | } |
||
540 | |||
541 | /* and finally, a preemption check! (it will also call guest_end() */ |
||
542 | RMSTAR_check_preemption(lev); |
||
543 | } |
||
544 | |||
545 | /* Registration functions */ |
||
546 | |||
547 | /* Registration function: |
||
548 | int flags the init flags ... see RMSTAR.h */ |
||
549 | LEVEL RMSTAR_register_level(int budget, int master) |
||
550 | { |
||
551 | LEVEL l; /* the level that we register */ |
||
552 | RMSTAR_level_des *lev; /* for readableness only */ |
||
553 | PID i; /* a counter */ |
||
554 | |||
555 | #ifdef RMSTAR_DEBUG |
||
556 | printk("RMSTAR_register_level\n"); |
||
557 | #endif |
||
558 | |||
559 | /* request an entry in the level_table */ |
||
1123 | pj | 560 | l = level_alloc_descriptor(sizeof(RMSTAR_level_des)); |
1089 | pj | 561 | |
1123 | pj | 562 | lev = (RMSTAR_level_des *)level_table[l]; |
1089 | pj | 563 | |
564 | printk(" lev=%d\n",(int)lev); |
||
565 | |||
566 | /* fill the standard descriptor */ |
||
1123 | pj | 567 | lev->l.private_insert = RMSTAR_private_insert; |
568 | lev->l.private_extract = RMSTAR_private_extract; |
||
569 | lev->l.private_dispatch = RMSTAR_private_dispatch; |
||
570 | lev->l.private_epilogue = RMSTAR_private_epilogue; |
||
1089 | pj | 571 | |
1123 | pj | 572 | lev->l.public_guarantee = NULL; |
573 | lev->l.public_create = RMSTAR_public_create; |
||
574 | lev->l.public_end = RMSTAR_public_end; |
||
575 | lev->l.public_dispatch = RMSTAR_public_dispatch; |
||
576 | lev->l.public_epilogue = RMSTAR_public_epilogue; |
||
577 | lev->l.public_activate = RMSTAR_public_activate; |
||
578 | lev->l.public_unblock = RMSTAR_public_unblock; |
||
579 | lev->l.public_block = RMSTAR_public_block; |
||
580 | lev->l.public_message = RMSTAR_public_message; |
||
1089 | pj | 581 | |
582 | /* fill the RMSTAR descriptor part */ |
||
583 | for(i=0; i<MAX_PROC; i++) { |
||
584 | lev->period[i] = 0; |
||
585 | lev->deadline_timer[i] = -1; |
||
586 | lev->flag[i] = 0; |
||
587 | lev->dline_miss[i] = 0; |
||
588 | lev->wcet_miss[i] = 0; |
||
589 | lev->nact[i] = 0; |
||
590 | } |
||
591 | |||
592 | iq_init(&lev->ready, NULL, 0); |
||
593 | lev->activated = NIL; |
||
594 | |||
595 | lev->budget = budget; |
||
596 | lev->scheduling_level = master; |
||
597 | |||
598 | return l; |
||
599 | } |
||
600 | |||
601 | int RMSTAR_get_dline_miss(PID p) |
||
602 | { |
||
603 | LEVEL l = proc_table[p].task_level; |
||
604 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 605 | |
606 | return lev->dline_miss[p]; |
||
1089 | pj | 607 | } |
608 | |||
609 | int RMSTAR_get_wcet_miss(PID p) |
||
610 | { |
||
611 | LEVEL l = proc_table[p].task_level; |
||
612 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 613 | |
614 | return lev->wcet_miss[p]; |
||
1089 | pj | 615 | } |
616 | |||
617 | int RMSTAR_get_nact(PID p) |
||
618 | { |
||
619 | LEVEL l = proc_table[p].task_level; |
||
620 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 621 | |
622 | return lev->nact[p]; |
||
1089 | pj | 623 | } |
624 | |||
625 | int RMSTAR_reset_dline_miss(PID p) |
||
626 | { |
||
627 | LEVEL l = proc_table[p].task_level; |
||
628 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 629 | |
630 | lev->dline_miss[p] = 0; |
||
631 | return 0; |
||
1089 | pj | 632 | } |
633 | |||
634 | int RMSTAR_reset_wcet_miss(PID p) |
||
635 | { |
||
636 | LEVEL l = proc_table[p].task_level; |
||
637 | RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]); |
||
1123 | pj | 638 | |
639 | lev->wcet_miss[p] = 0; |
||
640 | return 0; |
||
1089 | pj | 641 | } |
642 |