Rev 1585 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1120 | pj | 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 | * Paolo Gai <pj@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 WARRANTY; without even the implied warranty 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 | * |
||
1585 | tullio | 37 | * CVS : $Id: aster4.c,v 1.6 2006-07-03 13:08:29 tullio Exp $ |
1120 | pj | 38 | |
39 | Test Number 13 (D): |
||
40 | |||
41 | this is a part of the classic Hartik demo Aster, and it is based on aster 3. |
||
42 | |||
43 | The demo creates: |
||
44 | - a set of TBS tasks assigned to 2 TBS servers initialized with different bandwidth. |
||
45 | |||
46 | - a set of periodic tasks, just to make noise (function asteroide) |
||
47 | |||
48 | - a set of CBS tasks that are created to fill the available free |
||
49 | bandwidth (function soft_aster) |
||
50 | |||
51 | - a few service task (the one that creates the CBS tasks (aster), a clock, |
||
52 | JET info visualization |
||
53 | |||
54 | - a set of never ending "system tasks" that simulate a device driver |
||
55 | task that will end only at shutdown (function aper_asteroid) |
||
56 | |||
57 | - a keyboard task that will execute an hook to terminate the system |
||
58 | |||
59 | */ |
||
60 | |||
61 | /* |
||
62 | * Copyright (C) 2000 Paolo Gai |
||
63 | * |
||
64 | * This program is free software; you can redistribute it and/or modify |
||
65 | * it under the terms of the GNU General Public License as published by |
||
66 | * the Free Software Foundation; either version 2 of the License, or |
||
67 | * (at your option) any later version. |
||
68 | * |
||
69 | * This program is distributed in the hope that it will be useful, |
||
70 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
71 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
72 | * GNU General Public License for more details. |
||
73 | * |
||
74 | * You should have received a copy of the GNU General Public License |
||
75 | * along with this program; if not, write to the Free Software |
||
76 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
77 | * |
||
78 | */ |
||
79 | |||
80 | #include "kernel/kern.h" |
||
1552 | pj | 81 | #include "edf/edf/edf.h" |
82 | #include "cbs/cbs/cbs.h" |
||
1120 | pj | 83 | |
1377 | giacomo | 84 | #include <drivers/shark_linuxc26.h> |
85 | #include <drivers/shark_input26.h> |
||
86 | #include <drivers/shark_keyb26.h> |
||
87 | |||
1120 | pj | 88 | int num_aster = 0; |
89 | #define ASTER_LIM 60 |
||
90 | #define DISPLAY_MAX 15 |
||
91 | #define ASTER_MAX 70 |
||
92 | #define STAT_Y 9 |
||
93 | |||
94 | #define PER_MAX 5 |
||
95 | #define APER_MAX 8 |
||
96 | |||
97 | // These numbers works on a Pentium 133 */ |
||
98 | #define PER_WCET 25000 |
||
99 | #define APER_WCET 53000 |
||
100 | #define CLOCK_WCET 1000 |
||
101 | #define ASTER_WCET 1000 |
||
102 | #define SOFT_MET 6300 |
||
103 | |||
104 | #define APER_REP 22000 |
||
105 | |||
106 | PID aper_table[APER_MAX]; |
||
107 | |||
1547 | pj | 108 | int shutting_down = 0; |
109 | |||
1120 | pj | 110 | TASK asteroide(void) |
111 | { |
||
112 | int i; |
||
113 | int y = rand() % 7 + 1; |
||
114 | |||
115 | int load1,j; |
||
116 | |||
117 | char s[2]; |
||
118 | |||
119 | s[0] = '*'; s[1] = 0; |
||
120 | |||
121 | for (;;) { |
||
122 | i = 1; |
||
123 | while (i < ASTER_LIM) { |
||
124 | load1 = 10000; //8000 + rand()%2000; |
||
125 | for (j=0; j<load1; j++) { |
||
126 | s[0] = '*' + rand() % 100; |
||
127 | puts_xy(i,y,rand()%15+1,s); |
||
128 | } |
||
129 | |||
130 | task_activate(aper_table[rand()%APER_MAX]); |
||
131 | task_endcycle(); |
||
132 | |||
133 | puts_xy(i,y,WHITE," "); |
||
134 | i++; |
||
135 | } |
||
136 | } |
||
137 | //num_aster--; |
||
138 | } |
||
139 | |||
140 | TASK aper_asteroid(void *a) |
||
141 | { |
||
142 | int i; |
||
143 | int y = rand() % 7 + 1; |
||
144 | |||
145 | int load1,j; |
||
146 | int c; |
||
147 | |||
148 | char s[2]; |
||
149 | |||
150 | c = (int)a; |
||
151 | s[0] = '*'; s[1] = 0; |
||
152 | |||
153 | for (;;) { |
||
154 | i = 1; |
||
155 | while (i < ASTER_LIM) { |
||
156 | load1 = APER_REP; //8000 + rand()%2000; |
||
157 | for (j=0; j<load1; j++) { |
||
158 | s[0] = '*' + rand() % 100; |
||
159 | puts_xy(i,y,rand()%15+1,s); |
||
160 | } |
||
161 | s[0] = c; |
||
162 | puts_xy(i,y,rand()%15+1,s); |
||
163 | |||
1547 | pj | 164 | if (shutting_down) { |
165 | cprintf("Ending System Task %d\n",exec_shadow); |
||
166 | return 0; |
||
167 | } |
||
168 | |||
1120 | pj | 169 | task_endcycle(); |
170 | |||
171 | puts_xy(i,y,WHITE," "); |
||
172 | i++; |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | TASK soft_aster(void) |
||
178 | { |
||
179 | int i; |
||
180 | int y = rand() % 7 + 1; |
||
181 | |||
182 | int load1,j; |
||
183 | |||
184 | char s[2]; |
||
185 | |||
186 | s[0] = '*'; s[1] = 0; |
||
187 | |||
188 | i = 1; |
||
189 | while (i < ASTER_LIM) { |
||
190 | load1 = 1000 + rand()%9000; |
||
191 | for (j=0; j<load1; j++) { |
||
192 | s[0] = '*' + rand() % 100; |
||
193 | puts_xy(i,y,rand()%15+1,s); |
||
194 | } |
||
195 | s[0] = 1; |
||
196 | puts_xy(i,y,rand()%15+1,s); |
||
197 | |||
198 | task_activate(aper_table[rand()%APER_MAX]); |
||
199 | task_endcycle(); |
||
200 | |||
201 | puts_xy(i,y,WHITE," "); |
||
202 | i++; |
||
203 | } |
||
204 | num_aster--; |
||
205 | return 0; |
||
206 | } |
||
207 | |||
208 | TASK aster() |
||
209 | { |
||
210 | PID p; |
||
211 | |||
212 | HARD_TASK_MODEL m; |
||
213 | SOFT_TASK_MODEL m_soft; |
||
214 | int r; |
||
215 | int x; // adaptive bandwidth... |
||
216 | |||
217 | srand(7); |
||
218 | |||
219 | /* create a set of periodic tasks, just to make noise */ |
||
220 | hard_task_default_model(m); |
||
221 | hard_task_def_wcet(m,PER_WCET); |
||
222 | hard_task_def_ctrl_jet(m); |
||
223 | for (x=0; x<PER_MAX; x++) { |
||
224 | r = (rand() % 200); |
||
225 | hard_task_def_mit(m, (64+r)*1000); |
||
226 | p = task_create("per",asteroide,&m,NULL); |
||
227 | if (p!=-1) task_activate(p); |
||
228 | } |
||
229 | |||
230 | soft_task_default_model(m_soft); |
||
231 | soft_task_def_met(m_soft,SOFT_MET); |
||
232 | soft_task_def_ctrl_jet(m_soft); |
||
233 | |||
234 | x = 64; |
||
235 | |||
236 | while (1) { |
||
237 | if (num_aster < ASTER_MAX) { |
||
238 | r = (rand() % 200); |
||
239 | |||
240 | soft_task_def_period(m_soft, (x+r)*1000); |
||
241 | p = task_create("aaa",soft_aster,&m_soft,NULL); |
||
242 | if (p == -1) |
||
243 | { |
||
244 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
245 | printf_xy(62,3,WHITE,"adapt=%3u err=%d", |
||
246 | iq_query_first(&freedesc),errno); |
||
247 | } |
||
248 | else { |
||
249 | num_aster++; |
||
250 | printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
||
251 | task_activate(p); |
||
252 | x /= 2; |
||
253 | if (x<50) x = 50; |
||
254 | } |
||
255 | } |
||
256 | task_endcycle(); |
||
257 | } |
||
258 | } |
||
259 | |||
260 | TASK clock() |
||
261 | { |
||
262 | int s = 0, m = 0; |
||
263 | |||
264 | while(1) { |
||
265 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
1388 | giacomo | 266 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1)); |
267 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(5)); |
||
1120 | pj | 268 | task_endcycle(); |
269 | |||
270 | if (++s > 59) { |
||
271 | s = 0; |
||
272 | m++; |
||
273 | } |
||
274 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
1388 | giacomo | 275 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1)); |
276 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(5)); |
||
1120 | pj | 277 | task_endcycle(); |
278 | } |
||
279 | } |
||
280 | |||
281 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
282 | and plot on the screen the elapsed times... */ |
||
283 | TASK jetcontrol() |
||
284 | { |
||
285 | int i; /* a counter */ |
||
286 | TIME sum, max, curr, last[5]; |
||
287 | int nact; |
||
288 | int j; /* the elements set by jet_gettable */ |
||
289 | PID p; |
||
290 | |||
291 | |||
292 | kern_cli(); |
||
293 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
294 | kern_sti(); |
||
295 | |||
296 | for (;;) { |
||
297 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
298 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 || |
||
299 | (proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue; |
||
300 | |||
301 | for (j=0; j<5; j++) last[j] = 0; |
||
302 | jet_gettable(p, &last[0], 5); |
||
303 | kern_cli(); |
||
1388 | giacomo | 304 | if (proc_table[p].task_level == 5) |
1120 | pj | 305 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
306 | p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
||
307 | else |
||
308 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
309 | p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
||
310 | kern_sti(); |
||
311 | i++; |
||
312 | } |
||
313 | } |
||
314 | } |
||
315 | |||
316 | void endfun(KEY_EVT *k) |
||
317 | { |
||
1547 | pj | 318 | exit(0); |
1120 | pj | 319 | } |
320 | |||
1547 | pj | 321 | void exiting(void *arg) |
322 | { |
||
323 | cprintf("System shut down...\n"); |
||
324 | shutting_down = 1; |
||
325 | } |
||
326 | |||
1120 | pj | 327 | int main(int argc, char **argv) |
328 | { |
||
329 | KEY_EVT k; |
||
330 | |||
331 | PID p1,p2,p3; |
||
332 | HARD_TASK_MODEL m; |
||
333 | SOFT_TASK_MODEL m_aper; |
||
334 | SOFT_TASK_MODEL m_soft; |
||
335 | int i; |
||
336 | |||
1585 | tullio | 337 | k.ascii = 'c'; |
338 | k.scan = KEY_C; |
||
339 | k.flag = CNTL_BIT; |
||
1377 | giacomo | 340 | k.status = KEY_PRESSED; |
1585 | tullio | 341 | keyb_hook(k,endfun,FALSE); |
342 | |||
343 | k.flag = CNTR_BIT; |
||
344 | k.status = KEY_PRESSED; |
||
345 | keyb_hook(k,endfun,FALSE); |
||
1120 | pj | 346 | |
347 | clear(); |
||
1585 | tullio | 348 | cprintf("Press Ctrl-C to end the demo..."); |
1547 | pj | 349 | |
350 | sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN); |
||
1120 | pj | 351 | |
352 | hard_task_default_model(m); |
||
353 | hard_task_def_wcet(m,ASTER_WCET); |
||
354 | hard_task_def_mit(m,10000); |
||
355 | hard_task_def_group(m,1); |
||
356 | hard_task_def_ctrl_jet(m); |
||
357 | |||
358 | soft_task_default_model(m_soft); |
||
359 | soft_task_def_met(m_soft,1000); |
||
360 | soft_task_def_period(m_soft,100000); |
||
361 | soft_task_def_group(m_soft,1); |
||
362 | soft_task_def_ctrl_jet(m_soft); |
||
363 | soft_task_def_aperiodic(m_soft); |
||
364 | |||
365 | p1 = task_create("Aster",aster,&m,NULL); |
||
366 | if (p1 == -1) { |
||
1377 | giacomo | 367 | sys_shutdown_message("aster4.c(main): Could not create task <aster> ..."); |
1547 | pj | 368 | exit(0); |
1120 | pj | 369 | } |
370 | |||
371 | hard_task_def_mit(m,500000); |
||
372 | hard_task_def_wcet(m,CLOCK_WCET); |
||
373 | p2 = task_create("Clock",clock,&m,NULL); |
||
374 | if (p2 == -1) { |
||
1377 | giacomo | 375 | sys_shutdown_message("aster4.c(main): Could not create task <Clock> ..."); |
1547 | pj | 376 | exit(0); |
1120 | pj | 377 | } |
378 | |||
379 | p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
||
380 | if (p3 == -1) { |
||
1377 | giacomo | 381 | sys_shutdown_message("aster4.c(main): Could not create task <JetControl> ..."); |
1547 | pj | 382 | exit(0); |
1120 | pj | 383 | } |
384 | |||
385 | soft_task_default_model(m_aper); |
||
386 | soft_task_def_wcet(m_aper,APER_WCET); |
||
387 | soft_task_def_ctrl_jet(m_aper); |
||
388 | soft_task_def_system(m_aper); |
||
389 | soft_task_def_aperiodic(m_aper); |
||
390 | |||
391 | for (i=0; i<APER_MAX; i++) { |
||
1388 | giacomo | 392 | soft_task_def_level(m_aper, i/4 + 3); |
1120 | pj | 393 | soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±')); |
394 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
395 | if (aper_table[i] == -1) { |
||
1377 | giacomo | 396 | sys_shutdown_message("aster4.c(main): Could not create task <aper> ..."); |
1547 | pj | 397 | exit(0); |
1120 | pj | 398 | } |
399 | } |
||
400 | |||
401 | group_activate(1); |
||
402 | return 0; |
||
403 | } |
||
404 |