Subversion Repositories shark

Rev

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

Rev Author Line No. Line
671 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
737 anton 8
 * Authors:
671 giacomo 9
 *      Giacomo Guidi    <giacomo@gandalf.sssup.it>
10
 *      Mauro Marinoni
11
 *      Anton Cervin
12
 *
13
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
14
 *
15
 * http://www.sssup.it
16
 * http://retis.sssup.it
17
 * http://shark.sssup.it
18
 */
19
 
20
/*
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 *
35
 */
36
 
37
#include <kernel/model.h>
38
#include <kernel/descr.h>
39
#include <kernel/var.h>
40
#include <kernel/func.h>
41
 
741 giacomo 42
#include <ll/i386/64bit.h>
43
 
671 giacomo 44
#include <stdlib.h>
45
 
46
#include <modules/elastic.h>
47
 
48
#include <tracer.h>
49
 
707 anton 50
/* Task flags */
51
 
673 giacomo 52
#define ELASTIC_PRESENT       1
707 anton 53
#define ELASTIC_JOB_PRESENT   2  
671 giacomo 54
 
707 anton 55
/* Task statuses */
56
 
683 giacomo 57
#define ELASTIC_IDLE          APER_STATUS_BASE
58
 
744 anton 59
//#define ELASTIC_DEBUG
707 anton 60
 
61
#ifdef ELASTIC_DEBUG
62
char *pnow() {
63
  static char buf[40];
64
  struct timespec t;
65
  kern_gettime(&t);
66
  sprintf(buf, "%ld.%06ld", t.tv_sec, t.tv_nsec/1000);
67
  return buf;
68
}
69
char *ptime1(struct timespec *t) {
70
  static char buf[40];
71
  sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000);
72
  return buf;
73
}
74
char *ptime2(struct timespec *t) {
75
  static char buf[40];
76
  sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000);
77
  return buf;
78
}
79
#endif
80
 
81
 
671 giacomo 82
typedef struct {
83
 
697 anton 84
  /* Task parameters (set/changed by the user) */
85
 
86
  TIME Tmin;   /* The nominal (minimum) period */
87
  TIME Tmax;   /* The maximum tolerable period */
88
  TIME C;      /* The declared worst-case execution time */
89
  int  E;      /* The elasticity coefficient */
90
  int  beta;   /* PERIOD_SCALING or WCET_SCALING */
91
 
92
  /* Task variables (changed by the module) */
93
 
707 anton 94
  struct timespec release;    /* The current activation time */
95
  struct timespec dline;      /* The current absolute deadline */
96
  int dltimer;                /* Deadline timer handle */
671 giacomo 97
 
700 anton 98
  ext_bandwidth_t Umax;       /* The maximum utilization, Umax = C/Tmin  */
99
  ext_bandwidth_t Umin;       /* The minimum utilization, Umin = C/Tmax  */
671 giacomo 100
 
707 anton 101
  ext_bandwidth_t U;          /* New assigned utilization             */
102
  ext_bandwidth_t oldU;       /* Old utilization                      */
103
  TIME T;                     /* The current period, T = C/U          */
673 giacomo 104
 
671 giacomo 105
  int  flags;
106
 
107
} ELASTIC_task_descr;
108
 
109
typedef struct {
110
  level_des l;     /*+ the standard level descriptor          +*/
111
 
700 anton 112
  ext_bandwidth_t U;   /*+ the bandwidth reserved for elastic tasks  +*/
671 giacomo 113
 
741 giacomo 114
  int c_scaling_factor;   /*+ the computation time scaling factor +*/
671 giacomo 115
 
741 giacomo 116
  ELASTIC_task_descr *elist;
117
 
671 giacomo 118
  LEVEL scheduling_level;
119
 
120
  LEVEL current_level;
121
 
122
  int flags;
123
 
124
} ELASTIC_level_des;
125
 
673 giacomo 126
 
707 anton 127
static void ELASTIC_activation(ELASTIC_level_des *lev, PID p,
128
                               struct timespec *acttime)
129
{
130
  JOB_TASK_MODEL job;
131
  ELASTIC_task_descr *et = &lev->elist[p];
697 anton 132
 
707 anton 133
  /* Assign release time */
134
  et->release = *acttime;
135
 
136
  /* Assign absolute deadline */
137
  et->dline = *acttime;
138
  ADDUSEC2TIMESPEC(et->T, &et->dline);
139
 
140
#ifdef ELASTIC_DEBUG
141
  cprintf("At %s: activating %s; rel=%s; dl=%s\n", pnow(), proc_table[p].name,
142
          ptime1(&et->release), ptime2(&et->dline));
143
#endif  
144
 
741 giacomo 145
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].avail_time);
146
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].wcet);
707 anton 147
 
