Subversion Repositories shark

Rev

Rev 808 | Rev 811 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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