Rev 673 | Go to most recent revision | Details | 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 | |||
48 | #define ELASTIC_EMPTY_SLOT 0 |
||
49 | |||
50 | typedef struct { |
||
51 | |||
52 | struct timespec dline; |
||
53 | |||
54 | TIME Tmin; |
||
55 | TIME Tmax; |
||
56 | |||
57 | TIME period; |
||
58 | TIME wcet; |
||
59 | |||
60 | int kelastic; |
||
61 | int beta; |
||
62 | |||
63 | int nact; |
||
64 | |||
65 | int flags; |
||
66 | |||
67 | } ELASTIC_task_descr; |
||
68 | |||
69 | typedef struct { |
||
70 | level_des l; /*+ the standard level descriptor +*/ |
||
71 | |||
72 | bandwidth_t U; /*+ the used bandwidth by the server +*/ |
||
73 | |||
74 | ELASTIC_task_descr *elist; |
||
75 | |||
76 | LEVEL scheduling_level; |
||
77 | |||
78 | LEVEL current_level; |
||
79 | |||
80 | int flags; |
||
81 | |||
82 | } ELASTIC_level_des; |
||
83 | |||
84 | static void ELASTIC_activation(ELASTIC_level_des *lev, |
||
85 | PID p, |
||
86 | struct timespec *acttime) |
||
87 | { |
||
88 | JOB_TASK_MODEL job; |
||
89 | |||
90 | /* |
||
91 | job_task_default_model(job, lev->cbs_dline[p]); |
||
92 | job_task_def_noexc(job); |
||
93 | level_table[ lev->scheduling_level ]-> |
||
94 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
||
95 | |||
96 | */ |
||
97 | |||
98 | } |
||
99 | |||
100 | /* The on-line guarantee is enabled only if the appropriate flag is set... */ |
||
101 | static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
||
102 | { |
||
103 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
104 | |||
105 | if (*freebandwidth >= lev->U) { |
||
106 | *freebandwidth -= lev->U; |
||
107 | return 1; |
||
108 | } |
||
109 | else |
||
110 | return 0; |
||
111 | } |
||
112 | |||
113 | static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
114 | { |
||
115 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
116 | ELASTIC_TASK_MODEL *elastic; |
||
117 | |||
118 | if (m->pclass != ELASTIC_PCLASS) return -1; |
||
119 | if (m->level != 0 && m->level != l) return -1; |
||
120 | elastic = (ELASTIC_TASK_MODEL *)m; |
||
121 | |||
122 | return 0; /* OK, also if the task cannot be guaranteed... */ |
||
123 | |||
124 | } |
||
125 | |||
126 | static void ELASTIC_public_detach(LEVEL l, PID p) |
||
127 | { |
||
128 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
129 | |||
130 | } |
||
131 | |||
132 | static int ELASTIC_public_eligible(LEVEL l, PID p) |
||
133 | { |
||
134 | |||
135 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
136 | JOB_TASK_MODEL job; |
||
137 | |||
138 | return 0; |
||
139 | |||
140 | } |
||
141 | |||
142 | static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop) |
||
143 | { |
||
144 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
145 | level_table[ lev->scheduling_level ]-> |
||
146 | private_dispatch(lev->scheduling_level,p,nostop); |
||
147 | } |
||
148 | |||
149 | static void ELASTIC_public_epilogue(LEVEL l, PID p) |
||
150 | { |
||
151 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
152 | JOB_TASK_MODEL job; |
||
153 | |||
154 | } |
||
155 | |||
156 | static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t) |
||
157 | { |
||
158 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
159 | |||
160 | } |
||
161 | |||
162 | static void ELASTIC_public_unblock(LEVEL l, PID p) |
||
163 | { |
||
164 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
165 | struct timespec acttime; |
||
166 | |||
167 | kern_gettime(&acttime); |
||
168 | |||
169 | ELASTIC_activation(lev,p,&acttime); |
||
170 | |||
171 | } |
||
172 | |||
173 | static void ELASTIC_public_block(LEVEL l, PID p) |
||
174 | { |
||
175 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
176 | |||
177 | level_table[ lev->scheduling_level ]-> |
||
178 | private_extract(lev->scheduling_level,p); |
||
179 | |||
180 | } |
||
181 | |||
182 | static int ELASTIC_public_message(LEVEL l, PID p, void *m) |
||
183 | { |
||
184 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
185 | |||
186 | switch((long)(m)) { |
||
187 | |||
188 | case (long)(NULL): |
||
189 | |||
190 | jet_update_endcycle(); /* Update the Jet data... */ |
||
191 | TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
192 | |||
193 | break; |
||
194 | |||
195 | case 1: |
||
196 | |||
197 | TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l); |
||
198 | |||
199 | break; |
||
200 | |||
201 | } |
||
202 | |||
203 | return 0; |
||
204 | |||
205 | } |
||
206 | |||
207 | static void ELASTIC_public_end(LEVEL l, PID p) |
||
208 | { |
||
209 | ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]); |
||
210 | |||
211 | level_table[ lev->scheduling_level ]-> |
||
212 | private_extract(lev->scheduling_level,p); |
||
213 | |||
214 | } |
||
215 | |||
216 | /*+ Registration function +*/ |
||
217 | LEVEL ELASTIC_register_level(int flags, LEVEL master) |
||
218 | { |
||
219 | LEVEL l; /* the level that we register */ |
||
220 | ELASTIC_level_des *lev; /* for readableness only */ |
||
221 | PID i; |
||
222 | |||
223 | printk("ELASTIC_register_level\n"); |
||
224 | |||
225 | /* request an entry in the level_table */ |
||
226 | l = level_alloc_descriptor(sizeof(ELASTIC_level_des)); |
||
227 | |||
228 | lev = (ELASTIC_level_des *)level_table[l]; |
||
229 | |||
230 | /* fill the standard descriptor */ |
||
231 | if (flags & ELASTIC_ENABLE_GUARANTEE) |
||
232 | lev->l.public_guarantee = ELASTIC_public_guarantee; |
||
233 | else |
||
234 | lev->l.public_guarantee = NULL; |
||
235 | lev->l.public_create = ELASTIC_public_create; |
||
236 | lev->l.public_detach = ELASTIC_public_detach; |
||
237 | lev->l.public_end = ELASTIC_public_end; |
||
238 | lev->l.public_eligible = ELASTIC_public_eligible; |
||
239 | lev->l.public_dispatch = ELASTIC_public_dispatch; |
||
240 | lev->l.public_epilogue = ELASTIC_public_epilogue; |
||
241 | lev->l.public_activate = ELASTIC_public_activate; |
||
242 | lev->l.public_unblock = ELASTIC_public_unblock; |
||
243 | lev->l.public_block = ELASTIC_public_block; |
||
244 | lev->l.public_message = ELASTIC_public_message; |
||
245 | |||
246 | lev->elist = malloc(MAX_PROC * sizeof(ELASTIC_task_descr)); |
||
247 | if (lev->elist == NULL) { |
||
248 | printk("ELASTIC: Error allocating elastic task decriptor table\n"); |
||
249 | sys_end(); |
||
250 | } |
||
251 | |||
252 | /* fill the CBS descriptor part */ |
||
253 | for (i=0; i<MAX_PROC; i++) { |
||
254 | NULL_TIMESPEC(&(lev->elist[i].dline)); |
||
255 | lev->elist[i].Tmin = 0; |
||
256 | lev->elist[i].Tmax = 0; |
||
257 | lev->elist[i].period = 0; |
||
258 | lev->elist[i].wcet = 0; |
||
259 | lev->elist[i].kelastic = 0; |
||
260 | lev->elist[i].beta = 0; |
||
261 | lev->elist[i].nact = 0; |
||
262 | lev->elist[i].flags = ELASTIC_EMPTY_SLOT; |
||
263 | } |
||
264 | |||
265 | lev->U = 0; |
||
266 | |||
267 | lev->scheduling_level = master; |
||
268 | |||
269 | lev->current_level = l; |
||
270 | |||
271 | lev->flags = flags; |
||
272 | |||
273 | return l; |
||
274 | } |
||
275 |