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