Rev 741 | Rev 745 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | 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 | * |
||
737 | anton | 8 | * Authors: |
671 | giacomo | 9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
10 | * Mauro Marinoni |
||
11 | * Anton Cervin |
||
12 | * |
||
13 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
14 | * |
||
15 | * http://www.sssup.it |
||
16 | * http://retis.sssup.it |
||
17 | * http://shark.sssup.it |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
37 | #include <kernel/model.h> |
||
38 | #include <kernel/descr.h> |
||
39 | #include <kernel/var.h> |
||
40 | #include <kernel/func.h> |
||
41 | |||
741 | giacomo | 42 | #include <ll/i386/64bit.h> |
43 | |||
671 | giacomo | 44 | #include <stdlib.h> |
45 | |||
46 | #include <modules/elastic.h> |
||
47 | |||
48 | #include <tracer.h> |
||
49 | |||
707 | anton | 50 | /* Task flags */ |
51 | |||
673 | giacomo | 52 | #define ELASTIC_PRESENT 1 |
707 | anton | 53 | #define ELASTIC_JOB_PRESENT 2 |
671 | giacomo | 54 | |
707 | anton | 55 | /* Task statuses */ |
56 | |||
683 | giacomo | 57 | #define ELASTIC_IDLE APER_STATUS_BASE |
58 | |||
744 | anton | 59 | //#define ELASTIC_DEBUG |
707 | anton | 60 | |
61 | #ifdef ELASTIC_DEBUG |
||
62 | char *pnow() { |
||
63 | static char buf[40]; |
||
64 | struct timespec t; |
||
65 | kern_gettime(&t); |
||
66 | sprintf(buf, "%ld.%06ld", t.tv_sec, t.tv_nsec/1000); |
||
67 | return buf; |
||
68 | } |
||
69 | char *ptime1(struct timespec *t) { |
||
70 | static char buf[40]; |
||
71 | sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000); |
||
72 | return buf; |
||
73 | } |
||
74 | char *ptime2(struct timespec *t) { |
||
75 | static char buf[40]; |
||
76 | sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000); |
||
77 | return buf; |
||
78 | } |
||
79 | #endif |
||
80 | |||
81 | |||
671 | giacomo | 82 | typedef struct { |
83 | |||
697 | anton | 84 | /* Task parameters (set/changed by the user) */ |
85 | |||
86 | TIME Tmin; /* The nominal (minimum) period */ |
||
87 | TIME Tmax; /* The maximum tolerable period */ |
||
88 | TIME C; /* The declared worst-case execution time */ |
||
89 | int E; /* The elasticity coefficient */ |
||
90 | int beta; /* PERIOD_SCALING or WCET_SCALING */ |
||
91 | |||
92 | /* Task variables (changed by the module) */ |
||
93 | |||
707 | anton | 94 | struct timespec release; /* The current activation time */ |
95 | struct timespec dline; /* The current absolute deadline */ |
||
96 | int dltimer; /* Deadline timer handle */ |
||
671 | giacomo | 97 | |
700 | anton | 98 | ext_bandwidth_t Umax; /* The maximum utilization, Umax = C/Tmin */ |
99 | ext_bandwidth_t Umin; /* The minimum utilization, Umin = C/Tmax */ |
||
671 | giacomo | 100 | |
707 | anton | 101 | ext_bandwidth_t U; /* New assigned utilization */ |
102 | ext_bandwidth_t oldU; /* Old utilization */ |
||
103 | TIME T; /* The current period, T = C/U */ |
||
673 | giacomo | 104 | |
671 | giacomo | 105 | int flags; |
106 | |||
107 | } ELASTIC_task_descr; |
||
108 | |||
109 | typedef struct { |
||
110 | level_des l; /*+ the standard level descriptor +*/ |
||
111 | |||
700 | anton | 112 | ext_bandwidth_t U; /*+ the bandwidth reserved for elastic tasks +*/ |
671 | giacomo | 113 | |
741 | giacomo | 114 | int c_scaling_factor; /*+ the computation time scaling factor +*/ |
671 | giacomo | 115 | |
741 | giacomo | 116 | ELASTIC_task_descr *elist; |
117 | |||
671 | giacomo | 118 | LEVEL scheduling_level; |
119 | |||
120 | LEVEL current_level; |
||
121 | |||
122 | int flags; |
||
123 | |||
124 | } ELASTIC_level_des; |
||
125 | |||
673 | giacomo | 126 | |
707 | anton | 127 | static void ELASTIC_activation(ELASTIC_level_des *lev, PID p, |
128 | struct timespec *acttime) |
||
129 | { |
||
130 | JOB_TASK_MODEL job; |
||
131 | ELASTIC_task_descr *et = &lev->elist[p]; |
||
697 | anton | 132 | |
707 | anton | 133 | /* Assign release time */ |
134 | et->release = *acttime; |
||
135 | |||
136 | /* Assign absolute deadline */ |
||
137 | et->dline = *acttime; |
||
138 | ADDUSEC2TIMESPEC(et->T, &et->dline); |
||
139 | |||
140 | #ifdef ELASTIC_DEBUG |
||
141 | cprintf("At %s: activating %s; rel=%s; dl=%s\n", pnow(), proc_table[p].name, |
||
142 | ptime1(&et->release), ptime2(&et->dline)); |
||
143 | #endif |
||
144 | |||
741 | giacomo | 145 | mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].avail_time); |
146 | mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].wcet); |
||
707 | anton | 147 | |
148 | /* Job insertion */ |
||
149 | job_task_default_model(job, et->dline); |
||
150 | level_table[lev->scheduling_level]-> |
||
151 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
||
737 | anton | 152 | et->flags |= ELASTIC_JOB_PRESENT; |
707 | anton | 153 | } |
154 | |||
155 | |||
156 | static void ELASTIC_timer_act(void *arg) { |
||
157 | |||
158 | PID p = (PID)(arg); |
||
159 | ELASTIC_level_des *lev; |
||
160 | |||
161 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
162 | ELASTIC_task_descr *et = &lev->elist[p]; |
||
163 | |||
164 | /* Use the current deadline as the new activation time */ |
||
165 | ELASTIC_activation(lev, p, &et->dline); |
||
166 | |||
167 | event_need_reschedule(); |
||
168 | |||
169 | /* Next activation */ |
||
170 | et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act, (void *)(p)); |
||
171 | } |
||
172 | |||
173 | |||
174 | /* Check feasability and compute new utilizations for the task set */ |
||
175 | |||
697 | anton | 176 | static int ELASTIC_compress(ELASTIC_level_des *lev) { |
177 | |||
676 | giacomo | 178 | PID i; |
707 | anton | 179 | ELASTIC_task_descr *et; |
697 | anton | 180 | int ok; |
181 | |||
182 | ext_bandwidth_t Umin; // minimum utilization |
||
183 | ext_bandwidth_t Umax; // nominal (maximum) utilization of compressable tasks |
||
676 | giacomo | 184 | |
697 | anton | 185 | ext_bandwidth_t Uf; // amount of non-compressable utilization |
186 | int Ev; // sum of elasticity among compressable tasks |
||
187 | |||
707 | anton | 188 | JOB_TASK_MODEL job; |
189 | |||
697 | anton | 190 | Umin = 0; |
191 | Umax = 0; |
||
192 | |||
676 | giacomo | 193 | for (i=0; i<MAX_PROC; i++) { |
707 | anton | 194 | et = &lev->elist[i]; |
195 | if (et->flags & ELASTIC_PRESENT) { |
||
196 | if (et->E == 0) { |
||
197 | Umin += et->U; |
||
198 | Umax += et->U; |
||
697 | anton | 199 | } else { |
707 | anton | 200 | Umin += et->Umin; |
201 | Umax += et->Umax; |
||
202 | et->U = et->Umax; // reset previous saturations (if any) |
||
697 | anton | 203 | } |
691 | anton | 204 | } |
676 | giacomo | 205 | } |
206 | |||
744 | anton | 207 | if (Umin > lev->U) { |
208 | #ifdef ELASTIC_DEBUG |
||
209 | cprintf("ELASTIC_compress: Task set not feasible\n"); |
||
210 | #endif |
||
211 | return -1; // NOT FEASIBLE |
||
212 | } |
||
700 | anton | 213 | |
744 | anton | 214 | if (Umax <= lev->U) { |
215 | #ifdef ELASTIC_DEBUG |
||
216 | cprintf("ELASTIC_compress: Task set feasible with maximum utilizations\n"); |
||
217 | #endif |
||
218 | return 0; // FEASIBLE WITH MAXIMUM UTILIZATIONS |
||
219 | } |
||
220 | |||
697 | anton | 221 | do { |
222 | Uf = 0; |
||
223 | Ev = 0; |
||
224 | Umax = 0; |
||
673 | giacomo | 225 | |
697 | anton | 226 | for (i=0; i<MAX_PROC; i++) { |
707 | anton | 227 | et = &lev->elist[i]; |
228 | if (et->flags & ELASTIC_PRESENT) { |
||
229 | if (et->E == 0 || et->U == et->Umin) { |
||
230 | Uf += et->U; |
||
697 | anton | 231 | } else { |
707 | anton | 232 | Ev += et->E; |
233 | Umax += et->Umax; |
||
697 | anton | 234 | } |
235 | } |
||
236 | } |
||
237 | |||
238 | ok = 1; |
||
239 | |||
240 | for (i=0; i<MAX_PROC; i++) { |
||
707 | anton | 241 | et = &lev->elist[i]; |
242 | if (et->flags & ELASTIC_PRESENT) { |
||
243 | if (et->E > 0 && et->U > et->Umin) { |
||
244 | et->U = et->Umax - (Umax - lev->U + Uf) * et->E / Ev; |
||
245 | if (et->U < et->Umin) { |
||
246 | et->U = et->Umin; |
||
697 | anton | 247 | ok = 0; |
248 | } |
||
249 | } |
||
250 | } |
||
251 | } |
||
673 | giacomo | 252 | |
697 | anton | 253 | } while (ok == 0); |
673 | giacomo | 254 | |
707 | anton | 255 | // Increase periods of compressed tasks IMMEDIATELY. |
256 | // The other ones will be changed at their next activation |
||
257 | |||
258 | for (i=0; i<MAX_PROC; i++) { |
||
259 | et = &lev->elist[i]; |
||
260 | if (et->flags & ELASTIC_PRESENT) { |
||
261 | if (et->U != et->oldU) { |
||
262 | /* Utilization has been changed. Compute new period */ |
||
744 | anton | 263 | // overflow here??? |
264 | //et->T = ((long long)et->C * (long long)lev->c_scaling_factor * (long long)MAX_BANDWIDTH) / (et->U * (long long)SCALING_UNIT); |
||
265 | et->T = ((long long)et->C * (long long)MAX_BANDWIDTH) / (long long)et->U; |
||
707 | anton | 266 | } |
267 | if (et->U < et->oldU) { |
||
268 | /* Task has been compressed. Change its deadline NOW! */ |
||
269 | if (et->flags & ELASTIC_JOB_PRESENT) { |
||
737 | anton | 270 | /* Remove job from level */ |
707 | anton | 271 | level_table[lev->scheduling_level]-> |
272 | private_extract(lev->scheduling_level, i); |
||
273 | } |
||
274 | /* Compute new deadline */ |
||
275 | et->dline = et->release; |
||
276 | ADDUSEC2TIMESPEC(et->T, &et->dline); |
||
277 | if (et->dltimer != -1) { |
||
278 | /* Delete old deadline timer, post new one */ |
||
279 | kern_event_delete(et->dltimer); |
||
280 | et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act,(void *)(i)); |
||
281 | } |
||
282 | if (et->flags & ELASTIC_JOB_PRESENT) { |
||
283 | /* Reinsert job */ |
||
284 | job_task_default_model(job, et->dline); |
||
285 | level_table[lev->scheduling_level]-> |
||
286 | private_insert(lev->scheduling_level, i, (TASK_MODEL *)&job); |
||
287 | } |
||
288 | } |
||
289 | et->oldU = et->U; /* Update oldU */ |
||
290 | } |
||
291 | } |
||
292 | |||
293 | #ifdef ELASTIC_DEBUG |
||
744 | anton | 294 | cprintf("ELASTIC_compress: New periods: "); |
691 | anton | 295 | for (i=0; i<MAX_PROC; i++) { |
707 | anton | 296 | et = &lev->elist[i]; |
297 | if (et->flags & ELASTIC_PRESENT) { |
||
298 | cprintf("%s:%d ", proc_table[i].name, (int)et->T); |
||
691 | anton | 299 | } |
300 | } |
||
697 | anton | 301 | cprintf("\n"); |
707 | anton | 302 | #endif |
691 | anton | 303 | |
697 | anton | 304 | return 0; // FEASIBLE |
691 | anton | 305 | |
673 | giacomo | 306 | } |
307 | |||
697 | anton | 308 | |
671 | giacomo | 309 | /* The on-line guarantee is enabled only if the appropriate flag is set... */ |
310 | static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
||
311 | { |
||
312 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
313 | |||
691 | anton | 314 | if (*freebandwidth >= lev->U) { |
700 | anton | 315 | *freebandwidth -= (unsigned int)lev->U; |
691 | anton | 316 | return 1; |
317 | } else { |
||
318 | return 0; |
||
319 | } |
||
737 | anton | 320 | |
671 | giacomo | 321 | } |
322 | |||
691 | anton | 323 | |
671 | giacomo | 324 | static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m) |
325 | { |
||
326 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
691 | anton | 327 | ELASTIC_TASK_MODEL *elastic = (ELASTIC_TASK_MODEL *)m; |
707 | anton | 328 | ELASTIC_task_descr *et = &lev->elist[p]; |
671 | giacomo | 329 | |
330 | if (m->pclass != ELASTIC_PCLASS) return -1; |
||
331 | if (m->level != 0 && m->level != l) return -1; |
||
332 | |||
691 | anton | 333 | if (elastic->C == 0) return -1; |
673 | giacomo | 334 | if (elastic->Tmin > elastic->Tmax) return -1; |
335 | if (elastic->Tmax == 0) return -1; |
||
707 | anton | 336 | if (elastic->Tmin == 0) return -1; |
673 | giacomo | 337 | |
707 | anton | 338 | NULL_TIMESPEC(&(et->dline)); |
339 | et->Tmin = elastic->Tmin; |
||
340 | et->Tmax = elastic->Tmax; |
||
341 | et->C = elastic->C; |
||
342 | et->E = elastic->E; |
||
343 | et->beta = elastic->beta; |
||
673 | giacomo | 344 | |
744 | anton | 345 | // overflow here??? |
346 | //et->Umax = ((long long)MAX_BANDWIDTH * (long long)elastic->C * (long long)lev->c_scaling_factor) / ((long long)elastic->Tmin * (long long)SCALING_UNIT); |
||
347 | //et->Umin = ((long long)MAX_BANDWIDTH * (long long)elastic->C * (long long)lev->c_scaling_factor) / ((long long)elastic->Tmax * (long long)SCALING_UNIT); |
||
673 | giacomo | 348 | |
744 | anton | 349 | et->Umax = ((long long)MAX_BANDWIDTH * (long long)elastic->C) / (long long)elastic->Tmin; |
350 | et->Umin = ((long long)MAX_BANDWIDTH * (long long)elastic->C) / (long long)elastic->Tmax; |
||
351 | |||
707 | anton | 352 | et->U = et->Umax; |
353 | et->oldU = 0; |
||
354 | et->T = et->Tmin; |
||
355 | et->dltimer = -1; |
||
673 | giacomo | 356 | |
744 | anton | 357 | et->flags |= ELASTIC_PRESENT; |
358 | if (ELASTIC_compress(lev) == -1) { |
||
359 | et->flags &= ~ELASTIC_PRESENT; |
||
360 | #ifdef ELASTIC_DEBUG |
||
361 | cprintf("ELASTIC_public_create: compression failed!\n"); |
||
362 | #endif |
||
363 | return -1; |
||
364 | } |
||
365 | |||
741 | giacomo | 366 | mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].avail_time); |
367 | mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].wcet); |
||
744 | anton | 368 | |
674 | giacomo | 369 | proc_table[p].control |= CONTROL_CAP; |
673 | giacomo | 370 | |
697 | anton | 371 | return 0; |
671 | giacomo | 372 | } |
373 | |||
697 | anton | 374 | |
671 | giacomo | 375 | static void ELASTIC_public_detach(LEVEL l, PID p) |
376 | { |
||
707 | anton | 377 | //ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
671 | giacomo | 378 | |
379 | } |
||
380 | |||
381 | static int ELASTIC_public_eligible(LEVEL l, PID p) |
||
382 | { |
||
707 | anton | 383 | //ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
671 | giacomo | 384 | |
385 | return 0; |
||
386 | |||
387 | } |
||
388 | |||
389 | static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop) |
||
390 | { |
||
391 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
674 | giacomo | 392 | |
671 | giacomo | 393 | level_table[ lev->scheduling_level ]-> |
394 | private_dispatch(lev->scheduling_level,p,nostop); |
||
674 | giacomo | 395 | |
671 | giacomo | 396 | } |
397 | |||
398 | static void ELASTIC_public_epilogue(LEVEL l, PID p) |
||
399 | { |
||
400 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
401 | |||
674 | giacomo | 402 | /* check if the wcet is finished... */ |
403 | if (proc_table[p].avail_time <= 0) { |
||
404 | |||
707 | anton | 405 | TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation, |
406 | (unsigned short int)proc_table[p].context,0); |
||
674 | giacomo | 407 | kern_raise(XWCET_VIOLATION,p); |
408 | |||
409 | } |
||
691 | anton | 410 | |
707 | anton | 411 | level_table[lev->scheduling_level]-> |
674 | giacomo | 412 | private_epilogue(lev->scheduling_level,p); |
413 | |||
671 | giacomo | 414 | } |
415 | |||
416 | static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t) |
||
417 | { |
||
418 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
707 | anton | 419 | ELASTIC_task_descr *et = &lev->elist[p]; |
671 | giacomo | 420 | |
674 | giacomo | 421 | /* check if we are not in the SLEEP state */ |
422 | if (proc_table[p].status != SLEEP) { |
||
423 | return; |
||
424 | } |
||
425 | |||
426 | ELASTIC_activation(lev,p,t); |
||
427 | |||
428 | /* Next activation */ |
||
707 | anton | 429 | et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act, (void *)(p)); |
674 | giacomo | 430 | |
671 | giacomo | 431 | } |
432 | |||
433 | static void ELASTIC_public_unblock(LEVEL l, PID p) |
||
434 | { |
||
435 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
436 | struct timespec acttime; |
||
437 | |||
438 | kern_gettime(&acttime); |
||
439 | |||
440 | ELASTIC_activation(lev,p,&acttime); |
||
441 | |||
442 | } |
||
443 | |||
444 | static void ELASTIC_public_block(LEVEL l, PID p) |
||
445 | { |
||
446 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
707 | anton | 447 | ELASTIC_task_descr *et = &lev->elist[p]; |
671 | giacomo | 448 | |
707 | anton | 449 | level_table[lev->scheduling_level]-> |
671 | giacomo | 450 | private_extract(lev->scheduling_level,p); |
707 | anton | 451 | et->flags &= ~ELASTIC_JOB_PRESENT; |
671 | giacomo | 452 | |
453 | } |
||
454 | |||
455 | static int ELASTIC_public_message(LEVEL l, PID p, void *m) |
||
456 | { |
||
457 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
737 | anton | 458 | ELASTIC_task_descr *et = &lev->elist[p]; |
671 | giacomo | 459 | |
460 | switch((long)(m)) { |
||
461 | |||
462 | case (long)(NULL): |
||
463 | |||
707 | anton | 464 | level_table[lev->scheduling_level]-> |
676 | giacomo | 465 | private_extract(lev->scheduling_level,p); |
737 | anton | 466 | et->flags &= ~ELASTIC_JOB_PRESENT; |
676 | giacomo | 467 | |
683 | giacomo | 468 | proc_table[p].status = ELASTIC_IDLE; |
676 | giacomo | 469 | |
671 | giacomo | 470 | jet_update_endcycle(); /* Update the Jet data... */ |
471 | TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
472 | |||
473 | break; |
||
474 | |||
475 | case 1: |
||
476 | |||
676 | giacomo | 477 | level_table[ lev->scheduling_level ]-> |
478 | private_extract(lev->scheduling_level,p); |
||
737 | anton | 479 | et->flags &= ~ELASTIC_JOB_PRESENT; |
676 | giacomo | 480 | |
481 | proc_table[p].status = SLEEP; |
||
482 | |||
671 | giacomo | 483 | TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l); |
484 | |||
485 | break; |
||
486 | |||
487 | } |
||
488 | |||
489 | return 0; |
||
490 | |||
491 | } |
||
492 | |||
493 | static void ELASTIC_public_end(LEVEL l, PID p) |
||
494 | { |
||
495 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
737 | anton | 496 | ELASTIC_task_descr *et = &lev->elist[p]; |
671 | giacomo | 497 | |
498 | level_table[ lev->scheduling_level ]-> |
||
499 | private_extract(lev->scheduling_level,p); |
||
737 | anton | 500 | et->flags &= ~ELASTIC_JOB_PRESENT; |
671 | giacomo | 501 | |
502 | } |
||
503 | |||
504 | /*+ Registration function +*/ |
||
700 | anton | 505 | LEVEL ELASTIC_register_level(int flags, LEVEL master, ext_bandwidth_t U) |
671 | giacomo | 506 | { |
507 | LEVEL l; /* the level that we register */ |
||
508 | ELASTIC_level_des *lev; /* for readableness only */ |
||
509 | PID i; |
||
510 | |||
511 | printk("ELASTIC_register_level\n"); |
||
512 | |||
513 | /* request an entry in the level_table */ |
||
514 | l = level_alloc_descriptor(sizeof(ELASTIC_level_des)); |
||
515 | |||
516 | lev = (ELASTIC_level_des *)level_table[l]; |
||
517 | |||
518 | /* fill the standard descriptor */ |
||
519 | if (flags & ELASTIC_ENABLE_GUARANTEE) |
||
520 | lev->l.public_guarantee = ELASTIC_public_guarantee; |
||
521 | else |
||
522 | lev->l.public_guarantee = NULL; |
||
523 | lev->l.public_create = ELASTIC_public_create; |
||
524 | lev->l.public_detach = ELASTIC_public_detach; |
||
525 | lev->l.public_end = ELASTIC_public_end; |
||
526 | lev->l.public_eligible = ELASTIC_public_eligible; |
||
527 | lev->l.public_dispatch = ELASTIC_public_dispatch; |
||
528 | lev->l.public_epilogue = ELASTIC_public_epilogue; |
||
529 | lev->l.public_activate = ELASTIC_public_activate; |
||
530 | lev->l.public_unblock = ELASTIC_public_unblock; |
||
531 | lev->l.public_block = ELASTIC_public_block; |
||
532 | lev->l.public_message = ELASTIC_public_message; |
||
533 | |||
741 | giacomo | 534 | lev->elist = kern_alloc(MAX_PROC * sizeof(ELASTIC_task_descr)); |
535 | |||
676 | giacomo | 536 | /* fill the ELASTIC task descriptor part */ |
671 | giacomo | 537 | for (i=0; i<MAX_PROC; i++) { |
538 | NULL_TIMESPEC(&(lev->elist[i].dline)); |
||
539 | lev->elist[i].Tmin = 0; |
||
540 | lev->elist[i].Tmax = 0; |
||
691 | anton | 541 | lev->elist[i].T = 0; |
697 | anton | 542 | lev->elist[i].U = 0; |
691 | anton | 543 | lev->elist[i].C = 0; |
544 | lev->elist[i].E = 0; |
||
671 | giacomo | 545 | lev->elist[i].beta = 0; |
707 | anton | 546 | lev->elist[i].flags = 0; |
671 | giacomo | 547 | } |
548 | |||
741 | giacomo | 549 | lev->c_scaling_factor = SCALING_UNIT; |
550 | |||
691 | anton | 551 | lev->U = U; |
671 | giacomo | 552 | |
553 | lev->scheduling_level = master; |
||
554 | |||
555 | lev->current_level = l; |
||
556 | |||
707 | anton | 557 | lev->flags = 0; |
671 | giacomo | 558 | |
559 | return l; |
||
560 | } |
||
561 | |||
707 | anton | 562 | |
563 | /* Force the period of task p to a given value */ |
||
564 | |||
565 | int ELASTIC_set_period(PID p, TIME period) { |
||
566 | |||
567 | SYS_FLAGS f; |
||
568 | int saveE; |
||
569 | ext_bandwidth_t saveU; |
||
570 | |||
571 | f = kern_fsave(); |
||
572 | |||
573 | ELASTIC_level_des *lev; |
||
574 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
575 | ELASTIC_task_descr *et = &lev->elist[p]; |
||
576 | |||
577 | saveE = et->E; |
||
578 | saveU = et->U; |
||
579 | |||
737 | anton | 580 | et->E = 0; /* set elasticity to zero to force period */ |
741 | giacomo | 581 | et->U = ((long long)MAX_BANDWIDTH * (long long)et->C * (long long)lev->c_scaling_factor)/((long long)period * (long long)SCALING_UNIT); |
707 | anton | 582 | |
583 | if (ELASTIC_compress(lev) == -1) { |
||
584 | #ifdef ELASTIC_DEBUG |
||
585 | cprintf("ELASTIC_set_period failed: could not compress\n"); |
||
586 | #endif |
||
587 | et->E = saveE; |
||
588 | et->U = saveU; |
||
589 | kern_frestore(f); |
||
590 | return -1; |
||
591 | } |
||
592 | |||
593 | et->E = saveE; /* Restore E when compression is done */ |
||
594 | kern_frestore(f); |
||
595 | return 0; |
||
596 | } |
||
708 | giacomo | 597 | |
598 | int ELASTIC_get_period(PID p) { |
||
599 | |||
600 | SYS_FLAGS f; |
||
601 | ELASTIC_level_des *lev; |
||
602 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
737 | anton | 603 | TIME retval; |
708 | giacomo | 604 | |
605 | f = kern_fsave(); |
||
606 | |||
607 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
||
737 | anton | 608 | retval = lev->elist[p].T; |
708 | giacomo | 609 | kern_frestore(f); |
737 | anton | 610 | return retval; |
708 | giacomo | 611 | |
612 | } else { |
||
613 | |||
614 | kern_frestore(f); |
||
615 | return -1; |
||
616 | |||
617 | } |
||
618 | |||
619 | } |
||
620 | |||
744 | anton | 621 | |
622 | int ELASTIC_get_Tmin(PID p) { |
||
623 | |||
624 | SYS_FLAGS f; |
||
625 | ELASTIC_level_des *lev; |
||
626 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
627 | TIME retval; |
||
628 | |||
629 | f = kern_fsave(); |
||
630 | |||
631 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
||
632 | retval = lev->elist[p].Tmin; |
||
633 | kern_frestore(f); |
||
634 | return retval; |
||
635 | |||
636 | } else { |
||
637 | |||
638 | kern_frestore(f); |
||
639 | return -1; |
||
640 | |||
641 | } |
||
642 | |||
643 | } |
||
644 | |||
645 | |||
646 | int ELASTIC_get_Tmax(PID p) { |
||
647 | |||
648 | SYS_FLAGS f; |
||
649 | ELASTIC_level_des *lev; |
||
650 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
651 | TIME retval; |
||
652 | |||
653 | f = kern_fsave(); |
||
654 | |||
655 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
||
656 | retval = lev->elist[p].Tmax; |
||
657 | kern_frestore(f); |
||
658 | return retval; |
||
659 | |||
660 | } else { |
||
661 | |||
662 | kern_frestore(f); |
||
663 | return -1; |
||
664 | |||
665 | } |
||
666 | |||
667 | } |
||
668 | |||
669 | |||
670 | int ELASTIC_get_C(PID p) { |
||
671 | |||
672 | SYS_FLAGS f; |
||
673 | ELASTIC_level_des *lev; |
||
674 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
675 | TIME retval; |
||
676 | |||
677 | f = kern_fsave(); |
||
678 | |||
679 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
||
680 | retval = lev->elist[p].C; |
||
681 | kern_frestore(f); |
||
682 | return retval; |
||
683 | |||
684 | } else { |
||
685 | |||
686 | kern_frestore(f); |
||
687 | return -1; |
||
688 | |||
689 | } |
||
690 | |||
691 | } |
||
692 | |||
693 | |||
737 | anton | 694 | int ELASTIC_set_E(PID p, int E) |
695 | { |
||
708 | giacomo | 696 | SYS_FLAGS f; |
697 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
698 | ELASTIC_task_descr *et = &lev->elist[p]; |
||
699 | int saveE; |
||
700 | |||
701 | f = kern_fsave(); |
||
737 | anton | 702 | |
708 | giacomo | 703 | if (et->flags & ELASTIC_PRESENT) { |
704 | |||
705 | saveE = et->E; |
||
737 | anton | 706 | |
707 | et->E = E; |
||
708 | giacomo | 708 | if (ELASTIC_compress(lev) == -1) { |
709 | #ifdef ELASTIC_DEBUG |
||
710 | cprintf("ELASTIC_set_E failed: could not compress\n"); |
||
711 | #endif |
||
712 | et->E = saveE; |
||
713 | kern_frestore(f); |
||
714 | return -1; |
||
715 | } |
||
737 | anton | 716 | |
708 | giacomo | 717 | kern_frestore(f); |
718 | return 0; |
||
737 | anton | 719 | |
708 | giacomo | 720 | } else { |
737 | anton | 721 | |
708 | giacomo | 722 | kern_frestore(f); |
723 | return -1; |
||
724 | } |
||
725 | } |
||
726 | |||
727 | int ELASTIC_get_E(PID p) { |
||
737 | anton | 728 | |
708 | giacomo | 729 | SYS_FLAGS f; |
730 | ELASTIC_level_des *lev; |
||
731 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
737 | anton | 732 | |
708 | giacomo | 733 | f = kern_fsave(); |
737 | anton | 734 | |
708 | giacomo | 735 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
737 | anton | 736 | |
708 | giacomo | 737 | kern_frestore(f); |
738 | return lev->elist[p].E; |
||
737 | anton | 739 | |
708 | giacomo | 740 | } else { |
737 | anton | 741 | |
708 | giacomo | 742 | kern_frestore(f); |
743 | return -1; |
||
744 | } |
||
745 | } |
||
746 | |||
747 | int ELASTIC_set_beta(PID p, int beta) { |
||
737 | anton | 748 | |
708 | giacomo | 749 | SYS_FLAGS f; |
750 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
751 | ELASTIC_task_descr *et = &lev->elist[p]; |
||
752 | int saveBeta; |
||
753 | |||
754 | f = kern_fsave(); |
||
737 | anton | 755 | |
708 | giacomo | 756 | if (et->flags & ELASTIC_PRESENT) { |
737 | anton | 757 | |
708 | giacomo | 758 | saveBeta = et->beta; |
737 | anton | 759 | |
760 | et->beta = beta; |
||
761 | |||
708 | giacomo | 762 | if (ELASTIC_compress(lev) == -1) { |
763 | #ifdef ELASTIC_DEBUG |
||
764 | cprintf("ELASTIC_set_beta failed: could not compress\n"); |
||
765 | #endif |
||
766 | et->beta = saveBeta; |
||
767 | kern_frestore(f); |
||
768 | return -1; |
||
769 | } |
||
737 | anton | 770 | |
708 | giacomo | 771 | kern_frestore(f); |
772 | return 0; |
||
737 | anton | 773 | |
708 | giacomo | 774 | } else { |
737 | anton | 775 | |
708 | giacomo | 776 | kern_frestore(f); |
777 | return -1; |
||
737 | anton | 778 | |
708 | giacomo | 779 | } |
737 | anton | 780 | |
708 | giacomo | 781 | } |
782 | |||
783 | int ELASTIC_get_beta(PID p) { |
||
737 | anton | 784 | |
708 | giacomo | 785 | SYS_FLAGS f; |
786 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
737 | anton | 787 | int retval; |
788 | |||
708 | giacomo | 789 | f = kern_fsave(); |
737 | anton | 790 | |
708 | giacomo | 791 | if (lev->elist[p].flags & ELASTIC_PRESENT) { |
737 | anton | 792 | retval = lev->elist[p].beta; |
708 | giacomo | 793 | kern_frestore(f); |
737 | anton | 794 | return retval; |
795 | |||
708 | giacomo | 796 | } else { |
737 | anton | 797 | |
708 | giacomo | 798 | kern_frestore(f); |
799 | return -1; |
||
737 | anton | 800 | |
708 | giacomo | 801 | } |
737 | anton | 802 | |
708 | giacomo | 803 | } |
804 | |||
805 | int ELASTIC_set_bandwidth(LEVEL level, ext_bandwidth_t U) { |
||
737 | anton | 806 | |
708 | giacomo | 807 | SYS_FLAGS f; |
808 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level]; |
||
809 | |||
810 | f = kern_fsave(); |
||
811 | |||
812 | lev->U = U; |
||
813 | |||
814 | if (ELASTIC_compress(lev) == -1) { |
||
815 | #ifdef ELASTIC_DEBUG |
||
816 | cprintf("ELASTIC_set_bandwidth failed: could not compress\n"); |
||
817 | #endif |
||
818 | kern_frestore(f); |
||
819 | return -1; |
||
820 | } |
||
737 | anton | 821 | |
708 | giacomo | 822 | kern_frestore(f); |
823 | return 0; |
||
737 | anton | 824 | |
708 | giacomo | 825 | } |
826 | |||
827 | ext_bandwidth_t ELASTIC_get_bandwidth(LEVEL level) { |
||
737 | anton | 828 | |
708 | giacomo | 829 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];; |
830 | |||
831 | return lev->U; |
||
737 | anton | 832 | |
708 | giacomo | 833 | } |
741 | giacomo | 834 | |
835 | int ELASTIC_set_scaling_factor(LEVEL level, int scaling_factor) { |
||
836 | |||
837 | SYS_FLAGS f; |
||
838 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level]; |
||
839 | |||
840 | f = kern_fsave(); |
||
841 | |||
842 | lev->c_scaling_factor = scaling_factor; |
||
843 | |||
844 | if (ELASTIC_compress(lev) == -1) { |
||
845 | #ifdef ELASTIC_DEBUG |
||
846 | cprintf("ELASTIC_set_scaling_factor failed: could not compress\n"); |
||
847 | #endif |
||
848 | kern_frestore(f); |
||
849 | return -1; |
||
850 | } |
||
851 | |||
852 | kern_frestore(f); |
||
853 | return 0; |
||
854 | |||
855 | } |
||
856 | |||
857 | int ELASTIC_get_scaling_factor(LEVEL level) { |
||
858 | |||
859 | ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];; |
||
860 | |||
861 | return lev->c_scaling_factor; |
||
862 | |||
863 | } |