Rev 873 | Rev 879 | 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 | |
868 | trimarchi | 20 | #include "fsf_basic_types.h" |
21 | #include "fsf_configuration_parameters.h" |
||
22 | #include "fsf_core.h" |
||
241 | giacomo | 23 | #include "fsf_server.h" |
679 | trimarchi | 24 | #include "fsf_service_task.h" |
868 | trimarchi | 25 | #include "fsf_hierarchical.h" |
679 | trimarchi | 26 | #include "message.h" |
221 | giacomo | 27 | |
868 | trimarchi | 28 | #include "posixstar.h" |
29 | #include "edfstar.h" |
||
30 | #include "nonestar.h" |
||
31 | #include "rmstar.h" |
||
32 | |||
221 | giacomo | 33 | #include <pthread.h> |
34 | #include <stdlib.h> |
||
808 | trimarchi | 35 | #include "pistar.h" |
868 | trimarchi | 36 | #include <modules/comm_message.h> |
221 | giacomo | 37 | |
417 | giacomo | 38 | //#define FSF_DEBUG |
221 | giacomo | 39 | |
410 | trimarchi | 40 | int current_server=0; |
407 | giacomo | 41 | server_elem server_list[FSF_MAX_N_SERVERS]; |
406 | giacomo | 42 | bandwidth_t fsf_max_bw = 0; |
405 | trimarchi | 43 | |
241 | giacomo | 44 | int fsf_server_level; |
868 | trimarchi | 45 | int fsf_posix_level = -1; |
808 | trimarchi | 46 | int shared_object_level; |
679 | trimarchi | 47 | PID server_task; |
868 | trimarchi | 48 | fsf_contract_parameters_t contract; |
221 | giacomo | 49 | |
868 | trimarchi | 50 | |
679 | trimarchi | 51 | PORT channel[2]; |
52 | |||
868 | trimarchi | 53 | fsf_server_id_t service_server = -1; |
54 | fsf_contract_parameters_t service_contract; |
||
55 | |||
808 | trimarchi | 56 | int FSF_register_shared_object_module(void) { |
811 | trimarchi | 57 | fsf_register_shared_object(); |
808 | trimarchi | 58 | return PISTAR_register_module(); |
59 | } |
||
60 | |||
61 | |||
810 | trimarchi | 62 | int FSF_get_shared_object_level() { |
63 | return shared_object_level; |
||
64 | } |
||
65 | |||
868 | trimarchi | 66 | int FSF_register_module(int posix_level, int server_level, bandwidth_t max_bw) |
224 | giacomo | 67 | { |
68 | printk("FSF Module\n"); |
||
410 | trimarchi | 69 | current_server=0; |
241 | giacomo | 70 | fsf_server_level = server_level; |
868 | trimarchi | 71 | fsf_posix_level = posix_level; |
406 | giacomo | 72 | fsf_max_bw = max_bw; |
811 | trimarchi | 73 | shared_object_level = FSF_register_shared_object_module(); |
679 | trimarchi | 74 | |
224 | giacomo | 75 | return 0; |
76 | |||
77 | } |
||
78 | |||
868 | trimarchi | 79 | void FSF_start_service_task(void) { |
679 | trimarchi | 80 | |
868 | trimarchi | 81 | int err; |
82 | struct timespec default_period = {0,50000000}; |
||
83 | struct timespec default_budget = {0,1000000}; |
||
84 | DUMMY_TASK_MODEL m; |
||
85 | |||
86 | dummy_task_default_model(m); |
||
87 | |||
679 | trimarchi | 88 | // create the service task |
89 | // create the communication channel for negotiation and renegotiation |
||
90 | |||
91 | channel[1] = port_create("CHANW",sizeof(struct mess),1,STREAM,WRITE); |
||
92 | |||
93 | channel[0] = port_create("CHANR",sizeof(struct mess),1,STREAM,READ); |
||
94 | |||
868 | trimarchi | 95 | fsf_initialize_contract(&service_contract); |
96 | |||
97 | fsf_set_contract_basic_parameters(&service_contract,&default_budget,&default_period,FSF_DEFAULT_WORKLOAD); |
||
98 | negotiate_contract(&service_contract,&service_server); |
||
99 | |||
100 | //server_task = task_create("stask",service_task,model,NULL); |
||
101 | err = fsf_create_thread(service_server,&server_task,NULL,service_task,NULL,&m); |
||
102 | if (err) { |
||
679 | trimarchi | 103 | cprintf("error creating service task\n"); |
104 | sys_shutdown_message("Could not create service_task"); |
||
105 | sys_end(); |
||
106 | return; |
||
107 | } |
||
108 | |||
109 | task_activate(server_task); |
||
110 | |||
111 | } |
||
112 | |||
113 | |||
221 | giacomo | 114 | /* Convert the contract specification to |
115 | * budget parameters |
||
116 | */ |
||
241 | giacomo | 117 | int set_SERVER_budget_from_contract |
221 | giacomo | 118 | (const fsf_contract_parameters_t *contract, |
119 | int *budget) |
||
120 | { |
||
121 | |||
122 | int local_scheduler_level = 0; |
||
123 | |||
868 | trimarchi | 124 | switch (contract->policy) { |
125 | case FSF_POSIX: |
||
241 | giacomo | 126 | local_scheduler_level = POSIXSTAR_register_level(fsf_server_level,5000,32); |
221 | giacomo | 127 | break; |
868 | trimarchi | 128 | case FSF_EDF: |
241 | giacomo | 129 | local_scheduler_level = EDFSTAR_register_level(fsf_server_level); |
221 | giacomo | 130 | break; |
868 | trimarchi | 131 | case FSF_RM: |
241 | giacomo | 132 | local_scheduler_level = RMSTAR_register_level(fsf_server_level); |
221 | giacomo | 133 | break; |
868 | trimarchi | 134 | case FSF_NONE: |
855 | trimarchi | 135 | local_scheduler_level = NONESTAR_register_level(fsf_server_level); |
334 | giacomo | 136 | break; |
221 | giacomo | 137 | } |
405 | trimarchi | 138 | |
661 | giacomo | 139 | if (contract->d_equals_t == TRUE) { |
241 | giacomo | 140 | *budget = SERVER_setbudget(fsf_server_level, |
221 | giacomo | 141 | TIMESPEC2USEC(&(contract->budget_min)), |
142 | TIMESPEC2USEC(&(contract->period_max)), |
||
661 | giacomo | 143 | TIMESPEC2USEC(&(contract->period_max)), |
868 | trimarchi | 144 | local_scheduler_level,contract->policy); |
661 | giacomo | 145 | } else { |
146 | *budget = SERVER_setbudget(fsf_server_level, |
||
147 | TIMESPEC2USEC(&(contract->budget_min)), |
||
148 | TIMESPEC2USEC(&(contract->period_max)), |
||
149 | TIMESPEC2USEC(&(contract->deadline)), |
||
868 | trimarchi | 150 | local_scheduler_level,contract->policy); |
661 | giacomo | 151 | } |
221 | giacomo | 152 | |
153 | return 0; |
||
154 | |||
155 | } |
||
156 | |||
405 | trimarchi | 157 | int adjust_SERVER_budget |
158 | (int budget, const TIME budget_actual, |
||
661 | giacomo | 159 | const TIME period_actual, const TIME dline_actual) |
221 | giacomo | 160 | { |
161 | |||
241 | giacomo | 162 | SERVER_adjust_budget(fsf_server_level, |
405 | trimarchi | 163 | budget_actual, |
164 | period_actual, |
||
661 | giacomo | 165 | dline_actual, |
241 | giacomo | 166 | budget); |
221 | giacomo | 167 | |
168 | return 0; |
||
169 | |||
170 | } |
||
171 | |||
172 | /* Admission Test function */ |
||
173 | int add_contract(const fsf_contract_parameters_t *contract) |
||
174 | { |
||
175 | return 0; |
||
176 | |||
177 | } |
||
178 | |||
687 | trimarchi | 179 | void contract_to_server(const fsf_contract_parameters_t *contract, int i) { |
180 | |||
410 | trimarchi | 181 | TIME T,Q; |
182 | #ifdef FSF_DEBUG |
||
183 | int temp; |
||
184 | #endif |
||
185 | |||
186 | T=TIMESPEC2USEC(&contract->period_min); |
||
187 | Q=TIMESPEC2USEC(&contract->budget_max); |
||
188 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umax); |
||
189 | |||
417 | giacomo | 190 | T=TIMESPEC2USEC(&contract->period_min); |
191 | server_list[i].Tmin=T; |
||
192 | |||
410 | trimarchi | 193 | T=TIMESPEC2USEC(&contract->period_max); |
194 | server_list[i].Tmax=T; |
||
417 | giacomo | 195 | |
410 | trimarchi | 196 | Q=TIMESPEC2USEC(&contract->budget_min); |
197 | server_list[i].Cmin=Q; |
||
198 | |||
199 | mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[i].Umin); |
||
416 | trimarchi | 200 | server_list[i].U=server_list[i].Umin; |
661 | giacomo | 201 | |
202 | if (contract->d_equals_t == TRUE) { |
||
203 | server_list[i].deadline = 0; |
||
204 | server_list[i].d_equals_t = TRUE; |
||
205 | } else { |
||
206 | server_list[i].deadline = TIMESPEC2USEC(&contract->deadline);; |
||
207 | server_list[i].d_equals_t = FALSE; |
||
208 | } |
||
209 | |||
843 | trimarchi | 210 | server_list[i].Qs = contract->quality; |
211 | server_list[i].Is = contract->importance; |
||
212 | |||
410 | trimarchi | 213 | #ifdef FSF_DEBUG |
214 | mul32div32to32(server_list[i].Umax,100, MAX_BANDWIDTH, temp); |
||
215 | kern_printf("(Umax %d)",temp); |
||
216 | mul32div32to32(server_list[i].Umin,100, MAX_BANDWIDTH, temp); |
||
217 | kern_printf("(Umin %d)",temp); |
||
218 | #endif |
||
219 | |||
687 | trimarchi | 220 | } |
221 | |||
222 | int relink_contract_to_server(const fsf_contract_parameters_t *contract, |
||
223 | fsf_server_id_t server) |
||
224 | { |
||
225 | int i=0; |
||
226 | #ifdef FSF_DEBUG |
||
227 | kern_printf("(Relink Server %d)",server); |
||
228 | #endif |
||
229 | // find contract |
||
230 | while(i<current_server) { |
||
231 | if (server_list[i].server==server) break; |
||
232 | i++; |
||
233 | } |
||
234 | |||
235 | server_list[i].server=server; |
||
843 | trimarchi | 236 | // server_list[i].Qs=1; |
687 | trimarchi | 237 | |
238 | contract_to_server(contract, i); |
||
239 | |||
240 | |||
410 | trimarchi | 241 | return 0; |
242 | |||
243 | } |
||
244 | |||
221 | giacomo | 245 | int link_contract_to_server(const fsf_contract_parameters_t *contract, |
246 | fsf_server_id_t server) |
||
247 | { |
||
407 | giacomo | 248 | #ifdef FSF_DEBUG |
405 | trimarchi | 249 | kern_printf("(Link Server %d)",server); |
250 | #endif |
||
251 | |||
410 | trimarchi | 252 | server_list[current_server].server=server; |
843 | trimarchi | 253 | //server_list[current_server].Qs=1; |
405 | trimarchi | 254 | |
687 | trimarchi | 255 | contract_to_server(contract,current_server); |
405 | trimarchi | 256 | |
410 | trimarchi | 257 | current_server++; |
221 | giacomo | 258 | return 0; |
259 | |||
260 | } |
||
261 | |||
262 | int remove_contract(fsf_server_id_t server) |
||
263 | { |
||
405 | trimarchi | 264 | int i=0; |
265 | // find the contract |
||
410 | trimarchi | 266 | while(i<current_server) { |
405 | trimarchi | 267 | if (server_list[i].server==server) break; |
268 | i++; |
||
269 | } |
||
221 | giacomo | 270 | |
405 | trimarchi | 271 | // compress the array; |
410 | trimarchi | 272 | while (i<(current_server-1)) { |
405 | trimarchi | 273 | server_list[i].server=server_list[i+1].server; |
274 | server_list[i].Umin=server_list[i+1].Umin; |
||
416 | trimarchi | 275 | server_list[i].U=server_list[i+1].Umin; |
405 | trimarchi | 276 | server_list[i].Umax=server_list[i+1].Umax; |
277 | server_list[i].Cmin=server_list[i+1].Cmin; |
||
417 | giacomo | 278 | server_list[i].Tmin=server_list[i+1].Tmin; |
405 | trimarchi | 279 | server_list[i].Tmax=server_list[i+1].Tmax; |
280 | server_list[i].Qs=server_list[i+1].Qs; |
||
661 | giacomo | 281 | server_list[i].deadline = server_list[i+1].deadline; |
282 | server_list[i].d_equals_t = server_list[i+1].d_equals_t; |
||
843 | trimarchi | 283 | server_list[i].Is = server_list[i+1].Is; |
417 | giacomo | 284 | |
405 | trimarchi | 285 | i++; |
286 | } |
||
410 | trimarchi | 287 | current_server--; |
405 | trimarchi | 288 | |
289 | |||
221 | giacomo | 290 | return 0; |
291 | |||
292 | } |
||
293 | |||
868 | trimarchi | 294 | int |
295 | fsf_get_renegotiation_status |
||
296 | (fsf_server_id_t server, |
||
297 | fsf_renegotiation_status_t *renegotiation_status) |
||
298 | { |
||
221 | giacomo | 299 | |
868 | trimarchi | 300 | if (SERVER_get_renegotiation_status(fsf_server_level,server)) |
301 | *renegotiation_status=FSF_IN_PROGRESS; |
||
302 | else |
||
303 | *renegotiation_status=FSF_ADMITTED; |
||
304 | |||
305 | return 0; |
||
306 | |||
307 | |||
308 | } |
||
309 | |||
310 | |||
221 | giacomo | 311 | int fsf_negotiate_contract |
312 | (const fsf_contract_parameters_t *contract, |
||
313 | fsf_server_id_t *server) |
||
314 | { |
||
679 | trimarchi | 315 | struct mess message; |
221 | giacomo | 316 | |
679 | trimarchi | 317 | // send response server is -1 if the operation fail |
318 | message.type=NEGOTIATE_CONTRACT; |
||
319 | memmove(&message.contract,contract, sizeof(fsf_contract_parameters_t)); |
||
221 | giacomo | 320 | |
681 | trimarchi | 321 | port_send(channel[1],&message,BLOCK); |
679 | trimarchi | 322 | |
681 | trimarchi | 323 | port_receive(channel[0], &message, BLOCK); |
868 | trimarchi | 324 | |
679 | trimarchi | 325 | if (message.server==-1) |
326 | return FSF_ERR_CONTRACT_REJECTED; |
||
221 | giacomo | 327 | |
679 | trimarchi | 328 | *server=message.server; |
329 | |||
221 | giacomo | 330 | return 0; |
331 | |||
332 | } |
||
333 | |||
872 | trimarchi | 334 | int |
335 | fsf_negotiate_contract_for_new_thread |
||
336 | (const fsf_contract_parameters_t *contract, |
||
337 | fsf_server_id_t *server, |
||
338 | pthread_t *thread, |
||
339 | pthread_attr_t *attr, |
||
340 | fsf_thread_code_t thread_code, |
||
341 | void *arg) { |
||
342 | |||
343 | int err=0; |
||
344 | |||
345 | err = fsf_negotiate_contract(contract,server); |
||
346 | if (!err) { |
||
347 | err = pthread_create(thread, attr, thread_code, arg); |
||
348 | if (!err) |
||
349 | err = fsf_bind_thread_to_server(*server,*thread); |
||
350 | } else return err; |
||
351 | |||
352 | return err; |
||
353 | } |
||
354 | |||
355 | int |
||
356 | fsf_negotiate_contract_for_myself |
||
357 | (const fsf_contract_parameters_t *contract, |
||
358 | fsf_server_id_t *server) { |
||
359 | |||
360 | int err=0; |
||
361 | |||
362 | err = fsf_negotiate_contract(contract,server); |
||
363 | if (!err) { |
||
364 | err = fsf_bind_thread_to_server(*server,exec_shadow); |
||
365 | } else return err; |
||
366 | |||
367 | return err; |
||
368 | } |
||
369 | |||
868 | trimarchi | 370 | int fsf_unbind_thread_from_server |
371 | (pthread_t thread) |
||
372 | { |
||
373 | |||
374 | int local_scheduler_level, scheduler_id; |
||
375 | |||
376 | /* Move thread from the local scheduler module to posix level */ |
||
377 | |||
378 | #ifdef FSF_DEBUG |
||
379 | kern_printf("(UnBind thread = %d)",thread); |
||
380 | #endif |
||
381 | |||
382 | /* Check if thread exsists */ |
||
383 | if (thread == -1) |
||
384 | return FSF_ERR_BAD_ARGUMENT; |
||
385 | |||
386 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
387 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level,thread); |
||
388 | |||
389 | /* Check if thread is already bind */ |
||
390 | if (scheduler_id == FSF_NONE) { |
||
391 | /* Check if it is bind to a server */ |
||
392 | if (NONESTAR_getbudget(local_scheduler_level,thread) == -1) |
||
393 | return FSF_ERR_BAD_ARGUMENT; |
||
394 | else { |
||
395 | |||
396 | STD_command_message *msg; |
||
397 | NRT_TASK_MODEL nrt; |
||
398 | |||
399 | nrt_task_default_model(nrt); |
||
400 | nrt_task_def_save_arrivals(nrt); |
||
401 | |||
402 | /* Send change level command to local scheduler */ |
||
403 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
404 | |||
405 | msg->command = STD_SET_NEW_MODEL; |
||
406 | msg->param = (void *)(&nrt); |
||
407 | level_table[fsf_posix_level]->public_message(fsf_posix_level,thread,msg); |
||
408 | |||
409 | msg->command = STD_SET_NEW_LEVEL; |
||
410 | msg->param = (void *)(fsf_posix_level); |
||
411 | task_message(msg,thread,0); |
||
412 | |||
413 | free(msg); |
||
414 | } |
||
415 | } |
||
416 | |||
417 | return 0; |
||
418 | |||
419 | } |
||
420 | |||
873 | trimarchi | 421 | int |
422 | fsf_bind_local_thread_to_server |
||
423 | (fsf_server_id_t server, |
||
424 | pthread_t thread, |
||
425 | fsf_sched_params_t *sched_params) |
||
426 | { |
||
868 | trimarchi | 427 | |
873 | trimarchi | 428 | STD_command_message *msg; |
429 | int local_scheduler_level,scheduler_id; |
||
430 | |||
431 | /* Move thread from the posix module to local scheduler */ |
||
432 | |||
433 | #ifdef FSF_DEBUG |
||
434 | kern_printf("(Bind thread = %d to Server = %d)",thread,server); |
||
435 | #endif |
||
436 | |||
437 | /* Check if server and thread exsist */ |
||
438 | if (server == -1 || thread == -1) |
||
439 | return FSF_ERR_BAD_ARGUMENT; |
||
440 | |||
441 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
||
442 | if (local_scheduler_level==-1) |
||
443 | return FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD; |
||
444 | |||
445 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
446 | |||
447 | /* Check if thread is already bind */ |
||
448 | switch(scheduler_id) { |
||
449 | |||
450 | case FSF_RM: |
||
451 | { |
||
452 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
453 | HARD_TASK_MODEL *h=(HARD_TASK_MODEL *)sched_params; |
||
454 | |||
455 | if (m->pclass != HARD_PCLASS) |
||
456 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
457 | |||
458 | h = (HARD_TASK_MODEL *)m; |
||
459 | |||
460 | if (!h->wcet || !h->mit) return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
461 | |||
462 | /* now we know that m is a valid model */ |
||
463 | if (RMSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
464 | return FSF_ERR_BAD_ARGUMENT; |
||
465 | |||
466 | /* Set server on local scheduler */ |
||
467 | RMSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
468 | |||
469 | /* Send change level command to posix level */ |
||
470 | } |
||
877 | trimarchi | 471 | break; |
472 | |||
873 | trimarchi | 473 | case FSF_EDF: |
474 | { |
||
475 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
476 | HARD_TASK_MODEL *h=(HARD_TASK_MODEL *)sched_params; |
||
477 | |||
478 | if (m->pclass != HARD_PCLASS) |
||
479 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
480 | |||
481 | h = (HARD_TASK_MODEL *)m; |
||
482 | |||
483 | if (!h->wcet || !h->mit) return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
484 | |||
485 | if (EDFSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
486 | return FSF_ERR_BAD_ARGUMENT; |
||
487 | |||
488 | /* Set server on local scheduler */ |
||
489 | EDFSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
490 | |||
491 | } |
||
492 | break; |
||
493 | |||
494 | case FSF_POSIX: |
||
495 | { |
||
496 | TASK_MODEL *m=(TASK_MODEL*)sched_params; |
||
497 | |||
498 | if (m->pclass != NRT_PCLASS) |
||
499 | return FSF_ERR_SCHED_POLICY_NOT_COMPATIBLE; |
||
500 | |||
501 | if (POSIXSTAR_getbudget(local_scheduler_level,thread) != -1) |
||
502 | return FSF_ERR_BAD_ARGUMENT; |
||
503 | |||
504 | /* Set server on local scheduler */ |
||
505 | POSIXSTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
506 | } |
||
877 | trimarchi | 507 | break; |
873 | trimarchi | 508 | |
877 | trimarchi | 509 | default: |
510 | |||
873 | trimarchi | 511 | return FSF_ERR_BAD_ARGUMENT; |
877 | trimarchi | 512 | |
873 | trimarchi | 513 | } |
514 | |||
515 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
877 | trimarchi | 516 | if (msg) { |
517 | SYS_FLAGS f; |
||
518 | f=kern_fsave(); |
||
873 | trimarchi | 519 | msg->command = STD_SET_NEW_MODEL; |
520 | msg->param = (void *)(sched_params); |
||
521 | level_table[local_scheduler_level]->public_message(local_scheduler_level,thread,msg); |
||
522 | |||
523 | msg->command = STD_SET_NEW_LEVEL; |
||
524 | msg->param = (void *)(local_scheduler_level); |
||
525 | task_message(msg,thread,0); |
||
877 | trimarchi | 526 | kern_frestore(f); |
873 | trimarchi | 527 | free(msg); |
528 | } else return FSF_ERR_INTERNAL_ERROR; |
||
529 | |||
530 | return 0; |
||
531 | |||
532 | } |
||
533 | |||
534 | |||
868 | trimarchi | 535 | int fsf_bind_thread_to_server |
536 | (fsf_server_id_t server, |
||
537 | pthread_t thread) |
||
538 | { |
||
539 | |||
540 | STD_command_message *msg; |
||
541 | int local_scheduler_level,scheduler_id; |
||
542 | |||
543 | /* Move thread from the posix module to local scheduler */ |
||
544 | |||
545 | #ifdef FSF_DEBUG |
||
546 | kern_printf("(Bind thread = %d to Server = %d)",thread,server); |
||
547 | #endif |
||
548 | |||
549 | /* Check if server and thread exsist */ |
||
550 | if (server == -1 || thread == -1) |
||
551 | return FSF_ERR_BAD_ARGUMENT; |
||
552 | |||
553 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
||
873 | trimarchi | 554 | if (local_scheduler_level==-1) |
555 | return FSF_ERR_UNKNOWN_APPSCHEDULED_THREAD; |
||
556 | |||
868 | trimarchi | 557 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
558 | |||
559 | /* Check if thread is already bind */ |
||
560 | if (scheduler_id == FSF_NONE) { |
||
561 | DUMMY_TASK_MODEL rt_arg; |
||
562 | |||
563 | if (NONESTAR_getbudget(local_scheduler_level,thread) != -1) |
||
564 | return FSF_ERR_BAD_ARGUMENT; |
||
565 | |||
566 | /* Set server on local scheduler */ |
||
567 | NONESTAR_setbudget(local_scheduler_level,thread,(int)(server)); |
||
568 | |||
569 | /* Send change level command to posix level */ |
||
570 | msg = (STD_command_message *)malloc(sizeof(STD_command_message)); |
||
571 | |||
572 | msg->command = STD_SET_NEW_MODEL; |
||
573 | msg->param = (void *)(&rt_arg); |
||
574 | level_table[local_scheduler_level]->public_message(local_scheduler_level,thread,msg); |
||
575 | |||
576 | msg->command = STD_SET_NEW_LEVEL; |
||
577 | msg->param = (void *)(local_scheduler_level); |
||
578 | task_message(msg,thread,0); |
||
579 | |||
580 | free(msg); |
||
581 | } else return FSF_ERR_BAD_ARGUMENT; |
||
582 | |||
583 | return 0; |
||
584 | } |
||
585 | |||
241 | giacomo | 586 | int fsf_create_thread |
587 | (fsf_server_id_t server, |
||
588 | pthread_t *thread, |
||
589 | pthread_attr_t *attr, |
||
590 | fsf_thread_code_t thread_code, |
||
591 | void *arg, |
||
592 | void *local_scheduler_arg) |
||
221 | giacomo | 593 | { |
594 | |||
595 | int local_scheduler_level,scheduler_id; |
||
596 | |||
597 | /* Check if server and thread exsist */ |
||
241 | giacomo | 598 | if (server == NIL) |
873 | trimarchi | 599 | return FSF_ERR_BAD_ARGUMENT; |
221 | giacomo | 600 | |
241 | giacomo | 601 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
602 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
868 | trimarchi | 603 | #ifdef FSF_DEBUG |
604 | kern_printf("sched policy %d", scheduler_id); |
||
605 | #endif |
||
221 | giacomo | 606 | /* Check if thread is already bind */ |
607 | switch (scheduler_id) { |
||
873 | trimarchi | 608 | case FSF_POSIX: |
221 | giacomo | 609 | |
298 | giacomo | 610 | nrt_task_def_arg(*(NRT_TASK_MODEL *)(local_scheduler_arg),arg); |
611 | nrt_task_def_level(*(NRT_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
221 | giacomo | 612 | |
298 | giacomo | 613 | *thread = task_create("POSIXSTAR", thread_code, local_scheduler_arg, NULL); |
267 | giacomo | 614 | if (*thread == NIL) { |
615 | #ifdef FSF_DEBUG |
||
616 | kern_printf("(FSF:Error creating thread)"); |
||
617 | #endif |
||
873 | trimarchi | 618 | return FSF_ERR_INTERNAL_ERROR; |
267 | giacomo | 619 | } |
221 | giacomo | 620 | |
241 | giacomo | 621 | POSIXSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
234 | giacomo | 622 | |
221 | giacomo | 623 | break; |
868 | trimarchi | 624 | case FSF_EDF: |
221 | giacomo | 625 | |
250 | giacomo | 626 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
627 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
628 | |||
629 | *thread = task_create("EDFSTAR", thread_code, local_scheduler_arg, NULL); |
||
630 | if (*thread == NIL) |
||
873 | trimarchi | 631 | return FSF_ERR_INTERNAL_ERROR; |
250 | giacomo | 632 | |
633 | EDFSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
634 | |||
221 | giacomo | 635 | break; |
235 | giacomo | 636 | |
868 | trimarchi | 637 | case FSF_RM: |
235 | giacomo | 638 | |
273 | giacomo | 639 | hard_task_def_arg(*(HARD_TASK_MODEL *)(local_scheduler_arg),arg); |
640 | hard_task_def_level(*(HARD_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
641 | |||
642 | *thread = task_create("RMSTAR", thread_code, local_scheduler_arg, NULL); |
||
643 | if (*thread == NIL) |
||
873 | trimarchi | 644 | return FSF_ERR_INTERNAL_ERROR; |
273 | giacomo | 645 | |
646 | RMSTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
||
647 | |||
648 | break; |
||
868 | trimarchi | 649 | case FSF_NONE: |
334 | giacomo | 650 | |
868 | trimarchi | 651 | //dummy_task_def_arg(*( DUMMY_TASK_MODEL *)(local_scheduler_arg),arg); |
652 | dummy_task_def_level(*( DUMMY_TASK_MODEL *)(local_scheduler_arg),local_scheduler_level); |
||
334 | giacomo | 653 | |
855 | trimarchi | 654 | *thread = task_create("NONESTAR", thread_code, local_scheduler_arg, NULL); |
334 | giacomo | 655 | if (*thread == NIL) |
873 | trimarchi | 656 | return FSF_ERR_INTERNAL_ERROR; |
334 | giacomo | 657 | |
855 | trimarchi | 658 | NONESTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
334 | giacomo | 659 | |
660 | break; |
||
661 | |||
221 | giacomo | 662 | default: |
873 | trimarchi | 663 | return FSF_ERR_INTERNAL_ERROR; |
221 | giacomo | 664 | break; |
665 | } |
||
811 | trimarchi | 666 | |
667 | #ifdef FSF_DEBUG |
||
668 | kern_printf("(FSF:Insert thread = %d to Server = %d)",*thread,server); |
||
669 | #endif |
||
221 | giacomo | 670 | |
671 | return 0; |
||
672 | |||
673 | } |
||
674 | |||
808 | trimarchi | 675 | int fsf_settask_nopreemptive |
221 | giacomo | 676 | (fsf_server_id_t *server, |
677 | pthread_t thread) |
||
678 | { |
||
679 | int local_scheduler_level, scheduler_id; |
||
680 | |||
241 | giacomo | 681 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
682 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
221 | giacomo | 683 | |
684 | switch (scheduler_id) { |
||
868 | trimarchi | 685 | case FSF_POSIX: |
816 | trimarchi | 686 | POSIXSTAR_set_nopreemtive_current(local_scheduler_level); |
687 | return 1; |
||
808 | trimarchi | 688 | break; |
868 | trimarchi | 689 | case FSF_EDF: |
808 | trimarchi | 690 | EDFSTAR_set_nopreemtive_current(local_scheduler_level); |
691 | return 1; |
||
692 | break; |
||
868 | trimarchi | 693 | case FSF_RM: |
812 | trimarchi | 694 | RMSTAR_set_nopreemtive_current(local_scheduler_level); |
695 | return 1; |
||
808 | trimarchi | 696 | break; |
868 | trimarchi | 697 | case FSF_NONE: |
808 | trimarchi | 698 | break; |
699 | default: |
||
700 | return -1; |
||
701 | } |
||
702 | return -1; |
||
703 | } |
||
704 | |||
705 | |||
706 | int fsf_settask_preemptive |
||
707 | (fsf_server_id_t *server, |
||
708 | pthread_t thread) |
||
709 | { |
||
710 | int local_scheduler_level, scheduler_id; |
||
711 | |||
712 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
713 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
714 | |||
715 | switch (scheduler_id) { |
||
868 | trimarchi | 716 | case FSF_POSIX: |
823 | trimarchi | 717 | POSIXSTAR_unset_nopreemtive_current(local_scheduler_level); |
816 | trimarchi | 718 | return 1; |
808 | trimarchi | 719 | break; |
868 | trimarchi | 720 | case FSF_EDF: |
808 | trimarchi | 721 | EDFSTAR_unset_nopreemtive_current(local_scheduler_level); |
722 | return 1; |
||
723 | break; |
||
868 | trimarchi | 724 | case FSF_RM: |
812 | trimarchi | 725 | RMSTAR_unset_nopreemtive_current(local_scheduler_level); |
726 | return 1; |
||
808 | trimarchi | 727 | break; |
868 | trimarchi | 728 | case FSF_NONE: |
808 | trimarchi | 729 | break; |
730 | default: |
||
731 | return -1; |
||
732 | } |
||
733 | |||
734 | return -1; |
||
735 | |||
736 | } |
||
737 | |||
738 | |||
739 | int fsf_get_server |
||
868 | trimarchi | 740 | (pthread_t thread, |
741 | fsf_server_id_t *server) |
||
808 | trimarchi | 742 | { |
743 | int local_scheduler_level, scheduler_id; |
||
744 | |||
745 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
746 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
747 | |||
748 | switch (scheduler_id) { |
||
868 | trimarchi | 749 | case FSF_POSIX: |
829 | giacomo | 750 | *server = POSIXSTAR_getbudget(local_scheduler_level,thread); |
751 | return 0; |
||
868 | trimarchi | 752 | case FSF_EDF: |
829 | giacomo | 753 | *server = EDFSTAR_getbudget(local_scheduler_level,thread); |
754 | return 0; |
||
868 | trimarchi | 755 | case FSF_RM: |
829 | giacomo | 756 | *server = RMSTAR_getbudget(local_scheduler_level,thread); |
757 | return 0; |
||
868 | trimarchi | 758 | case FSF_NONE: |
855 | trimarchi | 759 | *server = NONESTAR_getbudget(local_scheduler_level,thread); |
829 | giacomo | 760 | return 0; |
235 | giacomo | 761 | default: |
221 | giacomo | 762 | return -1; |
763 | } |
||
764 | |||
765 | return -1; |
||
766 | |||
767 | } |
||
768 | |||
339 | giacomo | 769 | int fsf_get_server_level(void) |
770 | { |
||
771 | |||
772 | return fsf_server_level; |
||
773 | |||
774 | } |
||
775 | |||
221 | giacomo | 776 | int fsf_cancel_contract |
868 | trimarchi | 777 | (fsf_server_id_t server) |
221 | giacomo | 778 | { |
779 | |||
780 | int local_scheduler_level, scheduler_id; |
||
411 | trimarchi | 781 | SYS_FLAGS f; |
782 | TIME T,Q; |
||
783 | int i=0; |
||
221 | giacomo | 784 | |
785 | #ifdef FSF_DEBUG |
||
868 | trimarchi | 786 | kern_printf("(Remove server %d)",server); |
221 | giacomo | 787 | #endif |
788 | |||
789 | /* Check server id */ |
||
868 | trimarchi | 790 | if (server < 0) |
873 | trimarchi | 791 | return FSF_ERR_BAD_ARGUMENT; |
221 | giacomo | 792 | |
868 | trimarchi | 793 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
794 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
221 | giacomo | 795 | |
796 | switch (scheduler_id) { |
||
868 | trimarchi | 797 | case FSF_POSIX: |
221 | giacomo | 798 | |
799 | /* Check if some thread use the server */ |
||
868 | trimarchi | 800 | if(POSIXSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 801 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
221 | giacomo | 802 | |
803 | break; |
||
868 | trimarchi | 804 | case FSF_EDF: |
235 | giacomo | 805 | /* Check if some thread use the server */ |
868 | trimarchi | 806 | if(EDFSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 807 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 808 | break; |
809 | |||
868 | trimarchi | 810 | case FSF_RM: |
235 | giacomo | 811 | /* Check if some thread use the server */ |
868 | trimarchi | 812 | if(RMSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 813 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 814 | |
221 | giacomo | 815 | break; |
334 | giacomo | 816 | |
868 | trimarchi | 817 | case FSF_NONE: |
334 | giacomo | 818 | /* Check if some thread use the server */ |
868 | trimarchi | 819 | if(NONESTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 820 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
334 | giacomo | 821 | |
822 | break; |
||
823 | |||
221 | giacomo | 824 | } |
825 | |||
868 | trimarchi | 826 | SERVER_removebudget(fsf_server_level,server); |
221 | giacomo | 827 | |
828 | level_free_descriptor(local_scheduler_level); |
||
405 | trimarchi | 829 | |
868 | trimarchi | 830 | remove_contract(server); |
411 | trimarchi | 831 | |
832 | f=kern_fsave(); |
||
833 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
834 | kern_frestore(f); |
||
873 | trimarchi | 835 | return FSF_ERR_INTERNAL_ERROR; |
411 | trimarchi | 836 | } |
837 | #ifdef FSF_DEBUG |
||
838 | kern_printf("(Adjust budget)"); |
||
839 | #endif |
||
840 | for (i=0; i<current_server; i++) { |
||
841 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
417 | giacomo | 842 | if (T > server_list[i].Tmin ) { |
411 | trimarchi | 843 | server_list[i].actual_budget = server_list[i].Cmin; |
844 | server_list[i].actual_period = T; |
||
417 | giacomo | 845 | #ifdef FSF_DEBUG |
846 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
847 | #endif |
||
661 | giacomo | 848 | |
849 | if (server_list[i].d_equals_t == TRUE) |
||
850 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
851 | else |
||
852 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
853 | |||
411 | trimarchi | 854 | } else { |
417 | giacomo | 855 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
411 | trimarchi | 856 | server_list[i].actual_budget = Q; |
417 | giacomo | 857 | server_list[i].actual_period = server_list[i].Tmin; |
858 | #ifdef FSF_DEBUG |
||
859 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
860 | #endif |
||
661 | giacomo | 861 | |
862 | if (server_list[i].d_equals_t == TRUE) |
||
863 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].Tmin); |
||
864 | else |
||
865 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].deadline); |
||
866 | |||
411 | trimarchi | 867 | } |
416 | trimarchi | 868 | server_list[i].U=server_list[i].Umin; |
411 | trimarchi | 869 | |
870 | } |
||
221 | giacomo | 871 | |
405 | trimarchi | 872 | |
411 | trimarchi | 873 | kern_frestore(f); |
221 | giacomo | 874 | |
875 | return 0; |
||
411 | trimarchi | 876 | |
221 | giacomo | 877 | } |
878 | |||
405 | trimarchi | 879 | int recalculate_contract(bandwidth_t U) { |
416 | trimarchi | 880 | bandwidth_t current_bandwidth; |
418 | giacomo | 881 | unsigned int temp_U; |
416 | trimarchi | 882 | int Qt; |
405 | trimarchi | 883 | int isok=0; |
884 | int i=0; |
||
868 | trimarchi | 885 | int target_importance=FSF_DEFAULT_IMPORTANCE; |
886 | |||
887 | #define MAX_IMPORTANCE 5 |
||
405 | trimarchi | 888 | |
407 | giacomo | 889 | #ifdef FSF_DEBUG |
890 | int temp; |
||
891 | |||
892 | kern_printf("(Recalculate contract)"); |
||
893 | #endif |
||
405 | trimarchi | 894 | |
895 | /* The current bandwidth is the min bandwidth */ |
||
896 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
897 | #ifdef FSF_DEBUG |
||
410 | trimarchi | 898 | kern_printf("(nserver %d)", current_server); |
405 | trimarchi | 899 | #endif |
900 | |||
901 | do { |
||
902 | current_bandwidth=0; |
||
903 | Qt=0; |
||
410 | trimarchi | 904 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 905 | if (server_list[i].Is==target_importance |
906 | && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) |
||
405 | trimarchi | 907 | Qt+=server_list[i].Qs; |
416 | trimarchi | 908 | current_bandwidth+=server_list[i].U; |
868 | trimarchi | 909 | #ifdef FSF_DEBUG |
843 | trimarchi | 910 | kern_printf("(Qs %d, Qt %d, Is %d)", server_list[i].Qs, Qt,server_list[i].Is); |
868 | trimarchi | 911 | #endif |
405 | trimarchi | 912 | } |
413 | trimarchi | 913 | |
868 | trimarchi | 914 | #ifdef FSF_DEBUG |
405 | trimarchi | 915 | kern_printf("(Total Quality %d)", Qt); |
868 | trimarchi | 916 | #endif |
405 | trimarchi | 917 | isok=1; |
410 | trimarchi | 918 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 919 | if (server_list[i].Is==target_importance && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) { |
416 | trimarchi | 920 | temp_U=server_list[i].U; |
921 | server_list[i].U=U-current_bandwidth; |
||
922 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
923 | temp_U+=server_list[i].U; |
||
924 | |||
925 | if (temp_U<=server_list[i].Umin) { |
||
405 | trimarchi | 926 | server_list[i].U=server_list[i].Umin; |
416 | trimarchi | 927 | } else if (temp_U>server_list[i].Umax) { |
928 | server_list[i].U=server_list[i].Umax; |
||
405 | trimarchi | 929 | isok=0; |
930 | } else server_list[i].U=temp_U; |
||
931 | |||
932 | #ifdef FSF_DEBUG |
||
933 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
934 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
935 | #endif |
||
936 | } |
||
937 | } |
||
843 | trimarchi | 938 | target_importance++; |
868 | trimarchi | 939 | } while (!isok && target_importance<=MAX_IMPORTANCE); |
405 | trimarchi | 940 | |
941 | return 0; |
||
942 | } |
||
943 | |||
221 | giacomo | 944 | int fsf_renegotiate_contract |
945 | (const fsf_contract_parameters_t *new_contract, |
||
946 | fsf_server_id_t server) |
||
947 | { |
||
679 | trimarchi | 948 | |
949 | struct mess message; |
||
221 | giacomo | 950 | |
679 | trimarchi | 951 | // send response server is -1 if the operation fail |
952 | message.type=RENEGOTIATE_CONTRACT; |
||
953 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
954 | message.server = server; |
||
221 | giacomo | 955 | |
859 | trimarchi | 956 | port_send(channel[1],&message,BLOCK); |
957 | |||
958 | port_receive(channel[0], &message, BLOCK); |
||
959 | |||
679 | trimarchi | 960 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
961 | |||
405 | trimarchi | 962 | return 0; |
221 | giacomo | 963 | } |
241 | giacomo | 964 | |
868 | trimarchi | 965 | int fsf_request_contract_renegotiation |
966 | (const fsf_contract_parameters_t *new_contract, |
||
967 | fsf_server_id_t server, |
||
968 | int sig_notify, |
||
969 | union sigval sig_value) |
||
970 | { |
||
971 | |||
972 | struct mess message; |
||
973 | |||
974 | // send response server is -1 if the operation fail |
||
975 | message.type=REQUEST_RENEGOTIATE_CONTRACT; |
||
976 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
977 | message.server = server; |
||
978 | |||
979 | port_send(channel[1],&message,BLOCK); |
||
980 | |||
981 | port_receive(channel[0], &message, BLOCK); |
||
982 | |||
983 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
||
984 | |||
985 | return 0; |
||
986 | } |
||
987 | |||
407 | giacomo | 988 | void print_server_list() |
989 | { |
||
990 | |||
991 | int i; |
||
992 | |||
993 | kern_printf("Server List\n"); |
||
994 | |||
410 | trimarchi | 995 | for(i=0;i<current_server;i++) { |
407 | giacomo | 996 | |
662 | giacomo | 997 | 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 | 998 | |
999 | } |
||
1000 | |||
1001 | } |
||
808 | trimarchi | 1002 | |
1003 | |||
1004 | int fsf_get_remain_budget(fsf_server_id_t server) { |
||
1005 | |||
825 | trimarchi | 1006 | return SERVER_get_remain_capacity(fsf_server_level, server); |
808 | trimarchi | 1007 | } |
868 | trimarchi | 1008 | |
1009 | int fsf_get_budget_and_period |
||
1010 | (fsf_server_id_t server, |
||
1011 | struct timespec *budget, |
||
1012 | struct timespec *period) { |
||
1013 | TIME bg; |
||
1014 | TIME pd; |
||
1015 | |||
1016 | if (!SERVER_getbudgetinfo(fsf_server_level, &bg, &pd, NULL, server)) { |
||
1017 | if (budget) { |
||
1018 | NULL_TIMESPEC(budget); |
||
1019 | ADDUSEC2TIMESPEC(bg, budget); |
||
1020 | } |
||
1021 | if (period) { |
||
1022 | NULL_TIMESPEC(period); |
||
1023 | ADDUSEC2TIMESPEC(pd, period); |
||
1024 | } |
||
1025 | |||
1026 | return 0; |
||
1027 | } |
||
1028 | return FSF_ERR_BAD_ARGUMENT; |
||
1029 | } |
||
1030 | |||
1031 | int |
||
1032 | fsf_set_service_thread_data |
||
1033 | (const struct timespec *budget, |
||
1034 | const struct timespec *period, |
||
1035 | bool *accepted) { |
||
1036 | |||
1037 | if (budget==NULL && period==NULL) return FSF_ERR_BAD_ARGUMENT; |
||
1038 | fsf_set_contract_basic_parameters(&service_contract,budget,period,FSF_DEFAULT_WORKLOAD); |
||
1039 | *accepted = !fsf_renegotiate_contract(&service_contract,service_server)?true:false; |
||
1040 | return 0; |
||
1041 | |||
1042 | } |
||
1043 | |||
1044 | |||
1045 | |||
1046 | int fsf_get_service_thread_data |
||
1047 | (struct timespec *budget, |
||
1048 | struct timespec *period) { |
||
1049 | |||
1050 | return fsf_get_budget_and_period(service_server, budget, period); |
||
1051 | |||
1052 | } |
||
1053 |