Rev 334 | Rev 339 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
324 | 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 "mpegstar.h" |
||
47 | #include "fsf_server.h" |
||
48 | |||
338 | giacomo | 49 | //#define MPEGSTAR_DEBUG |
324 | giacomo | 50 | |
51 | /*+ Status used in the level +*/ |
||
52 | #define MPEGSTAR_READY MODULE_STATUS_BASE |
||
53 | |||
54 | /*+ the level redefinition for the Round Robin level +*/ |
||
55 | typedef struct { |
||
56 | level_des l; /*+ the standard level descriptor +*/ |
||
334 | giacomo | 57 | |
58 | int server_Q; |
||
59 | int server_T; |
||
60 | |||
338 | giacomo | 61 | int budget; |
62 | int current; |
||
334 | giacomo | 63 | |
324 | giacomo | 64 | int scheduling_level; |
338 | giacomo | 65 | int cap_lev; |
324 | giacomo | 66 | |
67 | } MPEGSTAR_level_des; |
||
68 | |||
338 | giacomo | 69 | |
70 | |||
71 | static void capacity_handler(void *l) |
||
72 | { |
||
73 | MPEGSTAR_level_des *lev = l; |
||
74 | lev->cap_lev = NIL; |
||
75 | event_need_reschedule(); |
||
76 | } |
||
77 | |||
324 | giacomo | 78 | static int MPEGSTAR_public_eligible(LEVEL l, PID p) |
79 | { |
||
80 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
81 | return level_table[ lev->scheduling_level ]-> |
||
82 | private_eligible(lev->scheduling_level,p); |
||
83 | |||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | static int MPEGSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
88 | { |
||
89 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
90 | |||
334 | giacomo | 91 | #ifdef MPEGSTAR_DEBUG |
92 | kern_printf("(MP:Crt:%d)",p); |
||
93 | #endif |
||
338 | giacomo | 94 | |
95 | if (m->pclass != HARD_PCLASS) return -1; |
||
334 | giacomo | 96 | if (m->level != 0 && m->level != l) return -1; |
338 | giacomo | 97 | |
98 | lev->current = p; |
||
334 | giacomo | 99 | |
100 | proc_table[p].avail_time = lev->server_Q; |
||
338 | giacomo | 101 | proc_table[p].wcet = lev->server_Q; |
102 | proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP); |
||
103 | |||
324 | giacomo | 104 | return 0; /* OK */ |
338 | giacomo | 105 | |
324 | giacomo | 106 | } |
107 | |||
108 | static void MPEGSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
||
109 | { |
||
110 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
338 | giacomo | 111 | struct timespec ty; |
324 | giacomo | 112 | |
338 | giacomo | 113 | #ifdef MPEGSTAR_DEBUG |
114 | kern_printf("(MS:Dsp:%d)",p); |
||
115 | #endif |
||
116 | |||
117 | if (!nostop) { |
||
118 | TIMESPEC_ASSIGN(&ty, &schedule_time); |
||
119 | |||
120 | /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume |
||
121 | * capacity on exe task always */ |
||
122 | ADDUSEC2TIMESPEC(proc_table[p].avail_time ,&ty); |
||
123 | lev->cap_lev = kern_event_post(&ty,capacity_handler, lev); |
||
334 | giacomo | 124 | level_table[ lev->scheduling_level ] -> |
125 | private_dispatch(lev->scheduling_level, p, nostop); |
||
338 | giacomo | 126 | } |
334 | giacomo | 127 | |
324 | giacomo | 128 | } |
129 | |||
130 | static void MPEGSTAR_public_epilogue(LEVEL l, PID p) |
||
131 | { |
||
132 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
338 | giacomo | 133 | if (lev->cap_lev!=NIL) { |
134 | kern_event_delete(lev->cap_lev); |
||
135 | lev->cap_lev=NIL; |
||
136 | } |
||
334 | giacomo | 137 | |
338 | giacomo | 138 | #ifdef MPEGSTAR_DEBUG |
139 | kern_printf("(MS:Epi:%d)",p); |
||
140 | #endif |
||
141 | |||
334 | giacomo | 142 | level_table[ lev->scheduling_level ] -> |
143 | private_epilogue(lev->scheduling_level,p); |
||
324 | giacomo | 144 | |
145 | } |
||
146 | |||
147 | static void MPEGSTAR_public_activate(LEVEL l, PID p) |
||
148 | { |
||
149 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
334 | giacomo | 150 | BUDGET_TASK_MODEL b; |
338 | giacomo | 151 | |
152 | budget_task_default_model(b, lev->budget); |
||
334 | giacomo | 153 | |
154 | #ifdef MPEGSTAR_DEBUG |
||
338 | giacomo | 155 | kern_printf("(MP:Act:%d:%d)",p,lev->budget); |
334 | giacomo | 156 | #endif |
324 | giacomo | 157 | |
334 | giacomo | 158 | level_table[ lev->scheduling_level ]-> |
159 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b); |
||
160 | |||
324 | giacomo | 161 | } |
162 | |||
163 | static void MPEGSTAR_public_unblock(LEVEL l, PID p) |
||
164 | { |
||
165 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
166 | |||
167 | } |
||
168 | |||
169 | static void MPEGSTAR_public_block(LEVEL l, PID p) |
||
170 | { |
||
171 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
172 | |||
173 | } |
||
174 | |||
175 | static int MPEGSTAR_public_message(LEVEL l, PID p, void *m) |
||
176 | { |
||
177 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
178 | |||
179 | switch ((long)(m)) { |
||
180 | |||
181 | /* Task EndCycle */ |
||
182 | case (long)(NULL): |
||
183 | |||
338 | giacomo | 184 | lev->current = NIL; |
185 | |||
186 | kern_printf("(Ext %d)",p); |
||
187 | |||
188 | if (lev->cap_lev != NIL) { |
||
189 | kern_event_delete(lev->cap_lev); |
||
190 | lev->cap_lev = NIL; |
||
191 | } |
||
192 | |||
334 | giacomo | 193 | level_table[ lev->scheduling_level ]-> |
338 | giacomo | 194 | private_extract(lev->scheduling_level, p); |
195 | |||
196 | level_table[ lev->scheduling_level ]-> |
||
334 | giacomo | 197 | public_message(lev->scheduling_level, p, NULL); |
198 | |||
324 | giacomo | 199 | break; |
200 | |||
201 | /* Task Disable */ |
||
202 | case (long)(1): |
||
203 | |||
204 | break; |
||
205 | |||
206 | default: |
||
207 | |||
208 | break; |
||
209 | |||
210 | } |
||
211 | |||
212 | return 0; |
||
213 | |||
214 | } |
||
215 | |||
216 | static void MPEGSTAR_public_end(LEVEL l, PID p) |
||
217 | { |
||
218 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
219 | |||
220 | } |
||
221 | |||
222 | /* Registration functions */ |
||
223 | |||
224 | /*+ Registration function: |
||
225 | TIME slice the slice for the Round Robin queue +*/ |
||
334 | giacomo | 226 | LEVEL MPEGSTAR_register_level(int master) |
324 | giacomo | 227 | { |
228 | LEVEL l; /* the level that we register */ |
||
229 | MPEGSTAR_level_des *lev; /* for readableness only */ |
||
230 | |||
231 | l = level_alloc_descriptor(sizeof(MPEGSTAR_level_des)); |
||
232 | |||
233 | lev = (MPEGSTAR_level_des *)level_table[l]; |
||
234 | |||
235 | lev->l.public_guarantee = NULL; |
||
236 | lev->l.public_create = MPEGSTAR_public_create; |
||
237 | lev->l.public_end = MPEGSTAR_public_end; |
||
238 | lev->l.public_dispatch = MPEGSTAR_public_dispatch; |
||
239 | lev->l.public_epilogue = MPEGSTAR_public_epilogue; |
||
240 | lev->l.public_activate = MPEGSTAR_public_activate; |
||
241 | lev->l.public_unblock = MPEGSTAR_public_unblock; |
||
242 | lev->l.public_block = MPEGSTAR_public_block; |
||
243 | lev->l.public_message = MPEGSTAR_public_message; |
||
244 | lev->l.public_eligible = MPEGSTAR_public_eligible; |
||
245 | |||
338 | giacomo | 246 | lev->budget = NIL; |
247 | lev->current = NIL; |
||
334 | giacomo | 248 | |
249 | lev->scheduling_level = master; |
||
250 | |||
324 | giacomo | 251 | return l; |
252 | |||
253 | } |
||
334 | giacomo | 254 | |
255 | int MPEGSTAR_setbudget(LEVEL l, PID p, int budget) |
||
256 | { |
||
257 | |||
258 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
259 | |||
338 | giacomo | 260 | lev->budget = budget; |
334 | giacomo | 261 | |
262 | return 0; |
||
263 | |||
264 | } |
||
265 | |||
266 | int MPEGSTAR_getbudget(LEVEL l, PID p) |
||
267 | { |
||
268 | |||
269 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
270 | |||
338 | giacomo | 271 | return lev->budget; |
334 | giacomo | 272 | |
273 | } |
||
274 | |||
275 | int MPEGSTAR_budget_has_thread(LEVEL l, int budget) |
||
338 | giacomo | 276 | { |
277 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
278 | |||
279 | if (lev->budget == budget) return 1; |
||
280 | return 0; |
||
281 | |||
282 | } |
||
283 | |||
284 | int MPEGSTAR_rescale(LEVEL l, TIME Q, TIME T) |
||
334 | giacomo | 285 | { |
286 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
338 | giacomo | 287 | |
288 | SERVER_adjust_budget(lev->scheduling_level,Q,T,lev->budget); |
||
289 | lev->server_Q = Q; |
||
290 | lev->server_T = T; |
||
291 | if (lev->current != NIL) { |
||
292 | proc_table[lev->current].avail_time = Q; |
||
293 | proc_table[lev->current].wcet = Q; |
||
294 | } |
||
295 | |||
334 | giacomo | 296 | return 0; |
297 | } |