Rev 853 | Rev 867 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
853 | trimarchi | 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 "nonestar.h" |
||
46 | #include "fsf_contract.h" |
||
47 | #include "fsf_server.h" |
||
48 | #include "tracer.h" |
||
49 | |||
50 | #define NONESTAR_DEBUG |
||
51 | |||
52 | /*+ Status used in the level +*/ |
||
53 | #define NONESTAR_READY MODULE_STATUS_BASE |
||
54 | |||
55 | #define NONESTAR_IDLE 0 |
||
56 | |||
57 | typedef struct { |
||
58 | level_des l; /*+ the standard level descriptor +*/ |
||
59 | |||
60 | int server_Q; |
||
61 | int server_T; |
||
62 | |||
63 | int budget; |
||
64 | int current; |
||
65 | int status; |
||
66 | |||
67 | int scheduling_level; |
||
68 | |||
69 | } NONESTAR_level_des; |
||
70 | |||
71 | static int NONESTAR_public_eligible(LEVEL l, PID p) |
||
72 | { |
||
73 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
74 | return level_table[ lev->scheduling_level ]-> |
||
75 | private_eligible(lev->scheduling_level,p); |
||
76 | |||
77 | return 0; |
||
78 | } |
||
79 | |||
80 | static int NONESTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
||
81 | { |
||
82 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
83 | |||
84 | #ifdef NONESTAR_DEBUG |
||
85 | kern_printf("(NN:Crt:%d)",p); |
||
86 | #endif |
||
87 | |||
857 | blundell | 88 | if (m->pclass != DUMMY_PCLASS) return -1; |
853 | trimarchi | 89 | if (m->level != 0 && m->level != l) return -1; |
857 | blundell | 90 | if (lev->current != NIL) return -1; |
853 | trimarchi | 91 | |
92 | lev->current = p; |
||
93 | lev->status = NONESTAR_IDLE; |
||
94 | |||
95 | proc_table[p].avail_time = lev->server_Q; |
||
96 | proc_table[p].wcet = lev->server_Q; |
||
97 | proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP); |
||
98 | |||
99 | return 0; /* OK */ |
||
100 | |||
101 | } |
||
102 | |||
103 | static void NONESTAR_public_dispatch(LEVEL l, PID p, int nostop) |
||
104 | { |
||
105 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
106 | |||
107 | #ifdef NONESTAR_DEBUG |
||
108 | kern_printf("(NN:Dsp:%d)",p); |
||
109 | #endif |
||
110 | |||
111 | if (!nostop) { |
||
112 | level_table[ lev->scheduling_level ] -> |
||
113 | private_dispatch(lev->scheduling_level, p, nostop); |
||
114 | } |
||
115 | |||
116 | } |
||
117 | |||
118 | static void NONESTAR_public_epilogue(LEVEL l, PID p) |
||
119 | { |
||
120 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
121 | int r; |
||
122 | |||
123 | #ifdef NONESTAR_DEBUG |
||
124 | kern_printf("(NN:Epi:%d)",p); |
||
125 | #endif |
||
126 | |||
127 | level_table[ lev->scheduling_level ] -> |
||
128 | private_epilogue(lev->scheduling_level,p); |
||
129 | /* |
||
130 | r = SERVER_get_remain_capacity(lev->scheduling_level,lev->budget); |
||
131 | if (r < 0) { |
||
132 | |||
133 | #ifdef NONESTAR_DEBUG |
||
134 | kern_printf("(NN:NONE END %d)",p); |
||
135 | #endif |
||
136 | |||
137 | lev->status = NONESTAR_IDLE; |
||
138 | |||
139 | level_table[ lev->scheduling_level ]-> |
||
140 | private_extract(lev->scheduling_level, p); |
||
141 | |||
142 | } |
||
143 | */ |
||
144 | } |
||
145 | |||
146 | static void NONESTAR_public_activate(LEVEL l, PID p, struct timespec *o) |
||
147 | { |
||
148 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
149 | BUDGET_TASK_MODEL b; |
||
150 | |||
151 | budget_task_default_model(b, lev->budget); |
||
152 | |||
153 | #ifdef NONESTAR_DEBUG |
||
154 | kern_printf("(NN:Act:%d:%d)",p,lev->budget); |
||
155 | #endif |
||
156 | |||
157 | lev->status = NONESTAR_READY; |
||
158 | |||
159 | level_table[ lev->scheduling_level ]-> |
||
160 | private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b); |
||
161 | |||
162 | } |
||
163 | |||
164 | static void NONESTAR_public_unblock(LEVEL l, PID p) |
||
165 | { |
||
166 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
167 | |||
168 | } |
||
169 | |||
170 | static void NONESTAR_public_block(LEVEL l, PID p) |
||
171 | { |
||
172 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
173 | |||
174 | } |
||
175 | |||
176 | static int NONESTAR_public_message(LEVEL l, PID p, void *m) |
||
177 | { |
||
178 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
179 | |||
180 | switch ((long)(m)) { |
||
181 | |||
182 | /* Task EndCycle */ |
||
183 | case (long)(NULL): |
||
184 | |||
185 | #ifdef NONESTAR_DEBUG |
||
186 | kern_printf("(NN:EndCycle:%d)",p); |
||
187 | #endif |
||
188 | |||
189 | lev->status = NONESTAR_IDLE; |
||
190 | |||
191 | level_table[ lev->scheduling_level ]-> |
||
192 | private_extract(lev->scheduling_level, p); |
||
193 | |||
194 | level_table[ lev->scheduling_level ]-> |
||
195 | public_message(lev->scheduling_level, p, NULL); |
||
196 | |||
197 | TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,proc_table[p].context,proc_table[p].task_level); |
||
198 | jet_update_endcycle(); /* Update the Jet data... */ |
||
199 | break; |
||
200 | |||
201 | /* Task Disable */ |
||
202 | case (long)(1): |
||
203 | |||
204 | break; |
||
205 | |||
206 | default: |
||
207 | |||
208 | break; |
||
209 | |||
210 | } |
||
211 | |||
212 | |||
213 | |||
214 | return 0; |
||
215 | |||
216 | } |
||
217 | |||
218 | static void NONESTAR_public_end(LEVEL l, PID p) |
||
219 | { |
||
220 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
221 | |||
222 | #ifdef NONESTAR_DEBUG |
||
223 | kern_printf("(NN:End:%d)", p); |
||
224 | #endif |
||
225 | |||
226 | lev->current = NIL; |
||
227 | lev->status = NONESTAR_IDLE; |
||
228 | proc_table[p].status = FREE; |
||
229 | |||
230 | } |
||
231 | |||
232 | /* Registration functions */ |
||
233 | |||
234 | /*+ Registration function: |
||
235 | TIME slice the slice for the Round Robin queue +*/ |
||
236 | LEVEL NONESTAR_register_level(int master) |
||
237 | { |
||
238 | LEVEL l; /* the level that we register */ |
||
239 | NONESTAR_level_des *lev; /* for readableness only */ |
||
240 | |||
241 | l = level_alloc_descriptor(sizeof(NONESTAR_level_des)); |
||
242 | |||
243 | lev = (NONESTAR_level_des *)level_table[l]; |
||
244 | |||
245 | lev->l.public_guarantee = NULL; |
||
246 | lev->l.public_create = NONESTAR_public_create; |
||
247 | lev->l.public_end = NONESTAR_public_end; |
||
248 | lev->l.public_dispatch = NONESTAR_public_dispatch; |
||
249 | lev->l.public_epilogue = NONESTAR_public_epilogue; |
||
250 | lev->l.public_activate = NONESTAR_public_activate; |
||
251 | lev->l.public_unblock = NONESTAR_public_unblock; |
||
252 | lev->l.public_block = NONESTAR_public_block; |
||
253 | lev->l.public_message = NONESTAR_public_message; |
||
254 | lev->l.public_eligible = NONESTAR_public_eligible; |
||
255 | |||
256 | lev->budget = NIL; |
||
257 | lev->current = NIL; |
||
258 | lev->status = NONESTAR_IDLE; |
||
259 | lev->server_Q = 0; |
||
260 | lev->server_T = 0; |
||
261 | |||
262 | lev->scheduling_level = master; |
||
263 | |||
264 | return l; |
||
265 | |||
266 | } |
||
267 | |||
268 | int NONESTAR_setbudget(LEVEL l, PID p, int budget) |
||
269 | { |
||
270 | |||
271 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
272 | |||
273 | lev->budget = budget; |
||
274 | |||
275 | return 0; |
||
276 | |||
277 | } |
||
278 | |||
279 | int NONESTAR_getbudget(LEVEL l, PID p) |
||
280 | { |
||
281 | |||
282 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
283 | |||
284 | return lev->budget; |
||
285 | |||
286 | } |
||
287 | |||
288 | int NONESTAR_budget_has_thread(LEVEL l, int budget) |
||
289 | { |
||
290 | NONESTAR_level_des *lev = (NONESTAR_level_des *)(level_table[l]); |
||
291 | |||
292 | if (lev->budget == budget) return 1; |
||
293 | return 0; |
||
294 | |||
295 | } |
||
296 | |||
297 | int NONESTAR_get_remain_capacity(int budget) |
||
298 | { |
||
299 | return SERVER_get_remain_capacity(fsf_get_server_level(),budget); |
||
300 | } |
||
301 | |||
302 | int NONESTAR_get_last_reclaiming(int budget) |
||
303 | { |
||
304 | return SERVER_get_last_reclaiming(fsf_get_server_level(),exec_shadow); |
||
305 | } |
||
306 | |||
307 |