Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1671 | tullio | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Copyright (C) 2000 Paolo Gai |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | */ |
||
35 | |||
36 | #include "kernel/kern.h" |
||
37 | |||
38 | #include "fsf.h" |
||
39 | #include "fsf_server.h" |
||
40 | |||
41 | #include "stdlib.h" |
||
42 | #include "unistd.h" |
||
43 | #include "string.h" |
||
44 | #include "pistar.h" |
||
45 | |||
46 | #include "pthread.h" |
||
47 | |||
48 | #include "drivers/glib.h" |
||
49 | #include "global.h" |
||
50 | |||
51 | #include <drivers/shark_keyb26.h> |
||
52 | |||
53 | |||
54 | char *readFilePortName = "readFilePort"; |
||
55 | char *displayPortName = "displayPortName"; |
||
56 | |||
57 | #define TEST_PERIOD 50000 |
||
58 | |||
59 | mutex_t mux; |
||
60 | int main_chunk; |
||
61 | |||
62 | |||
63 | |||
64 | /* 10% */ |
||
65 | struct timespec decoderPeriod = {0,30000000}; |
||
66 | struct timespec decoderBudget = {0,3000000}; |
||
67 | |||
68 | /* 10% */ |
||
69 | struct timespec readTaskPeriod = {0,30000000}; |
||
70 | struct timespec readTaskBudget = {0,3000000}; |
||
71 | |||
72 | /* 45% */ |
||
73 | struct timespec displayPeriod = {0,40000000}; |
||
74 | struct timespec displayBudget = {0,18000000}; |
||
75 | |||
76 | // 5 % |
||
77 | struct timespec overloadPeriod = {0,10000000}; |
||
78 | struct timespec overloadBudget = {0,500000}; |
||
79 | |||
80 | fsf_server_id_t decoderServer; |
||
81 | fsf_server_id_t readTaskServer; |
||
82 | fsf_server_id_t displayServer; |
||
83 | fsf_server_id_t overloadServer; |
||
84 | |||
85 | fsf_contract_parameters_t overloadContract; |
||
86 | fsf_contract_parameters_t decoderContract; |
||
87 | fsf_contract_parameters_t readTaskContract; |
||
88 | fsf_contract_parameters_t displayContract; |
||
89 | |||
90 | |||
91 | void program_end() |
||
92 | { |
||
93 | |||
94 | grx_close(); |
||
95 | exit(0); |
||
96 | } |
||
97 | |||
98 | void *mpeg2decoder(void *arg); |
||
99 | void *readTask(void *arg); |
||
100 | void *displayTask(void *arg); |
||
101 | void *overLoadTask(void *arg); |
||
102 | |||
103 | /*************************************************************** |
||
104 | * |
||
105 | * Create the display task and bind it to a server |
||
106 | * |
||
107 | * Author: Robert Bäckgren |
||
108 | ******************************************************************/ |
||
109 | void addDisplayTaskToServer(fsf_server_id_t server) |
||
110 | { |
||
111 | int err; |
||
112 | pthread_t j = -1; |
||
113 | HARD_TASK_MODEL ht; |
||
114 | static fsf_sched_params_t pr; |
||
115 | |||
116 | |||
117 | pr.policy=FSF_EDF; |
||
118 | pr.params=&ht; |
||
119 | |||
120 | |||
121 | hard_task_default_model(ht); |
||
122 | hard_task_def_mit(ht,40000); |
||
123 | hard_task_def_wcet(ht,18000); |
||
124 | nrt_task_def_group(ht,3); |
||
125 | |||
126 | /* |
||
127 | err = pthread_create(&j, NULL, displayTask, NULL); |
||
128 | if (err) { |
||
129 | grx_close(); |
||
130 | grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0); |
||
131 | exit(err); |
||
132 | } |
||
133 | |||
134 | err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr)); |
||
135 | if (err) { |
||
136 | grx_close(); |
||
137 | exit(err); |
||
138 | |||
139 | } |
||
140 | */ |
||
141 | err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL, |
||
142 | displayTask,NULL); |
||
143 | if (err) { |
||
144 | //grx_close(); |
||
145 | //grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0); |
||
146 | exit(err); |
||
147 | } |
||
148 | task_activate(j); |
||
149 | |||
150 | } |
||
151 | |||
152 | /*********************************************************************' |
||
153 | * |
||
154 | * Create the input task and bind it to a server |
||
155 | * |
||
156 | * Author: Robert Bäckgren |
||
157 | *********************************************************************/ |
||
158 | void addReadTaskToServer(fsf_server_id_t server) |
||
159 | { |
||
160 | int err; |
||
161 | pthread_t j = -1; |
||
162 | NRT_TASK_MODEL ht; |
||
163 | static fsf_sched_params_t pr; |
||
164 | |||
165 | |||
166 | pr.policy=FSF_RR; |
||
167 | pr.params=&ht; |
||
168 | |||
169 | |||
170 | nrt_task_default_model(ht); |
||
171 | nrt_task_def_group(ht,1); |
||
172 | |||
173 | /* |
||
174 | err = pthread_create(&j, NULL, readTask, NULL); |
||
175 | if (err) { |
||
176 | grx_close(); |
||
177 | perror("Could not create task..."); |
||
178 | exit(err); |
||
179 | } |
||
180 | |||
181 | err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr)); |
||
182 | if (err) { |
||
183 | grx_close(); |
||
184 | //perror("Could not bind task.."); |
||
185 | exit(err); |
||
186 | } |
||
187 | */ |
||
188 | |||
189 | err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL, |
||
190 | readTask,NULL); |
||
191 | if (err) { |
||
192 | //grx_close(); |
||
193 | //grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0); |
||
194 | exit(err); |
||
195 | } |
||
196 | task_activate(j); |
||
197 | } |
||
198 | |||
199 | /********************************************************************** |
||
200 | * |
||
201 | * Create the decoder task and bind it to a server |
||
202 | * |
||
203 | * Author: Robert Bäckgren |
||
204 | **********************************************************************/ |
||
205 | void addDecoderThreadToServer(fsf_server_id_t server) |
||
206 | { |
||
207 | |||
208 | int err; |
||
209 | pthread_t j = -1; |
||
210 | NRT_TASK_MODEL ht; |
||
211 | static fsf_sched_params_t pr; |
||
212 | |||
213 | |||
214 | |||
215 | pr.policy=FSF_RR; |
||
216 | pr.params=&ht; |
||
217 | |||
218 | |||
219 | nrt_task_default_model(ht); |
||
220 | nrt_task_def_group(ht,1); |
||
221 | |||
222 | /* |
||
223 | err = pthread_create(&j, NULL, mpeg2decoder, NULL); |
||
224 | if (err) { |
||
225 | grx_close(); |
||
226 | perror("Could not create task..."); |
||
227 | exit(err); |
||
228 | } |
||
229 | |||
230 | err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr)); |
||
231 | if (err) { |
||
232 | grx_close(); |
||
233 | //perror("Could not bind task.."); |
||
234 | exit(err); |
||
235 | } |
||
236 | */ |
||
237 | err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL, |
||
238 | mpeg2decoder,NULL); |
||
239 | if (err) { |
||
240 | //grx_close(); |
||
241 | //grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0); |
||
242 | exit(err); |
||
243 | } |
||
244 | task_activate(j); |
||
245 | } |
||
246 | |||
247 | |||
248 | /*************************************************************************** |
||
249 | * |
||
250 | * Create a dummy task and bind it to a server |
||
251 | * |
||
252 | * Author: Robert Bäckgren |
||
253 | *****************************************************************************/ |
||
254 | int addOverLoadTaskToServer(fsf_server_id_t server) |
||
255 | { |
||
256 | int err; |
||
257 | pthread_t j = -1; |
||
258 | HARD_TASK_MODEL ht; |
||
259 | static fsf_sched_params_t pr; |
||
260 | |||
261 | |||
262 | |||
263 | pr.policy=FSF_EDF; |
||
264 | pr.params=&ht; |
||
265 | |||
266 | |||
267 | hard_task_default_model(ht); |
||
268 | hard_task_def_mit(ht,2000000); |
||
269 | hard_task_def_wcet(ht,20000); |
||
270 | nrt_task_def_group(ht,4); |
||
271 | |||
272 | /* |
||
273 | err = pthread_create(&j, NULL, overLoadTask, NULL); |
||
274 | if (err) { |
||
275 | grx_text("Failed to create the decoder task",270,270,rgb16(255,255,255),0); |
||
276 | return 0; |
||
277 | } |
||
278 | |||
279 | err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr)); |
||
280 | if (err) { |
||
281 | grx_close(); |
||
282 | //perror("Could not bind task.."); |
||
283 | exit(err); |
||
284 | } |
||
285 | */ |
||
286 | err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL, |
||
287 | overLoadTask,NULL); |
||
288 | if (err) { |
||
289 | //grx_close(); |
||
290 | //grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0); |
||
291 | exit(err); |
||
292 | } |
||
293 | task_activate(j); |
||
294 | return 1; |
||
295 | } |
||
296 | |||
297 | void ending_system(KEY_EVT *e) { |
||
298 | |||
299 | grx_close(); |
||
300 | |||
301 | exit(0); |
||
302 | } |
||
303 | |||
304 | |||
305 | int main(int argc, char **argv) |
||
306 | { |
||
307 | |||
308 | char ch; |
||
309 | int err; |
||
310 | int i = 1; |
||
311 | char tmp[100]; |
||
312 | struct timespec simtime; |
||
313 | KEY_EVT k; |
||
314 | union sigval no_sigval = {0}; |
||
315 | |||
316 | PI_mutexattr_t a; |
||
317 | KEY_EVT ev; |
||
318 | |||
319 | |||
320 | |||
321 | union sigval sval; |
||
322 | |||
323 | |||
324 | ev.ascii = 'c'; |
||
325 | ev.scan = KEY_C; |
||
326 | ev.status = KEY_PRESSED; |
||
327 | ev.flag = CNTR_BIT; |
||
328 | keyb_hook(ev, ending_system, FALSE); |
||
329 | |||
330 | PI_mutexattr_default(a); |
||
331 | fsf_init(); |
||
332 | |||
333 | mutex_init(&mux,&a); |
||
334 | |||
335 | // Set up the different servers |
||
336 | fsf_initialize_contract(&readTaskContract); |
||
337 | err=fsf_set_contract_basic_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_WORKLOAD); |
||
338 | if (err) { |
||
339 | exit(err); |
||
340 | } |
||
341 | err=fsf_set_contract_reclamation_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1); |
||
342 | if (err) exit(err); |
||
343 | err=fsf_set_contract_timing_requirements(&readTaskContract,true,NULL,0,no_sigval,0,no_sigval); |
||
344 | if (err) exit(err); |
||
345 | |||
346 | fsf_set_contract_scheduling_policy(&readTaskContract, FSF_RR); |
||
347 | |||
348 | fsf_initialize_contract(&decoderContract); |
||
349 | err=fsf_set_contract_basic_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_WORKLOAD); |
||
350 | if (err) { |
||
351 | grx_close(); |
||
352 | exit(err); |
||
353 | } |
||
354 | |||
355 | err=fsf_set_contract_reclamation_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1); |
||
356 | if (err) exit(err); |
||
357 | err=fsf_set_contract_timing_requirements(&decoderContract,true,NULL,0,no_sigval,0,no_sigval); |
||
358 | if (err) exit(err); |
||
359 | |||
360 | fsf_set_contract_scheduling_policy(&decoderContract, FSF_RR); |
||
361 | |||
362 | fsf_initialize_contract(&displayContract); |
||
363 | err=fsf_set_contract_basic_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_WORKLOAD); |
||
364 | if (err) { |
||
365 | exit(err); |
||
366 | } |
||
367 | |||
368 | err=fsf_set_contract_reclamation_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1); |
||
369 | if (err) exit(err); |
||
370 | err=fsf_set_contract_timing_requirements(&displayContract,true,NULL,0,no_sigval,0,no_sigval); |
||
371 | if (err) exit(err); |
||
372 | |||
373 | fsf_set_contract_scheduling_policy(&displayContract, FSF_EDF); |
||
374 | |||
375 | fsf_initialize_contract(&overloadContract); |
||
376 | err=fsf_set_contract_basic_parameters(&overloadContract,&overloadBudget,&overloadPeriod,FSF_DEFAULT_WORKLOAD); |
||
377 | if (err) { |
||
378 | exit(err); |
||
379 | } |
||
380 | |||
381 | err=fsf_set_contract_reclamation_parameters(&overloadContract,&overloadBudget,&overloadPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1); |
||
382 | if (err) exit(err); |
||
383 | err=fsf_set_contract_timing_requirements(&overloadContract,true,NULL,0,no_sigval,0,no_sigval); |
||
384 | if (err) exit(err); |
||
385 | |||
386 | fsf_set_contract_scheduling_policy(&overloadContract, FSF_EDF); |
||
387 | |||
388 | err = fsf_negotiate_contract(&readTaskContract,&readTaskServer); |
||
389 | if (err) { |
||
390 | exit(err); |
||
391 | } |
||
392 | |||
393 | err = fsf_negotiate_contract(&decoderContract,&decoderServer); |
||
394 | if (err) { |
||
395 | exit(err); |
||
396 | } |
||
397 | err = fsf_negotiate_contract(&displayContract,&displayServer); |
||
398 | if (err) { |
||
399 | exit(err); |
||
400 | } |
||
401 | |||
402 | err = fsf_negotiate_contract(&overloadContract,&overloadServer); |
||
403 | if (err) { |
||
404 | exit(err); |
||
405 | } |
||
406 | |||
407 | print_server_list(); |
||
408 | |||
409 | |||
410 | // Create and bind different ports to communication links (This ports a declared in global.h) |
||
411 | if((readTaskPort = port_create(readFilePortName, sizeof(struct readDecodeMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1) |
||
412 | { |
||
413 | //grx_text("failed to create readTask Port",0,0,rgb16(255,255,255),0); |
||
414 | exit(-1); |
||
415 | } |
||
416 | if((decoderTaskPort->displayTaskPort = port_create(displayPortName, sizeof(struct decodeDisplayMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1) |
||
417 | { |
||
418 | //grx_text("failed to create displayTask Port",0,0,rgb16(255,255,255),0); |
||
419 | exit(-1); |
||
420 | } |
||
421 | if((decoderTaskPort->readTaskPort = port_connect(readFilePortName, sizeof(struct readDecodeMessage), STREAM, READ)) == -1) |
||
422 | { |
||
423 | //grx_text("failed to connect to readTask Port",0,0,rgb16(255,255,255),0); |
||
424 | exit(-1); |
||
425 | } |
||
426 | if((displayTaskPort = port_connect(displayPortName, sizeof(struct decodeDisplayMessage), STREAM, READ)) == -1) |
||
427 | { |
||
428 | //grx_text("failed to connect to displayTask Port",0,0,rgb16(255,255,255),0); |
||
429 | exit(-1); |
||
430 | } |
||
431 | |||
432 | // graphic card Initialization |
||
433 | if (grx_init() < 1) { |
||
434 | exit(-1); |
||
435 | } |
||
436 | |||
437 | if (grx_open(800, 600, 16) < 0) { |
||
438 | cprintf("GRX Err\n"); |
||
439 | exit(-1); |
||
440 | } |
||
441 | |||
442 | /* |
||
443 | kern_gettime(&simtime); |
||
444 | for (i=1; i<10;i++) { |
||
445 | simtime.tv_sec+=1; |
||
446 | kern_event_post(&simtime,(void *)((void *)(addOverLoadTaskToServer)), (void *)overloadServer); |
||
447 | } |
||
448 | |||
449 | simtime.tv_sec+=10; |
||
450 | kern_event_post(&simtime,(void *)((void *)(ending_system)), NULL); |
||
451 | */ |
||
452 | ch = keyb_getch(BLOCK); |
||
453 | kern_printf("Main %d\n", ch); |
||
454 | while(ch != ESC) { |
||
455 | |||
456 | switch (ch) |
||
457 | { |
||
458 | |||
459 | case '1': |
||
460 | addReadTaskToServer(readTaskServer); |
||
461 | addDecoderThreadToServer(decoderServer); |
||
462 | addDisplayTaskToServer(displayServer); |
||
463 | |||
464 | break; |
||
465 | case '2': |
||
466 | sprintf(tmp,"Number of dummy task: %d", i); |
||
467 | //grx_text(tmp,0,0,rgb16(255,255,255),0); |
||
468 | i++; |
||
469 | addOverLoadTaskToServer(overloadServer); |
||
470 | break; |
||
471 | case '4': |
||
472 | ending_system(NULL); |
||
473 | break; |
||
474 | } |
||
475 | |||
476 | ch = keyb_getch(BLOCK); |
||
477 | |||
478 | } |
||
479 | |||
480 | ending_system(NULL); |
||
481 | // while(1); |
||
482 | |||
483 | return 0; |
||
484 | |||
485 | } |
||
486 |