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