Rev 1578 | 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, Gerardo Lamastra and Giuseppe Lipari |
||
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 | * |
||
1578 | tullio | 37 | * CVS : $Id: aster5.c,v 1.7 2006-07-03 11:14:56 tullio Exp $ |
1120 | pj | 38 | |
39 | this is a part of the classic Hartik demo Aster. |
||
40 | |||
41 | it is based on test 13 (d), and use the CBS to serve the periodic tasks. |
||
42 | |||
43 | There are not periodic tasks, only CBS tasks. |
||
44 | |||
45 | The tasks use a PI, NPP or NOP mutex to access the video memory. |
||
46 | |||
47 | A flag (LONGSC) is provided to try long and short critical sections. |
||
48 | |||
49 | This demo is really interesting because you can note the behavior of |
||
50 | the system, and the differences between the various protocols... |
||
51 | |||
52 | */ |
||
53 | |||
54 | #include "kernel/kern.h" |
||
1552 | pj | 55 | #include "edf/edf/edf.h" |
56 | #include "cbs/cbs/cbs.h" |
||
1120 | pj | 57 | |
1377 | giacomo | 58 | #include <drivers/shark_keyb26.h> |
59 | |||
1120 | pj | 60 | int num_aster = 0; |
61 | #define ASTER_LIM 60 |
||
62 | #define DISPLAY_MAX 15 |
||
63 | #define ASTER_MAX 70 |
||
64 | #define STAT_Y 9 |
||
65 | |||
66 | #define PER_MAX 5 |
||
67 | #define APER_MAX 8 |
||
68 | |||
69 | #define PER_WCET 6200 |
||
70 | #define APER_WCET 18400 |
||
71 | #define JET_WCET 10000 |
||
72 | #define JET_PERIOD 100000 |
||
73 | |||
74 | #define APER_REP 22000 |
||
75 | |||
76 | //PID aper_table[APER_MAX]; |
||
77 | |||
78 | mutex_t m1; |
||
79 | |||
80 | |||
81 | #define PIMUTEX |
||
82 | //#define NPPMUTEX |
||
83 | //#define NOPMUTEX |
||
84 | |||
85 | #define LONGSC |
||
86 | |||
87 | #ifdef LONGSC |
||
88 | #define SOFT_MET 3000 /* 3000 12000 */ |
||
89 | #define CLOCK_WCET 400 /* 200 300*/ |
||
90 | #define ASTER_WCET 400 /* 200 300*/ |
||
91 | #else |
||
92 | #define SOFT_MET 80000 /* 4500 */ |
||
93 | #define CLOCK_WCET 2000 /* 200*/ |
||
94 | #define ASTER_WCET 2000 /* 200*/ |
||
95 | #endif |
||
96 | |||
97 | TASK asteroide(void) |
||
98 | { |
||
99 | int i; |
||
100 | int y = rand() % 7 + 1; |
||
101 | |||
102 | int load1,j; |
||
103 | |||
104 | char s[2]; |
||
105 | |||
106 | s[0] = '*'; s[1] = 0; |
||
107 | |||
108 | for (;;) { |
||
109 | i = 1; |
||
110 | while (i < ASTER_LIM) { |
||
111 | load1 = 10000; //8000 + rand()%2000; |
||
112 | #ifdef LONGSC |
||
113 | mutex_lock(&m1); |
||
114 | #endif |
||
115 | for (j=0; j<load1; j++) { |
||
116 | s[0] = '*' + rand() % 100; |
||
117 | #ifndef LONGSC |
||
118 | mutex_lock(&m1); |
||
119 | #endif |
||
120 | puts_xy(i,y,rand()%15+1,s); |
||
121 | #ifndef LONGSC |
||
122 | mutex_unlock(&m1); |
||
123 | #endif |
||
124 | } |
||
125 | #ifdef LONGSC |
||
126 | mutex_unlock(&m1); |
||
127 | #endif |
||
128 | |||
129 | // task_activate(aper_table[rand()%APER_MAX]); |
||
130 | task_endcycle(); |
||
131 | |||
132 | mutex_lock(&m1); |
||
133 | puts_xy(i,y,WHITE," "); |
||
134 | mutex_unlock(&m1); |
||
135 | i++; |
||
136 | } |
||
137 | } |
||
138 | //num_aster--; |
||
139 | } |
||
140 | |||
141 | TASK aper_asteroid(void *a) |
||
142 | { |
||
143 | int i; |
||
144 | int y = rand() % 7 + 1; |
||
145 | |||
146 | int load1,j; |
||
147 | int c; |
||
148 | |||
149 | char s[2]; |
||
150 | |||
151 | c = (int)a; |
||
152 | s[0] = '*'; s[1] = 0; |
||
153 | |||
154 | for (;;) { |
||
155 | i = 1; |
||
156 | while (i < ASTER_LIM) { |
||
157 | load1 = APER_REP; //8000 + rand()%2000; |
||
158 | #ifdef LONGSC |
||
159 | mutex_lock(&m1); |
||
160 | #endif |
||
161 | for (j=0; j<load1; j++) { |
||
162 | s[0] = '*' + rand() % 100; |
||
163 | #ifndef LONGSC |
||
164 | mutex_lock(&m1); |
||
165 | #endif |
||
166 | puts_xy(i,y,rand()%15+1,s); |
||
167 | #ifndef LONGSC |
||
168 | mutex_unlock(&m1); |
||
169 | #endif |
||
170 | } |
||
171 | s[0] = c; |
||
172 | #ifndef LONGSC |
||
173 | mutex_lock(&m1); |
||
174 | #endif |
||
175 | puts_xy(i,y,rand()%15+1,s); |
||
176 | mutex_unlock(&m1); |
||
177 | |||
178 | task_endcycle(); |
||
179 | |||
180 | mutex_lock(&m1); |
||
181 | puts_xy(i,y,WHITE," "); |
||
182 | mutex_unlock(&m1); |
||
183 | i++; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | |||
188 | TASK soft_aster(void) |
||
189 | { |
||
190 | int i; |
||
191 | int y = rand() % 7 + 1; |
||
192 | |||
193 | int load1,j; |
||
194 | |||
195 | char s[2]; |
||
196 | |||
197 | s[0] = '*'; s[1] = 0; |
||
198 | |||
199 | /*for (;;)*/ { |
||
200 | i = 1; |
||
201 | while (i < ASTER_LIM) { |
||
202 | load1 = 1000 + rand()%9000; |
||
203 | #ifdef LONGSC |
||
204 | mutex_lock(&m1); |
||
205 | #endif |
||
206 | for (j=0; j<load1; j++) { |
||
207 | s[0] = '*' + rand() % 100; |
||
208 | #ifndef LONGSC |
||
209 | mutex_lock(&m1); |
||
210 | #endif |
||
211 | puts_xy(i,y,rand()%15+1,s); |
||
212 | #ifndef LONGSC |
||
213 | mutex_unlock(&m1); |
||
214 | #endif |
||
215 | } |
||
216 | s[0] = 1; |
||
217 | #ifndef LONGSC |
||
218 | mutex_lock(&m1); |
||
219 | #endif |
||
220 | puts_xy(i,y,rand()%15+1,s); |
||
221 | mutex_unlock(&m1); |
||
222 | |||
223 | // task_activate(aper_table[rand()%APER_MAX]); |
||
224 | task_endcycle(); |
||
225 | |||
226 | mutex_lock(&m1); |
||
227 | puts_xy(i,y,WHITE," "); |
||
228 | mutex_unlock(&m1); |
||
229 | i++; |
||
230 | } |
||
231 | } |
||
232 | num_aster--; |
||
233 | return 0; |
||
234 | } |
||
235 | |||
236 | TASK aster() |
||
237 | { |
||
238 | PID p; |
||
239 | // HARD_TASK_MODEL m; |
||
240 | SOFT_TASK_MODEL m_soft; |
||
241 | int r; |
||
242 | int x; // adaptive bandwidth... |
||
243 | |||
244 | srand(7); |
||
245 | |||
246 | /* periodic_task_default_model(m,0,PER_WCET); |
||
247 | periodic_task_def_ctrl_jet(m); |
||
248 | for (x=0; x<PER_MAX; x++) { |
||
249 | r = (rand() % 200); |
||
250 | periodic_task_def_period(m, (64+r)*1000); |
||
251 | p = task_create("per",asteroide,&m,NULL); |
||
252 | if (p!=-1) task_activate(p); |
||
253 | } |
||
254 | */ |
||
255 | soft_task_default_model(m_soft); |
||
256 | soft_task_def_met(m_soft,SOFT_MET); |
||
257 | soft_task_def_ctrl_jet(m_soft); |
||
258 | |||
259 | x = 128; //64; |
||
260 | |||
261 | while (1) { |
||
262 | if (num_aster < ASTER_MAX) { |
||
263 | r = (rand() % 200); |
||
264 | |||
265 | soft_task_def_period(m_soft, (x+r)*1000); |
||
266 | p = task_create("aaa",soft_aster,&m_soft,NULL); |
||
267 | if (p == -1) |
||
268 | { |
||
269 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
270 | mutex_lock(&m1); |
||
271 | printf_xy(62,3,WHITE,"adapt=%3u err=%d", |
||
272 | iq_query_first(&freedesc),errno); |
||
273 | mutex_unlock(&m1); |
||
274 | } |
||
275 | else { |
||
276 | num_aster++; |
||
277 | mutex_lock(&m1); |
||
278 | printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
||
279 | mutex_unlock(&m1); |
||
280 | |||
281 | task_activate(p); |
||
282 | x /= 2; |
||
283 | if (x<50) x = 50; |
||
284 | } |
||
285 | } |
||
286 | task_endcycle(); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | TASK clock() |
||
291 | { |
||
292 | int s = 0, m = 0; |
||
293 | |||
294 | while(1) { |
||
295 | mutex_lock(&m1); |
||
296 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
1388 | giacomo | 297 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1)); |
1120 | pj | 298 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2)); |
299 | |||
300 | mutex_unlock(&m1); |
||
301 | task_endcycle(); |
||
302 | |||
303 | if (++s > 59) { |
||
304 | s = 0; |
||
305 | m++; |
||
306 | } |
||
307 | mutex_lock(&m1); |
||
308 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
1388 | giacomo | 309 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1)); |
1120 | pj | 310 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2)); |
311 | mutex_unlock(&m1); |
||
312 | task_endcycle(); |
||
313 | } |
||
314 | } |
||
315 | |||
316 | |||
317 | |||
318 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
319 | and plot on the screen the elapsed times... */ |
||
320 | TASK jetcontrol() |
||
321 | { |
||
322 | int i; /* a counter */ |
||
323 | TIME sum, max, curr, last[5]; |
||
324 | int nact; |
||
325 | int j; /* the elements set by jet_gettable */ |
||
326 | PID p; |
||
327 | |||
328 | |||
329 | mutex_lock(&m1); |
||
330 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
331 | mutex_unlock(&m1); |
||
332 | |||
333 | for (;;) { |
||
334 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
335 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*|| |
||
336 | (proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS || |
||
337 | (proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue; |
||
338 | |||
339 | for (j=0; j<5; j++) last[j] = 0; |
||
340 | jet_gettable(p, &last[0], 5); |
||
341 | mutex_lock(&m1); |
||
342 | if (proc_table[p].task_level == 2) |
||
343 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³p%-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
344 | p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
||
345 | // p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), last[4]); |
||
346 | else |
||
347 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
348 | 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]); |
||
349 | // p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)proc_table[p].status, (int)proc_table[p].shadow, (int)proc_table[p].timespec_priority.tv_sec,(int)proc_table[p].timespec_priority.tv_nsec/1000 , (int)last[3], (int)last[4]); |
||
350 | mutex_unlock(&m1); |
||
351 | i++; |
||
352 | } |
||
353 | } |
||
354 | } |
||
355 | |||
356 | void fine(KEY_EVT *e) |
||
357 | { |
||
1547 | pj | 358 | exit(0);} |
1120 | pj | 359 | |
360 | int main(int argc, char **argv) |
||
361 | { |
||
362 | PID p1,p2,p3;//,p4,p5,p6; |
||
363 | HARD_TASK_MODEL m; |
||
364 | // NRT_TASK_MODEL m_nrt; |
||
365 | SOFT_TASK_MODEL m_aper; |
||
366 | SOFT_TASK_MODEL m_soft; |
||
367 | // int i; |
||
368 | struct timespec fineprg; |
||
369 | |||
370 | #ifdef PIMUTEX |
||
371 | PI_mutexattr_t a; |
||
372 | #endif |
||
373 | |||
374 | #ifdef NPPMUTEX |
||
375 | NPP_mutexattr_t a; |
||
376 | #endif |
||
377 | |||
378 | #ifdef NOPMUTEX |
||
379 | NOP_mutexattr_t a; |
||
380 | #endif |
||
381 | |||
382 | KEY_EVT emerg; |
||
1377 | giacomo | 383 | |
1578 | tullio | 384 | emerg.ascii = 'c'; |
385 | emerg.scan = KEY_C; |
||
386 | emerg.flag = CNTL_BIT; |
||
1377 | giacomo | 387 | emerg.status = KEY_PRESSED; |
388 | keyb_hook(emerg,fine,FALSE); |
||
1578 | tullio | 389 | |
390 | emerg.flag = CNTR_BIT; |
||
391 | emerg.status = KEY_PRESSED; |
||
392 | keyb_hook(emerg,fine,FALSE); |
||
1120 | pj | 393 | |
394 | clear(); |
||
395 | |||
396 | hard_task_default_model(m); |
||
397 | hard_task_def_wcet(m,ASTER_WCET); |
||
398 | hard_task_def_mit(m,100000); |
||
399 | hard_task_def_group(m,1); |
||
400 | hard_task_def_ctrl_jet(m); |
||
401 | |||
402 | // nrt_task_default_model(m_nrt); |
||
403 | // nrt_task_def_group(m_nrt,1); |
||
404 | // nrt_task_def_ctrl_jet(m_nrt); |
||
405 | |||
406 | |||
407 | soft_task_default_model(m_aper); |
||
408 | soft_task_def_group(m_aper,1); |
||
409 | soft_task_def_ctrl_jet(m_aper); |
||
410 | soft_task_def_aperiodic(m_aper); |
||
411 | |||
412 | soft_task_default_model(m_soft); |
||
413 | soft_task_def_period(m_soft,JET_PERIOD); |
||
414 | soft_task_def_met(m_soft,JET_WCET); |
||
415 | soft_task_def_group(m_soft,1); |
||
416 | soft_task_def_ctrl_jet(m_soft); |
||
417 | soft_task_def_aperiodic(m_soft); |
||
418 | |||
419 | |||
420 | p1 = task_create("Aster",aster,&m,NULL); |
||
421 | if (p1 == -1) { |
||
1377 | giacomo | 422 | sys_shutdown_message("test7.c(main): Could not create task <aster> ..."); |
1547 | pj | 423 | exit(1); |
1120 | pj | 424 | } |
425 | |||
426 | hard_task_def_mit(m,500000); |
||
427 | hard_task_def_wcet(m,CLOCK_WCET); |
||
428 | p2 = task_create("Clock",clock,&m,NULL); |
||
429 | if (p2 == -1) { |
||
1377 | giacomo | 430 | sys_shutdown_message("test7.c(main): Could not create task <Clock> ..."); |
1547 | pj | 431 | exit(1); |
1120 | pj | 432 | } |
433 | |||
434 | // p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
||
435 | p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
||
436 | if (p2 == -1) { |
||
1377 | giacomo | 437 | sys_shutdown_message("test7.c(main): Could not create task <JetControl> ..."); |
1547 | pj | 438 | exit(1); |
1120 | pj | 439 | } |
440 | /* |
||
441 | aperiodic_task_default_model(m_aper,APER_WCET); |
||
442 | aperiodic_task_def_ctrl_jet(m_aper); |
||
443 | aperiodic_task_def_system(m_aper); |
||
444 | |||
445 | for (i=0; i<APER_MAX; i++) { |
||
446 | aperiodic_task_def_level(m_aper, i/4 + 2); |
||
447 | aperiodic_task_def_arg(m_aper, (i/4 ? 'Û' : '±')); |
||
448 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
449 | if (aper_table[i] == -1) { |
||
450 | perror("test7.c(main): Could not create task <aper> ..."); |
||
1547 | pj | 451 | exit(1); |
1120 | pj | 452 | } |
453 | } |
||
454 | */ |
||
455 | task_nopreempt(); |
||
456 | |||
457 | #ifdef PIMUTEX |
||
458 | PI_mutexattr_default(a); |
||
459 | #endif |
||
460 | |||
461 | #ifdef NPPMUTEX |
||
462 | NPP_mutexattr_default(a); |
||
463 | #endif |
||
464 | |||
465 | #ifdef NOPMUTEX |
||
466 | NOP_mutexattr_default(a); |
||
467 | #endif |
||
468 | |||
469 | mutex_init(&m1, &a); |
||
470 | |||
471 | fineprg.tv_sec = 1800; |
||
472 | fineprg.tv_nsec = 0; |
||
473 | group_activate(1); |
||
474 | return 0; |
||
475 | } |
||
476 |