Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Paolo Gai <pj@hartik.sssup.it> |
||
6 | * |
||
7 | * Authors : Marco Caccamo and Paolo Gai |
||
8 | * |
||
9 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
10 | * |
||
11 | * http://www.sssup.it |
||
12 | * http://retis.sssup.it |
||
13 | * http://shark.sssup.it |
||
14 | */ |
||
15 | |||
16 | /** |
||
17 | ------------ |
||
18 | CVS : $Id: prova.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $ |
||
19 | |||
20 | File: $File$ |
||
21 | Revision: $Revision: 1.1.1.1 $ |
||
22 | Last update: $Date: 2002-09-02 09:37:41 $ |
||
23 | ------------ |
||
24 | |||
25 | testcash.c |
||
26 | test for the CASH Module, directly derived from Test Number 13 (D) |
||
27 | |||
28 | **/ |
||
29 | |||
30 | /* |
||
31 | * Copyright (C) 2000 Marco Caccamo and Paolo Gai |
||
32 | * |
||
33 | * This program is free software; you can redistribute it and/or modify |
||
34 | * it under the terms of the GNU General Public License as published by |
||
35 | * the Free Software Foundation; either version 2 of the License, or |
||
36 | * (at your option) any later version. |
||
37 | * |
||
38 | * This program is distributed in the hope that it will be useful, |
||
39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
41 | * GNU General Public License for more details. |
||
42 | * |
||
43 | * You should have received a copy of the GNU General Public License |
||
44 | * along with this program; if not, write to the Free Software |
||
45 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
46 | * |
||
47 | */ |
||
48 | |||
49 | |||
50 | #include <modules/edf.h> |
||
51 | #include "cbs_ft.h" |
||
52 | #include <math.h> |
||
53 | #include <stdlib.h> |
||
54 | |||
55 | #define ASTER_LIM 60 |
||
56 | #define DISPLAY_MAX 15 |
||
57 | |||
58 | #define STAT_Y 9 |
||
59 | |||
60 | #define INPUT 0.5 |
||
61 | |||
62 | |||
63 | |||
64 | #define MAX_STAT 10000 |
||
65 | #define RVAL 1 |
||
66 | #define XVAL 2 |
||
67 | #define DVAL 3 |
||
68 | |||
69 | |||
70 | struct statistic { |
||
71 | TIME r_time; |
||
72 | TIME ex_time; |
||
73 | long dead_post; |
||
74 | }; |
||
75 | |||
76 | |||
77 | |||
78 | struct statistic stat[MAX_STAT]; |
||
79 | TIME val[MAX_STAT]; |
||
80 | |||
81 | int n_stat = 0; |
||
82 | |||
83 | TASK hard_aster1p(void) |
||
84 | { |
||
85 | int i; |
||
86 | int y = 1; |
||
87 | int load1,j; |
||
88 | |||
89 | char s[2]; |
||
90 | |||
91 | s[0] = 'P'; s[1] = 0; |
||
92 | |||
93 | |||
94 | for (;;) { |
||
95 | i = 1; |
||
96 | while (i < ASTER_LIM) { |
||
97 | load1 = 20000; //+ rand() % 25000; |
||
98 | for (j=0; j<load1; j++) { |
||
99 | if (CBS_FT_Checkpoint()) |
||
100 | break; |
||
101 | puts_xy(i,y,rand()%15+1,s); |
||
102 | } |
||
103 | //kern_cli(); |
||
104 | //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
||
105 | //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
||
106 | //kern_sti(); |
||
107 | //n_stat++; |
||
108 | task_endcycle(); |
||
109 | puts_xy(i,y,WHITE," "); |
||
110 | i++; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | |||
116 | TASK hard_aster1b(void) |
||
117 | { |
||
118 | int i; |
||
119 | int y = 1; |
||
120 | |||
121 | int load1,j; |
||
122 | |||
123 | char s[2]; |
||
124 | |||
125 | s[0] = 'B'; s[1] = 0; |
||
126 | |||
127 | for (;;) { |
||
128 | i = 1; |
||
129 | while (i < ASTER_LIM) { |
||
130 | load1 = 20000;// + rand()%4000; |
||
131 | for (j=0; j<load1; j++) { |
||
132 | puts_xy(i,y,rand()%15+1,s); |
||
133 | } |
||
134 | //kern_cli(); |
||
135 | //stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
||
136 | //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
||
137 | //kern_sti(); |
||
138 | //n_stat++; |
||
139 | task_endcycle(); |
||
140 | puts_xy(i,y,WHITE," "); |
||
141 | i++; |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | |||
146 | |||
147 | TASK hard_aster2p(void) |
||
148 | { |
||
149 | int i; |
||
150 | int y = 3; |
||
151 | |||
152 | int load1,j; |
||
153 | |||
154 | char s[2]; |
||
155 | |||
156 | s[0] = 'P'; s[1] = 0; |
||
157 | |||
158 | for (;;) { |
||
159 | i = 1; |
||
160 | while (i < ASTER_LIM) { |
||
161 | load1 = 20000 + rand() % 20000; |
||
162 | for (j=0; j<load1; j++) { |
||
163 | if (CBS_FT_Checkpoint()) |
||
164 | break; |
||
165 | puts_xy(i,y,rand()%15+1,s); |
||
166 | } |
||
167 | //kern_cli(); |
||
168 | //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
||
169 | //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
||
170 | //kern_sti(); |
||
171 | //n_stat++; |
||
172 | task_endcycle(); |
||
173 | puts_xy(i,y,WHITE," "); |
||
174 | i++; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | TASK hard_aster2b(void) |
||
180 | { |
||
181 | int i; |
||
182 | int y = 3; |
||
183 | |||
184 | int load1,j; |
||
185 | |||
186 | char s[2]; |
||
187 | |||
188 | s[0] = 'T'; s[1] = 0; |
||
189 | |||
190 | for (;;) { |
||
191 | i = 1; |
||
192 | while (i < ASTER_LIM) { |
||
193 | load1 = 20000; |
||
194 | for (j=0; j<load1; j++) { |
||
195 | puts_xy(i,y,rand()%15+1,s); |
||
196 | } |
||
197 | //kern_cli(); |
||
198 | //stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
||
199 | //jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
||
200 | //kern_sti(); |
||
201 | //n_stat++; |
||
202 | task_endcycle(); |
||
203 | puts_xy(i,y,WHITE," "); |
||
204 | i++; |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | |||
209 | |||
210 | TASK clock() |
||
211 | { |
||
212 | int s = 0, m = 0; |
||
213 | |||
214 | while(1) { |
||
215 | printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
||
216 | printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
||
217 | printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
218 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_FT_usedbandwidth(1)); |
||
219 | task_endcycle(); |
||
220 | |||
221 | if (++s > 59) { |
||
222 | s = 0; |
||
223 | m++; |
||
224 | } |
||
225 | printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
||
226 | printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
||
227 | printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
||
228 | printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_FT_usedbandwidth(1)); |
||
229 | task_endcycle(); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | |||
234 | |||
235 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
236 | and plot on the screen the elapsed times... */ |
||
237 | TASK jetcontrol() |
||
238 | { |
||
239 | int i; /* a counter */ |
||
240 | TIME sum, max, curr, last[5]; |
||
241 | int nact; |
||
242 | int j; /* the elements set by jet_gettable */ |
||
243 | PID p; |
||
244 | |||
245 | |||
246 | kern_cli(); |
||
247 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
248 | kern_sti(); |
||
249 | |||
250 | for (;;) { |
||
251 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
252 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
||
253 | |||
254 | for (j=0; j<5; j++) last[j] = 0; |
||
255 | jet_gettable(p, &last[0], 5); |
||
256 | kern_cli(); |
||
257 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6ld ³ %-6ld ³ %-4d ³ %-7ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld", p, sum/(nact==0 ? 1 : nact), max, |
||
258 | nact, curr, last[0], last[1], last[2], last[3], last[4]); |
||
259 | kern_sti(); |
||
260 | i++; |
||
261 | } |
||
262 | task_endcycle(); |
||
263 | } |
||
264 | } |
||
265 | |||
266 | |||
267 | void save_stat(struct statistic p[], int n, char *name, int type) |
||
268 | { |
||
269 | DOS_FILE *f; |
||
270 | int i; |
||
271 | char outstring[500]; |
||
272 | |||
273 | |||
274 | for(i = 0; i < 500; i++) |
||
275 | outstring[i] = '0'; |
||
276 | |||
277 | f = DOS_fopen(name, "w"); |
||
278 | if (!f) { |
||
279 | cprintf("Cannot open %s!!!", name); |
||
280 | goto end1; |
||
281 | } |
||
282 | |||
283 | for(i = 0; i < n; i++) { |
||
284 | if (type == RVAL) |
||
285 | val[i] = p[i].r_time; |
||
286 | if (type == XVAL) |
||
287 | val[i] = p[i].ex_time; |
||
288 | if (type == DVAL) |
||
289 | val[i] = p[i].dead_post; |
||
290 | } |
||
291 | |||
292 | memset(outstring, 0, 300); |
||
293 | sprintf(outstring, "%ld \n", (long int)n); |
||
294 | cprintf("%s", outstring); |
||
295 | DOS_fwrite(outstring, 1, strlen(outstring), f); |
||
296 | |||
297 | for(i = 0; i < n; i++) { |
||
298 | memset(outstring, 0, 300); |
||
299 | sprintf(outstring, "%ld %lu\n", (long int)i, val[i]); |
||
300 | //cprintf("%s", outstring); |
||
301 | DOS_fwrite(outstring, 1, strlen(outstring), f); |
||
302 | } |
||
303 | DOS_fclose(f); |
||
304 | end1:cprintf("OK?"); |
||
305 | } |
||
306 | |||
307 | |||
308 | void result_save(void *p) |
||
309 | { |
||
310 | save_stat(stat, n_stat, "stat1.tim", RVAL); |
||
311 | } |
||
312 | |||
313 | |||
314 | void fine() |
||
315 | { |
||
316 | ll_abort(666); |
||
317 | } |
||
318 | |||
319 | int main(int argc, char **argv) |
||
320 | { |
||
321 | PID p1,p2,p3, p4, p5, p6; |
||
322 | |||
323 | HARD_TASK_MODEL m; |
||
324 | FT_TASK_MODEL ftb; |
||
325 | FT_TASK_MODEL ftp; |
||
326 | |||
327 | // int i; |
||
328 | struct timespec fineprg; |
||
329 | |||
330 | |||
331 | //sys_atrunlevel(result_save, NULL, RUNLEVEL_AFTER_EXIT); |
||
332 | srand(7); |
||
333 | |||
334 | hard_task_default_model(m); |
||
335 | hard_task_def_wcet(m,500); |
||
336 | hard_task_def_mit(m,500000); |
||
337 | hard_task_def_periodic(m); |
||
338 | hard_task_def_group(m,1); |
||
339 | hard_task_def_ctrl_jet(m); |
||
340 | |||
341 | |||
342 | p1 = task_create("Clock",clock,&m,NULL); |
||
343 | if (p1 == -1) { |
||
344 | perror("testhd.c(main): Could not create task <Clock> ..."); |
||
345 | sys_end(); |
||
346 | } |
||
347 | |||
348 | |||
349 | hard_task_def_wcet(m,500); |
||
350 | hard_task_def_periodic(m); |
||
351 | hard_task_def_mit(m,100000); |
||
352 | |||
353 | |||
354 | p2 = task_create("JetControl",jetcontrol,&m,NULL); |
||
355 | if (p2 == -1) { |
||
356 | perror("testhd.c(main): Could not create task <JetControl> ..."); |
||
357 | sys_end(); |
||
358 | } |
||
359 | |||
360 | |||
361 | ft_task_default_model(ftb); |
||
362 | ft_task_def_usemath(ftb); |
||
363 | ft_task_def_backup(ftb); |
||
364 | ft_task_def_ctrl_jet(ftb); |
||
365 | ft_task_def_backup_wcet(ftb, 7000); |
||
366 | |||
367 | |||
368 | |||
369 | p3 = task_create("Hard_aster1b", hard_aster1b, &ftb,NULL); |
||
370 | if (p3 == -1) { |
||
371 | perror("testhd.c(main): Could not create task <aster1b> ..."); |
||
372 | sys_end(); |
||
373 | } |
||
374 | |||
375 | ft_task_default_model(ftp); |
||
376 | ft_task_def_usemath(ftp); |
||
377 | ft_task_def_ctrl_jet(ftp); |
||
378 | ft_task_def_group(ftp, 1); |
||
379 | ft_task_def_period(ftp, 50000); |
||
380 | ft_task_def_budget(ftp, 15000); |
||
381 | ft_task_def_primary_exec(ftp, 7300); |
||
382 | ft_task_def_primary(ftp); |
||
383 | ft_task_def_backup_task(ftp, p3); |
||
384 | |||
385 | |||
386 | p4 = task_create("Hard_aster1p", hard_aster1p, &ftp, NULL); |
||
387 | if (p4 == -1) { |
||
388 | perror("testhd.c(main): Could not create task <aster1p> ..."); |
||
389 | sys_end(); |
||
390 | } |
||
391 | |||
392 | |||
393 | ft_task_def_backup_wcet(ftb, 6700); |
||
394 | |||
395 | |||
396 | p5 = task_create("Hard_aster2b", hard_aster2b, &ftb, NULL); |
||
397 | if (p5 == -1) { |
||
398 | perror("testhd.c(main): Could not create task <aster2b> ..."); |
||
399 | sys_end(); |
||
400 | } |
||
401 | |||
402 | |||
403 | ft_task_def_period(ftp, 100000); |
||
404 | ft_task_def_budget(ftp, 8000); |
||
405 | ft_task_def_primary_exec(ftp, 11000); |
||
406 | ft_task_def_backup_task(ftp, p5); |
||
407 | |||
408 | |||
409 | p6 = task_create("Hard_aster2p", hard_aster2p, &ftp, NULL); |
||
410 | if (p6 == -1) { |
||
411 | perror("testhd.c(main): Could not create task <aster2p> ..."); |
||
412 | sys_end(); |
||
413 | } |
||
414 | |||
415 | |||
416 | printf_xy(0,STAT_Y + 15,WHITE,"Hard asteroide PID= %-3d ",p3); |
||
417 | printf_xy(0,STAT_Y + 17,WHITE,"Clock PID= %-3d ",p1); |
||
418 | printf_xy(0,STAT_Y + 18,WHITE,"JetControl PID= %-3d ",p2); |
||
419 | |||
420 | |||
421 | |||
422 | task_nopreempt(); |
||
423 | fineprg.tv_sec = 10; |
||
424 | fineprg.tv_nsec = 0; |
||
425 | kern_event_post(&fineprg,fine,NULL); |
||
426 | group_activate(1); |
||
427 | return 0; |
||
428 | } |
||
429 |