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