Rev 338 | Rev 340 | 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; |
65 | |||
66 | } MPEGSTAR_level_des; |
||
67 | |||
68 | static int MPEGSTAR_public_eligible(LEVEL l, PID p) |
||
69 | { |
||
70 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
71 | return level_table[ lev->scheduling_level ]-> |
||
72 | private_eligible(lev->scheduling_level,p); |
||
73 | |||
74 | return 0; |
||
75 | } |
||
76 | |||
77 | static int MPEGSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
78 | { |
||
79 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
80 | |||
334 | giacomo | 81 | #ifdef MPEGSTAR_DEBUG |
82 | kern_printf("(MP:Crt:%d)",p); |
||
83 | #endif |
||
338 | giacomo | 84 | |
85 | if (m->pclass != HARD_PCLASS) return -1; |
||
334 | giacomo | 86 | if (m->level != 0 && m->level != l) return -1; |
338 | giacomo | 87 | |
88 | lev->current = p; |
||
334 | giacomo | 89 | |
90 | proc_table[p].avail_time = lev->server_Q; |
||
338 | giacomo | 91 | proc_table[p].wcet = lev->server_Q; |
92 | proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP); |
||
93 | |||
324 | giacomo | 94 | return 0; /* OK */ |
338 | giacomo | 95 | |
324 | giacomo | 96 | } |
97 | |||
98 | static void MPEGSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
||
99 | { |
||
100 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
101 | |||
338 | giacomo | 102 | #ifdef MPEGSTAR_DEBUG |
103 | kern_printf("(MS:Dsp:%d)",p); |
||
104 | #endif |
||
105 | |||
106 | if (!nostop) { |
||
339 | giacomo | 107 | level_table[ lev->scheduling_level ] -> |
108 | private_dispatch(lev->scheduling_level, p, nostop); |
||
338 | giacomo | 109 | } |
334 | giacomo | 110 | |
324 | giacomo | 111 | } |
112 | |||
113 | static void MPEGSTAR_public_epilogue(LEVEL l, PID p) |
||
114 | { |
||
115 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
334 | giacomo | 116 | |
338 | giacomo | 117 | #ifdef MPEGSTAR_DEBUG |
118 | kern_printf("(MS:Epi:%d)",p); |
||
119 | #endif |
||
120 | |||
334 | giacomo | 121 | level_table[ lev->scheduling_level ] -> |
122 | private_epilogue(lev->scheduling_level,p); |
||
324 | giacomo | 123 | |
124 | } |
||
125 | |||
126 | static void MPEGSTAR_public_activate(LEVEL l, PID p) |
||
127 | { |
||
128 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
334 | giacomo | 129 | BUDGET_TASK_MODEL b; |
338 | giacomo | 130 | |
131 | budget_task_default_model(b, lev->budget); |
||
334 | giacomo | 132 | |
133 | #ifdef MPEGSTAR_DEBUG |
||
338 | giacomo | 134 | kern_printf("(MP:Act:%d:%d)",p,lev->budget); |
334 | giacomo | 135 | #endif |
324 | giacomo | 136 | |
334 | giacomo | 137 | level_table[ lev->scheduling_level ]-> |
138 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b); |
||
139 | |||
324 | giacomo | 140 | } |
141 | |||
142 | static void MPEGSTAR_public_unblock(LEVEL l, PID p) |
||
143 | { |
||
144 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
145 | |||
146 | } |
||
147 | |||
148 | static void MPEGSTAR_public_block(LEVEL l, PID p) |
||
149 | { |
||
150 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
151 | |||
152 | } |
||
153 | |||
154 | static int MPEGSTAR_public_message(LEVEL l, PID p, void *m) |
||
155 | { |
||
156 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
157 | |||
158 | switch ((long)(m)) { |
||
159 | |||
160 | /* Task EndCycle */ |
||
161 | case (long)(NULL): |
||
162 | |||
338 | giacomo | 163 | lev->current = NIL; |
164 | |||
339 | giacomo | 165 | #ifdef MPEGSTAR_DEBUG |
166 | kern_printf("(MS:EndCycle:%d)",p); |
||
167 | #endif |
||
338 | giacomo | 168 | |
334 | giacomo | 169 | level_table[ lev->scheduling_level ]-> |
338 | giacomo | 170 | private_extract(lev->scheduling_level, p); |
171 | |||
172 | level_table[ lev->scheduling_level ]-> |
||
334 | giacomo | 173 | public_message(lev->scheduling_level, p, NULL); |
174 | |||
324 | giacomo | 175 | break; |
176 | |||
177 | /* Task Disable */ |
||
178 | case (long)(1): |
||
179 | |||
180 | break; |
||
181 | |||
182 | default: |
||
183 | |||
184 | break; |
||
185 | |||
186 | } |
||
187 | |||
188 | return 0; |
||
189 | |||
190 | } |
||
191 | |||
192 | static void MPEGSTAR_public_end(LEVEL l, PID p) |
||
193 | { |
||
194 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
195 | |||
196 | } |
||
197 | |||
198 | /* Registration functions */ |
||
199 | |||
200 | /*+ Registration function: |
||
201 | TIME slice the slice for the Round Robin queue +*/ |
||
334 | giacomo | 202 | LEVEL MPEGSTAR_register_level(int master) |
324 | giacomo | 203 | { |
204 | LEVEL l; /* the level that we register */ |
||
205 | MPEGSTAR_level_des *lev; /* for readableness only */ |
||
206 | |||
207 | l = level_alloc_descriptor(sizeof(MPEGSTAR_level_des)); |
||
208 | |||
209 | lev = (MPEGSTAR_level_des *)level_table[l]; |
||
210 | |||
211 | lev->l.public_guarantee = NULL; |
||
212 | lev->l.public_create = MPEGSTAR_public_create; |
||
213 | lev->l.public_end = MPEGSTAR_public_end; |
||
214 | lev->l.public_dispatch = MPEGSTAR_public_dispatch; |
||
215 | lev->l.public_epilogue = MPEGSTAR_public_epilogue; |
||
216 | lev->l.public_activate = MPEGSTAR_public_activate; |
||
217 | lev->l.public_unblock = MPEGSTAR_public_unblock; |
||
218 | lev->l.public_block = MPEGSTAR_public_block; |
||
219 | lev->l.public_message = MPEGSTAR_public_message; |
||
220 | lev->l.public_eligible = MPEGSTAR_public_eligible; |
||
221 | |||
338 | giacomo | 222 | lev->budget = NIL; |
223 | lev->current = NIL; |
||
339 | giacomo | 224 | lev->server_Q = 0; |
225 | lev->server_T = 0; |
||
334 | giacomo | 226 | |
227 | lev->scheduling_level = master; |
||
228 | |||
324 | giacomo | 229 | return l; |
230 | |||
231 | } |
||
334 | giacomo | 232 | |
233 | int MPEGSTAR_setbudget(LEVEL l, PID p, int budget) |
||
234 | { |
||
235 | |||
236 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
237 | |||
338 | giacomo | 238 | lev->budget = budget; |
334 | giacomo | 239 | |
240 | return 0; |
||
241 | |||
242 | } |
||
243 | |||
244 | int MPEGSTAR_getbudget(LEVEL l, PID p) |
||
245 | { |
||
246 | |||
247 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
248 | |||
338 | giacomo | 249 | return lev->budget; |
334 | giacomo | 250 | |
251 | } |
||
252 | |||
253 | int MPEGSTAR_budget_has_thread(LEVEL l, int budget) |
||
338 | giacomo | 254 | { |
255 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
||
256 | |||
257 | if (lev->budget == budget) return 1; |
||
258 | return 0; |
||
259 | |||
260 | } |
||
261 | |||
339 | giacomo | 262 | int MPEGSTAR_rescale(int budget, TIME Q, TIME T) |
334 | giacomo | 263 | { |
339 | giacomo | 264 | LEVEL l = SERVER_get_local_scheduler_level_from_budget(fsf_get_server_level(),budget); |
334 | giacomo | 265 | MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]); |
338 | giacomo | 266 | |
267 | SERVER_adjust_budget(lev->scheduling_level,Q,T,lev->budget); |
||
268 | lev->server_Q = Q; |
||
269 | lev->server_T = T; |
||
270 | if (lev->current != NIL) { |
||
271 | proc_table[lev->current].avail_time = Q; |
||
272 | proc_table[lev->current].wcet = Q; |
||
273 | } |
||
274 | |||
334 | giacomo | 275 | return 0; |
276 | } |