Rev 1550 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1541 | trimarchi | 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 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2002 Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | */ |
||
37 | |||
38 | #include "kernel/kern.h" |
||
39 | |||
1556 | trimarchi | 40 | #include "edf/edf/edf.h" |
41 | #include "cbs/cbs/cbs.h" |
||
1541 | trimarchi | 42 | |
43 | #include "pthread.h" |
||
1556 | trimarchi | 44 | #include "posix/posix/posix.h" |
1541 | trimarchi | 45 | |
1556 | trimarchi | 46 | #include "fsf.h" |
1541 | trimarchi | 47 | #include "fsf_server.h" |
48 | |||
1556 | trimarchi | 49 | #include "dummy/dummy/dummy.h" |
1541 | trimarchi | 50 | |
1556 | trimarchi | 51 | #include "sem/sem/sem.h" |
52 | #include "pi/pi/pi.h" |
||
53 | #include "pc/pc/pc.h" |
||
1541 | trimarchi | 54 | |
1556 | trimarchi | 55 | #include "hartport/hartport/hartport.h" |
56 | #include "cabs/cabs/cabs.h" |
||
1541 | trimarchi | 57 | |
58 | #include "drivers/keyb.h" |
||
59 | #include <stdlib.h> |
||
60 | // -------------------------------------------------- |
||
61 | // -------------------------------------------------- |
||
62 | // Init Part |
||
63 | // -------------------------------------------------- |
||
64 | // -------------------------------------------------- |
||
65 | |||
66 | /*+ sysyem tick in us +*/ |
||
67 | #define TICK 0 |
||
68 | |||
69 | /*+ RR tick in us +*/ |
||
70 | #define RRTICK 10000 |
||
71 | |||
72 | int grubstar_level; |
||
73 | int posix_level; |
||
74 | |||
75 | |||
76 | //fsf_shared_object_t obj; |
||
77 | //fsf_shared_operation_t op; |
||
78 | |||
79 | TIME __kernel_register_levels__(void *arg) |
||
80 | { |
||
81 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
82 | |||
83 | EDF_register_level(EDF_ENABLE_ALL); |
||
84 | posix_level=POSIX_register_level(RRTICK, 1, mb, 32); |
||
85 | grubstar_level = GRUBSTAR_register_level(5, 0); |
||
86 | FSF_register_module(posix_level,grubstar_level, (int)(MAX_BANDWIDTH * 0.9)); |
||
87 | dummy_register_level(); |
||
88 | |||
89 | // for the keyboard... |
||
90 | CBS_register_level(CBS_ENABLE_ALL, 0); |
||
91 | |||
92 | PI_register_module(); |
||
93 | PC_register_module(); |
||
94 | |||
95 | SEM_register_module(); |
||
96 | |||
97 | PTHREAD_register_module(1, 0, 1); |
||
98 | |||
99 | return TICK; |
||
100 | } |
||
101 | |||
102 | |||
103 | TASK __init__(void *arg) |
||
104 | { |
||
105 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
106 | |||
107 | HARTPORT_init(); |
||
108 | |||
109 | KEYB_init(NULL); |
||
110 | |||
111 | __call_main__(mb); |
||
112 | |||
113 | return (void *)0; |
||
114 | |||
115 | } |
||
116 | |||
117 | // -------------------------------------------------- |
||
118 | // -------------------------------------------------- |
||
119 | // The Test |
||
120 | // -------------------------------------------------- |
||
121 | // -------------------------------------------------- |
||
122 | |||
123 | pthread_t jposix = -1; |
||
124 | pthread_t j1 = -1; |
||
125 | pthread_t j2 = -1; |
||
126 | fsf_server_id_t server1 = -1; |
||
127 | fsf_server_id_t server2 = -1; |
||
128 | fsf_contract_parameters_t contract; |
||
129 | |||
130 | void *star(void *arg) |
||
131 | { |
||
132 | struct timespec actual,end; |
||
133 | int actpersecond,act; |
||
134 | int cycle,rec; |
||
135 | |||
136 | act = 0; |
||
137 | actpersecond = 0; |
||
138 | cycle = 0; |
||
139 | rec = 0; |
||
140 | for (;;) { |
||
141 | |||
142 | cycle++; |
||
143 | kern_gettime(&actual); |
||
144 | rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow); |
||
145 | |||
146 | if (act == 0) { |
||
147 | TIMESPEC_ASSIGN(&end,&actual); |
||
148 | end.tv_sec++; |
||
149 | } |
||
150 | |||
151 | if (TIMESPEC_A_LT_B(&actual,&end)) { |
||
152 | act++; |
||
153 | } else { |
||
154 | actpersecond = act; |
||
155 | act = 0; |
||
156 | } |
||
157 | |||
158 | //pthread_mutex_lock(&mux); |
||
159 | printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d", |
||
160 | exec_shadow,actpersecond,cycle,rec); |
||
161 | //pthread_mutex_unlock(&mux); |
||
162 | |||
163 | } |
||
164 | |||
165 | return NULL; |
||
166 | |||
167 | } |
||
168 | |||
169 | void *periodic_star(void *arg) |
||
170 | { |
||
171 | struct timespec actual,end; |
||
172 | int actpersecond,act; |
||
173 | int cycle,rec; |
||
174 | |||
175 | act = 0; |
||
176 | actpersecond = 0; |
||
177 | cycle = 0; |
||
178 | rec = 0; |
||
179 | for (;;) { |
||
180 | |||
181 | cycle++; |
||
182 | kern_gettime(&actual); |
||
183 | rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow); |
||
184 | |||
185 | if (act == 0) { |
||
186 | TIMESPEC_ASSIGN(&end,&actual); |
||
187 | end.tv_sec++; |
||
188 | } |
||
189 | |||
190 | if (TIMESPEC_A_LT_B(&actual,&end)) { |
||
191 | act++; |
||
192 | } else { |
||
193 | actpersecond = act; |
||
194 | act = 0; |
||
195 | } |
||
196 | |||
197 | //fsf_lock_object(&op); |
||
198 | printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d", |
||
199 | exec_shadow,actpersecond,cycle,rec); |
||
200 | //fsf_unlock_object(&op); |
||
201 | |||
202 | task_endcycle(); |
||
203 | |||
204 | } |
||
205 | |||
206 | return NULL; |
||
207 | |||
208 | } |
||
209 | |||
210 | int keyinc = 5; |
||
211 | |||
212 | void *edftask(void *arg) |
||
213 | { |
||
214 | long long j; |
||
215 | while(1) { |
||
216 | for (j=0; j<10000*keyinc; j++); |
||
217 | task_endcycle(); |
||
218 | } |
||
219 | |||
220 | return NULL; |
||
221 | } |
||
222 | |||
223 | |||
224 | void create() |
||
225 | { |
||
226 | struct timespec period1 = {0,90000000}; //30% |
||
227 | struct timespec period2 = {0,75000000}; //80% |
||
228 | struct timespec budget1 = {0,30000000}; |
||
229 | struct timespec budget2 = {0,60000000}; |
||
230 | |||
231 | FSF_start_service_task(); |
||
232 | |||
233 | |||
234 | kern_printf("(Start Create)"); |
||
235 | |||
236 | fsf_initialize_contract(&contract); |
||
237 | |||
238 | fsf_set_contract_basic_parameters(&contract,&budget1,&period1,FSF_DEFAULT_WORKLOAD); |
||
239 | fsf_set_contract_scheduling_policy(&contract, FSF_EDF); |
||
240 | fsf_set_contract_reclamation_parameters(&contract,&budget2, &period2, FSF_DEFAULT_GRANULARITY, NULL, 1, 0); |
||
241 | fsf_negotiate_contract(&contract,&server1); |
||
242 | |||
243 | |||
244 | fsf_set_contract_basic_parameters(&contract,&budget1,&period1,FSF_DEFAULT_WORKLOAD); |
||
245 | fsf_set_contract_scheduling_policy(&contract, FSF_EDF); |
||
246 | fsf_set_contract_reclamation_parameters(&contract,&budget2, &period2,FSF_DEFAULT_GRANULARITY, NULL, 1, 1); |
||
247 | |||
248 | fsf_negotiate_contract(&contract,&server2); |
||
249 | |||
250 | kern_printf("(End Create)"); |
||
251 | |||
252 | |||
253 | } |
||
254 | |||
255 | void renegotiate(void) { |
||
256 | struct timespec period2 = {0,75000000}; |
||
257 | struct timespec budget2 = {0,60000000}; |
||
258 | struct timespec budget1 = {0,60000000}; |
||
259 | union sigval sval; |
||
260 | for (;;) { |
||
261 | fsf_set_contract_basic_parameters(&contract,&budget2,&period2,FSF_DEFAULT_WORKLOAD); |
||
262 | fsf_set_contract_reclamation_parameters(&contract,&budget1, &period2,FSF_DEFAULT_GRANULARITY, NULL, 20, 0); |
||
263 | |||
264 | //fsf_request_contract_renegotiation(&contract,server2, 0, sval); |
||
265 | |||
266 | fsf_renegotiate_contract(&contract, server2); |
||
267 | budget2.tv_nsec -=60000; |
||
268 | |||
269 | task_endcycle(); |
||
270 | } |
||
271 | |||
272 | } |
||
273 | |||
274 | |||
275 | int main(int argc, char **argv) |
||
276 | { |
||
277 | |||
278 | int err; |
||
279 | HARD_TASK_MODEL ht; |
||
280 | struct timespec endtimer; |
||
281 | |||
282 | //fsf_init_shared_object(&obj,1); |
||
283 | |||
284 | //op.op_id=1; |
||
285 | //op.wcet.tv_sec=0; |
||
286 | //op.wcet.tv_nsec=100000; |
||
287 | //fsf_declare_shared_object_operation(&obj, &op); |
||
288 | |||
289 | srand(kern_gettime(NULL)); |
||
290 | create(); |
||
291 | |||
292 | kern_gettime(&endtimer); |
||
293 | endtimer.tv_sec += 20; |
||
1550 | pj | 294 | kern_event_post(&endtimer, (void (*)(void *))(exit), NULL); |
1541 | trimarchi | 295 | |
296 | hard_task_default_model(ht); |
||
297 | hard_task_def_mit(ht,200000); |
||
298 | hard_task_def_wcet(ht,5000); |
||
299 | err = fsf_create_thread(server1,&j1,NULL,periodic_star,NULL,&ht); |
||
300 | kern_printf("(%d)",err); |
||
301 | task_activate(j1); |
||
302 | |||
303 | hard_task_default_model(ht); |
||
304 | hard_task_def_mit(ht,1000000); |
||
305 | hard_task_def_wcet(ht,50000); |
||
306 | err = fsf_create_thread(server1,&j1,NULL,renegotiate,NULL,&ht); |
||
307 | kern_printf("(%d)",err); |
||
308 | task_activate(j1); |
||
309 | |||
310 | hard_task_default_model(ht); |
||
311 | hard_task_def_mit(ht,159000); |
||
312 | hard_task_def_wcet(ht,5000); |
||
313 | err = fsf_create_thread(server2,&j2,NULL,periodic_star,NULL,&ht); |
||
314 | kern_printf("(%d)",err); |
||
315 | task_activate(j2); |
||
316 | |||
317 | hard_task_default_model(ht); |
||
318 | hard_task_def_mit(ht,159000); |
||
319 | hard_task_def_wcet(ht,5000); |
||
320 | err = fsf_create_thread(server2,&j2,NULL,periodic_star,NULL,&ht); |
||
321 | kern_printf("(%d)",err); |
||
322 | task_activate(j2); |
||
323 | |||
324 | return 0; |
||
325 | |||
326 | } |
||
327 |