Rev 1625 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1624 | 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 | |||
1650 | pj | 56 | exit(1); |
1624 | giacomo | 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 | char tmp[100]; |
||
93 | |||
94 | long long i; |
||
95 | int task_qos; |
||
96 | int var_load, rd_per; |
||
97 | |||
98 | TIME exectime; |
||
99 | |||
100 | task_qos = 7; |
||
101 | var_load = 5; |
||
102 | rd_per = 0; |
||
103 | |||
104 | while(1) { |
||
105 | |||
106 | print_timer(307,10+30*exec_shadow); |
||
107 | sprintf(tmp,"Test Thread V QOS = %5d PID = %3d VLOAD = %3d",task_qos,exec_shadow,var_load); |
||
108 | |||
109 | //mutex_lock(&mux); |
||
110 | grx_text(tmp,307,20+30*exec_shadow,rgb16(255,255,255),0); |
||
111 | //mutex_unlock(&mux); |
||
112 | |||
113 | jet_gettable(exec_shadow, &exectime, 1); |
||
114 | sprintf(tmp,"Thread Exec Timer = %10d us",(int)exectime); |
||
115 | grx_text(tmp,307,30+30*exec_shadow,rgb16(255,255,255),0); |
||
116 | |||
117 | if (rd_per > LOAD_VARIATION) { |
||
118 | var_load += rand()%3-1; |
||
119 | if (var_load > 20) var_load = 20; |
||
120 | if (var_load < 0) var_load = 0; |
||
121 | rd_per = 0; |
||
122 | } else { |
||
123 | rd_per++; |
||
124 | } |
||
125 | |||
126 | for(i = 0; i < 10000*(task_qos+var_load); i++); |
||
127 | |||
128 | } |
||
129 | |||
130 | return NULL; |
||
131 | |||
132 | } |
||
133 | |||
134 | #define MAX_C_QOS 30 |
||
135 | #define MIN_C_QOS 2 |
||
136 | |||
137 | void *test_task_constant(void *arg) { |
||
138 | |||
139 | char tmp[100]; |
||
140 | |||
141 | long long i; |
||
142 | int task_qos; |
||
143 | |||
144 | task_qos = 7; |
||
145 | |||
146 | while(1) { |
||
147 | |||
148 | print_timer(307,10+20*exec_shadow); |
||
149 | sprintf(tmp,"Test Task C QOS = %5d PID = %3d",task_qos,exec_shadow); |
||
150 | //mutex_lock(&mux); |
||
151 | grx_text(tmp,307,20+20*exec_shadow,rgb16(255,255,255),0); |
||
152 | //mutex_unlock(&mux); |
||
153 | |||
154 | for(i = 0; i < 10000*task_qos; i++); |
||
155 | |||
156 | } |
||
157 | |||
158 | return NULL; |
||
159 | |||
160 | } |
||
161 | |||
162 | void draw_box(int x1, int y1, int x2, int y2) |
||
163 | { |
||
164 | |||
165 | grx_rect(x1,y1,x2,y2,rgb16(160,160,160)); |
||
166 | grx_rect(x1+2,y1+2,x2-2,y2-2,rgb16(210,210,210)); |
||
167 | |||
168 | } |
||
169 | |||
170 | void layout_screen() |
||
171 | { |
||
172 | |||
173 | draw_box(0,0,300,500); |
||
174 | grx_text("Application Task List",5,5,rgb16(255,255,255),0); |
||
175 | |||
176 | draw_box(303,0,799,500); |
||
177 | grx_text("Task Output",305,5,rgb16(255,255,255),0); |
||
178 | |||
179 | draw_box(0,503,799,599); |
||
180 | grx_line(140,505,140,597,rgb16(255,255,255)); |
||
181 | grx_line(140,583,797,583,rgb16(255,255,255)); |
||
182 | |||
183 | grx_text("Application Statistics",142,507,rgb16(255,255,255),0); |
||
184 | |||
185 | } |
||
186 | |||
187 | void program_end() |
||
188 | { |
||
189 | |||
190 | grx_close(); |
||
191 | |||
192 | } |
||
193 | |||
194 | void *mpeg2decoder(void *arg); |
||
195 | |||
196 | void add_posixstar_thread(fsf_server_id_t server) |
||
197 | { |
||
198 | NRT_TASK_MODEL nrt; |
||
199 | pthread_t j = -1; |
||
200 | |||
201 | nrt_task_default_model(nrt); |
||
202 | fsf_create_thread(server, &j, NULL, test_task_variable, NULL, &nrt); |
||
203 | |||
204 | } |
||
205 | |||
206 | void add_edfstar_thread(fsf_server_id_t server) |
||
207 | { |
||
208 | |||
209 | pthread_t j = -1; |
||
210 | HARD_TASK_MODEL ht; |
||
211 | |||
212 | hard_task_default_model(ht); |
||
213 | hard_task_def_mit(ht,100000); |
||
214 | hard_task_def_wcet(ht,90000); |
||
215 | |||
216 | fsf_create_thread(server, &j, NULL, mpeg2decoder, NULL, &ht); |
||
217 | |||
218 | } |
||
219 | |||
220 | int main(int argc, char **argv) |
||
221 | { |
||
222 | |||
223 | char ch; |
||
224 | int err; |
||
225 | |||
226 | KEY_EVT k; |
||
227 | |||
228 | PI_mutexattr_t a; |
||
229 | |||
230 | struct timespec period1 = {0,10000000}; |
||
231 | struct timespec period2 = {0,10000000}; |
||
232 | struct timespec budget1 = {0,4000000}; |
||
233 | struct timespec budget2 = {0,4000000}; |
||
234 | |||
235 | fsf_server_id_t server1, server2; |
||
236 | fsf_contract_parameters_t contract1, contract2; |
||
237 | |||
238 | sys_atrunlevel(program_end, NULL, RUNLEVEL_BEFORE_EXIT); |
||
239 | |||
240 | k.flag = ALTL_BIT; |
||
241 | k.scan = KEY_C; |
||
242 | k.ascii = 'c'; |
||
243 | keyb_hook(k,program_key_end); |
||
244 | |||
245 | srand(sys_gettime(NULL)); |
||
246 | |||
247 | // graphic card Initialization |
||
248 | if (grx_init() < 1) { |
||
1650 | pj | 249 | exit(1); |
1624 | giacomo | 250 | } |
251 | |||
252 | if (grx_open(800, 600, 16) < 0) { |
||
253 | cprintf("GRX Err\n"); |
||
1650 | pj | 254 | exit(1); |
1624 | giacomo | 255 | } |
256 | |||
257 | layout_screen(); |
||
258 | |||
259 | PI_mutexattr_default(a); |
||
260 | |||
261 | mutex_init(&mux,&a); |
||
262 | |||
263 | fsf_initialize_contract(&contract1); |
||
264 | fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
265 | fsf_initialize_contract(&contract2); |
||
266 | fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
267 | fsf_set_local_scheduler_parameter(&contract2, FSF_SCHEDULER_EDF); |
||
268 | |||
269 | err = fsf_negotiate_contract(&contract1,&server1); |
||
270 | if (err) cprintf("(FSF ERROR %d)",err); |
||
271 | err = fsf_negotiate_contract(&contract2,&server2); |
||
272 | if (err) cprintf("(FSF ERROR %d)",err); |
||
273 | |||
274 | ch = keyb_getch(BLOCK); |
||
275 | |||
276 | while(ch != ESC) { |
||
277 | |||
278 | switch (ch) { |
||
279 | |||
280 | case '1': |
||
281 | add_posixstar_thread(server1); |
||
282 | break; |
||
283 | case '2': |
||
284 | add_edfstar_thread(server2); |
||
285 | break; |
||
286 | case '3': |
||
287 | break; |
||
288 | case '4': |
||
289 | break; |
||
290 | case '5': |
||
291 | break; |
||
292 | } |
||
293 | |||
294 | ch = keyb_getch(BLOCK); |
||
295 | |||
296 | } |
||
297 | |||
1650 | pj | 298 | exit(1); |
1624 | giacomo | 299 | |
300 | return 0; |
||
301 | |||
302 | } |