Subversion Repositories shark

Rev

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