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: testh.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 Number 17 (h): |
||
27 | |||
28 | this is a part of the classic Hartik demo Aster. |
||
29 | |||
30 | it is based on test 13 (d), and use the CBS to serve the periodic tasks. |
||
31 | |||
32 | There are not periodic tasks, only CBS tasks. |
||
33 | |||
34 | The tasks use a PI, NPP or NOP mutex to access the video memory. |
||
35 | |||
36 | A flag (LONGSC) is provided to try long and short critical sections. |
||
37 | |||
38 | **/ |
||
39 | |||
40 | /* |
||
41 | * Copyright (C) 2000 Paolo Gai |
||
42 | * |
||
43 | * This program is free software; you can redistribute it and/or modify |
||
44 | * it under the terms of the GNU General Public License as published by |
||
45 | * the Free Software Foundation; either version 2 of the License, or |
||
46 | * (at your option) any later version. |
||
47 | * |
||
48 | * This program is distributed in the hope that it will be useful, |
||
49 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
50 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
51 | * GNU General Public License for more details. |
||
52 | * |
||
53 | * You should have received a copy of the GNU General Public License |
||
54 | * along with this program; if not, write to the Free Software |
||
55 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
56 | * |
||
57 | */ |
||
58 | |||
59 | #include "kernel/kern.h" |
||
60 | #include "modules/edf.h" |
||
61 | #include "modules/cbs.h" |
||
62 | #include "drivers/keyb.h" |
||
63 | |||
64 | int num_aster = 0; |
||
65 | #define ASTER_LIM 60 |
||
66 | #define DISPLAY_MAX 15 |
||
67 | #define ASTER_MAX 70 |
||
68 | #define STAT_Y 9 |
||
69 | |||
70 | #define PER_MAX 5 |
||
71 | #define APER_MAX 8 |
||
72 | |||
73 | #define PER_WCET 6200 |
||
74 | #define APER_WCET 18400 |
||
75 | #define JET_WCET 10000 |
||
76 | #define JET_PERIOD 100000 |
||
77 | |||
78 | #define APER_REP 22000 |
||
79 | |||
80 | //PID aper_table[APER_MAX]; |
||
81 | |||
82 | mutex_t m1; |
||
83 | |||
84 | |||
85 | #define PIMUTEX |
||
86 | //#define NPPMUTEX |
||
87 | //#define NOPMUTEX |
||
88 | |||
89 | #define LONGSC |
||
90 | |||
91 | #ifdef LONGSC |
||
92 | #define SOFT_MET 3000 /* 3000 12000 */ |
||
93 | #define CLOCK_WCET 400 /* 200 300*/ |
||
94 | #define ASTER_WCET 400 /* 200 300*/ |
||
95 | #else |
||
96 | #define SOFT_MET 80000 /* 4500 */ |
||
97 | #define CLOCK_WCET 2000 /* 200*/ |
||
98 | #define ASTER_WCET 2000 /* 200*/ |
||
99 | #endif |
||
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_lock(&m1); |
||
178 | #endif |
||
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 | puts_xy(i,y,rand()%15+1,s); |
||
225 | mutex_unlock(&m1); |
||
226 | |||
227 | // task_activate(aper_table[rand()%APER_MAX]); |
||
228 | task_endcycle(); |
||
229 | |||
230 | mutex_lock(&m1); |
||
231 | puts_xy(i,y,WHITE," "); |
||
232 | mutex_unlock(&m1); |
||
233 | i++; |
||
234 | } |
||
235 | } |
||
236 | num_aster--; |
||
237 | return 0; |
||
238 | } |
||
239 | |||
240 | TASK aster() |
||
241 | { |
||
242 | PID p; |
||
243 | // HARD_TASK_MODEL m; |
||
244 | SOFT_TASK_MODEL m_soft; |
||
245 | int r; |
||
246 | int x; // adaptive bandwidth... |
||
247 | |||
248 | srand(7); |
||
249 | |||
250 | /* periodic_task_default_model(m,0,PER_WCET); |
||
251 | periodic_task_def_ctrl_jet(m); |
||
252 | for (x=0; x<PER_MAX; x++) { |
||
253 | r = (rand() % 200); |
||
254 | periodic_task_def_period(m, (64+r)*1000); |
||
255 | p = task_create("per",asteroide,&m,NULL); |
||
256 | if (p!=-1) task_activate(p); |
||
257 | } |
||
258 | */ |
||
259 | soft_task_default_model(m_soft); |
||
260 | soft_task_def_met(m_soft,SOFT_MET); |
||
261 | soft_task_def_ctrl_jet(m_soft); |
||
262 | |||
263 | x = 128; //64; |
||
264 | |||
265 | while (1) { |
||
266 | /* { |
||
267 | PID p; |
||
268 | int x; |
||
269 | p = level_table[0]->level_scheduler(0); |
||
270 | printf_xy(1,8,WHITE," "); |
||
271 | |||
272 | x = 0; |
||
273 | do { |
||
274 | printf_xy(3*x+1,8,WHITE,"%3d",p); |
||
275 | p = proc_table[p].next; |
||
276 | x++; |
||
277 | } while (p != NIL); |
||
278 | } |
||
279 | */ |
||
280 | if (num_aster < ASTER_MAX) { |
||
281 | r = (rand() % 200); |
||
282 | |||
283 | soft_task_def_period(m_soft, (x+r)*1000); |
||
284 | p = task_create("aaa",soft_aster,&m_soft,NULL); |
||
285 | if (p == -1) |
||
286 | { |
||
287 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
288 | mutex_lock(&m1); |
||
289 | printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno); |
||
290 | mutex_unlock(&m1); |
||
291 | } |
||
292 | else { |
||
293 | num_aster++; |
||
294 | mutex_lock(&m1); |
||
295 | printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
||
296 | mutex_unlock(&m1); |
||
297 | |||
298 | task_activate(p); |
||
299 | x /= 2; |
||
300 | if (x<50) x = 50; |
||
301 | } |
||
302 | } |
||
303 | task_endcycle(); |
||
304 | } |
||
305 | } |
||
306 | |||
307 | TASK clock() |
||
308 | { |
||
309 | int s = 0, m = 0; |
||
310 | |||
311 | while(1) { |
||
312 | mutex_lock(&m1); |
||
313 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
314 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
315 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2)); |
||
316 | |||
317 | mutex_unlock(&m1); |
||
318 | task_endcycle(); |
||
319 | |||
320 | if (++s > 59) { |
||
321 | s = 0; |
||
322 | m++; |
||
323 | } |
||
324 | mutex_lock(&m1); |
||
325 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
326 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
327 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2)); |
||
328 | mutex_unlock(&m1); |
||
329 | task_endcycle(); |
||
330 | } |
||
331 | } |
||
332 | |||
333 | |||
334 | |||
335 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
336 | and plot on the screen the elapsed times... */ |
||
337 | TASK jetcontrol() |
||
338 | { |
||
339 | int i; /* a counter */ |
||
340 | TIME sum, max, curr, last[5]; |
||
341 | int nact; |
||
342 | int j; /* the elements set by jet_gettable */ |
||
343 | PID p; |
||
344 | |||
345 | |||
346 | mutex_lock(&m1); |
||
347 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
348 | mutex_unlock(&m1); |
||
349 | |||
350 | for (;;) { |
||
351 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
352 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*|| |
||
353 | (proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS || |
||
354 | (proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue; |
||
355 | |||
356 | for (j=0; j<5; j++) last[j] = 0; |
||
357 | jet_gettable(p, &last[0], 5); |
||
358 | mutex_lock(&m1); |
||
359 | if (proc_table[p].task_level == 2) |
||
360 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³p%-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
361 | 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]); |
||
362 | // 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]); |
||
363 | else |
||
364 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
365 | 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]); |
||
366 | // 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]); |
||
367 | mutex_unlock(&m1); |
||
368 | i++; |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | |||
373 | void fine(KEY_EVT *e) |
||
374 | { |
||
375 | sys_end(); |
||
376 | } |
||
377 | |||
378 | int main(int argc, char **argv) |
||
379 | { |
||
380 | PID p1,p2,p3;//,p4,p5,p6; |
||
381 | HARD_TASK_MODEL m; |
||
382 | // NRT_TASK_MODEL m_nrt; |
||
383 | SOFT_TASK_MODEL m_aper; |
||
384 | SOFT_TASK_MODEL m_soft; |
||
385 | // int i; |
||
386 | struct timespec fineprg; |
||
387 | |||
388 | #ifdef PIMUTEX |
||
389 | PI_mutexattr_t a; |
||
390 | #endif |
||
391 | |||
392 | #ifdef NPPMUTEX |
||
393 | NPP_mutexattr_t a; |
||
394 | #endif |
||
395 | |||
396 | #ifdef NOPMUTEX |
||
397 | NOP_mutexattr_t a; |
||
398 | #endif |
||
399 | |||
400 | |||
401 | KEY_EVT emerg; |
||
402 | //keyb_set_map(itaMap); |
||
403 | emerg.ascii = 'x'; |
||
404 | emerg.scan = KEY_X; |
||
405 | emerg.flag = ALTL_BIT; |
||
406 | keyb_hook(emerg,fine); |
||
407 | |||
408 | hard_task_default_model(m); |
||
409 | hard_task_def_wcet(m,ASTER_WCET); |
||
410 | hard_task_def_mit(m,100000); |
||
411 | hard_task_def_group(m,1); |
||
412 | hard_task_def_ctrl_jet(m); |
||
413 | |||
414 | // nrt_task_default_model(m_nrt); |
||
415 | // nrt_task_def_group(m_nrt,1); |
||
416 | // nrt_task_def_ctrl_jet(m_nrt); |
||
417 | |||
418 | |||
419 | soft_task_default_model(m_aper); |
||
420 | soft_task_def_group(m_aper,1); |
||
421 | soft_task_def_ctrl_jet(m_aper); |
||
422 | soft_task_def_aperiodic(m_aper); |
||
423 | |||
424 | soft_task_default_model(m_soft); |
||
425 | soft_task_def_period(m_soft,JET_PERIOD); |
||
426 | soft_task_def_met(m_soft,JET_WCET); |
||
427 | soft_task_def_group(m_soft,1); |
||
428 | soft_task_def_ctrl_jet(m_soft); |
||
429 | soft_task_def_aperiodic(m_soft); |
||
430 | |||
431 | |||
432 | p1 = task_create("Aster",aster,&m,NULL); |
||
433 | if (p1 == -1) { |
||
434 | perror("test7.c(main): Could not create task <aster> ..."); |
||
435 | sys_end(); |
||
436 | l1_exit(-1); |
||
437 | } |
||
438 | |||
439 | hard_task_def_mit(m,500000); |
||
440 | hard_task_def_wcet(m,CLOCK_WCET); |
||
441 | p2 = task_create("Clock",clock,&m,NULL); |
||
442 | if (p2 == -1) { |
||
443 | perror("test7.c(main): Could not create task <Clock> ..."); |
||
444 | sys_end(); |
||
445 | l1_exit(-1); |
||
446 | } |
||
447 | |||
448 | // p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
||
449 | p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
||
450 | if (p2 == -1) { |
||
451 | perror("test7.c(main): Could not create task <JetControl> ..."); |
||
452 | sys_end(); |
||
453 | l1_exit(-1); |
||
454 | } |
||
455 | /* |
||
456 | aperiodic_task_default_model(m_aper,APER_WCET); |
||
457 | aperiodic_task_def_ctrl_jet(m_aper); |
||
458 | aperiodic_task_def_system(m_aper); |
||
459 | |||
460 | for (i=0; i<APER_MAX; i++) { |
||
461 | aperiodic_task_def_level(m_aper, i/4 + 2); |
||
462 | aperiodic_task_def_arg(m_aper, (i/4 ? 'Û' : '±')); |
||
463 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
464 | if (aper_table[i] == -1) { |
||
465 | perror("test7.c(main): Could not create task <aper> ..."); |
||
466 | sys_end(); |
||
467 | l1_exit(-1); |
||
468 | } |
||
469 | } |
||
470 | */ |
||
471 | task_nopreempt(); |
||
472 | |||
473 | #ifdef PIMUTEX |
||
474 | PI_mutexattr_default(a); |
||
475 | #endif |
||
476 | |||
477 | #ifdef NPPMUTEX |
||
478 | NPP_mutexattr_default(a); |
||
479 | #endif |
||
480 | |||
481 | #ifdef NOPMUTEX |
||
482 | NOP_mutexattr_default(a); |
||
483 | #endif |
||
484 | |||
485 | mutex_init(&m1, &a); |
||
486 | |||
487 | fineprg.tv_sec = 1800; |
||
488 | fineprg.tv_nsec = 0; |
||
489 | //kern_event_post(&fineprg,(void (*)(void *))fine,NULL); |
||
490 | group_activate(1); |
||
491 | return 0; |
||
492 | } |
||
493 |