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