Go to most recent revision | 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: testm.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 22 (M): |
||
27 | |||
28 | this is a part of the classic Hartik demo Aster. |
||
29 | |||
30 | it is based on test 10(A), and test the PS with RM. |
||
31 | |||
32 | The JetControl is served by a dedicated Polling Server, too. |
||
33 | |||
34 | There are APER_MAX tasks sleeping, and when an asteroide task finish |
||
35 | the current activation, it activate also an aperiodic task chosen |
||
36 | randomly (if the task chosen is already active, the task_activate do |
||
37 | nothing!) |
||
38 | |||
39 | |||
40 | **/ |
||
41 | |||
42 | /* |
||
43 | * Copyright (C) 2000 Paolo Gai |
||
44 | * |
||
45 | * This program is free software; you can redistribute it and/or modify |
||
46 | * it under the terms of the GNU General Public License as published by |
||
47 | * the Free Software Foundation; either version 2 of the License, or |
||
48 | * (at your option) any later version. |
||
49 | * |
||
50 | * This program is distributed in the hope that it will be useful, |
||
51 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
52 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
53 | * GNU General Public License for more details. |
||
54 | * |
||
55 | * You should have received a copy of the GNU General Public License |
||
56 | * along with this program; if not, write to the Free Software |
||
57 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
58 | * |
||
59 | */ |
||
60 | |||
61 | #include "kernel/kern.h" |
||
62 | #include "modules//edf.h" |
||
63 | #include "drivers/keyb.h" |
||
64 | |||
65 | int num_aster = 0; |
||
66 | #define ASTER_LIM 60 |
||
67 | #define DISPLAY_MAX 15 |
||
68 | #define ASTER_MAX 70 |
||
69 | #define STAT_Y 9 |
||
70 | |||
71 | #define APER_MAX 8 |
||
72 | |||
73 | #define PER_WCET 7800 |
||
74 | #define APER_WCET 14000 |
||
75 | #define CLOCK_WCET 200 |
||
76 | #define ASTER_WCET 200 |
||
77 | |||
78 | #define APER_REP 22000 |
||
79 | |||
80 | PID aper_table[APER_MAX]; |
||
81 | |||
82 | TASK asteroide(void) |
||
83 | { |
||
84 | int i; |
||
85 | int y = rand() % 7 + 1; |
||
86 | |||
87 | int load1,j; |
||
88 | |||
89 | char s[2]; |
||
90 | |||
91 | s[0] = '*'; s[1] = 0; |
||
92 | |||
93 | /*for (;;)*/ { |
||
94 | i = 1; |
||
95 | while (i < ASTER_LIM) { |
||
96 | load1 = 10000; //8000 + rand()%2000; |
||
97 | for (j=0; j<load1; j++) { |
||
98 | s[0] = '*' + rand() % 100; |
||
99 | puts_xy(i,y,rand()%15+1,s); |
||
100 | } |
||
101 | |||
102 | task_activate(aper_table[rand()%APER_MAX]); |
||
103 | task_endcycle(); |
||
104 | |||
105 | puts_xy(i,y,WHITE," "); |
||
106 | i++; |
||
107 | } |
||
108 | } |
||
109 | num_aster--; |
||
110 | return 0; |
||
111 | } |
||
112 | |||
113 | TASK aper_asteroid(void *a) |
||
114 | { |
||
115 | int i; |
||
116 | int y = rand() % 7 + 1; |
||
117 | |||
118 | int load1,j; |
||
119 | int c; |
||
120 | |||
121 | char s[2]; |
||
122 | |||
123 | c = (int)a; |
||
124 | s[0] = '*'; s[1] = 0; |
||
125 | |||
126 | for (;;) { |
||
127 | i = 1; |
||
128 | while (i < ASTER_LIM) { |
||
129 | load1 = APER_REP; //8000 + rand()%2000; |
||
130 | for (j=0; j<load1; j++) { |
||
131 | s[0] = '*' + rand() % 100; |
||
132 | puts_xy(i,y,rand()%15+1,s); |
||
133 | } |
||
134 | s[0] = c; |
||
135 | puts_xy(i,y,rand()%15+1,s); |
||
136 | |||
137 | task_endcycle(); |
||
138 | |||
139 | puts_xy(i,y,WHITE," "); |
||
140 | i++; |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | TASK aster() |
||
146 | { |
||
147 | PID p; |
||
148 | |||
149 | HARD_TASK_MODEL m; |
||
150 | int r; |
||
151 | int x; // adaptive bandwidth... |
||
152 | |||
153 | hard_task_default_model(m); |
||
154 | hard_task_def_wcet(m,PER_WCET); |
||
155 | hard_task_def_ctrl_jet(m); |
||
156 | |||
157 | x = 64; |
||
158 | |||
159 | srand(7); |
||
160 | while (1) { |
||
161 | if (num_aster < ASTER_MAX) { |
||
162 | r = (rand() % 200); |
||
163 | |||
164 | hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
||
165 | hard_task_def_mit(m, (x+r)*1000); |
||
166 | p = task_create("aaa",asteroide,&m,NULL); |
||
167 | if (p == -1) |
||
168 | { |
||
169 | if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
||
170 | printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno); |
||
171 | } |
||
172 | else { |
||
173 | num_aster++; |
||
174 | printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
||
175 | task_activate(p); |
||
176 | x /= 2; |
||
177 | if (x<50) x = 50; |
||
178 | } |
||
179 | } |
||
180 | task_endcycle(); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | TASK clock() |
||
185 | { |
||
186 | int s = 0, m = 0; |
||
187 | |||
188 | while(1) { |
||
189 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
190 | printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
||
191 | task_endcycle(); |
||
192 | |||
193 | if (++s > 59) { |
||
194 | s = 0; |
||
195 | m++; |
||
196 | } |
||
197 | printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
||
198 | printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
||
199 | task_endcycle(); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | |||
204 | |||
205 | /* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
||
206 | and plot on the screen the elapsed times... */ |
||
207 | TASK jetcontrol() |
||
208 | { |
||
209 | int i; /* a counter */ |
||
210 | TIME sum, max, curr, last[5]; |
||
211 | int nact; |
||
212 | int j; /* the elements set by jet_gettable */ |
||
213 | PID p; |
||
214 | |||
215 | |||
216 | kern_cli(); |
||
217 | printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
||
218 | kern_sti(); |
||
219 | |||
220 | for (;;) { |
||
221 | for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
||
222 | if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
||
223 | |||
224 | for (j=0; j<5; j++) last[j] = 0; |
||
225 | jet_gettable(p, &last[0], 5); |
||
226 | kern_cli(); |
||
227 | printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
||
228 | 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]); |
||
229 | kern_sti(); |
||
230 | i++; |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | |||
235 | |||
236 | void fine(KEY_EVT *e) |
||
237 | { |
||
238 | sys_end(); |
||
239 | } |
||
240 | |||
241 | |||
242 | int main(int argc, char **argv) |
||
243 | { |
||
244 | PID p1,p2,p3; //,p4,p5,p6; |
||
245 | HARD_TASK_MODEL m; |
||
246 | NRT_TASK_MODEL m_nrt; |
||
247 | SOFT_TASK_MODEL m_aper; |
||
248 | int i; |
||
249 | struct timespec fineprg; |
||
250 | |||
251 | KEY_EVT emerg; |
||
252 | //keyb_set_map(itaMap); |
||
253 | emerg.ascii = 'x'; |
||
254 | emerg.scan = KEY_X; |
||
255 | emerg.flag = ALTL_BIT; |
||
256 | keyb_hook(emerg,fine); |
||
257 | |||
258 | hard_task_default_model(m); |
||
259 | hard_task_def_wcet(m,ASTER_WCET); |
||
260 | hard_task_def_mit(m,10000); |
||
261 | hard_task_def_group(m,1); |
||
262 | hard_task_def_ctrl_jet(m); |
||
263 | |||
264 | nrt_task_default_model(m_nrt); |
||
265 | nrt_task_def_group(m_nrt,1); |
||
266 | nrt_task_def_ctrl_jet(m_nrt); |
||
267 | |||
268 | p1 = task_create("Aster",aster,&m,NULL); |
||
269 | if (p1 == -1) { |
||
270 | perror("test7.c(main): Could not create task <aster> ..."); |
||
271 | sys_end(); |
||
272 | l1_exit(-1); |
||
273 | } |
||
274 | |||
275 | hard_task_def_mit(m,500000); |
||
276 | hard_task_def_wcet(m,CLOCK_WCET); |
||
277 | p2 = task_create("Clock",clock,&m,NULL); |
||
278 | if (p2 == -1) { |
||
279 | perror("test7.c(main): Could not create task <Clock> ..."); |
||
280 | sys_end(); |
||
281 | l1_exit(-1); |
||
282 | } |
||
283 | |||
284 | soft_task_default_model(m_aper); |
||
285 | soft_task_def_ctrl_jet(m_aper); |
||
286 | soft_task_def_level(m_aper, 1); |
||
287 | soft_task_def_group(m_aper,1); |
||
288 | soft_task_def_aperiodic(m_aper); |
||
289 | p3 = task_create("JetControl",jetcontrol,&m_aper,NULL); |
||
290 | if (p3 == -1) { |
||
291 | perror("test7.c(main): Could not create task <JetControl> ..."); |
||
292 | sys_end(); |
||
293 | l1_exit(-1); |
||
294 | } |
||
295 | |||
296 | soft_task_def_wcet(m_aper,APER_WCET); |
||
297 | soft_task_def_ctrl_jet(m_aper); |
||
298 | soft_task_def_aperiodic(m_aper); |
||
299 | |||
300 | for (i=0; i<APER_MAX; i++) { |
||
301 | soft_task_def_level(m_aper, i/4 + 3); |
||
302 | soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±')); |
||
303 | aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
||
304 | if (aper_table[i] == -1) { |
||
305 | perror("test7.c(main): Could not create task <aper> ..."); |
||
306 | sys_end(); |
||
307 | l1_exit(-1); |
||
308 | } |
||
309 | } |
||
310 | |||
311 | fineprg.tv_sec = 1000; |
||
312 | fineprg.tv_nsec = 0; |
||
313 | kern_event_post(&fineprg,(void (*)(void *))fine,NULL); |
||
314 | |||
315 | group_activate(1); |
||
316 | return 0; |
||
317 | } |
||
318 |