148
  /* Job insertion */
149
  job_task_default_model(job, et->dline);
150
  level_table[lev->scheduling_level]->
151
    private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job);
737 anton 152
  et->flags |= ELASTIC_JOB_PRESENT;
707 anton 153
}
154
 
155
 
156
static void ELASTIC_timer_act(void *arg) {
157
 
158
  PID p = (PID)(arg);
159
  ELASTIC_level_des *lev;
160
 
161
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
162
  ELASTIC_task_descr *et = &lev->elist[p];
163
 
164
  /* Use the current deadline as the new activation time */
165
  ELASTIC_activation(lev, p, &et->dline);
166
 
167
  event_need_reschedule();
168
 
169
  /* Next activation */
170
  et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act, (void *)(p));
171
}
172
 
173
 
174
/* Check feasability and compute new utilizations for the task set */
175
 
697 anton 176
static int ELASTIC_compress(ELASTIC_level_des *lev) {
177
 
676 giacomo 178
  PID i;
707 anton 179
  ELASTIC_task_descr *et;
697 anton 180
  int ok;
181
 
182
  ext_bandwidth_t Umin;  // minimum utilization
183
  ext_bandwidth_t Umax;  // nominal (maximum) utilization of compressable tasks
745 giacomo 184
  unsigned int temp;
676 giacomo 185
 
697 anton 186
  ext_bandwidth_t Uf;    // amount of non-compressable utilization
187
  int Ev;                // sum of elasticity among compressable tasks
188
 
707 anton 189
  JOB_TASK_MODEL job;
190
 
697 anton 191
  Umin = 0;
192
  Umax = 0;
193
 
676 giacomo 194
  for (i=0; i<MAX_PROC; i++) {
707 anton 195
    et = &lev->elist[i];
196
    if (et->flags & ELASTIC_PRESENT) {
197
      if (et->E == 0) {
198
        Umin += et->U;
199
        Umax += et->U;
697 anton 200
      } else {
707 anton 201
        Umin += et->Umin;
202
        Umax += et->Umax;
203
        et->U = et->Umax;   // reset previous saturations (if any)
697 anton 204
      }
691 anton 205
    }
676 giacomo 206
  }
207
 
744 anton 208
  if (Umin > lev->U) {
209
#ifdef ELASTIC_DEBUG
210
    cprintf("ELASTIC_compress: Task set not feasible\n");
211
#endif
212
    return -1;  // NOT FEASIBLE
213
  }
700 anton 214
 
744 anton 215
  if (Umax <= lev->U) {
216
#ifdef ELASTIC_DEBUG
217
    cprintf("ELASTIC_compress: Task set feasible with maximum utilizations\n");
218
#endif
219
    return 0;  // FEASIBLE WITH MAXIMUM UTILIZATIONS
220
  }
221
 
697 anton 222
  do {
223
    Uf = 0;
224
    Ev = 0;
225
    Umax = 0;
673 giacomo 226
 
697 anton 227
    for (i=0; i<MAX_PROC; i++) {
707 anton 228
      et = &lev->elist[i];
229
      if (et->flags & ELASTIC_PRESENT) {
230
        if (et->E == 0 || et->U == et->Umin) {
231
          Uf += et->U;
697 anton 232
        } else {
707 anton 233
          Ev += et->E;
234
          Umax += et->Umax;
697 anton 235
        }
236
      }
237
    }
238
 
239
    ok = 1;
240
 
241
    for (i=0; i<MAX_PROC; i++) {
707 anton 242
      et = &lev->elist[i];
243
      if (et->flags & ELASTIC_PRESENT) {
244
        if (et->E > 0 && et->U > et->Umin) {
245
          et->U = et->Umax - (Umax - lev->U + Uf) * et->E / Ev;
246
          if (et->U < et->Umin) {
247
            et->U = et->Umin;
697 anton 248
            ok = 0;
249
          }
250
        }
251
      }
252
    }
673 giacomo 253
 
697 anton 254
  } while (ok == 0);
673 giacomo 255
 
707 anton 256
  // Increase periods of compressed tasks IMMEDIATELY.
257
  // The other ones will be changed at their next activation
258
 
259
  for (i=0; i<MAX_PROC; i++) {
260
    et = &lev->elist[i];
261
    if (et->flags & ELASTIC_PRESENT) {
262
      if (et->U != et->oldU) {
263
        /* Utilization has been changed. Compute new period */
745 giacomo 264
        temp = (long long)et->C * (long long)MAX_BANDWIDTH / et->U;
265
        mul32div32to32(temp,lev->c_scaling_factor,SCALING_UNIT,et->T);
707 anton 266
      }
267
      if (et->U < et->oldU) {
268
        /* Task has been compressed. Change its deadline NOW! */
269
        if (et->flags & ELASTIC_JOB_PRESENT) {
737 anton 270
          /* Remove job from level */
707 anton 271
          level_table[lev->scheduling_level]->
272
            private_extract(lev->scheduling_level, i);
273
        }
274
        /* Compute new deadline */
275
        et->dline = et->release;
276
        ADDUSEC2TIMESPEC(et->T, &et->dline);
277
        if (et->dltimer != -1) {
278
          /* Delete old deadline timer, post new one */
279
          kern_event_delete(et->dltimer);
280
          et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act,(void *)(i));
281
        }
282
        if (et->flags & ELASTIC_JOB_PRESENT) {
283
          /* Reinsert job */
284
          job_task_default_model(job, et->dline);
285
          level_table[lev->scheduling_level]->
286
            private_insert(lev->scheduling_level, i, (TASK_MODEL *)&job);
287
        }
288
      }
289
      et->oldU = et->U;  /* Update oldU */
290
    }
291
  }
