Rev 1120 | 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: 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 | ------------ |
||
1123 | pj | 19 | CVS : $Id: perf3.c,v 1.2 2003-01-07 17:10:18 pj Exp $ |
1120 | pj | 20 | |
21 | File: $File$ |
||
1123 | pj | 22 | Revision: $Revision: 1.2 $ |
23 | Last update: $Date: 2003-01-07 17:10:18 $ |
||
1120 | pj | 24 | ------------ |
25 | |||
26 | Performance Test 3: |
||
27 | |||
28 | this test is based on test D. |
||
29 | |||
30 | the test creates some random events. each event measure the difference |
||
31 | beetween his activation time and thecurrent time. |
||
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 | |||
58 | int num_aster = 0; |
||
59 | #define ASTER_LIM 60 |
||
60 | #define DISPLAY_MAX 15 |
||
61 | #define ASTER_MAX 70 |
||
62 | #define STAT_Y 9 |
||
63 | |||
64 | #define PER_MAX 5 |
||
65 | #define APER_MAX 8 |
||
66 | |||
67 | #define PER_WCET 8200 |
||
68 | #define APER_WCET 20400 |
||
69 | #define CLOCK_WCET 1600 |
||
70 | #define ASTER_WCET 1600 |
||
71 | #define SOFT_MET 3300 |
||
72 | |||
73 | #define APER_REP 22000 |
||
74 | |||
75 | PID aper_table[APER_MAX]; |
||
76 | |||
77 | int shutting_down = 0; |
||
78 | |||
79 | TASK asteroide(void) |
||
80 | { |
||
81 | int i; |
||
82 | int y = rand() % 7 + 1; |
||
83 | |||
84 | int load1,j; |
||
85 | |||
86 | char s[2]; |
||
87 | |||
88 | s[0] = '*'; s[1] = 0; |
||
89 | |||
90 | for (;;) { |
||
91 | i = 1; |
||
92 | while (i < ASTER_LIM) { |
||
93 | load1 = 10000; //8000 + rand()%2000; |
||
94 | for (j=0; j<load1; j++) { |
||
95 | s[0] = '*' + rand() % 100; |
||
96 | puts_xy(i,y,rand()%15+1,s); |
||
97 | } |
||
98 | |||
99 | task_activate(aper_table[rand()%APER_MAX]); |
||
100 | task_endcycle(); |
||
101 | |||
102 | puts_xy(i,y,WHITE," "); |
||
103 | i++; |
||
104 | } |
||
105 | } |
||
106 | //num_aster--; |
||
107 | } |
||
108 | |||
109 | TASK aper_asteroid(void *a) |
||
110 | { |
||
111 | int i; |
||
112 | int y = rand() % 7 + 1; |
||
113 | |||
114 | int load1,j; |
||
115 | int c; |
||
116 | |||
117 | char s[2]; |
||
118 | |||
119 | c = (int)a; |
||
120 | s[0] = '*'; s[1] = 0; |
||
121 | |||
122 | for (;;) { |
||
123 | i = 1; |
||
124 | while (i < ASTER_LIM) { |
||
125 | load1 = APER_REP; //8000 + rand()%2000; |
||
126 | for (j=0; j<load1; j++) { |
||
127 | s[0] = '*' + rand() % 100; |
||
128 | puts_xy(i,y,rand()%15+1,s); |
||
129 | } |
||
130 | s[0] = c; |
||
131 | puts_xy(i,y,rand()%15+1,s); |
||
132 | |||
133 | if (shutting_down) { |
||
134 | kern_printf("±%d±",exec_shadow); |
||
135 | return 0; |
||
136 | } |
||
137 | |||
138 | task_endcycle(); |
||
139 | |||
140 | puts_xy(i,y,WHITE," "); |
||
141 | i++; |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | |||
146 | TASK soft_aster(void) |
||
147 | { |
||
148 | int i; |
||
149 | int y = rand() % 7 + 1; |
||
150 | |||
151 | int load1,j; |
||
152 | |||
153 | char s[2]; |
||
154 | |||
155 | s[0] = '*'; s[1] = 0; |
||
156 | |||
157 | /*for (;;)*/ { |
||
158 | i = 1; |
||
159 | while (i < ASTER_LIM) { |
||
160 | load1 = 1000 + rand()%9000; |
||
161 | for (j=0; j<load1; j++) { |
||
162 | s[0] = '*' + rand() % 100; |
||
163 | puts_xy(i,y,rand()%15+1,s); |
||
164 | } |
||
165 | s[0] = 1; |
||
166 | puts_xy(i,y,rand()%15+1,s); |
||
167 | |||
168 | task_activate(aper_table[rand()%APER_MAX]); |
||
169 | task_endcycle(); |
||
170 | |||
171 | puts_xy(i,y,WHITE," "); |
||
172 | i++; |
||
173 | } |
||
174 | } |
||
175 | num_aster--; |
||
176 | return 0; |
||
177 | } |
||
178 | |||
179 | TASK aster() |
||
180 | { |
||
181 | PID p; |
||
182 | |||
183 | HARD_TASK_MODEL m; |
||
184 | SOFT_TASK_MODEL m_soft; |
||
185 | int r; |
||
186 | int x; // adaptive bandwidth... |
||
187 | |||
188 | srand(7); |
||
189 | |||
190 | hard_task_default_model(m); |
||
191 | hard_task_def_wcet(m,PER_WCET); |
||
192 | hard_task_def_ctrl_jet(m); |
||
193 | for (x=0; x<PER_MAX; x++) { |
||
194 | r = (rand() % 200); |
||
195 | hard_task_def_mit(m, (64+r)*1000); |
||
196 | p = task_create("per",asteroide,&m,NULL); |
||
197 | if (p!=-1) task_activate(p); |
||
198 | } |
||
199 | |||
200 | soft_task_default_model(m_soft); |
||
201 | soft_task_def_met(m_soft,SOFT_MET); |
||
202 | soft_task_def_ctrl_jet(m_soft); |
||
203 | |||
204 | x = 64; |
||
205 | |||
206 | while (1) { |
||
207 | if (num_aster < ASTER_MAX) { |
||
208 | r = (rand() % 200); |
||
209 | |||
210 | soft_task_def_period(m_soft, (x+r)*1000); |
||
211 | p = task_create("aaa",soft_aster,&m_soft,NULL); |
||
212 | if (p == -1) |
||
213 | { |
||
214 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
215 | printf_xy(62,3,WHITE,"adapt=%3u err=%d", |
||
216 | iq_query_first(&freedesc), errno); |
||
217 | } |
||
218 | else { |
||
219 | num_aster++; |
||
220 | printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
||
221 | task_activate(p); |
||
222 | x /= 2; |
||
223 | if (x<50) x = 50; |
||
224 | } |
||
225 | } |
||
226 | task_endcycle(); |
||
227 | } |
||
228 | } |
||
229 | |||
230 | TASK clock() |
||
231 | { |
||
232 | int s = 0, m = 0; |
||
233 | |||
234 | while(1) { |
||
235 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
236 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
237 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4)); |
||
238 | task_endcycle(); |
||
239 | |||
240 | if (++s > 59) { |
||
241 | s = 0; |
||
242 | m++; |
||
243 | } |
||
244 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
245 | printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
246 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4)); |
||
247 | task_endcycle(); |
||
248 | } |
||
249 | } |
||
250 | |||
251 | |||
252 | |||
253 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
254 | and plot on the screen the elapsed times... */ |
||
255 | TASK jetcontrol() |
||
256 | { |
||
257 | int i; /* a counter */ |
||
258 | TIME sum, max, curr, last[5]; |
||
259 | int nact; |
||
260 | int j; /* the elements set by jet_gettable */ |
||
261 | PID p; |
||
262 | |||
263 | |||
264 | kern_cli(); |
||
265 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
266 | kern_sti(); |
||
267 | |||
268 | for (;;) { |
||
269 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
270 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 || |
||
271 | ((proc_table[p].pclass & 0xFF00) == HARD_PCLASS)) continue; |
||
272 | |||
273 | for (j=0; j<5; j++) last[j] = 0; |
||
274 | jet_gettable(p, &last[0], 5); |
||
275 | kern_cli(); |
||
276 | if (proc_table[p].task_level == 4) |
||
277 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
278 | p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
||
279 | else |
||
280 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
281 | 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]); |
||
282 | kern_sti(); |
||
283 | i++; |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | |||
288 | void fine() |
||
289 | { |
||
290 | sys_end(); |
||
291 | } |
||
292 | |||
293 | void exiting(void *arg) |
||
294 | { |
||
295 | kern_printf("EXITING"); |
||
296 | shutting_down = 1; |
||
297 | } |
||
298 | |||
299 | |||
300 | |||
301 | |||
302 | |||
303 | struct timespec last_random_time; |
||
304 | TIME max=0; |
||
305 | TIME sum=0; |
||
306 | int n=0; |
||
307 | |||
308 | void random_event(void *arg) |
||
309 | { |
||
310 | struct timespec t, sub; |
||
311 | TIME delta; |
||
312 | |||
313 | // get the current time |
||
1123 | pj | 314 | kern_gettime(&t); |
1120 | pj | 315 | |
316 | // compute the delta |
||
317 | SUBTIMESPEC(&t, &last_random_time, &sub); |
||
318 | delta = TIMESPEC2USEC(&sub); |
||
319 | |||
320 | // update the statistics |
||
321 | if (max < delta) max = delta; |
||
322 | sum += delta; |
||
323 | n++; |
||
324 | |||
325 | /* kern_printf("sub=%d.%d t=%d.%d last=%d.%d °\n",sub.tv_sec, sub.tv_nsec/1000, |
||
326 | t.tv_sec, t.tv_nsec/1000, |
||
327 | last_random_time.tv_sec, last_random_time.tv_nsec/1000); |
||
328 | */ //return; |
||
329 | // create a new event |
||
330 | if (shutting_down) |
||
331 | return; |
||
332 | |||
333 | delta = (rand()%30000)+100; |
||
334 | ADDUSEC2TIMESPEC(delta, &t); |
||
335 | TIMESPEC_ASSIGN(&last_random_time, &t); |
||
336 | kern_event_post(&last_random_time, random_event, NULL); |
||
337 | } |
||
338 | |||
339 | void perftest_printdata(void *arg) |
||
340 | { |
||
341 | kern_printf("\n°°° max=%ld sum=%ld n=%d °°°",max,sum,n); |
||
342 | } |
||
343 | |||
344 | int main(int argc, char **argv) |
||
345 | { |
||
346 | PID p2; //p1,p3; //,p4,p5,p6; |
||
347 | HARD_TASK_MODEL m; |
||
348 | // NRT_TASK_MODEL m_nrt; |
||
349 | // SOFT_TASK_MODEL m_aper; |
||
350 | SOFT_TASK_MODEL m_soft; |
||
351 | int i; |
||
352 | struct timespec fineprg; |
||
353 | |||
354 | sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN); |
||
355 | sys_atrunlevel(perftest_printdata, NULL, RUNLEVEL_BEFORE_EXIT); |
||
356 | |||
357 | kern_printf("\n\n"); |
||
358 | |||
359 | srand(1234); |
||
360 | NULL_TIMESPEC(&last_random_time); |
||
361 | i = rand()%30000+2000; |
||
362 | ADDUSEC2TIMESPEC(i, &last_random_time); |
||
363 | // last_random_time.tv_sec = 2; |
||
364 | // last_random_time.tv_nsec = 0; |
||
365 | kern_cli(); |
||
366 | kern_event_post(&last_random_time, random_event, NULL); |
||
367 | kern_sti(); |
||
368 | |||
369 | hard_task_default_model(m); |
||
370 | hard_task_def_wcet(m,ASTER_WCET); |
||
371 | hard_task_def_mit(m,10000); |
||
372 | hard_task_def_group(m,1); |
||
373 | hard_task_def_ctrl_jet(m); |
||
374 | |||
375 | // nrt_task_default_model(m_nrt); |
||
376 | // nrt_task_def_group(m_nrt,1); |
||
377 | // nrt_task_def_ctrl_jet(m_nrt); |
||
378 | |||
379 | soft_task_default_model(m_soft); |
||
380 | soft_task_def_met(m_soft,1000); |
||
381 | soft_task_def_period(m_soft,100000); |
||
382 | soft_task_def_group(m_soft,1); |
||
383 | soft_task_def_ctrl_jet(m_soft); |
||
384 | soft_task_def_aperiodic(m_soft); |
||
385 | |||
386 | /* |
||
387 | p1 = task_create("Aster",aster,&m,NULL); |
||
388 | if (p1 == -1) { |
||
389 | perror("test7.c(main): Could not create task <aster> ..."); |
||
390 | sys_end(); |
||
391 | l1_exit(-1); |
||
392 | } |
||
393 | */ |
||
394 | hard_task_def_mit(m,500000); |
||
395 | hard_task_def_wcet(m,CLOCK_WCET); |
||
396 | p2 = task_create("Clock",clock,&m,NULL); |
||
397 | if (p2 == -1) { |
||
398 | perror("test7.c(main): Could not create task <Clock> ..."); |
||
399 | sys_end(); |
||
400 | l1_exit(-1); |
||
401 | } |
||
402 | /* |
||
403 | // p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
||
404 | p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
||
405 | if (p3 == -1) { |
||
406 | perror("test7.c(main): Could not create task <JetControl> ..."); |
||
407 | sys_end(); |
||
408 | l1_exit(-1); |
||
409 | } |
||
410 | |||
411 | soft_task_default_model(m_aper); |
||
412 | soft_task_def_wcet(m_aper,APER_WCET); |
||
413 | soft_task_def_ctrl_jet(m_aper); |
||
414 | soft_task_def_system(m_aper); |
||
415 | soft_task_def_aperiodic(m_aper); |
||
416 | |||
417 | for (i=0; i<APER_MAX; i++) { |
||
418 | soft_task_def_level(m_aper, i/4 + 2); |
||
419 | soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±')); |
||
420 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
421 | if (aper_table[i] == -1) { |
||
422 | perror("test7.c(main): Could not create task <aper> ..."); |
||
423 | sys_end(); |
||
424 | l1_exit(-1); |
||
425 | } |
||
426 | } |
||
427 | */ |
||
428 | task_nopreempt(); |
||
429 | fineprg.tv_sec = 6; |
||
430 | fineprg.tv_nsec = 0; |
||
431 | kern_event_post(&fineprg,fine,NULL); |
||
432 | group_activate(1); |
||
433 | return 0; |
||
434 | } |
||
435 |