Rev 678 | Rev 691 | 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 | * |
||
8 | * Authors : |
||
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 | |||
42 | #include <stdlib.h> |
||
43 | |||
44 | #include <modules/elastic.h> |
||
45 | |||
46 | #include <tracer.h> |
||
47 | |||
673 | giacomo | 48 | #define ELASTIC_EMPTY_SLOT 0 |
49 | #define ELASTIC_PRESENT 1 |
||
671 | giacomo | 50 | |
683 | giacomo | 51 | #define ELASTIC_IDLE APER_STATUS_BASE |
52 | |||
676 | giacomo | 53 | #define ELASTIC_DEBUG |
54 | |||
671 | giacomo | 55 | typedef struct { |
56 | |||
57 | struct timespec dline; |
||
58 | |||
59 | TIME Tmin; |
||
60 | TIME Tmax; |
||
61 | |||
62 | TIME period; |
||
63 | TIME wcet; |
||
673 | giacomo | 64 | |
65 | bandwidth_t Up; |
||
671 | giacomo | 66 | |
67 | int kelastic; |
||
68 | int beta; |
||
69 | |||
70 | int flags; |
||
71 | |||
72 | } ELASTIC_task_descr; |
||
73 | |||
74 | typedef struct { |
||
75 | level_des l; /*+ the standard level descriptor +*/ |
||
76 | |||
77 | bandwidth_t U; /*+ the used bandwidth by the server +*/ |
||
78 | |||
683 | giacomo | 79 | ELASTIC_task_descr *elist;//[MAX_PROC]; |
671 | giacomo | 80 | |
81 | LEVEL scheduling_level; |
||
82 | |||
83 | LEVEL current_level; |
||
84 | |||
85 | int flags; |
||
86 | |||
87 | } ELASTIC_level_des; |
||
88 | |||
676 | giacomo | 89 | static int ELASTIC_recompute(ELASTIC_level_des *lev) { |
673 | giacomo | 90 | |
676 | giacomo | 91 | PID i; |
92 | |||
93 | for (i=0; i<MAX_PROC; i++) { |
||
94 | if (lev->elist[i].flags & ELASTIC_PRESENT) |
||
95 | lev->elist[i].period = lev->elist[i].Tmax; |
||
96 | } |
||
97 | |||
673 | giacomo | 98 | return 0; |
99 | |||
100 | } |
||
101 | |||
676 | giacomo | 102 | static int ELASTIC_check_guarantie(ELASTIC_level_des *lev) { |
673 | giacomo | 103 | |
104 | return 0; |
||
105 | |||
106 | } |
||
107 | |||
671 | giacomo | 108 | static void ELASTIC_activation(ELASTIC_level_des *lev, |
109 | PID p, |
||
110 | struct timespec *acttime) |
||
111 | { |
||
112 | JOB_TASK_MODEL job; |
||
674 | giacomo | 113 | |
114 | /* Job deadline */ |
||
115 | TIMESPEC_ASSIGN(&(lev->elist[p].dline),acttime); |
||
116 | ADDUSEC2TIMESPEC(lev->elist[p].period,&(lev->elist[p].dline)); |
||
117 | |||
683 | giacomo | 118 | proc_table[p].avail_time = lev->elist[p].wcet; |
119 | proc_table[p].wcet = lev->elist[p].wcet; |
||
120 | |||
674 | giacomo | 121 | /* Job insertion */ |
122 | job_task_default_model(job, lev->elist[p].dline); |
||
671 | giacomo | 123 | level_table[ lev->scheduling_level ]-> |
124 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
||
125 | |||
674 | giacomo | 126 | } |
671 | giacomo | 127 | |
674 | giacomo | 128 | static void ELASTIC_timer_act(void *arg) { |
129 | |||
130 | PID p = (PID)(arg); |
||
131 | ELASTIC_level_des *lev; |
||
132 | struct timespec acttime; |
||
683 | giacomo | 133 | |
134 | #ifdef ELASTIC_DEBUG |
||
135 | printk("(ELASTIC:Timer:%d)",p); |
||
136 | #endif |
||
137 | |||
674 | giacomo | 138 | kern_gettime(&acttime); |
139 | |||
140 | lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level]; |
||
141 | |||
142 | ELASTIC_activation(lev, p, &acttime); |
||
683 | giacomo | 143 | event_need_reschedule(); |
144 | |||
145 | /* Next activation */ |
||
146 | kern_event_post(&(lev->elist[p].dline), ELASTIC_timer_act, (void *)(p)); |
||
147 | |||
671 | giacomo | 148 | } |
149 | |||
150 | /* The on-line guarantee is enabled only if the appropriate flag is set... */ |
||
151 | static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
||
152 | { |
||
153 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
154 | |||
683 | giacomo | 155 | return 1; |
673 | giacomo | 156 | |
671 | giacomo | 157 | } |
158 | |||
159 | static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
160 | { |
||
161 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
162 | ELASTIC_TASK_MODEL *elastic; |
||
163 | |||
164 | if (m->pclass != ELASTIC_PCLASS) return -1; |
||
165 | if (m->level != 0 && m->level != l) return -1; |
||
166 | elastic = (ELASTIC_TASK_MODEL *)m; |
||
167 | |||
673 | giacomo | 168 | if (elastic->wcet == 0) return -1; |
169 | if (elastic->Tmin > elastic->Tmax) return -1; |
||
170 | if (elastic->Tmax == 0) return -1; |
||
171 | |||
172 | lev->elist[p].flags |= ELASTIC_PRESENT; |
||
173 | |||
174 | NULL_TIMESPEC(&(lev->elist[p].dline)); |
||
175 | lev->elist[p].Tmin = elastic->Tmin; |
||
176 | lev->elist[p].Tmax = elastic->Tmax; |
||
177 | lev->elist[p].wcet = elastic->wcet; |
||
178 | lev->elist[p].kelastic = elastic->kelastic; |
||
179 | lev->elist[p].beta = elastic->beta; |
||
180 | |||
181 | if (lev->flags & ELASTIC_ENABLE_GUARANTEE) |
||
676 | giacomo | 182 | if (ELASTIC_check_guarantie(lev) != 0) { |
673 | giacomo | 183 | lev->elist[p].flags = ELASTIC_EMPTY_SLOT; |
184 | return -1; |
||
185 | } |
||
186 | |||
676 | giacomo | 187 | ELASTIC_recompute(lev); |
673 | giacomo | 188 | |
189 | if (lev->elist[p].period == 0) { |
||
190 | lev->elist[p].flags = ELASTIC_EMPTY_SLOT; |
||
191 | return -1; |
||
192 | } |
||
193 | |||
674 | giacomo | 194 | proc_table[p].avail_time = elastic->wcet; |
673 | giacomo | 195 | proc_table[p].wcet = elastic->wcet; |
674 | giacomo | 196 | proc_table[p].control |= CONTROL_CAP; |
673 | giacomo | 197 | |
671 | giacomo | 198 | return 0; /* OK, also if the task cannot be guaranteed... */ |
199 | |||
200 | } |
||
201 | |||
202 | static void ELASTIC_public_detach(LEVEL l, PID p) |
||
203 | { |
||
204 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
205 | |||
206 | } |
||
207 | |||
208 | static int ELASTIC_public_eligible(LEVEL l, PID p) |
||
209 | { |
||
210 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
211 | |||
212 | return 0; |
||
213 | |||
214 | } |
||
215 | |||
216 | static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop) |
||
217 | { |
||
218 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
674 | giacomo | 219 | |
683 | giacomo | 220 | #ifdef ELASTIC_DEBUG |
221 | printk("(ELASTIC:Dsp:%d)",p); |
||
222 | #endif |
||
223 | |||
671 | giacomo | 224 | level_table[ lev->scheduling_level ]-> |
225 | private_dispatch(lev->scheduling_level,p,nostop); |
||
674 | giacomo | 226 | |
671 | giacomo | 227 | } |
228 | |||
229 | static void ELASTIC_public_epilogue(LEVEL l, PID p) |
||
230 | { |
||
231 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
232 | |||
683 | giacomo | 233 | #ifdef ELASTIC_DEBUG |
234 | printk("(ELASTIC:Epi:%d)",p); |
||
235 | #endif |
||
236 | |||
674 | giacomo | 237 | /* check if the wcet is finished... */ |
238 | if (proc_table[p].avail_time <= 0) { |
||
239 | |||
240 | TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,(unsigned short int)proc_table[p].context,0); |
||
241 | kern_raise(XWCET_VIOLATION,p); |
||
242 | |||
243 | } |
||
244 | |||
245 | level_table[ lev->scheduling_level ]-> |
||
246 | private_epilogue(lev->scheduling_level,p); |
||
247 | |||
671 | giacomo | 248 | } |
249 | |||
250 | static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t) |
||
251 | { |
||
252 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
253 | |||
674 | giacomo | 254 | #ifdef ELASTIC_DEBUG |
255 | printk("(ELASTIC:Act:%d)", p); |
||
256 | #endif |
||
257 | |||
258 | /* check if we are not in the SLEEP state */ |
||
259 | if (proc_table[p].status != SLEEP) { |
||
260 | |||
261 | return; |
||
262 | |||
263 | } |
||
264 | |||
265 | ELASTIC_activation(lev,p,t); |
||
266 | |||
267 | /* Next activation */ |
||
268 | kern_event_post(&(lev->elist[p].dline), ELASTIC_timer_act, (void *)(p)); |
||
269 | |||
671 | giacomo | 270 | } |
271 | |||
272 | static void ELASTIC_public_unblock(LEVEL l, PID p) |
||
273 | { |
||
274 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
275 | struct timespec acttime; |
||
276 | |||
277 | kern_gettime(&acttime); |
||
278 | |||
279 | ELASTIC_activation(lev,p,&acttime); |
||
280 | |||
281 | } |
||
282 | |||
283 | static void ELASTIC_public_block(LEVEL l, PID p) |
||
284 | { |
||
285 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
286 | |||
287 | level_table[ lev->scheduling_level ]-> |
||
288 | private_extract(lev->scheduling_level,p); |
||
289 | |||
290 | } |
||
291 | |||
292 | static int ELASTIC_public_message(LEVEL l, PID p, void *m) |
||
293 | { |
||
294 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
676 | giacomo | 295 | struct timespec acttime; |
671 | giacomo | 296 | |
297 | switch((long)(m)) { |
||
298 | |||
299 | case (long)(NULL): |
||
300 | |||
683 | giacomo | 301 | #ifdef ELASTIC_DEBUG |
302 | printk("(ELASTIC:EndCyc:%d)",p); |
||
303 | #endif |
||
304 | |||
676 | giacomo | 305 | level_table[ lev->scheduling_level ]-> |
306 | private_extract(lev->scheduling_level,p); |
||
307 | |||
683 | giacomo | 308 | proc_table[p].status = ELASTIC_IDLE; |
676 | giacomo | 309 | |
671 | giacomo | 310 | jet_update_endcycle(); /* Update the Jet data... */ |
311 | TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
312 | |||
313 | break; |
||
314 | |||
315 | case 1: |
||
316 | |||
683 | giacomo | 317 | #ifdef ELASTIC_DEBUG |
318 | printk("(ELASTIC:Disable:%d)",p); |
||
319 | #endif |
||
320 | |||
676 | giacomo | 321 | level_table[ lev->scheduling_level ]-> |
322 | private_extract(lev->scheduling_level,p); |
||
323 | |||
324 | proc_table[p].status = SLEEP; |
||
325 | |||
671 | giacomo | 326 | TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l); |
327 | |||
328 | break; |
||
329 | |||
330 | } |
||
331 | |||
332 | return 0; |
||
333 | |||
334 | } |
||
335 | |||
336 | static void ELASTIC_public_end(LEVEL l, PID p) |
||
337 | { |
||
338 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
339 | |||
340 | level_table[ lev->scheduling_level ]-> |
||
341 | private_extract(lev->scheduling_level,p); |
||
342 | |||
343 | } |
||
344 | |||
345 | /*+ Registration function +*/ |
||
346 | LEVEL ELASTIC_register_level(int flags, LEVEL master) |
||
347 | { |
||
348 | LEVEL l; /* the level that we register */ |
||
349 | ELASTIC_level_des *lev; /* for readableness only */ |
||
350 | PID i; |
||
351 | |||
352 | printk("ELASTIC_register_level\n"); |
||
353 | |||
354 | /* request an entry in the level_table */ |
||
355 | l = level_alloc_descriptor(sizeof(ELASTIC_level_des)); |
||
356 | |||
357 | lev = (ELASTIC_level_des *)level_table[l]; |
||
358 | |||
359 | /* fill the standard descriptor */ |
||
360 | if (flags & ELASTIC_ENABLE_GUARANTEE) |
||
361 | lev->l.public_guarantee = ELASTIC_public_guarantee; |
||
362 | else |
||
363 | lev->l.public_guarantee = NULL; |
||
364 | lev->l.public_create = ELASTIC_public_create; |
||
365 | lev->l.public_detach = ELASTIC_public_detach; |
||
366 | lev->l.public_end = ELASTIC_public_end; |
||
367 | lev->l.public_eligible = ELASTIC_public_eligible; |
||
368 | lev->l.public_dispatch = ELASTIC_public_dispatch; |
||
369 | lev->l.public_epilogue = ELASTIC_public_epilogue; |
||
370 | lev->l.public_activate = ELASTIC_public_activate; |
||
371 | lev->l.public_unblock = ELASTIC_public_unblock; |
||
372 | lev->l.public_block = ELASTIC_public_block; |
||
373 | lev->l.public_message = ELASTIC_public_message; |
||
374 | |||
683 | giacomo | 375 | lev->elist = kern_alloc(MAX_PROC * sizeof(ELASTIC_task_descr)); |
671 | giacomo | 376 | |
676 | giacomo | 377 | /* fill the ELASTIC task descriptor part */ |
671 | giacomo | 378 | for (i=0; i<MAX_PROC; i++) { |
379 | NULL_TIMESPEC(&(lev->elist[i].dline)); |
||
380 | lev->elist[i].Tmin = 0; |
||
381 | lev->elist[i].Tmax = 0; |
||
382 | lev->elist[i].period = 0; |
||
383 | lev->elist[i].wcet = 0; |
||
676 | giacomo | 384 | lev->elist[i].Up = 0; |
671 | giacomo | 385 | lev->elist[i].kelastic = 0; |
386 | lev->elist[i].beta = 0; |
||
387 | lev->elist[i].flags = ELASTIC_EMPTY_SLOT; |
||
388 | } |
||
389 | |||
390 | lev->U = 0; |
||
391 | |||
392 | lev->scheduling_level = master; |
||
393 | |||
394 | lev->current_level = l; |
||
395 | |||
396 | lev->flags = flags; |
||
397 | |||
398 | return l; |
||
399 | } |
||
400 |