292
 
293
#ifdef ELASTIC_DEBUG
744 anton 294
  cprintf("ELASTIC_compress: New periods: ");
691 anton 295
  for (i=0; i<MAX_PROC; i++) {
707 anton 296
    et = &lev->elist[i];
297
    if (et->flags & ELASTIC_PRESENT) {
298
      cprintf("%s:%d ", proc_table[i].name, (int)et->T);
691 anton 299
    }
300
  }
697 anton 301
  cprintf("\n");
707 anton 302
#endif
691 anton 303
 
697 anton 304
  return 0; // FEASIBLE
691 anton 305
 
673 giacomo 306
}
307
 
697 anton 308
 
671 giacomo 309
/* The on-line guarantee is enabled only if the appropriate flag is set... */
310
static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth)
311
{
312
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
313
 
691 anton 314
  if (*freebandwidth >= lev->U) {
700 anton 315
    *freebandwidth -= (unsigned int)lev->U;
691 anton 316
    return 1;
317
  } else {
318
    return 0;
319
  }
737 anton 320
 
671 giacomo 321
}
322
 
691 anton 323
 
671 giacomo 324
static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m)
325
{
326
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
691 anton 327
  ELASTIC_TASK_MODEL *elastic = (ELASTIC_TASK_MODEL *)m;
707 anton 328
  ELASTIC_task_descr *et = &lev->elist[p];
745 giacomo 329
  unsigned int temp;
671 giacomo 330
 
331
  if (m->pclass != ELASTIC_PCLASS) return -1;
332
  if (m->level != 0 && m->level != l) return -1;
333
 
691 anton 334
  if (elastic->C == 0) return -1;
673 giacomo 335
  if (elastic->Tmin > elastic->Tmax) return -1;
336
  if (elastic->Tmax == 0) return -1;
707 anton 337
  if (elastic->Tmin == 0) return -1;
673 giacomo 338
 
707 anton 339
  NULL_TIMESPEC(&(et->dline));
340
  et->Tmin = elastic->Tmin;
341
  et->Tmax = elastic->Tmax;
342
  et->C = elastic->C;
343
  et->E = elastic->E;
344
  et->beta = elastic->beta;
673 giacomo 345
 
745 giacomo 346
  mul32div32to32(elastic->C,lev->c_scaling_factor,SCALING_UNIT,temp);
347
  et->Umax = ((long long)MAX_BANDWIDTH * (long long)temp) / (long long)elastic->Tmin;
348
  et->Umin = ((long long)MAX_BANDWIDTH * (long long)temp) / (long long)elastic->Tmax;
673 giacomo 349
 
707 anton 350
  et->U = et->Umax;
351
  et->oldU = 0;
352
  et->T = et->Tmin;
353
  et->dltimer = -1;
673 giacomo 354
 
744 anton 355
  et->flags |= ELASTIC_PRESENT;
356
  if (ELASTIC_compress(lev) == -1) {
357
    et->flags &= ~ELASTIC_PRESENT;
358
#ifdef ELASTIC_DEBUG
359
    cprintf("ELASTIC_public_create: compression failed!\n");
360
#endif
361
    return -1;
362
  }
363
 
741 giacomo 364
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].avail_time);
365
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,proc_table[p].wcet);
744 anton 366
 
