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