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