674 giacomo 367
  proc_table[p].control    |= CONTROL_CAP;
673 giacomo 368
 
697 anton 369
  return 0;
671 giacomo 370
}
371
 
697 anton 372
 
671 giacomo 373
static void ELASTIC_public_detach(LEVEL l, PID p)
374
{
707 anton 375
  //ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
671 giacomo 376
 
377
}
378
 
379
static int ELASTIC_public_eligible(LEVEL l, PID p)
380
{
707 anton 381
  //ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
671 giacomo 382
 
383
  return 0;
384
 
385
}
386
 
387
static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop)
388
{
389
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
674 giacomo 390
 
671 giacomo 391
  level_table[ lev->scheduling_level ]->
392
    private_dispatch(lev->scheduling_level,p,nostop);
674 giacomo 393
 
671 giacomo 394
}
395
 
396
static void ELASTIC_public_epilogue(LEVEL l, PID p)
397
{
398
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
399
 
674 giacomo 400
  /* check if the wcet is finished... */
401
  if (proc_table[p].avail_time <= 0) {
402
 
707 anton 403
    TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,
404
                    (unsigned short int)proc_table[p].context,0);
674 giacomo 405
    kern_raise(XWCET_VIOLATION,p);
406
 
407
  }
691 anton 408
 
707 anton 409
  level_table[lev->scheduling_level]->
674 giacomo 410
      private_epilogue(lev->scheduling_level,p);
411
 
671 giacomo 412
}
413
 
414
static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t)
415
{
416
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
707 anton 417
  ELASTIC_task_descr *et = &lev->elist[p];
671 giacomo 418
 
674 giacomo 419
  /* check if we are not in the SLEEP state */
420
  if (proc_table[p].status != SLEEP) {
421
    return;
422
  }
423
 
424
  ELASTIC_activation(lev,p,t);
425
 
426
  /* Next activation */
707 anton 427
  et->dltimer = kern_event_post(&et->dline, ELASTIC_timer_act, (void *)(p));
674 giacomo 428
 
671 giacomo 429
}
430
 
431
static void ELASTIC_public_unblock(LEVEL l, PID p)
432
{
433
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
434
  struct timespec acttime;
435
 
436
  kern_gettime(&acttime);
437
 
438
  ELASTIC_activation(lev,p,&acttime);
439
 
440
}
441
 
442
static void ELASTIC_public_block(LEVEL l, PID p)
443
{
444
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
707 anton 445
  ELASTIC_task_descr *et = &lev->elist[p];
671 giacomo 446
 
707 anton 447
  level_table[lev->scheduling_level]->
671 giacomo 448
    private_extract(lev->scheduling_level,p);
707 anton 449
  et->flags &= ~ELASTIC_JOB_PRESENT;
671 giacomo 450
 
451
}
452
 
453
static int ELASTIC_public_message(LEVEL l, PID p, void *m)
454
{
455
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
737 anton 456
  ELASTIC_task_descr *et = &lev->elist[p];
671 giacomo 457
 
458
  switch((long)(m)) {
459
 
460
    case (long)(NULL):
461
 
707 anton 462
      level_table[lev->scheduling_level]->
676 giacomo 463
        private_extract(lev->scheduling_level,p);
737 anton 464
      et->flags &= ~ELASTIC_JOB_PRESENT;
676 giacomo 465
 
683 giacomo 466
      proc_table[p].status = ELASTIC_IDLE;
676 giacomo 467
 
671 giacomo 468
      jet_update_endcycle(); /* Update the Jet data... */
469
      TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l);
470
 
471
      break;
472
 
473
    case 1:
474
 
676 giacomo 475
      level_table[ lev->scheduling_level ]->
476
        private_extract(lev->scheduling_level,p);
737 anton 477
      et->flags &= ~ELASTIC_JOB_PRESENT;
676 giacomo 478
 
479
      proc_table[p].status = SLEEP;
480
 
671 giacomo 481
      TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l);
