Subversion Repositories shark

Rev

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

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