Rev 835 | Rev 838 | 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 | * Trimarchi Michael <trimarchi@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) 2000 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 WARR2ANTY; without even the implied waRR2anty 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 | |||
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 "posixstar.h" |
||
808 | trimarchi | 46 | #include "fsf_contract.h" |
241 | giacomo | 47 | #include "fsf_server.h" |
221 | giacomo | 48 | |
822 | trimarchi | 49 | //#define POSIXSTAR_DEBUG |
221 | giacomo | 50 | |
51 | /*+ Status used in the level +*/ |
||
52 | #define POSIXSTAR_READY MODULE_STATUS_BASE |
||
53 | |||
54 | #define POSIXSTAR_CHANGE_LEVEL 1 |
||
55 | |||
815 | trimarchi | 56 | /* flags */ |
57 | #define POSIXSTAR_FLAG_NOPREEMPT 4 |
||
58 | |||
221 | giacomo | 59 | /*+ the level redefinition for the Round Robin level +*/ |
60 | typedef struct { |
||
61 | level_des l; /*+ the standard level descriptor +*/ |
||
62 | |||
63 | int nact[MAX_PROC]; /*+ number of pending activations +*/ |
||
64 | |||
65 | int priority[MAX_PROC]; /*+ priority of each task +*/ |
||
66 | |||
67 | IQUEUE *ready; /*+ the ready queue array +*/ |
||
68 | |||
69 | int slice; /*+ the level's time slice +*/ |
||
70 | |||
71 | int maxpriority; /*+ the priority are from 0 to maxpriority |
||
72 | (i.e 0 to 31) +*/ |
||
73 | |||
74 | int yielding; /*+ equal to 1 when a sched_yield is called +*/ |
||
75 | |||
76 | int budget[MAX_PROC]; |
||
77 | |||
815 | trimarchi | 78 | int flag[MAX_PROC]; |
79 | |||
221 | giacomo | 80 | PID activated; |
81 | int scheduling_level; |
||
296 | trimarchi | 82 | int cap_lev; |
83 | struct timespec cap_lasttime; |
||
221 | giacomo | 84 | |
85 | } POSIXSTAR_level_des; |
||
86 | |||
296 | trimarchi | 87 | static void capacity_handler(void *l) |
88 | { |
||
89 | POSIXSTAR_level_des *lev = l; |
||
90 | lev->cap_lev = NIL; |
||
91 | event_need_reschedule(); |
||
92 | } |
||
221 | giacomo | 93 | /* the private scheduler choice a task and insert in cbsstar module */ |
94 | /* This is not efficient but very fair :-) |
||
95 | The need of all this stuff is because if a task execute a long time |
||
96 | due to (shadow!) priority inheritance, then the task shall go to the |
||
97 | tail of the queue many times... */ |
||
98 | |||
99 | static void POSIXSTAR_private_scheduler(POSIXSTAR_level_des * lev) |
||
100 | { |
||
101 | /* the old posix scheduler select the private job for CBS */ |
||
102 | PID p = NIL; |
||
103 | |||
104 | int prio; |
||
105 | |||
815 | trimarchi | 106 | |
221 | giacomo | 107 | prio = lev->maxpriority; |
108 | |||
109 | for (;;) { |
||
110 | p = iq_query_first(&lev->ready[prio]); |
||
111 | if (p == NIL) { |
||
112 | if (prio) { |
||
113 | prio--; |
||
114 | continue; |
||
115 | } |
||
116 | else { |
||
117 | p=NIL; |
||
118 | break; |
||
119 | } |
||
120 | } |
||
121 | |||
393 | giacomo | 122 | if (proc_table[p].avail_time <= 0) { |
298 | giacomo | 123 | while (proc_table[p].avail_time<=0) |
221 | giacomo | 124 | proc_table[p].avail_time += proc_table[p].wcet; |
125 | iq_extract(p,&lev->ready[prio]); |
||
126 | iq_insertlast(p,&lev->ready[prio]); |
||
127 | } |
||
128 | else { |
||
129 | break; |
||
130 | } |
||
131 | } |
||
828 | trimarchi | 132 | |
133 | /* check if the task is preempteble or not */ |
||
835 | trimarchi | 134 | if (lev->activated != NIL && (lev->flag[lev->activated] & POSIXSTAR_FLAG_NOPREEMPT)) return; |
828 | trimarchi | 135 | |
221 | giacomo | 136 | if (p!=lev->activated) { |
137 | if (lev->activated != NIL ) { |
||
138 | level_table[ lev->scheduling_level ]-> |
||
139 | private_extract(lev->scheduling_level, lev->activated); |
||
140 | } |
||
141 | lev->activated = p; |
||
142 | |||
143 | if (p != NIL) { |
||
144 | BUDGET_TASK_MODEL b; |
||
145 | budget_task_default_model(b, lev->budget[p]); |
||
146 | #ifdef POSIXSTAR_DEBUG |
||
147 | kern_printf("(PS:SchAct:%d:%d)",p,lev->budget[p]); |
||
148 | #endif |
||
149 | level_table[ lev->scheduling_level ]-> |
||
150 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | static int POSIXSTAR_public_eligible(LEVEL l, PID p) |
||
156 | { |
||
157 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
296 | trimarchi | 158 | return level_table[ lev->scheduling_level ]-> |
221 | giacomo | 159 | private_eligible(lev->scheduling_level,p); |
296 | trimarchi | 160 | |
221 | giacomo | 161 | return 0; |
162 | } |
||
163 | |||
296 | trimarchi | 164 | |
165 | static void POSIXSTAR_account_capacity(POSIXSTAR_level_des *lev, PID p) |
||
166 | { |
||
393 | giacomo | 167 | struct timespec ty; |
168 | TIME tx; |
||
296 | trimarchi | 169 | |
393 | giacomo | 170 | SUBTIMESPEC(&schedule_time, &lev->cap_lasttime, &ty); |
171 | tx = TIMESPEC2USEC(&ty); |
||
296 | trimarchi | 172 | |
393 | giacomo | 173 | proc_table[p].avail_time -= tx; |
296 | trimarchi | 174 | |
175 | } |
||
176 | |||
221 | giacomo | 177 | static int POSIXSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
178 | { |
||
179 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
180 | NRT_TASK_MODEL *nrt; |
||
181 | |||
182 | /* DEBUG */ |
||
183 | #ifdef POSIXSTAR_DEBUG |
||
184 | kern_printf("(PS:Crt:%d)",p); |
||
185 | #endif |
||
186 | |||
187 | if (m->pclass != NRT_PCLASS) return -1; |
||
188 | if (m->level != 0 && m->level != l) return -1; |
||
189 | |||
190 | nrt = (NRT_TASK_MODEL *)m; |
||
191 | |||
192 | /* the task state is set at SLEEP by the general task_create */ |
||
193 | |||
194 | /* I used the wcet field because using wcet can account if a task |
||
195 | consume more than the timeslice... */ |
||
196 | |||
197 | if (nrt->inherit == NRT_INHERIT_SCHED && |
||
198 | proc_table[exec_shadow].task_level == l) { |
||
199 | /* We inherit the scheduling properties if the scheduling level |
||
200 | *is* the same */ |
||
201 | lev->priority[p] = lev->priority[exec_shadow]; |
||
202 | |||
203 | proc_table[p].avail_time = proc_table[exec_shadow].avail_time; |
||
204 | proc_table[p].wcet = proc_table[exec_shadow].wcet; |
||
205 | |||
206 | lev->nact[p] = (lev->nact[exec_shadow] == -1) ? -1 : 0; |
||
207 | } |
||
208 | else { |
||
209 | if (nrt->weight<=lev->maxpriority) |
||
210 | lev->priority[p] = nrt->weight; |
||
211 | else lev->priority[p]=lev->maxpriority; |
||
212 | |||
213 | if (nrt->slice) { |
||
214 | proc_table[p].avail_time = nrt->slice; |
||
215 | proc_table[p].wcet = nrt->slice; |
||
216 | } |
||
217 | else { |
||
218 | proc_table[p].avail_time = lev->slice; |
||
219 | proc_table[p].wcet = lev->slice; |
||
220 | } |
||
815 | trimarchi | 221 | |
392 | trimarchi | 222 | #if defined POSIXSTAR_DEBUG |
223 | kern_printf("(slice %d)", proc_table[p].wcet); |
||
224 | #endif |
||
221 | giacomo | 225 | if (nrt->arrivals == SAVE_ARRIVALS) |
226 | lev->nact[p] = 0; |
||
227 | else |
||
228 | lev->nact[p] = -1; |
||
229 | |||
230 | } |
||
231 | |||
834 | trimarchi | 232 | lev->flag[p] = 0; |
393 | giacomo | 233 | proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP); |
234 | |||
235 | return 0; |
||
236 | |||
221 | giacomo | 237 | } |
238 | |||
239 | static void POSIXSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
||
240 | { |
||
241 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
296 | trimarchi | 242 | struct timespec ty; |
221 | giacomo | 243 | /* the task state is set EXE by the scheduler() |
244 | we extract the task from the ready queue |
||
245 | NB: we can't assume that p is the first task in the queue!!! */ |
||
246 | |||
247 | #ifdef POSIXSTAR_DEBUG |
||
296 | trimarchi | 248 | if( !nostop) kern_printf("(PS:Dsp:%d)",p); else |
249 | kern_printf("(PS:Dsp_shad:%d)",p); |
||
221 | giacomo | 250 | #endif |
383 | trimarchi | 251 | |
384 | trimarchi | 252 | if (!nostop || proc_table[exec].task_level==l) { |
253 | TIMESPEC_ASSIGN(&ty, &schedule_time); |
||
254 | TIMESPEC_ASSIGN(&lev->cap_lasttime, &schedule_time); |
||
383 | trimarchi | 255 | |
256 | /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume |
||
257 | * capacity on exe task always */ |
||
392 | trimarchi | 258 | ADDUSEC2TIMESPEC(proc_table[exec].avail_time, &ty); |
384 | trimarchi | 259 | |
260 | lev->cap_lev = kern_event_post(&ty,capacity_handler, lev); |
||
221 | giacomo | 261 | level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop); |
296 | trimarchi | 262 | } |
263 | else |
||
384 | trimarchi | 264 | level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop); |
265 | |||
221 | giacomo | 266 | } |
267 | |||
226 | giacomo | 268 | static void POSIXSTAR_public_epilogue(LEVEL l, PID p) |
269 | { |
||
270 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
402 | giacomo | 271 | |
226 | giacomo | 272 | #ifdef POSIXSTAR_DEBUG |
273 | kern_printf("(PS:Epi:%d)",p); |
||
274 | #endif |
||
275 | |||
296 | trimarchi | 276 | if (lev->cap_lev!=NIL) { |
393 | giacomo | 277 | kern_event_delete(lev->cap_lev); |
278 | lev->cap_lev=NIL; |
||
296 | trimarchi | 279 | } |
280 | |||
393 | giacomo | 281 | if (proc_table[exec].task_level==l ) { |
282 | |||
828 | trimarchi | 283 | POSIXSTAR_account_capacity(lev,exec); |
221 | giacomo | 284 | |
393 | giacomo | 285 | if (lev->yielding) { |
286 | lev->yielding = 0; |
||
287 | iq_extract(p,&lev->ready[lev->priority[exec]]); |
||
288 | iq_insertlast(p,&lev->ready[lev->priority[exec]]); |
||
402 | giacomo | 289 | } else { |
290 | |||
291 | if (proc_table[exec].avail_time <= 0) { |
||
292 | |||
293 | POSIXSTAR_private_scheduler(lev); |
||
294 | |||
836 | trimarchi | 295 | if (exec==lev->activated) { |
402 | giacomo | 296 | level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p); |
297 | } |
||
298 | |||
299 | } else { |
||
300 | |||
301 | level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p); |
||
302 | |||
303 | } |
||
304 | |||
393 | giacomo | 305 | } |
306 | |||
402 | giacomo | 307 | proc_table[exec].status = POSIXSTAR_READY; |
221 | giacomo | 308 | |
402 | giacomo | 309 | } else { |
310 | |||
311 | level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p); |
||
312 | |||
313 | } |
||
314 | |||
221 | giacomo | 315 | } |
316 | |||
317 | static void POSIXSTAR_internal_activate(POSIXSTAR_level_des *lev, PID p) |
||
318 | { |
||
319 | |||
320 | /* Insert task in the correct position */ |
||
321 | proc_table[p].status = POSIXSTAR_READY; |
||
322 | iq_insertlast(p,&lev->ready[lev->priority[p]]); |
||
323 | |||
324 | } |
||
325 | |||
326 | |||
783 | giacomo | 327 | static void POSIXSTAR_public_activate(LEVEL l, PID p, struct timespec *t) |
221 | giacomo | 328 | { |
329 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
330 | |||
331 | /* Test if we are trying to activate a non sleeping task */ |
||
332 | /* save activation (only if needed...) */ |
||
333 | if (proc_table[p].status != SLEEP) { |
||
334 | if (lev->nact[p] != -1) |
||
335 | lev->nact[p]++; |
||
336 | return; |
||
337 | } |
||
338 | |||
339 | #ifdef POSIXSTAR_DEBUG |
||
340 | kern_printf("(PS:Act:%d)",p); |
||
341 | #endif |
||
342 | |||
343 | POSIXSTAR_internal_activate(lev, p); |
||
344 | POSIXSTAR_private_scheduler(lev); |
||
345 | |||
346 | } |
||
347 | |||
348 | |||
349 | static void POSIXSTAR_public_unblock(LEVEL l, PID p) |
||
350 | { |
||
351 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
352 | |||
353 | /* Similar to POSIX_task_activate, but we don't check in what state |
||
354 | the task is */ |
||
355 | |||
356 | #ifdef POSIXSTAR_DEBUG |
||
357 | kern_printf("(PS:UnBlk:%d)",p); |
||
358 | #endif |
||
359 | /* Insert task in the coPOSIXect position */ |
||
360 | proc_table[p].status = POSIXSTAR_READY; |
||
361 | iq_insertlast(p,&lev->ready[lev->priority[p]]); |
||
362 | POSIXSTAR_private_scheduler(lev); |
||
363 | |||
364 | } |
||
365 | |||
366 | static void POSIXSTAR_public_block(LEVEL l, PID p) |
||
367 | { |
||
368 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
369 | |||
370 | /* Extract the running task from the level |
||
371 | . we have already extract it from the ready queue at the dispatch time. |
||
372 | . the capacity event have to be removed by the generic kernel |
||
373 | . the wcet don't need modification... |
||
374 | . the state of the task is set by the calling function |
||
375 | |||
376 | So, we do nothing!!! |
||
377 | */ |
||
378 | |||
379 | #ifdef POSIXSTAR_DEBUG |
||
380 | kern_printf("(PS:Blk:%d)", p); |
||
381 | #endif |
||
382 | |||
383 | iq_extract(p,&lev->ready[lev->priority[p]]); |
||
384 | POSIXSTAR_private_scheduler(lev); |
||
385 | |||
386 | } |
||
387 | |||
388 | static int POSIXSTAR_public_message(LEVEL l, PID p, void *m) |
||
389 | { |
||
390 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
391 | |||
392 | #ifdef POSIXSTAR_DEBUG |
||
393 | kern_printf("(PS:Msg:%d)",p); |
||
394 | #endif |
||
395 | |||
396 | switch ((long)(m)) { |
||
397 | |||
398 | /* Task EndCycle */ |
||
399 | case (long)(NULL): |
||
400 | |||
401 | if (lev->nact[p] > 0) { |
||
402 | /* continue!!!! */ |
||
403 | lev->nact[p]--; |
||
404 | iq_extract(p,&lev->ready[lev->priority[p]]); |
||
405 | iq_insertfirst(p,&lev->ready[lev->priority[p]]); |
||
406 | proc_table[p].status = POSIXSTAR_READY; |
||
407 | } |
||
408 | else { |
||
409 | proc_table[p].status = SLEEP; |
||
410 | iq_extract(p,&lev->ready[lev->priority[p]]); |
||
411 | } |
||
412 | |||
413 | jet_update_endcycle(); /* Update the Jet data... */ |
||
414 | POSIXSTAR_private_scheduler(lev); |
||
415 | |||
416 | break; |
||
417 | |||
418 | /* Task Disable */ |
||
419 | case (long)(1): |
||
420 | |||
421 | break; |
||
422 | |||
423 | default: |
||
424 | |||
241 | giacomo | 425 | break; |
221 | giacomo | 426 | |
427 | } |
||
428 | |||
429 | return 0; |
||
430 | |||
431 | } |
||
432 | |||
433 | static void POSIXSTAR_public_end(LEVEL l, PID p) |
||
434 | { |
||
435 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
436 | |||
437 | #ifdef POSIXSTAR_DEBUG |
||
438 | kern_printf("(PS:End:%d)", p); |
||
439 | #endif |
||
440 | |||
441 | lev->nact[p] = -1; |
||
348 | trimarchi | 442 | /* extract task from the queue */ |
443 | iq_extract(p,&lev->ready[lev->priority[p]]); |
||
221 | giacomo | 444 | |
445 | /* then, we insert the task in the free queue */ |
||
446 | proc_table[p].status = FREE; |
||
447 | iq_priority_insert(p,NULL); |
||
448 | POSIXSTAR_private_scheduler(lev); |
||
449 | |||
450 | } |
||
451 | |||
452 | /* Registration functions */ |
||
453 | |||
454 | /*+ Registration function: |
||
455 | TIME slice the slice for the Round Robin queue +*/ |
||
456 | LEVEL POSIXSTAR_register_level(int master, TIME slice, |
||
457 | int prioritylevels) |
||
458 | { |
||
459 | LEVEL l; /* the level that we register */ |
||
460 | POSIXSTAR_level_des *lev; /* for readableness only */ |
||
461 | PID i; /* a counter */ |
||
462 | int x; /* a counter */ |
||
463 | |||
464 | #ifdef POSIXSTRA_DEBUG |
||
465 | kern_printf("POSIXSTAR_register_level\n"); |
||
466 | #endif |
||
467 | |||
468 | l = level_alloc_descriptor(sizeof(POSIXSTAR_level_des)); |
||
469 | |||
470 | lev = (POSIXSTAR_level_des *)level_table[l]; |
||
471 | |||
270 | giacomo | 472 | lev->l.public_guarantee = NULL; |
221 | giacomo | 473 | lev->l.public_create = POSIXSTAR_public_create; |
474 | lev->l.public_end = POSIXSTAR_public_end; |
||
475 | lev->l.public_dispatch = POSIXSTAR_public_dispatch; |
||
476 | lev->l.public_epilogue = POSIXSTAR_public_epilogue; |
||
477 | lev->l.public_activate = POSIXSTAR_public_activate; |
||
478 | lev->l.public_unblock = POSIXSTAR_public_unblock; |
||
479 | lev->l.public_block = POSIXSTAR_public_block; |
||
480 | lev->l.public_message = POSIXSTAR_public_message; |
||
481 | lev->l.public_eligible = POSIXSTAR_public_eligible; |
||
482 | |||
483 | /* fill the POSIX descriptor part */ |
||
484 | for (i = 0; i < MAX_PROC; i++) { |
||
485 | lev->nact[i] = -1; |
||
486 | lev->budget[i] = -1; |
||
487 | } |
||
488 | |||
489 | lev->maxpriority = prioritylevels - 1; |
||
490 | |||
491 | lev->ready = (IQUEUE *)kern_alloc(sizeof(IQUEUE) * prioritylevels); |
||
492 | |||
493 | for (x = 0; x < prioritylevels; x++) |
||
494 | iq_init(&lev->ready[x], NULL, 0); |
||
495 | |||
496 | if (slice < POSIXSTAR_MINIMUM_SLICE) slice = POSIXSTAR_MINIMUM_SLICE; |
||
497 | if (slice > POSIXSTAR_MAXIMUM_SLICE) slice = POSIXSTAR_MAXIMUM_SLICE; |
||
498 | lev->slice = slice; |
||
499 | lev->activated = NIL; |
||
500 | lev->scheduling_level = master; |
||
298 | giacomo | 501 | lev->cap_lev = NIL; |
296 | trimarchi | 502 | NULL_TIMESPEC(&lev->cap_lasttime); |
503 | |||
221 | giacomo | 504 | return l; |
505 | |||
506 | } |
||
507 | |||
508 | int POSIXSTAR_setbudget(LEVEL l, PID p, int budget) |
||
509 | { |
||
510 | |||
511 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
512 | |||
513 | lev->budget[p] = budget; |
||
514 | |||
515 | return 0; |
||
516 | |||
517 | } |
||
518 | |||
519 | int POSIXSTAR_getbudget(LEVEL l, PID p) |
||
520 | { |
||
521 | |||
522 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
523 | |||
524 | return lev->budget[p]; |
||
525 | |||
526 | } |
||
527 | |||
528 | int POSIXSTAR_budget_has_thread(LEVEL l, int budget) |
||
529 | { |
||
530 | |||
531 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
532 | int i; |
||
533 | |||
534 | for(i = 0; i< MAX_PROC; i++) |
||
535 | if (lev->budget[i] == budget) return 1; |
||
536 | |||
537 | return 0; |
||
538 | |||
539 | } |
||
540 | |||
541 | /*+ this function forces the running task to go to his queue tail; |
||
542 | (it works only on the POSIX level) +*/ |
||
543 | int POSIXSTAR_sched_yield(LEVEL l) |
||
544 | { |
||
545 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
546 | |||
547 | if (proc_table[exec_shadow].task_level != l) |
||
548 | return -1; |
||
549 | |||
550 | proc_table[exec_shadow].context = kern_context_save(); |
||
551 | lev->yielding = 1; |
||
552 | scheduler(); |
||
553 | kern_context_load(proc_table[exec_shadow].context); |
||
554 | return 0; |
||
555 | } |
||
556 | |||
557 | /*+ this function returns the maximum level allowed for the POSIX level +*/ |
||
558 | int POSIXSTAR_get_priority_max(LEVEL l) |
||
559 | { |
||
560 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
561 | return lev->maxpriority; |
||
562 | } |
||
563 | |||
564 | /*+ this function returns the default timeslice for the POSIX level +*/ |
||
565 | int POSIXSTAR_rr_get_interval(LEVEL l) |
||
566 | { |
||
567 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
568 | return lev->slice; |
||
569 | } |
||
570 | |||
571 | /*+ this functions returns some paramaters of a task; |
||
572 | policy must be NRT_RR_POLICY or NRT_FIFO_POLICY; |
||
573 | priority must be in the range [0..prioritylevels] |
||
574 | returns ENOSYS or ESRCH if there are problems +*/ |
||
575 | int POSIXSTAR_getschedparam(LEVEL l, PID p, int *policy, int *priority) |
||
576 | { |
||
577 | if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
||
578 | return ESRCH; |
||
579 | |||
580 | if (proc_table[p].task_level != l) |
||
581 | return ENOSYS; |
||
582 | |||
393 | giacomo | 583 | *policy = NRT_RR_POLICY; |
221 | giacomo | 584 | *priority = ((POSIXSTAR_level_des *)(level_table[l]))->priority[p]; |
585 | |||
586 | return 0; |
||
587 | } |
||
588 | |||
589 | /*+ this functions sets paramaters of a task +*/ |
||
590 | int POSIXSTAR_setschedparam(LEVEL l, PID p, int policy, int priority) |
||
591 | { |
||
592 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
593 | |||
594 | if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
||
595 | return ESRCH; |
||
596 | |||
597 | if (proc_table[p].task_level != l) |
||
598 | return ENOSYS; |
||
599 | if (lev->priority[p] != priority) { |
||
600 | if (proc_table[p].status == POSIXSTAR_READY) { |
||
601 | iq_extract(p,&lev->ready[lev->priority[p]]); |
||
602 | lev->priority[p] = priority; |
||
603 | iq_insertlast(p,&lev->ready[priority]); |
||
604 | } |
||
605 | else |
||
606 | lev->priority[p] = priority; |
||
607 | } |
||
608 | |||
609 | return 0; |
||
610 | } |
||
611 | |||
815 | trimarchi | 612 | |
613 | void POSIXSTAR_set_nopreemtive_current(LEVEL l) { |
||
614 | |||
615 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
616 | |||
617 | lev->flag[lev->activated]|=POSIXSTAR_FLAG_NOPREEMPT; |
||
618 | } |
||
619 | |||
620 | void POSIXSTAR_unset_nopreemtive_current(LEVEL l) { |
||
621 | |||
622 | POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
||
623 | |||
624 | lev->flag[lev->activated]&=~POSIXSTAR_FLAG_NOPREEMPT; |
||
625 | } |