482
 
483
      break;
484
 
485
  }
486
 
487
  return 0;
488
 
489
}
490
 
491
static void ELASTIC_public_end(LEVEL l, PID p)
492
{
493
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
737 anton 494
  ELASTIC_task_descr *et = &lev->elist[p];
671 giacomo 495
 
746 anton 496
  if (et->flags & ELASTIC_JOB_PRESENT) {
497
    level_table[ lev->scheduling_level ]->
498
      private_extract(lev->scheduling_level,p);
499
    et->flags &= ~ELASTIC_JOB_PRESENT;
500
  }
671 giacomo 501
 
502
}
503
 
504
/*+ Registration function +*/
700 anton 505
LEVEL ELASTIC_register_level(int flags, LEVEL master, ext_bandwidth_t U)
671 giacomo 506
{
507
  LEVEL l;            /* the level that we register */
508
  ELASTIC_level_des *lev;  /* for readableness only */
509
  PID i;
510
 
511
  printk("ELASTIC_register_level\n");
512
 
513
  /* request an entry in the level_table */
514
  l = level_alloc_descriptor(sizeof(ELASTIC_level_des));
515
 
516
  lev = (ELASTIC_level_des *)level_table[l];
517
 
518
  /* fill the standard descriptor */
519
  if (flags & ELASTIC_ENABLE_GUARANTEE)
520
    lev->l.public_guarantee = ELASTIC_public_guarantee;
521
  else
522
    lev->l.public_guarantee = NULL;
523
  lev->l.public_create    = ELASTIC_public_create;
524
  lev->l.public_detach    = ELASTIC_public_detach;
525
  lev->l.public_end       = ELASTIC_public_end;
526
  lev->l.public_eligible  = ELASTIC_public_eligible;
527
  lev->l.public_dispatch  = ELASTIC_public_dispatch;
528
  lev->l.public_epilogue  = ELASTIC_public_epilogue;
529
  lev->l.public_activate  = ELASTIC_public_activate;
530
  lev->l.public_unblock   = ELASTIC_public_unblock;
531
  lev->l.public_block     = ELASTIC_public_block;
532
  lev->l.public_message   = ELASTIC_public_message;
533
 
741 giacomo 534
  lev->elist = kern_alloc(MAX_PROC * sizeof(ELASTIC_task_descr));
535
 
676 giacomo 536
  /* fill the ELASTIC task descriptor part */
671 giacomo 537
  for (i=0; i<MAX_PROC; i++) {
538
     NULL_TIMESPEC(&(lev->elist[i].dline));
539
     lev->elist[i].Tmin = 0;
540
     lev->elist[i].Tmax = 0;
691 anton 541
     lev->elist[i].T = 0;
697 anton 542
     lev->elist[i].U = 0;
691 anton 543
     lev->elist[i].C = 0;
544
     lev->elist[i].E = 0;
671 giacomo 545
     lev->elist[i].beta = 0;
707 anton 546
     lev->elist[i].flags = 0;
671 giacomo 547
  }
548
 
741 giacomo 549
  lev->c_scaling_factor = SCALING_UNIT;
550
 
691 anton 551
  lev->U = U;
671 giacomo 552
 
553
  lev->scheduling_level = master;
554
 
555
  lev->current_level = l;
556
 
707 anton 557
  lev->flags = 0;
671 giacomo 558
 
559
  return l;
560
}
561
 
707 anton 562
 
563
/* Force the period of task p to a given value */
564
 
565
int ELASTIC_set_period(PID p, TIME period) {
566
 
567
  SYS_FLAGS f;
745 giacomo 568
  int saveE;          
569
  unsigned int temp;
707 anton 570
  ext_bandwidth_t saveU;
571
 
572
  f = kern_fsave();
573
 
574
  ELASTIC_level_des *lev;
575
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
576
  ELASTIC_task_descr *et = &lev->elist[p];
577
 
578
  saveE = et->E;
579
  saveU = et->U;
580
 
737 anton 581
  et->E = 0;  /* set elasticity to zero to force period */
745 giacomo 582
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,temp);
583
  et->U = ((long long)MAX_BANDWIDTH * (long long)(temp))/((long long)period);
707 anton 584
 
585
  if (ELASTIC_compress(lev) == -1) {
586
#ifdef ELASTIC_DEBUG
587
    cprintf("ELASTIC_set_period failed: could not compress\n");
588
#endif
589
    et->E = saveE;
590
    et->U = saveU;
591
    kern_frestore(f);
592
    return -1;
593
  }
