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