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