594
 
595
  et->E = saveE;     /* Restore E when compression is done */
596
  kern_frestore(f);
597
  return 0;
598
}
708 giacomo 599
 
600
int ELASTIC_get_period(PID p) {
601
 
602
  SYS_FLAGS f;
603
  ELASTIC_level_des *lev;
604
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 605
  TIME retval;
708 giacomo 606
 
607
  f = kern_fsave();
608
 
609
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
737 anton 610
    retval = lev->elist[p].T;
708 giacomo 611
    kern_frestore(f);
737 anton 612
    return retval;
708 giacomo 613
 
614
  } else {
615
 
616
    kern_frestore(f);
617
    return -1;
618
 
619
  }
620
 
621
}
622
 
744 anton 623
 
746 anton 624
int ELASTIC_set_Tmin(PID p, TIME Tmin)
625
{
626
  SYS_FLAGS f;
627
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
628
  ELASTIC_task_descr *et = &lev->elist[p];
629
  TIME saveTmin;
630
 
631
  f = kern_fsave();
632
 
633
  if (et->flags & ELASTIC_PRESENT) {
634
 
635
    saveTmin = et->Tmin;
636
 
637
    et->Tmin = Tmin;
638
    if (ELASTIC_compress(lev) == -1) {
639
#ifdef ELASTIC_DEBUG
640
      cprintf("ELASTIC_set_Tmin failed: could not compress\n");
641
#endif
642
      et->Tmin = saveTmin;
643
      kern_frestore(f);
644
      return -1;
645
    }
646
 
647
    kern_frestore(f);
648
    return 0;
649
 
650
  } else {
651
 
652
    kern_frestore(f);
653
    return -1;
654
  }
655
}
656
 
657
 
744 anton 658
int ELASTIC_get_Tmin(PID p) {
659
 
660
  SYS_FLAGS f;
661
  ELASTIC_level_des *lev;
662
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
663
  TIME retval;
664
 
665
  f = kern_fsave();
666
 
667
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
668
    retval = lev->elist[p].Tmin;
669
    kern_frestore(f);
670
    return retval;
671
 
672
  } else {
673
 
674
    kern_frestore(f);
675
    return -1;
676
 
677
  }
678
 
679
}
680
 
681
 
682
int ELASTIC_get_Tmax(PID p) {
683
 
684
  SYS_FLAGS f;
685
  ELASTIC_level_des *lev;
686
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
687
  TIME retval;
688
 
689
  f = kern_fsave();
690
 
691
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
692
    retval = lev->elist[p].Tmax;
693
    kern_frestore(f);
694
    return retval;
695
 
696
  } else {
697
 
698
    kern_frestore(f);
699
    return -1;
700
 
701
  }
702
 
703
}
704
 
705
 
706
int ELASTIC_get_C(PID p) {
707
 
708
  SYS_FLAGS f;
709
  ELASTIC_level_des *lev;
710
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
711
  TIME retval;
712
 
713
  f = kern_fsave();
714
 
715
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
716
    retval = lev->elist[p].C;
717
    kern_frestore(f);
718
    return retval;
719
 
720
  } else {
721
 
722
    kern_frestore(f);
723
    return -1;
724
 
725
  }
726
 
727
}
728
 
729
 
737 anton 730
int ELASTIC_set_E(PID p, int E)
731
{
708 giacomo 732
  SYS_FLAGS f;
733
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
734
  ELASTIC_task_descr *et = &lev->elist[p];
735
  int saveE;
736
 
737
  f = kern_fsave();
737 anton 738
 
708 giacomo 739
  if (et->flags & ELASTIC_PRESENT) {
740
 
741
    saveE = et->E;
737 anton 742
 
743
    et->E = E;
708 giacomo 744
    if (ELASTIC_compress(lev) == -1) {
745
#ifdef ELASTIC_DEBUG
746
      cprintf("ELASTIC_set_E failed: could not compress\n");
747
#endif
748
      et->E = saveE;
749
      kern_frestore(f);
750
      return -1;
751
    }
737 anton 752
 
708 giacomo 753
    kern_frestore(f);
754
    return 0;
737 anton 755
 
708 giacomo 756
  } else {
737 anton 757
 
708 giacomo 758
    kern_frestore(f);
759
    return -1;
760
  }
761
}
762
 
