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