Rev 877 | Rev 880 | 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); |
||
879 | trimarchi | 653 | #ifdef FSF_DEBUG |
654 | kern_printf("(None Server create task)"); |
||
655 | #endif |
||
855 | trimarchi | 656 | *thread = task_create("NONESTAR", thread_code, local_scheduler_arg, NULL); |
334 | giacomo | 657 | if (*thread == NIL) |
873 | trimarchi | 658 | return FSF_ERR_INTERNAL_ERROR; |
334 | giacomo | 659 | |
855 | trimarchi | 660 | NONESTAR_setbudget(local_scheduler_level, *thread, (int)(server)); |
334 | giacomo | 661 | |
662 | break; |
||
663 | |||
221 | giacomo | 664 | default: |
873 | trimarchi | 665 | return FSF_ERR_INTERNAL_ERROR; |
221 | giacomo | 666 | break; |
667 | } |
||
811 | trimarchi | 668 | |
669 | #ifdef FSF_DEBUG |
||
670 | kern_printf("(FSF:Insert thread = %d to Server = %d)",*thread,server); |
||
671 | #endif |
||
221 | giacomo | 672 | |
673 | return 0; |
||
674 | |||
675 | } |
||
676 | |||
808 | trimarchi | 677 | int fsf_settask_nopreemptive |
221 | giacomo | 678 | (fsf_server_id_t *server, |
679 | pthread_t thread) |
||
680 | { |
||
681 | int local_scheduler_level, scheduler_id; |
||
682 | |||
241 | giacomo | 683 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
684 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
221 | giacomo | 685 | |
686 | switch (scheduler_id) { |
||
868 | trimarchi | 687 | case FSF_POSIX: |
816 | trimarchi | 688 | POSIXSTAR_set_nopreemtive_current(local_scheduler_level); |
689 | return 1; |
||
808 | trimarchi | 690 | break; |
868 | trimarchi | 691 | case FSF_EDF: |
808 | trimarchi | 692 | EDFSTAR_set_nopreemtive_current(local_scheduler_level); |
693 | return 1; |
||
694 | break; |
||
868 | trimarchi | 695 | case FSF_RM: |
812 | trimarchi | 696 | RMSTAR_set_nopreemtive_current(local_scheduler_level); |
697 | return 1; |
||
808 | trimarchi | 698 | break; |
868 | trimarchi | 699 | case FSF_NONE: |
808 | trimarchi | 700 | break; |
701 | default: |
||
702 | return -1; |
||
703 | } |
||
704 | return -1; |
||
705 | } |
||
706 | |||
707 | |||
708 | int fsf_settask_preemptive |
||
709 | (fsf_server_id_t *server, |
||
710 | pthread_t thread) |
||
711 | { |
||
712 | int local_scheduler_level, scheduler_id; |
||
713 | |||
714 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
715 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
716 | |||
717 | switch (scheduler_id) { |
||
868 | trimarchi | 718 | case FSF_POSIX: |
823 | trimarchi | 719 | POSIXSTAR_unset_nopreemtive_current(local_scheduler_level); |
816 | trimarchi | 720 | return 1; |
808 | trimarchi | 721 | break; |
868 | trimarchi | 722 | case FSF_EDF: |
808 | trimarchi | 723 | EDFSTAR_unset_nopreemtive_current(local_scheduler_level); |
724 | return 1; |
||
725 | break; |
||
868 | trimarchi | 726 | case FSF_RM: |
812 | trimarchi | 727 | RMSTAR_unset_nopreemtive_current(local_scheduler_level); |
728 | return 1; |
||
808 | trimarchi | 729 | break; |
868 | trimarchi | 730 | case FSF_NONE: |
808 | trimarchi | 731 | break; |
732 | default: |
||
733 | return -1; |
||
734 | } |
||
735 | |||
736 | return -1; |
||
737 | |||
738 | } |
||
739 | |||
740 | |||
741 | int fsf_get_server |
||
868 | trimarchi | 742 | (pthread_t thread, |
743 | fsf_server_id_t *server) |
||
808 | trimarchi | 744 | { |
745 | int local_scheduler_level, scheduler_id; |
||
746 | |||
747 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread); |
||
748 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread); |
||
749 | |||
750 | switch (scheduler_id) { |
||
868 | trimarchi | 751 | case FSF_POSIX: |
829 | giacomo | 752 | *server = POSIXSTAR_getbudget(local_scheduler_level,thread); |
753 | return 0; |
||
868 | trimarchi | 754 | case FSF_EDF: |
829 | giacomo | 755 | *server = EDFSTAR_getbudget(local_scheduler_level,thread); |
756 | return 0; |
||
868 | trimarchi | 757 | case FSF_RM: |
829 | giacomo | 758 | *server = RMSTAR_getbudget(local_scheduler_level,thread); |
759 | return 0; |
||
868 | trimarchi | 760 | case FSF_NONE: |
855 | trimarchi | 761 | *server = NONESTAR_getbudget(local_scheduler_level,thread); |
829 | giacomo | 762 | return 0; |
235 | giacomo | 763 | default: |
221 | giacomo | 764 | return -1; |
765 | } |
||
766 | |||
767 | return -1; |
||
768 | |||
769 | } |
||
770 | |||
339 | giacomo | 771 | int fsf_get_server_level(void) |
772 | { |
||
773 | |||
774 | return fsf_server_level; |
||
775 | |||
776 | } |
||
777 | |||
221 | giacomo | 778 | int fsf_cancel_contract |
868 | trimarchi | 779 | (fsf_server_id_t server) |
221 | giacomo | 780 | { |
781 | |||
782 | int local_scheduler_level, scheduler_id; |
||
411 | trimarchi | 783 | SYS_FLAGS f; |
784 | TIME T,Q; |
||
785 | int i=0; |
||
221 | giacomo | 786 | |
787 | #ifdef FSF_DEBUG |
||
868 | trimarchi | 788 | kern_printf("(Remove server %d)",server); |
221 | giacomo | 789 | #endif |
790 | |||
791 | /* Check server id */ |
||
868 | trimarchi | 792 | if (server < 0) |
873 | trimarchi | 793 | return FSF_ERR_BAD_ARGUMENT; |
221 | giacomo | 794 | |
868 | trimarchi | 795 | local_scheduler_level = SERVER_get_local_scheduler_level_from_budget(fsf_server_level,server); |
796 | scheduler_id = SERVER_get_local_scheduler_id_from_budget(fsf_server_level,server); |
||
221 | giacomo | 797 | |
798 | switch (scheduler_id) { |
||
868 | trimarchi | 799 | case FSF_POSIX: |
221 | giacomo | 800 | |
801 | /* Check if some thread use the server */ |
||
868 | trimarchi | 802 | if(POSIXSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 803 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
221 | giacomo | 804 | |
805 | break; |
||
868 | trimarchi | 806 | case FSF_EDF: |
235 | giacomo | 807 | /* Check if some thread use the server */ |
868 | trimarchi | 808 | if(EDFSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 809 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 810 | break; |
811 | |||
868 | trimarchi | 812 | case FSF_RM: |
235 | giacomo | 813 | /* Check if some thread use the server */ |
868 | trimarchi | 814 | if(RMSTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 815 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
235 | giacomo | 816 | |
221 | giacomo | 817 | break; |
334 | giacomo | 818 | |
868 | trimarchi | 819 | case FSF_NONE: |
334 | giacomo | 820 | /* Check if some thread use the server */ |
868 | trimarchi | 821 | if(NONESTAR_budget_has_thread(local_scheduler_level,server)) |
873 | trimarchi | 822 | return FSF_ERR_NOT_CONTRACTED_SERVER; |
334 | giacomo | 823 | |
824 | break; |
||
825 | |||
221 | giacomo | 826 | } |
827 | |||
868 | trimarchi | 828 | SERVER_removebudget(fsf_server_level,server); |
221 | giacomo | 829 | |
830 | level_free_descriptor(local_scheduler_level); |
||
405 | trimarchi | 831 | |
868 | trimarchi | 832 | remove_contract(server); |
411 | trimarchi | 833 | |
834 | f=kern_fsave(); |
||
835 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
836 | kern_frestore(f); |
||
873 | trimarchi | 837 | return FSF_ERR_INTERNAL_ERROR; |
411 | trimarchi | 838 | } |
839 | #ifdef FSF_DEBUG |
||
840 | kern_printf("(Adjust budget)"); |
||
841 | #endif |
||
842 | for (i=0; i<current_server; i++) { |
||
843 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
417 | giacomo | 844 | if (T > server_list[i].Tmin ) { |
411 | trimarchi | 845 | server_list[i].actual_budget = server_list[i].Cmin; |
846 | server_list[i].actual_period = T; |
||
417 | giacomo | 847 | #ifdef FSF_DEBUG |
848 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
849 | #endif |
||
661 | giacomo | 850 | |
851 | if (server_list[i].d_equals_t == TRUE) |
||
852 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
853 | else |
||
854 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
855 | |||
411 | trimarchi | 856 | } else { |
417 | giacomo | 857 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
411 | trimarchi | 858 | server_list[i].actual_budget = Q; |
417 | giacomo | 859 | server_list[i].actual_period = server_list[i].Tmin; |
860 | #ifdef FSF_DEBUG |
||
861 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
862 | #endif |
||
661 | giacomo | 863 | |
864 | if (server_list[i].d_equals_t == TRUE) |
||
865 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].Tmin); |
||
866 | else |
||
867 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin, server_list[i].deadline); |
||
868 | |||
411 | trimarchi | 869 | } |
416 | trimarchi | 870 | server_list[i].U=server_list[i].Umin; |
411 | trimarchi | 871 | |
872 | } |
||
221 | giacomo | 873 | |
405 | trimarchi | 874 | |
411 | trimarchi | 875 | kern_frestore(f); |
221 | giacomo | 876 | |
877 | return 0; |
||
411 | trimarchi | 878 | |
221 | giacomo | 879 | } |
880 | |||
405 | trimarchi | 881 | int recalculate_contract(bandwidth_t U) { |
416 | trimarchi | 882 | bandwidth_t current_bandwidth; |
418 | giacomo | 883 | unsigned int temp_U; |
416 | trimarchi | 884 | int Qt; |
405 | trimarchi | 885 | int isok=0; |
886 | int i=0; |
||
868 | trimarchi | 887 | int target_importance=FSF_DEFAULT_IMPORTANCE; |
888 | |||
889 | #define MAX_IMPORTANCE 5 |
||
405 | trimarchi | 890 | |
407 | giacomo | 891 | #ifdef FSF_DEBUG |
892 | int temp; |
||
893 | |||
894 | kern_printf("(Recalculate contract)"); |
||
895 | #endif |
||
405 | trimarchi | 896 | |
897 | /* The current bandwidth is the min bandwidth */ |
||
898 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
899 | #ifdef FSF_DEBUG |
||
410 | trimarchi | 900 | kern_printf("(nserver %d)", current_server); |
405 | trimarchi | 901 | #endif |
902 | |||
903 | do { |
||
904 | current_bandwidth=0; |
||
905 | Qt=0; |
||
410 | trimarchi | 906 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 907 | if (server_list[i].Is==target_importance |
908 | && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) |
||
405 | trimarchi | 909 | Qt+=server_list[i].Qs; |
416 | trimarchi | 910 | current_bandwidth+=server_list[i].U; |
868 | trimarchi | 911 | #ifdef FSF_DEBUG |
843 | trimarchi | 912 | kern_printf("(Qs %d, Qt %d, Is %d)", server_list[i].Qs, Qt,server_list[i].Is); |
868 | trimarchi | 913 | #endif |
405 | trimarchi | 914 | } |
413 | trimarchi | 915 | |
868 | trimarchi | 916 | #ifdef FSF_DEBUG |
405 | trimarchi | 917 | kern_printf("(Total Quality %d)", Qt); |
868 | trimarchi | 918 | #endif |
405 | trimarchi | 919 | isok=1; |
410 | trimarchi | 920 | for (i=0; i<current_server; i++) { |
843 | trimarchi | 921 | if (server_list[i].Is==target_importance && server_list[i].U<server_list[i].Umax && server_list[i].Qs>0) { |
416 | trimarchi | 922 | temp_U=server_list[i].U; |
923 | server_list[i].U=U-current_bandwidth; |
||
924 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
925 | temp_U+=server_list[i].U; |
||
926 | |||
927 | if (temp_U<=server_list[i].Umin) { |
||
405 | trimarchi | 928 | server_list[i].U=server_list[i].Umin; |
416 | trimarchi | 929 | } else if (temp_U>server_list[i].Umax) { |
930 | server_list[i].U=server_list[i].Umax; |
||
405 | trimarchi | 931 | isok=0; |
932 | } else server_list[i].U=temp_U; |
||
933 | |||
934 | #ifdef FSF_DEBUG |
||
935 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
936 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
937 | #endif |
||
938 | } |
||
939 | } |
||
843 | trimarchi | 940 | target_importance++; |
868 | trimarchi | 941 | } while (!isok && target_importance<=MAX_IMPORTANCE); |
405 | trimarchi | 942 | |
943 | return 0; |
||
944 | } |
||
945 | |||
221 | giacomo | 946 | int fsf_renegotiate_contract |
947 | (const fsf_contract_parameters_t *new_contract, |
||
948 | fsf_server_id_t server) |
||
949 | { |
||
679 | trimarchi | 950 | |
951 | struct mess message; |
||
221 | giacomo | 952 | |
679 | trimarchi | 953 | // send response server is -1 if the operation fail |
954 | message.type=RENEGOTIATE_CONTRACT; |
||
955 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
956 | message.server = server; |
||
221 | giacomo | 957 | |
859 | trimarchi | 958 | port_send(channel[1],&message,BLOCK); |
959 | |||
960 | port_receive(channel[0], &message, BLOCK); |
||
961 | |||
679 | trimarchi | 962 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
963 | |||
405 | trimarchi | 964 | return 0; |
221 | giacomo | 965 | } |
241 | giacomo | 966 | |
868 | trimarchi | 967 | int fsf_request_contract_renegotiation |
968 | (const fsf_contract_parameters_t *new_contract, |
||
969 | fsf_server_id_t server, |
||
970 | int sig_notify, |
||
971 | union sigval sig_value) |
||
972 | { |
||
973 | |||
974 | struct mess message; |
||
975 | |||
976 | // send response server is -1 if the operation fail |
||
977 | message.type=REQUEST_RENEGOTIATE_CONTRACT; |
||
978 | memmove(&message.contract,new_contract, sizeof(fsf_contract_parameters_t)); |
||
979 | message.server = server; |
||
980 | |||
981 | port_send(channel[1],&message,BLOCK); |
||
982 | |||
983 | port_receive(channel[0], &message, BLOCK); |
||
984 | |||
985 | if (message.server==-1) return FSF_ERR_CONTRACT_REJECTED; |
||
986 | |||
987 | return 0; |
||
988 | } |
||
989 | |||
407 | giacomo | 990 | void print_server_list() |
991 | { |
||
992 | |||
993 | int i; |
||
994 | |||
995 | kern_printf("Server List\n"); |
||
996 | |||
410 | trimarchi | 997 | for(i=0;i<current_server;i++) { |
407 | giacomo | 998 | |
662 | giacomo | 999 | 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 | 1000 | |
1001 | } |
||
1002 | |||
1003 | } |
||
808 | trimarchi | 1004 | |
1005 | |||
1006 | int fsf_get_remain_budget(fsf_server_id_t server) { |
||
1007 | |||
825 | trimarchi | 1008 | return SERVER_get_remain_capacity(fsf_server_level, server); |
808 | trimarchi | 1009 | } |
868 | trimarchi | 1010 | |
1011 | int fsf_get_budget_and_period |
||
1012 | (fsf_server_id_t server, |
||
1013 | struct timespec *budget, |
||
1014 | struct timespec *period) { |
||
1015 | TIME bg; |
||
1016 | TIME pd; |
||
1017 | |||
1018 | if (!SERVER_getbudgetinfo(fsf_server_level, &bg, &pd, NULL, server)) { |
||
1019 | if (budget) { |
||
1020 | NULL_TIMESPEC(budget); |
||
1021 | ADDUSEC2TIMESPEC(bg, budget); |
||
1022 | } |
||
1023 | if (period) { |
||
1024 | NULL_TIMESPEC(period); |
||
1025 | ADDUSEC2TIMESPEC(pd, period); |
||
1026 | } |
||
1027 | |||
1028 | return 0; |
||
1029 | } |
||
1030 | return FSF_ERR_BAD_ARGUMENT; |
||
1031 | } |
||
1032 | |||
1033 | int |
||
1034 | fsf_set_service_thread_data |
||
1035 | (const struct timespec *budget, |
||
1036 | const struct timespec *period, |
||
1037 | bool *accepted) { |
||
1038 | |||
1039 | if (budget==NULL && period==NULL) return FSF_ERR_BAD_ARGUMENT; |
||
1040 | fsf_set_contract_basic_parameters(&service_contract,budget,period,FSF_DEFAULT_WORKLOAD); |
||
1041 | *accepted = !fsf_renegotiate_contract(&service_contract,service_server)?true:false; |
||
1042 | return 0; |
||
1043 | |||
1044 | } |
||
1045 | |||
1046 | |||
1047 | |||
1048 | int fsf_get_service_thread_data |
||
1049 | (struct timespec *budget, |
||
1050 | struct timespec *period) { |
||
1051 | |||
1052 | return fsf_get_budget_and_period(service_server, budget, period); |
||
1053 | |||
1054 | } |
||
1055 |