Rev 681 | Rev 808 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
221 | giacomo | 1 | //===================================================================== |
2 | // FFFFFFIII RRRRR SSTTTTTTT |
||
3 | // FF IIR RR SS |
||
4 | // FF IR SS |
||
5 | // FFFFFF RRRR SSSSST |
||
6 | // FF FI RRR SS |
||
7 | // FF II RRR SS |
||
8 | // FF IIIIIR RS |
||
9 | // |
||
10 | // Basic FSF(FIRST Scheduling Framework) contract management |
||
11 | // S.Ha.R.K. Implementation |
||
12 | //===================================================================== |
||
13 | |||
405 | trimarchi | 14 | #include "ll/i386/64bit.h" |
679 | trimarchi | 15 | #include <kernel/kern.h> |
16 | #include <modules/sem.h> |
||
17 | #include <modules/hartport.h> |
||
18 | #include <modules/cabs.h> |
||
405 | trimarchi | 19 | |
221 | giacomo | 20 | #include "fsf_contract.h" |
241 | giacomo | 21 | #include "fsf_server.h" |
679 | trimarchi | 22 | #include "fsf_service_task.h" |
23 | #include "message.h" |
||
221 | giacomo | 24 | |
25 | #include <pthread.h> |
||
26 | #include <stdlib.h> |
||
27 | |||
679 | trimarchi | 28 | |
417 | giacomo | 29 | //#define FSF_DEBUG |
221 | giacomo | 30 | |
410 | trimarchi | 31 | int current_server=0; |
407 | giacomo | 32 | server_elem server_list[FSF_MAX_N_SERVERS]; |
406 | giacomo | 33 | bandwidth_t fsf_max_bw = 0; |
405 | trimarchi | 34 | |
241 | giacomo | 35 | int fsf_server_level; |
679 | trimarchi | 36 | PID server_task; |
221 | giacomo | 37 | |
679 | trimarchi | 38 | PORT channel[2]; |
39 | |||
406 | giacomo | 40 | int FSF_register_module(int server_level, bandwidth_t max_bw) |
224 | giacomo | 41 | { |
42 | printk("FSF Module\n"); |
||
410 | trimarchi | 43 | current_server=0; |
241 | giacomo | 44 | fsf_server_level = server_level; |
406 | giacomo | 45 | fsf_max_bw = max_bw; |
679 | trimarchi | 46 | |
224 | giacomo | 47 | return 0; |
48 | |||
49 | } |
||
50 | |||
679 | trimarchi | 51 | void FSF_start_service_task(SOFT_TASK_MODEL *model) { |
52 | |||
53 | // create the service task |
||
54 | // create the communication channel for negotiation and renegotiation |
||
55 | |||
56 | channel[1] = port_create("CHANW",sizeof(struct mess),1,STREAM,WRITE); |
||
57 | |||
58 | channel[0] = port_create("CHANR",sizeof(struct mess),1,STREAM,READ); |
||
59 | |||
60 | server_task = task_create("stask",service_task,model,NULL); |
||
61 | if (server_task == -1) { |
||
62 | cprintf("error creating service task\n"); |
||
63 | sys_shutdown_message("Could not create service_task"); |
||
64 | sys_end(); |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | task_activate(server_task); |
||
69 | |||
70 | } |
||
71 | |||
72 | |||
221 | giacomo | 73 | /* Convert the contract specification to |
74 | * budget parameters |
||
75 | */ |
||
241 | giacomo | 76 | int set_SERVER_budget_from_contract |
221 | giacomo | 77 | (const fsf_contract_parameters_t *contract, |
78 | int *budget) |
||
79 | { |
||
80 | |||
81 | int local_scheduler_level = 0; |
||
82 | |||
83 | switch (contract->local_scheduler_id) { |
||
84 | case FSF_SCHEDULER_POSIX: |
||
241 | giacomo | 85 | local_scheduler_level = POSIXSTAR_register_level(fsf_server_level,5000,32); |
221 | giacomo | 86 | break; |
87 | case FSF_SCHEDULER_EDF: |
||
241 | giacomo | 88 | local_scheduler_level = EDFSTAR_register_level(fsf_server_level); |
221 | giacomo | 89 | break; |
90 | case FSF_SCHEDULER_RM: |
||
241 | giacomo | 91 | local_scheduler_level = RMSTAR_register_level(fsf_server_level); |
221 | giacomo | 92 | break; |
334 | giacomo | 93 | case FSF_SCHEDULER_MPEG: |
94 | local_scheduler_level = MPEGSTAR_register_level(fsf_server_level); |
||
95 | break; |
||
221 | giacomo | 96 | } |
405 | trimarchi | 97 | |
661 | giacomo | 98 | if (contract->d_equals_t == TRUE) { |
241 | giacomo | 99 | *budget = SERVER_setbudget(fsf_server_level, |
221 | giacomo | 100 | TIMESPEC2USEC(&(contract->budget_min)), |
101 | TIMESPEC2USEC(&(contract->period_max)), |
||
661 | giacomo | 102 | TIMESPEC2USEC(&(contract->period_max)), |
221 | giacomo | 103 | local_scheduler_level,contract->local_scheduler_id); |
661 | giacomo | 104 | } else { |
105 | *budget = SERVER_setbudget(fsf_server_level, |
||
106 | TIMESPEC2USEC(&(contract->budget_min)), |
||
107 | TIMESPEC2USEC(&(contract->period_max)), |
||
108 | TIMESPEC2USEC(&(contract->deadline)), |
||
109 | local_scheduler_level,contract->local_scheduler_id); |
||
110 | } |
||
221 | giacomo | 111 | |
112 | return 0; |
||
113 | |||
114 | } |
||
115 | |||
405 | trimarchi | 116 | int adjust_SERVER_budget |
117 | (int budget, const TIME budget_actual, |
||
661 | giacomo | 118 | const TIME period_actual, const TIME dline_actual) |
221 | giacomo | 119 | { |
120 | |||
241 | giacomo | 121 | SERVER_adjust_budget(fsf_server_level, |
405 | trimarchi | 122 | budget_actual, |
123 | period_actual, |
||
661 | giacomo | 124 | dline_actual, |
241 | giacomo | 125 | budget); |
221 | giacomo | 126 | |
127 | return 0; |
||
128 | |||
129 | } |
||
130 | |||
131 | /* Admission Test function */ |
||
132 | int add_contract(const fsf_contract_parameters_t *contract) |
||
133 | { |
||
134 | return 0; |
||
135 | |||
136 | } |
||
137 | |||
687 | trimarchi | 138 | void contract_to_server(const fsf_contract_parameters_t *contract, int i) { |
139 | |||
410 | trimarchi | 140 | TIME T,Q; |
141 | #ifdef FSF_DEBUG |
||
142 | int temp; |
||
143 | #endif |
||
144 | |||
145 | T=TIMESPEC2USEC(&contract->period_min); |
||
146 | Q=TIMESPEC2USEC(&contract->budget_max); |
||
147 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umax); |
||
148 | |||
417 | giacomo | 149 | T=TIMESPEC2USEC(&contract->period_min); |
150 | server_list[i].Tmin=T; |
||
151 | |||
410 | trimarchi | 152 | T=TIMESPEC2USEC(&contract->period_max); |
153 | server_list[i].Tmax=T; |
||
417 | giacomo | 154 | |
410 | trimarchi | 155 | Q=TIMESPEC2USEC(&contract->budget_min); |
156 | server_list[i].Cmin=Q; |
||
157 | |||
158 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[i].Umin); |
||
416 | trimarchi | 159 | server_list[i].U=server_list[i].Umin; |
661 | giacomo | 160 | |
161 | if (contract->d_equals_t == TRUE) { |
||
162 | server_list[i].deadline = 0; |
||
163 | server_list[i].d_equals_t = TRUE; |
||
164 | } else { |
||
165 | server_list[i].deadline = TIMESPEC2USEC(&contract->deadline);; |
||
166 | server_list[i].d_equals_t = FALSE; |
||
167 | } |
||
168 | |||
410 | trimarchi | 169 | #ifdef FSF_DEBUG |
170 | mul32div32to32(server_list[i].Umax,100, MAX_BANDWIDTH, temp); |
||
171 | kern_printf("(Umax %d)",temp); |
||
172 | mul32div32to32(server_list[i].Umin,100, MAX_BANDWIDTH, temp); |
||
173 | kern_printf("(Umin %d)",temp); |
||
174 | #endif |
||
175 | |||
687 | trimarchi | 176 | } |
177 | |||
178 | int relink_contract_to_server(const fsf_contract_parameters_t *contract, |
||
179 | fsf_server_id_t server) |
||
180 | { |
||
181 | int i=0; |
||
182 | #ifdef FSF_DEBUG |
||
183 | kern_printf("(Relink Server %d)",server); |
||
184 | #endif |
||
185 | // find contract |
||
186 | while(i<current_server) { |
||
187 | if (server_list[i].server==server) break; |
||
188 | i++; |
||
189 | } |
||
190 | |||
191 | server_list[i].server=server; |
||
192 | server_list[i].Qs=1; |
||
193 | |||
194 | contract_to_server(contract, i); |
||
195 | |||
196 | |||
410 | trimarchi | 197 | return 0; |
198 | |||
199 | } |
||
200 | |||
221 | giacomo | 201 | int link_contract_to_server(const fsf_contract_parameters_t *contract, |
202 | fsf_server_id_t server) |
||
203 | { |
||
407 | giacomo | 204 | #ifdef FSF_DEBUG |
405 | trimarchi | 205 | kern_printf("(Link Server %d)",server); |
206 | #endif |
||
207 | |||
410 | trimarchi | 208 | server_list[current_server].server=server; |
209 | server_list[current_server].Qs=1; |
||
405 | trimarchi | 210 | |
687 | trimarchi | 211 | contract_to_server(contract,current_server); |
405 | trimarchi | 212 | |
410 | trimarchi | 213 | current_server++; |
221 | giacomo | 214 | return 0; |
215 | |||
216 | } |
||
217 | |||
218 | int remove_contract(fsf_server_id_t server) |
||
219 | { |
||
405 | trimarchi | 220 | int i=0; |
221 | // find the contract |
||
410 | trimarchi | 222 | while(i<current_server) { |
405 | trimarchi | 223 | if (server_list[i].server==server) break; |
224 | i++; |
||
225 | } |
||
221 | giacomo | 226 | |
405 | trimarchi | 227 | // compress the array; |
410 | trimarchi | 228 | while (i<(current_server-1)) { |
405 | trimarchi | 229 | server_list[i].server=server_list[i+1].server; |
230 | server_list[i].Umin=server_list[i+1].Umin; |
||
416 | trimarchi | 231 | server_list[i].U=server_list[i+1].Umin; |
405 | trimarchi | 232 | server_list[i].Umax=server_list[i+1].Umax; |
233 | server_list[i].Cmin=server_list[i+1].Cmin; |
||
417 | giacomo | 234 | server_list[i].Tmin=server_list[i+1].Tmin; |
405 | trimarchi | 235 | server_list[i].Tmax=server_list[i+1].Tmax; |
236 | server_list[i].Qs=server_list[i+1].Qs; |
||
661 | giacomo | 237 | server_list[i].deadline = server_list[i+1].deadline; |
238 | server_list[i].d_equals_t = server_list[i+1].d_equals_t; |
||
417 | giacomo | 239 | |
405 | trimarchi | 240 | i++; |
241 | } |
||
410 | trimarchi | 242 | current_server--; |
405 | trimarchi | 243 | |
244 | |||
221 | giacomo | 245 | return 0; |
246 | |||
247 | } |
||
248 | |||
249 | |||
250 | int fsf_negotiate_contract |
||
251 | (const fsf_contract_parameters_t *contract, |
||
252 | fsf_server_id_t *server) |
||
253 | { |
||
679 | trimarchi | 254 | struct mess message; |
221 | giacomo | 255 | |
679 | trimarchi | 256 | // send response server is -1 if the operation fail |
257 | message.type=NEGOTIATE_CONTRACT; |
||
258 | memmove(&message.contract,contract, sizeof(fsf_contract_parameters_t)); |
||
221 | giacomo | 259 | |
681 | trimarchi | 260 | port_send(channel[1],&message,BLOCK); |
679 | trimarchi | 261 | |
681 | trimarchi | 262 | port_receive(channel[0], &message, BLOCK); |
679 | trimarchi | 263 | |
264 | if (message.server==-1) |
||
265 | return FSF_ERR_CONTRACT_REJECTED; |
||
221 | giacomo | 266 | |
679 | trimarchi | 267 | *server=message.server; |
268 | |||
221 | giacomo | 269 | return 0; |
270 | |||
271 | } |
||
272 | |||
241 | giacomo | 273 | int fsf_create_thread |
274 | (fsf_server_id_t server, |
||
275 | pthread_t *thread, |
||
276 | pthread_attr_t *attr, |
||
277 | fsf_thread_code_t thread_code, |
||
278 | void *arg, |
||
279 | void *local_scheduler_arg) |
||
221 | giacomo | 280 | { |
281 | |||
282 | int local_scheduler_level,scheduler_id; |
||
283 | |||
284 | #ifdef FSF_DEBUG |
||
267 | giacomo | 285 | kern_printf("(FSF:Insert thread = %d to Server = %d)",*thread,server); |
221 | giacomo | 286 | #endif |
287 | |||
288 | /* Check if server and thread exsist */ |
||
241 | giacomo | 289 | if (server == NIL) |
290 | return FSF_ERR_INVALID_SERVER; |
||
221 | giacomo | 291 | |
241 | giacomo | 292 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
293 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
221 | giacomo | 294 | |
295 | /* Check if thread is already bind */ |
||
296 | switch (scheduler_id) { |
||
297 | case FSF_SCHEDULER_POSIX: |
||
298 | |||
298 | giacomo | 299 | nrt_task_def_arg(*(NRT_TASK_MODEL *)(local_scheduler_arg),arg); |
300 | nrt_task_def_level(*(NRT_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
221 | giacomo | 301 | |
298 | giacomo | 302 | *thread = task_create("POSIXSTAR", thread_code, local_scheduler_arg, NULL); |
267 | giacomo | 303 | if (*thread == NIL) { |
304 | #ifdef FSF_DEBUG |
||
305 | kern_printf("(FSF:Error creating thread)"); |
||
306 | #endif |
||
241 | giacomo | 307 | return FSF_ERR_CREATE_THREAD; |
267 | giacomo | 308 | } |
221 | giacomo | 309 | |
241 | giacomo | 310 | POSIXSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
234 | giacomo | 311 | |
221 | giacomo | 312 | break; |
313 | case FSF_SCHEDULER_EDF: |
||
314 | |||
250 | giacomo | 315 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
316 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
317 | |||
318 | *thread = task_create("EDFSTAR", thread_code, local_scheduler_arg, NULL); |
||
319 | if (*thread == NIL) |
||
320 | return FSF_ERR_CREATE_THREAD; |
||
321 | |||
322 | EDFSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
323 | |||
221 | giacomo | 324 | break; |
235 | giacomo | 325 | |
221 | giacomo | 326 | case FSF_SCHEDULER_RM: |
235 | giacomo | 327 | |
273 | giacomo | 328 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
329 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
330 | |||
331 | *thread = task_create("RMSTAR", thread_code, local_scheduler_arg, NULL); |
||
332 | if (*thread == NIL) |
||
333 | return FSF_ERR_CREATE_THREAD; |
||
334 | |||
335 | RMSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
336 | |||
337 | break; |
||
334 | giacomo | 338 | case FSF_SCHEDULER_MPEG: |
339 | |||
340 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
||
341 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
342 | |||
338 | giacomo | 343 | *thread = task_create("MPEGSTAR", thread_code, local_scheduler_arg, NULL); |
334 | giacomo | 344 | if (*thread == NIL) |
345 | return FSF_ERR_CREATE_THREAD; |
||
346 | |||
347 | MPEGSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
348 | |||
349 | break; |
||
350 | |||
221 | giacomo | 351 | default: |
241 | giacomo | 352 | return FSF_ERR_INVALID_SERVER; |
221 | giacomo | 353 | break; |
354 | } |
||
355 | |||
356 | return 0; |
||
357 | |||
358 | } |
||
359 | |||
360 | int fsf_get_server |
||
361 | (fsf_server_id_t *server, |
||
362 | pthread_t thread) |
||
363 | { |
||
364 | int local_scheduler_level, scheduler_id; |
||
365 | |||
241 | giacomo | 366 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
367 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
221 | giacomo | 368 | |
369 | switch (scheduler_id) { |
||
370 | case FSF_SCHEDULER_POSIX: |
||
371 | return POSIXSTAR_getbudget(local_scheduler_level,thread); |
||
372 | case FSF_SCHEDULER_EDF: |
||
235 | giacomo | 373 | return EDFSTAR_getbudget(local_scheduler_level,thread); |
221 | giacomo | 374 | case FSF_SCHEDULER_RM: |
235 | giacomo | 375 | return RMSTAR_getbudget(local_scheduler_level,thread); |
334 | giacomo | 376 | case FSF_SCHEDULER_MPEG: |
377 | return MPEGSTAR_getbudget(local_scheduler_level,thread); |
||
235 | giacomo | 378 | default: |
221 | giacomo | 379 | return -1; |
380 | } |
||
381 | |||
382 | return -1; |
||
383 | |||
384 | } |
||
385 | |||
339 | giacomo | 386 | int fsf_get_server_level(void) |
387 | { |
||
388 | |||
389 | return fsf_server_level; |
||
390 | |||
391 | } |
||
392 | |||
221 | giacomo | 393 | int fsf_cancel_contract |
394 | (fsf_server_id_t *server) |
||
395 | { |
||
396 | |||
397 | int local_scheduler_level, scheduler_id; |
||
411 | trimarchi | 398 | SYS_FLAGS f; |
399 | TIME T,Q; |
||
400 | int i=0; |
||
221 | giacomo | 401 | |
402 | #ifdef FSF_DEBUG |
||
403 | kern_printf("(Remove server %d)",*server); |
||
404 | #endif |
||
405 | |||
406 | /* Check server id */ |
||
407 | if (*server < 0) |
||
408 | return FSF_ERR_INVALID_SERVER; |
||
409 | |||
241 | giacomo | 410 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,*server); |
411 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,*server); |
||
221 | giacomo | 412 | |
413 | switch (scheduler_id) { |
||
414 | case FSF_SCHEDULER_POSIX: |
||
415 | |||
416 | /* Check if some thread use the server */ |
||
417 | if(POSIXSTAR_budget_has_thread(local_scheduler_level,*server)) |
||
418 | return FSF_ERR_SERVER_USED; |
||
419 | |||
420 | break; |
||
421 | case FSF_SCHEDULER_EDF: |
||
235 | giacomo | 422 | /* Check if some thread use the server */ |
423 | if(EDFSTAR_budget_has_thread(local_scheduler_level,*server)) |
||
424 | return FSF_ERR_SERVER_USED; |
||
425 | break; |
||
426 | |||
221 | giacomo | 427 | case FSF_SCHEDULER_RM: |
235 | giacomo | 428 | /* Check if some thread use the server */ |
429 | if(RMSTAR_budget_has_thread(local_scheduler_level,*server)) |
||
430 | return FSF_ERR_SERVER_USED; |
||
431 | |||
221 | giacomo | 432 | break; |
334 | giacomo | 433 | |
434 | case FSF_SCHEDULER_MPEG: |
||
435 | /* Check if some thread use the server */ |
||
436 | if(MPEGSTAR_budget_has_thread(local_scheduler_level,*server)) |
||
437 | return FSF_ERR_SERVER_USED; |
||
438 | |||
439 | break; |
||
440 | |||
221 | giacomo | 441 | } |
442 | |||
241 | giacomo | 443 | SERVER_removebudget(fsf_server_level,*server); |
221 | giacomo | 444 | |
445 | level_free_descriptor(local_scheduler_level); |
||
405 | trimarchi | 446 | |
221 | giacomo | 447 | remove_contract(*server); |
411 | trimarchi | 448 | |
449 | f=kern_fsave(); |
||
450 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
451 | kern_frestore(f); |
||
452 | return FSF_ERR_CREATE_SERVER; |
||
453 | } |
||
454 | #ifdef FSF_DEBUG |
||
455 | kern_printf("(Adjust budget)"); |
||
456 | #endif |
||
457 | for (i=0; i<current_server; i++) { |
||
458 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
417 | giacomo | 459 | if (T > server_list[i].Tmin ) { |
411 | trimarchi | 460 | server_list[i].actual_budget = server_list[i].Cmin; |
461 | server_list[i].actual_period = T; |
||
417 | giacomo | 462 | #ifdef FSF_DEBUG |
463 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
464 | #endif |
||
661 | giacomo | 465 | |
466 | if (server_list[i].d_equals_t == TRUE) |
||
467 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
468 | else |
||
469 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
470 | |||
411 | trimarchi | 471 | } else { |
417 | giacomo | 472 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
411 | trimarchi | 473 | server_list[i].actual_budget = Q; |
417 | giacomo | 474 | server_list[i].actual_period = server_list[i].Tmin; |
475 | #ifdef FSF_DEBUG |
||
476 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
477 | #endif |
||
661 | giacomo | 478 | |
479 | if (server_list[i].d_equals_t == TRUE) |
||
480 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].Tmin); |
||
481 | else |
||
482 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].deadline); |
||
483 | |||
411 | trimarchi | 484 | } |
416 | trimarchi | 485 | server_list[i].U=server_list[i].Umin; |
411 | trimarchi | 486 | |
487 | } |
||
221 | giacomo | 488 | |
405 | trimarchi | 489 | |
221 | giacomo | 490 | *server = -1; |
411 | trimarchi | 491 | kern_frestore(f); |
221 | giacomo | 492 | |
493 | return 0; |
||
411 | trimarchi | 494 | |
221 | giacomo | 495 | } |
496 | |||
405 | trimarchi | 497 | int recalculate_contract(bandwidth_t U) { |
416 | trimarchi | 498 | bandwidth_t current_bandwidth; |
418 | giacomo | 499 | unsigned int temp_U; |
416 | trimarchi | 500 | int Qt; |
405 | trimarchi | 501 | int isok=0; |
502 | int i=0; |
||
503 | |||
407 | giacomo | 504 | #ifdef FSF_DEBUG |
505 | int temp; |
||
506 | |||
507 | kern_printf("(Recalculate contract)"); |
||
508 | #endif |
||
405 | trimarchi | 509 | |
510 | /* The current bandwidth is the min bandwidth */ |
||
511 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
512 | #ifdef FSF_DEBUG |
||
410 | trimarchi | 513 | kern_printf("(nserver %d)", current_server); |
405 | trimarchi | 514 | #endif |
515 | |||
516 | do { |
||
517 | current_bandwidth=0; |
||
518 | Qt=0; |
||
410 | trimarchi | 519 | for (i=0; i<current_server; i++) { |
416 | trimarchi | 520 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) |
405 | trimarchi | 521 | Qt+=server_list[i].Qs; |
416 | trimarchi | 522 | current_bandwidth+=server_list[i].U; |
405 | trimarchi | 523 | } |
413 | trimarchi | 524 | |
405 | trimarchi | 525 | #ifdef FSF_DEBUG |
526 | kern_printf("(Total Quality %d)", Qt); |
||
527 | #endif |
||
528 | isok=1; |
||
410 | trimarchi | 529 | for (i=0; i<current_server; i++) { |
416 | trimarchi | 530 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) { |
531 | temp_U=server_list[i].U; |
||
532 | server_list[i].U=U-current_bandwidth; |
||
533 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
534 | temp_U+=server_list[i].U; |
||
535 | |||
536 | if (temp_U<=server_list[i].Umin) { |
||
405 | trimarchi | 537 | server_list[i].U=server_list[i].Umin; |
416 | trimarchi | 538 | } else if (temp_U>server_list[i].Umax) { |
539 | server_list[i].U=server_list[i].Umax; |
||
405 | trimarchi | 540 | isok=0; |
541 | } else server_list[i].U=temp_U; |
||
542 | |||
543 | #ifdef FSF_DEBUG |
||
544 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
545 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
546 | #endif |
||
547 | } |
||
548 | } |
||
549 | |||
550 | } while (!isok); |
||
551 | |||
552 | return 0; |
||
553 | } |
||
554 | |||
221 | giacomo | 555 | int fsf_renegotiate_contract |
556 | (const fsf_contract_parameters_t *new_contract, |
||
557 | fsf_server_id_t server) |
||
558 | { |
||
679 | trimarchi | 559 | |
560 | struct mess message; |
||
221 | giacomo | 561 | |
679 | trimarchi | 562 | // send response server is -1 if the operation fail |
563 | message.type=RENEGOTIATE_CONTRACT; |
||
564 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
565 | message.server = server; |
||
221 | giacomo | 566 | |
679 | trimarchi | 567 | //port_send(channel,&message,BLOCK); |
568 | |||
569 | //port_receive(channel, &message, BLOCK); |
||
570 | |||
571 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
||
572 | |||
405 | trimarchi | 573 | return 0; |
221 | giacomo | 574 | } |
241 | giacomo | 575 | |
407 | giacomo | 576 | void print_server_list() |
577 | { |
||
578 | |||
579 | int i; |
||
580 | |||
581 | kern_printf("Server List\n"); |
||
582 | |||
410 | trimarchi | 583 | for(i=0;i<current_server;i++) { |
407 | giacomo | 584 | |
662 | giacomo | 585 | kern_printf("[%d] Q:%d T:%d D:%d [DeT = %d]\n",server_list[i].server,(int)server_list[i].actual_budget,(int)server_list[i].actual_period,(int)server_list[i].deadline,(int)server_list[i].d_equals_t); |
407 | giacomo | 586 | |
587 | } |
||
588 | |||
589 | } |