763
int ELASTIC_get_E(PID p) {
737 anton 764
 
708 giacomo 765
  SYS_FLAGS f;
766
  ELASTIC_level_des *lev;
767
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 768
 
708 giacomo 769
  f = kern_fsave();
737 anton 770
 
708 giacomo 771
  if (lev->elist[p].flags & ELASTIC_PRESENT) {
737 anton 772
 
708 giacomo 773
    kern_frestore(f);
774
    return lev->elist[p].E;
737 anton 775
 
708 giacomo 776
  } else {
737 anton 777
 
708 giacomo 778
    kern_frestore(f);
779
    return -1;
780
  }
781
}
782
 
783
int ELASTIC_set_beta(PID p, int beta) {
737 anton 784
 
708 giacomo 785
  SYS_FLAGS f;
786
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
787
  ELASTIC_task_descr *et = &lev->elist[p];
788
  int saveBeta;
789
 
790
  f = kern_fsave();
737 anton 791
 
708 giacomo 792
  if (et->flags & ELASTIC_PRESENT) {
737 anton 793
 
708 giacomo 794
    saveBeta = et->beta;
737 anton 795
 
796
    et->beta = beta;
797
 
708 giacomo 798
    if (ELASTIC_compress(lev) == -1) {
799
#ifdef ELASTIC_DEBUG
800
      cprintf("ELASTIC_set_beta failed: could not compress\n");
801
#endif
802
      et->beta = saveBeta;
803
      kern_frestore(f);
804
      return -1;
805
    }
737 anton 806
 
708 giacomo 807
    kern_frestore(f);
808
    return 0;
737 anton 809
 
708 giacomo 810
  } else {
737 anton 811
 
708 giacomo 812
    kern_frestore(f);
813
    return -1;
737 anton 814
 
708 giacomo 815
  }
737 anton 816
 
708 giacomo 817
}
818
 
819
int ELASTIC_get_beta(PID p) {
737 anton 820
 
708 giacomo 821
  SYS_FLAGS f;
822
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 823
  int retval;
824
 
708 giacomo 825
  f = kern_fsave();
737 anton 826
 
708 giacomo 827
  if (lev->elist[p].flags & ELASTIC_PRESENT) {
737 anton 828
    retval = lev->elist[p].beta;
708 giacomo 829
    kern_frestore(f);
737 anton 830
    return retval;
831
 
708 giacomo 832
  } else {
737 anton 833
 
708 giacomo 834
    kern_frestore(f);
835
    return -1;
737 anton 836
 
708 giacomo 837
  }
737 anton 838
 
708 giacomo 839
}
840
 
841
int ELASTIC_set_bandwidth(LEVEL level, ext_bandwidth_t U) {
737 anton 842
 
708 giacomo 843
  SYS_FLAGS f;
844
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];
845
 
846
  f = kern_fsave();
847
 
848
  lev->U = U;
849
 
850
  if (ELASTIC_compress(lev) == -1) {
851
#ifdef ELASTIC_DEBUG
852
    cprintf("ELASTIC_set_bandwidth failed: could not compress\n");
853
#endif
854
    kern_frestore(f);
855
    return -1;
856
  }
737 anton 857
 
708 giacomo 858
  kern_frestore(f);
859
  return 0;
737 anton 860
 
708 giacomo 861
}
862
 
863
ext_bandwidth_t ELASTIC_get_bandwidth(LEVEL level) {
737 anton 864
 
708 giacomo 865
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];;
866
 
867
  return lev->U;
737 anton 868
 
708 giacomo 869
}
741 giacomo 870
 
871
int ELASTIC_set_scaling_factor(LEVEL level, int scaling_factor) {
872
 
873
  SYS_FLAGS f;
874
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];
875
 
876
  f = kern_fsave();
877
 
878
  lev->c_scaling_factor = scaling_factor;
879
 
880
  if (ELASTIC_compress(lev) == -1) {
881
#ifdef ELASTIC_DEBUG
882
    cprintf("ELASTIC_set_scaling_factor failed: could not compress\n");
883
#endif
884
    kern_frestore(f);
885
    return -1;
886
  }
887
 
888
  kern_frestore(f);
889
  return 0;
890
 
891
}
892
 
893
int ELASTIC_get_scaling_factor(LEVEL level) {
894
 
895
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];;
896
 
897
  return lev->c_scaling_factor;
898
 
899
}