Rev 1183 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1182 | giacomo | 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_contract.h" |
||
39 | |||
40 | #include "stdlib.h" |
||
41 | #include "unistd.h" |
||
42 | #include "string.h" |
||
43 | |||
44 | #include "pthread.h" |
||
45 | |||
46 | #include "drivers/keyb.h" |
||
47 | #include "drivers/glib.h" |
||
48 | |||
49 | #define TEST_PERIOD 50000 |
||
50 | |||
51 | mutex_t mux; |
||
52 | |||
53 | void program_key_end(KEY_EVT *k) |
||
54 | { |
||
55 | |||
56 | sys_end(); |
||
57 | |||
58 | } |
||
59 | |||
60 | void print_timer(int x, int y) |
||
61 | { |
||
62 | |||
63 | long nsec,sec,min,hrs,day; |
||
64 | struct timespec actual_timer; |
||
65 | char tmp[100]; |
||
66 | |||
67 | sys_gettime(&actual_timer); |
||
68 | |||
69 | nsec = actual_timer.tv_nsec; |
||
70 | sec = actual_timer.tv_sec; |
||
71 | min = sec / 60; |
||
72 | sec %= 60; |
||
73 | hrs = min / 60; |
||
74 | min %= 60; |
||
75 | day = hrs / 24; |
||
76 | hrs %= 24; |
||
77 | |||
78 | sprintf(tmp,"Time: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec); |
||
79 | //mutex_lock(&mux); |
||
80 | grx_text(tmp,x,y,rgb16(255,255,255),0); |
||
81 | //mutex_unlock(&mux); |
||
82 | |||
83 | } |
||
84 | |||
85 | #define LOAD_VARIATION 10 |
||
86 | |||
87 | #define MAX_V_QOS 30 |
||
88 | #define MIN_V_QOS 2 |
||
89 | |||
90 | void *test_task_variable(void *arg) { |
||
91 | |||
92 | struct timespec next_time; |
||
93 | bool was_deadline_missed = false, was_budget_overran = false; |
||
94 | |||
95 | char tmp[100]; |
||
96 | |||
97 | long long i; |
||
98 | int task_qos; |
||
99 | int var_load, rd_per; |
||
100 | |||
101 | TIME exectime; |
||
102 | |||
103 | task_qos = 7; |
||
104 | var_load = 5; |
||
105 | rd_per = 0; |
||
106 | |||
107 | while(1) { |
||
108 | |||
109 | print_timer(307,10+30*exec_shadow); |
||
110 | sprintf(tmp,"Test Thread V QOS = %5d PID = %3d VLOAD = %3d",task_qos,exec_shadow,var_load); |
||
111 | |||
112 | //mutex_lock(&mux); |
||
113 | if (!was_deadline_missed) |
||
114 | grx_text(tmp,307,20+30*exec_shadow,rgb16(255,255,255),0); |
||
115 | else |
||
116 | grx_text(tmp,307,20+30*exec_shadow,rgb16(255,0,0),0); |
||
117 | //mutex_unlock(&mux); |
||
118 | |||
119 | jet_gettable(exec_shadow, &exectime, 1); |
||
120 | sprintf(tmp,"Thread Exec Timer = %10d us",(int)exectime); |
||
121 | grx_text(tmp,307,30+30*exec_shadow,rgb16(255,255,255),0); |
||
122 | |||
123 | if (rd_per > LOAD_VARIATION) { |
||
124 | var_load += rand()%3-1; |
||
125 | if (var_load > 20) var_load = 20; |
||
126 | if (var_load < 0) var_load = 0; |
||
127 | rd_per = 0; |
||
128 | } else { |
||
129 | rd_per++; |
||
130 | } |
||
131 | |||
132 | for(i = 0; i < 10000*(task_qos+var_load); i++); |
||
133 | |||
134 | kern_gettime(&next_time); |
||
135 | ADDUSEC2TIMESPEC(TEST_PERIOD, &next_time); |
||
136 | fsf_schedule_next_timed_job(&next_time, NULL, NULL, &was_deadline_missed, &was_budget_overran); |
||
137 | |||
138 | } |
||
139 | |||
140 | return NULL; |
||
141 | |||
142 | } |
||
143 | |||
144 | #define MAX_C_QOS 30 |
||
145 | #define MIN_C_QOS 2 |
||
146 | |||
147 | void *test_task_constant(void *arg) { |
||
148 | |||
149 | struct timespec next_time; |
||
150 | bool was_deadline_missed = false, was_budget_overran = false; |
||
151 | |||
152 | char tmp[100]; |
||
153 | |||
154 | long long i; |
||
155 | int task_qos; |
||
156 | |||
157 | task_qos = 7; |
||
158 | |||
159 | while(1) { |
||
160 | |||
161 | print_timer(307,10+20*exec_shadow); |
||
162 | sprintf(tmp,"Test Task C QOS = %5d PID = %3d",task_qos,exec_shadow); |
||
163 | //mutex_lock(&mux); |
||
164 | if (!was_deadline_missed) |
||
165 | grx_text(tmp,307,20+20*exec_shadow,rgb16(255,255,255),0); |
||
166 | else |
||
167 | grx_text(tmp,307,20+20*exec_shadow,rgb16(255,0,0),0); |
||
168 | //mutex_unlock(&mux); |
||
169 | |||
170 | for(i = 0; i < 10000*task_qos; i++); |
||
171 | |||
172 | kern_gettime(&next_time); |
||
173 | ADDUSEC2TIMESPEC(TEST_PERIOD, &next_time); |
||
174 | fsf_schedule_next_timed_job(&next_time, NULL, NULL, &was_deadline_missed, &was_budget_overran); |
||
175 | |||
176 | } |
||
177 | |||
178 | return NULL; |
||
179 | |||
180 | } |
||
181 | |||
182 | void draw_box(int x1, int y1, int x2, int y2) |
||
183 | { |
||
184 | |||
185 | grx_rect(x1,y1,x2,y2,rgb16(160,160,160)); |
||
186 | grx_rect(x1+2,y1+2,x2-2,y2-2,rgb16(210,210,210)); |
||
187 | |||
188 | } |
||
189 | |||
190 | void layout_screen() |
||
191 | { |
||
192 | |||
193 | draw_box(0,0,300,500); |
||
194 | grx_text("Application Task List",5,5,rgb16(255,255,255),0); |
||
195 | |||
196 | draw_box(303,0,799,500); |
||
197 | grx_text("Task Output",305,5,rgb16(255,255,255),0); |
||
198 | |||
199 | draw_box(0,503,799,599); |
||
200 | grx_line(140,505,140,597,rgb16(255,255,255)); |
||
201 | grx_line(140,583,797,583,rgb16(255,255,255)); |
||
202 | |||
203 | grx_text("Application Statistics",142,507,rgb16(255,255,255),0); |
||
204 | |||
205 | } |
||
206 | |||
207 | void program_end() |
||
208 | { |
||
209 | |||
210 | grx_close(); |
||
211 | |||
212 | } |
||
213 | |||
214 | void *mpeg2decoder(void *arg); |
||
215 | |||
216 | void add_posixstar_thread(fsf_server_id_t server) |
||
217 | { |
||
218 | |||
219 | int err; |
||
220 | pthread_t j = -1; |
||
221 | NRT_TASK_MODEL nrt; |
||
222 | |||
223 | nrt_task_default_model(nrt); |
||
224 | nrt_task_def_save_arrivals(nrt); |
||
225 | |||
226 | err = pthread_create(&j, NULL, test_task_variable, NULL); |
||
227 | if (err) { |
||
228 | perror("Could not create task..."); |
||
229 | sys_end(); |
||
230 | } |
||
231 | |||
232 | fsf_bind_thread_to_server(server, j, &nrt); |
||
233 | |||
234 | } |
||
235 | |||
236 | void add_edfstar_thread(fsf_server_id_t server) |
||
237 | { |
||
238 | |||
239 | int err; |
||
240 | pthread_t j = -1; |
||
241 | HARD_TASK_MODEL ht; |
||
242 | |||
243 | hard_task_default_model(ht); |
||
244 | hard_task_def_mit(ht,100000); |
||
245 | hard_task_def_wcet(ht,90000); |
||
246 | |||
247 | err = pthread_create(&j, NULL, mpeg2decoder, NULL); |
||
248 | if (err) { |
||
249 | perror("Could not create task..."); |
||
250 | sys_end(); |
||
251 | } |
||
252 | |||
253 | //fsf_bind_thread_to_server(server, j, &ht); |
||
254 | |||
255 | } |
||
256 | |||
257 | int main(int argc, char **argv) |
||
258 | { |
||
259 | |||
260 | char ch; |
||
261 | int err; |
||
262 | |||
263 | KEY_EVT k; |
||
264 | |||
265 | PI_mutexattr_t a; |
||
266 | |||
267 | struct timespec period1 = {0,10000000}; |
||
268 | struct timespec period2 = {0,10000000}; |
||
269 | struct timespec budget1 = {0,4500000}; |
||
270 | struct timespec budget2 = {0,4500000}; |
||
271 | |||
272 | fsf_server_id_t server1, server2; |
||
273 | fsf_contract_parameters_t contract1, contract2; |
||
274 | |||
275 | sys_atrunlevel(program_end, NULL, RUNLEVEL_BEFORE_EXIT); |
||
276 | |||
277 | k.flag = ALTL_BIT; |
||
278 | k.scan = KEY_C; |
||
279 | k.ascii = 'c'; |
||
280 | keyb_hook(k,program_key_end); |
||
281 | |||
282 | srand(sys_gettime(NULL)); |
||
283 | |||
284 | // graphic card Initialization |
||
285 | if (grx_init() < 1) { |
||
286 | sys_end(); |
||
287 | } |
||
288 | |||
289 | if (grx_open(800, 600, 16) < 0) { |
||
290 | cprintf("GRX Err\n"); |
||
291 | sys_end(); |
||
292 | } |
||
293 | |||
294 | layout_screen(); |
||
295 | |||
296 | PI_mutexattr_default(a); |
||
297 | |||
298 | mutex_init(&mux,&a); |
||
299 | |||
300 | fsf_initialize_contract(&contract1); |
||
301 | fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
302 | fsf_initialize_contract(&contract2); |
||
303 | fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
304 | fsf_set_local_scheduler_parameter(&contract2, FSF_SCHEDULER_EDF); |
||
305 | |||
306 | err = fsf_negotiate_contract(&contract1,&server1); |
||
307 | if (err) cprintf("(FSF ERROR %d)",err); |
||
308 | err = fsf_negotiate_contract(&contract2,&server2); |
||
309 | if (err) cprintf("(FSF ERROR %d)",err); |
||
310 | |||
311 | ch = keyb_getch(BLOCK); |
||
312 | |||
313 | while(ch != ESC) { |
||
314 | |||
315 | switch (ch) { |
||
316 | |||
317 | case '1': |
||
318 | add_posixstar_thread(server1); |
||
319 | break; |
||
320 | case '2': |
||
321 | add_edfstar_thread(server2); |
||
322 | break; |
||
323 | case '3': |
||
324 | break; |
||
325 | case '4': |
||
326 | break; |
||
327 | case '5': |
||
328 | break; |
||
329 | } |
||
330 | |||
331 | ch = keyb_getch(BLOCK); |
||
332 | |||
333 | } |
||
334 | |||
335 | sys_end(); |
||
336 | |||
337 | return 0; |
||
338 | |||
339 | } |