Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Gerardo Lamastra <gerardo@sssup.it> |
||
6 | * |
||
7 | * Authors : Paolo Gai <pj@hartik.sssup.it> |
||
8 | * (see authors.txt for full list of hartik's authors) |
||
9 | * |
||
10 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
11 | * |
||
12 | * http://www.sssup.it |
||
13 | * http://retis.sssup.it |
||
14 | * http://hartik.sssup.it |
||
15 | */ |
||
16 | |||
17 | /** |
||
18 | ------------ |
||
19 | CVS : $Id: testss.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $ |
||
20 | |||
21 | File: $File$ |
||
22 | Revision: $Revision: 1.1.1.1 $ |
||
23 | Last update: $Date: 2002-09-02 09:37:48 $ |
||
24 | ------------ |
||
25 | |||
26 | Test for Sporadic Server (ss): |
||
27 | |||
28 | this is a part of the classic Hartik demo Aster. |
||
29 | |||
30 | it is based on test 17 (h), and the JobControl Task uses an |
||
31 | SOFT_TASK_MODEL served by a sporadic server |
||
32 | There are two "dummy" tasks that increment a counter and print |
||
33 | the value. One uses a SOFT_TASK_MODEL served by sporadic server, |
||
34 | the other uses a NRT_TASK_MODEL handled by RR module. |
||
35 | |||
36 | **/ |
||
37 | |||
38 | /* |
||
39 | * Copyright (C) 2000 Paolo Gai |
||
40 | * |
||
41 | * This program is free software; you can redistribute it and/or modify |
||
42 | * it under the terms of the GNU General Public License as published by |
||
43 | * the Free Software Foundation; either version 2 of the License, or |
||
44 | * (at your option) any later version. |
||
45 | * |
||
46 | * This program is distributed in the hope that it will be useful, |
||
47 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
48 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
49 | * GNU General Public License for more details. |
||
50 | * |
||
51 | * You should have received a copy of the GNU General Public License |
||
52 | * along with this program; if not, write to the Free Software |
||
53 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
54 | * |
||
55 | */ |
||
56 | |||
57 | #include "kernel/kern.h" |
||
58 | #include "modules/edf.h" |
||
59 | #include "modules/cbs.h" |
||
60 | #include "modules/ss.h" |
||
61 | #include "drivers/keyb.h" |
||
62 | |||
63 | int num_aster = 0; |
||
64 | #define EDF_LEV 0 |
||
65 | #define CBS_LEV 1 |
||
66 | #define SS_LEV 2 |
||
67 | |||
68 | #define ASTER_LIM 60 |
||
69 | #define DISPLAY_MAX 8 |
||
70 | #define ASTER_MAX 70 |
||
71 | #define STAT_Y 9 |
||
72 | |||
73 | #define PER_MAX 5 |
||
74 | #define APER_MAX 8 |
||
75 | |||
76 | #define PER_WCET 16000 |
||
77 | #define APER_WCET 22000 |
||
78 | #define JET_WCET 20000 |
||
79 | |||
80 | #define APER_REP 22000 |
||
81 | |||
82 | PID aper_table[APER_MAX]; |
||
83 | |||
84 | mutex_t m1; |
||
85 | |||
86 | |||
87 | #define PIMUTEX |
||
88 | //#define PCMUTEX |
||
89 | //#define NPPMUTEX |
||
90 | //#define NOPMUTEX |
||
91 | |||
92 | #define LONGSC |
||
93 | |||
94 | #ifdef LONGSC |
||
95 | #define SOFT_MET 12000 /* 12000 */ |
||
96 | #define CLOCK_WCET 300 /* 300*/ |
||
97 | #define ASTER_WCET 300 /* 300*/ |
||
98 | #else |
||
99 | #define SOFT_MET 5000 /* 4500 */ |
||
100 | #define CLOCK_WCET 2000 /* 200*/ |
||
101 | #define ASTER_WCET 2000 /* 200*/ |
||
102 | #endif |
||
103 | |||
104 | PID p1,p2,p3,p4,p5; |
||
105 | |||
106 | TASK asteroide(void) |
||
107 | { |
||
108 | int i; |
||
109 | int y = rand() % 7 + 1; |
||
110 | |||
111 | int load1,j; |
||
112 | |||
113 | char s[2]; |
||
114 | |||
115 | s[0] = '*'; s[1] = 0; |
||
116 | |||
117 | for (;;) { |
||
118 | i = 1; |
||
119 | while (i < ASTER_LIM) { |
||
120 | load1 = 10000; //8000 + rand()%2000; |
||
121 | #ifdef LONGSC |
||
122 | mutex_lock(&m1); |
||
123 | #endif |
||
124 | for (j=0; j<load1; j++) { |
||
125 | s[0] = '*' + rand() % 100; |
||
126 | #ifndef LONGSC |
||
127 | mutex_lock(&m1); |
||
128 | #endif |
||
129 | puts_xy(i,y,rand()%15+1,s); |
||
130 | #ifndef LONGSC |
||
131 | mutex_unlock(&m1); |
||
132 | #endif |
||
133 | } |
||
134 | #ifdef LONGSC |
||
135 | mutex_unlock(&m1); |
||
136 | #endif |
||
137 | |||
138 | task_activate(aper_table[rand()%APER_MAX]); |
||
139 | task_endcycle(); |
||
140 | |||
141 | mutex_lock(&m1); |
||
142 | puts_xy(i,y,WHITE," "); |
||
143 | mutex_unlock(&m1); |
||
144 | i++; |
||
145 | } |
||
146 | } |
||
147 | //num_aster--; |
||
148 | } |
||
149 | |||
150 | TASK aper_asteroid(void *a) |
||
151 | { |
||
152 | int i; |
||
153 | int y = rand() % 7 + 1; |
||
154 | |||
155 | int load1,j; |
||
156 | int c; |
||
157 | |||
158 | char s[2]; |
||
159 | |||
160 | c = (int)a; |
||
161 | s[0] = '*'; s[1] = 0; |
||
162 | |||
163 | for (;;) { |
||
164 | i = 1; |
||
165 | while (i < ASTER_LIM) { |
||
166 | load1 = APER_REP; //8000 + rand()%2000; |
||
167 | #ifdef LONGSC |
||
168 | mutex_lock(&m1); |
||
169 | #endif |
||
170 | for (j=0; j<load1; j++) { |
||
171 | s[0] = '*' + rand() % 100; |
||
172 | #ifndef LONGSC |
||
173 | mutex_lock(&m1); |
||
174 | #endif |
||
175 | puts_xy(i,y,rand()%15+1,s); |
||
176 | #ifndef LONGSC |
||
177 | mutex_unlock(&m1); |
||
178 | #endif |
||
179 | } |
||
180 | s[0] = c; |
||
181 | #ifndef LONGSC |
||
182 | mutex_unlock(&m1); |
||
183 | #endif |
||
184 | mutex_lock(&m1); |
||
185 | puts_xy(i,y,rand()%15+1,s); |
||
186 | mutex_unlock(&m1); |
||
187 | |||
188 | task_endcycle(); |
||
189 | |||
190 | mutex_lock(&m1); |
||
191 | puts_xy(i,y,WHITE," "); |
||
192 | mutex_unlock(&m1); |
||
193 | i++; |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | |||
198 | TASK soft_aster(void) |
||
199 | { |
||
200 | int i; |
||
201 | int y = rand() % 7 + 1; |
||
202 | |||
203 | int load1,j; |
||
204 | |||
205 | char s[2]; |
||
206 | |||
207 | s[0] = '*'; s[1] = 0; |
||
208 | |||
209 | /*for (;;)*/ { |
||
210 | i = 1; |
||
211 | while (i < ASTER_LIM) { |
||
212 | load1 = 1000 + rand()%9000; |
||
213 | #ifdef LONGSC |
||
214 | mutex_lock(&m1); |
||
215 | #endif |
||
216 | for (j=0; j<load1; j++) { |
||
217 | s[0] = '*' + rand() % 100; |
||
218 | #ifndef LONGSC |
||
219 | mutex_lock(&m1); |
||
220 | #endif |
||
221 | puts_xy(i,y,rand()%15+1,s); |
||
222 | #ifndef LONGSC |
||
223 | mutex_unlock(&m1); |
||
224 | #endif |
||
225 | } |
||
226 | s[0] = 1; |
||
227 | #ifndef LONGSC |
||
228 | mutex_lock(&m1); |
||
229 | #endif |
||
230 | //mutex_lock(&m1); |
||
231 | puts_xy(i,y,rand()%15+1,s); |
||
232 | mutex_unlock(&m1); |
||
233 | |||
234 | task_activate(aper_table[rand()%APER_MAX]); |
||
235 | task_endcycle(); |
||
236 | |||
237 | mutex_lock(&m1); |
||
238 | puts_xy(i,y,WHITE," "); |
||
239 | mutex_unlock(&m1); |
||
240 | i++; |
||
241 | } |
||
242 | } |
||
243 | num_aster--; |
||
244 | return 0; |
||
245 | } |
||
246 | |||
247 | TASK aster() |
||
248 | { |
||
249 | PID p; |
||
250 | |||
251 | // HARD_TASK_MODEL m; |
||
252 | SOFT_TASK_MODEL m_soft; |
||
253 | int r; |
||
254 | int x; // adaptive bandwidth... |
||
255 | |||
256 | srand(7); |
||
257 | |||
258 | /* periodic_task_default_model(m,0,PER_WCET); |
||
259 | periodic_task_def_ctrl_jet(m); |
||
260 | for (x=0; x<PER_MAX; x++) { |
||
261 | r = (rand() % 200); |
||
262 | periodic_task_def_period(m, (64+r)*1000); |
||
263 | p = task_create("per",asteroide,&m,NULL); |
||
264 | if (p!=-1) task_activate(p); |
||
265 | } |
||
266 | */ |
||
267 | soft_task_default_model(m_soft); |
||
268 | soft_task_def_met(m_soft,SOFT_MET); |
||
269 | soft_task_def_ctrl_jet(m_soft); |
||
270 | // soft_task_def_aperiodic(m_soft); |
||
271 | |||
272 | x = 128; //64; |
||
273 | |||
274 | while (1) { |
||
275 | /* { |
||
276 | PID p; |
||
277 | int x; |
||
278 | p = level_table[0]->level_scheduler(0); |
||
279 | printf_xy(1,8,WHITE," "); |
||
280 | |||
281 | x = 0; |
||
282 | do { |
||
283 | printf_xy(3*x+1,8,WHITE,"%3d",p); |
||
284 | p = proc_table[p].next; |
||
285 | x++; |
||
286 | } while (p != NIL); |
||
287 | } |
||
288 | */ |
||
289 | if (num_aster < ASTER_MAX) { |
||
290 | r = (rand() % 200); |
||
291 | |||
292 | soft_task_def_period(m_soft, (x+r)*1000); |
||
293 | p = task_create("aaa",soft_aster,&m_soft,NULL); |
||
294 | if (p == -1) |
||
295 | { |
||
296 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
297 | mutex_lock(&m1); |
||
298 | printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno); |
||
299 | mutex_unlock(&m1); |
||
300 | } |
||
301 | else { |
||
302 | num_aster++; |
||
303 | mutex_lock(&m1); |
||
304 | printf_xy(62,3,WHITE,"adapt=%3u ",x); |
||
305 | mutex_unlock(&m1); |
||
306 | task_activate(p); |
||
307 | x /= 2; |
||
308 | if (x<50) x = 50; |
||
309 | } |
||
310 | } |
||
311 | task_endcycle(); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | TASK clock() |
||
316 | { |
||
317 | int s = 0, m = 0; |
||
318 | |||
319 | while(1) { |
||
320 | mutex_lock(&m1); |
||
321 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
322 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV)); |
||
323 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV)); |
||
324 | printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV)); |
||
325 | mutex_unlock(&m1); |
||
326 | |||
327 | task_endcycle(); |
||
328 | |||
329 | if (++s > 59) { |
||
330 | s = 0; |
||
331 | m++; |
||
332 | } |
||
333 | mutex_lock(&m1); |
||
334 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
335 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV)); |
||
336 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV)); |
||
337 | printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV)); |
||
338 | mutex_unlock(&m1); |
||
339 | task_endcycle(); |
||
340 | } |
||
341 | } |
||
342 | |||
343 | |||
344 | |||
345 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
346 | and plot on the screen the elapsed times... */ |
||
347 | TASK jetcontrol() |
||
348 | { |
||
349 | int i; /* a counter */ |
||
350 | TIME sum, max, curr, last[5]; |
||
351 | int nact; |
||
352 | int j; /* the elements set by jet_gettable */ |
||
353 | PID p; |
||
354 | |||
355 | |||
356 | mutex_lock(&m1); |
||
357 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
358 | mutex_unlock(&m1); |
||
359 | |||
360 | for (;;) { |
||
361 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
362 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*|| |
||
363 | (proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS || |
||
364 | (proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue; |
||
365 | |||
366 | for (j=0; j<5; j++) last[j] = 0; |
||
367 | jet_gettable(p, &last[0], 5); |
||
368 | mutex_lock(&m1); |
||
369 | if (proc_table[p].task_level == 1) |
||
370 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
371 | 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]); |
||
372 | // 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]); |
||
373 | else |
||
374 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
375 | 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]); |
||
376 | // 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]); |
||
377 | mutex_unlock(&m1); |
||
378 | i++; |
||
379 | task_activate(p3); |
||
380 | task_endcycle(); |
||
381 | } |
||
382 | } |
||
383 | } |
||
384 | |||
385 | void fine(KEY_EVT *e) |
||
386 | { |
||
387 | sys_end(); |
||
388 | } |
||
389 | |||
390 | void mydummyaper(void) { |
||
391 | int i=0; |
||
392 | while(1) { |
||
393 | mutex_lock(&m1); |
||
394 | printf_xy(1,24,RED,"dummyAPER pid=%d: %d",p4,i++); |
||
395 | mutex_unlock(&m1); |
||
396 | task_activate(p4); |
||
397 | task_endcycle(); |
||
398 | } |
||
399 | } |
||
400 | |||
401 | void mydummynrt(void) { |
||
402 | int i=0; |
||
403 | while(1) { |
||
404 | mutex_lock(&m1); |
||
405 | printf_xy(40,24,RED,"dummyNRT pid=%d: %d",p5,i++); |
||
406 | mutex_unlock(&m1); |
||
407 | } |
||
408 | } |
||
409 | |||
410 | int main(int argc, char **argv) |
||
411 | { |
||
412 | // PID p1,p2,p5; |
||
413 | HARD_TASK_MODEL m; |
||
414 | NRT_TASK_MODEL m_nrt; |
||
415 | SOFT_TASK_MODEL m_aper; |
||
416 | SOFT_TASK_MODEL m_soft; |
||
417 | struct timespec fineprg; |
||
418 | |||
419 | #ifdef PIMUTEX |
||
420 | PI_mutexattr_t a; |
||
421 | #endif |
||
422 | |||
423 | #ifdef PCMUTEX |
||
424 | PC_mutexattr_t a; |
||
425 | #endif |
||
426 | |||
427 | #ifdef NPPMUTEX |
||
428 | NPP_mutexattr_t a; |
||
429 | #endif |
||
430 | |||
431 | #ifdef NOPMUTEX |
||
432 | NOP_mutexattr_t a; |
||
433 | #endif |
||
434 | |||
435 | |||
436 | KEY_EVT emerg; |
||
437 | //keyb_set_map(itaMap); |
||
438 | emerg.ascii = 'x'; |
||
439 | emerg.scan = KEY_X; |
||
440 | emerg.flag = ALTL_BIT; |
||
441 | keyb_hook(emerg,fine); |
||
442 | |||
443 | hard_task_default_model(m); |
||
444 | hard_task_def_mit(m,100000); |
||
445 | hard_task_def_wcet(m,ASTER_WCET); |
||
446 | hard_task_def_group(m,1); |
||
447 | hard_task_def_ctrl_jet(m); |
||
448 | |||
449 | nrt_task_default_model(m_nrt); |
||
450 | nrt_task_def_group(m_nrt,1); |
||
451 | nrt_task_def_ctrl_jet(m_nrt); |
||
452 | |||
453 | |||
454 | soft_task_default_model(m_aper); |
||
455 | soft_task_def_group(m_aper,1); |
||
456 | soft_task_def_ctrl_jet(m_aper); |
||
457 | soft_task_def_aperiodic(m_aper); |
||
458 | |||
459 | soft_task_default_model(m_soft); |
||
460 | soft_task_def_period(m_soft,10000); |
||
461 | soft_task_def_met(m_soft,JET_WCET); |
||
462 | soft_task_def_group(m_soft,1); |
||
463 | soft_task_def_ctrl_jet(m_soft); |
||
464 | soft_task_def_aperiodic(m_soft); |
||
465 | |||
466 | |||
467 | p1 = task_create("Aster",aster,&m,NULL); |
||
468 | if (p1 == -1) { |
||
469 | perror("test7.c(main): Could not create task <aster> ..."); |
||
470 | sys_end(); |
||
471 | l1_exit(-1); |
||
472 | } |
||
473 | |||
474 | hard_task_def_mit(m,50000); |
||
475 | hard_task_def_wcet(m,CLOCK_WCET); |
||
476 | p2 = task_create("Clock",clock,&m,NULL); |
||
477 | if (p2 == -1) { |
||
478 | perror("test7.c(main): Could not create task <Clock> ..."); |
||
479 | sys_end(); |
||
480 | l1_exit(-1); |
||
481 | } |
||
482 | |||
483 | // p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
||
484 | p3 = task_create("JetControl",jetcontrol,&m_aper,NULL); |
||
485 | if (p3 == -1) { |
||
486 | perror("test7.c(main): Could not create task <JetControl> ..."); |
||
487 | sys_end(); |
||
488 | l1_exit(-1); |
||
489 | } |
||
490 | |||
491 | p4 = task_create("MyDummyAper",(void *(*)(void*))mydummyaper,&m_aper,NULL); |
||
492 | if (p4 == -1) { |
||
493 | perror("Could not create task <MyDummyAper> ..."); |
||
494 | sys_end(); |
||
495 | l1_exit(-1); |
||
496 | } |
||
497 | |||
498 | p5 = task_create("MyDummyNRT",(void *(*)(void*))mydummynrt,&m_nrt,NULL); |
||
499 | if (p5 == -1) { |
||
500 | perror("Could not create task <MyDummyNRT> ..."); |
||
501 | sys_end(); |
||
502 | l1_exit(-1); |
||
503 | } |
||
504 | /* |
||
505 | aperiodic_task_default_model(m_aper,APER_WCET); |
||
506 | aperiodic_task_def_ctrl_jet(m_aper); |
||
507 | aperiodic_task_def_system(m_aper); |
||
508 | |||
509 | for (i=0; i<APER_MAX; i++) { |
||
510 | aperiodic_task_def_level(m_aper, i/4 + 2); |
||
511 | aperiodic_task_def_arg(m_aper, (i/4 ? 'Û' : '±')); |
||
512 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
513 | if (aper_table[i] == -1) { |
||
514 | perror("test7.c(main): Could not create task <aper> ..."); |
||
515 | sys_end(); |
||
516 | l1_exit(-1); |
||
517 | } |
||
518 | } |
||
519 | */ |
||
520 | // task_nopreempt(); |
||
521 | |||
522 | |||
523 | #ifdef PIMUTEX |
||
524 | PI_mutexattr_default(a); |
||
525 | #endif |
||
526 | |||
527 | #ifdef PCMUTEX |
||
528 | PC_mutexattr_default(a); |
||
529 | #endif |
||
530 | |||
531 | #ifdef NPPMUTEX |
||
532 | NPP_mutexattr_default(a); |
||
533 | #endif |
||
534 | |||
535 | #ifdef NOPMUTEX |
||
536 | NOP_mutexattr_default(a); |
||
537 | #endif |
||
538 | |||
539 | mutex_init(&m1, &a); |
||
540 | |||
541 | fineprg.tv_sec = 1800; |
||
542 | fineprg.tv_nsec = 0; |
||
543 | kern_event_post(&fineprg,(void (*)(void *))fine,NULL); |
||
544 | group_activate(1); |
||
545 | return 0; |
||
546 | } |
||
547 |