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