Subversion Repositories shark

Rev

Rev 744 | 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
 
496
  level_table[ lev->scheduling_level ]->
497
    private_extract(lev->scheduling_level,p);
737 anton 498
  et->flags &= ~ELASTIC_JOB_PRESENT;
671 giacomo 499
 
500
}
501
 
502
/*+ Registration function +*/
700 anton 503
LEVEL ELASTIC_register_level(int flags, LEVEL master, ext_bandwidth_t U)
671 giacomo 504
{
505
  LEVEL l;            /* the level that we register */
506
  ELASTIC_level_des *lev;  /* for readableness only */
507
  PID i;
508
 
509
  printk("ELASTIC_register_level\n");
510
 
511
  /* request an entry in the level_table */
512
  l = level_alloc_descriptor(sizeof(ELASTIC_level_des));
513
 
514
  lev = (ELASTIC_level_des *)level_table[l];
515
 
516
  /* fill the standard descriptor */
517
  if (flags & ELASTIC_ENABLE_GUARANTEE)
518
    lev->l.public_guarantee = ELASTIC_public_guarantee;
519
  else
520
    lev->l.public_guarantee = NULL;
521
  lev->l.public_create    = ELASTIC_public_create;
522
  lev->l.public_detach    = ELASTIC_public_detach;
523
  lev->l.public_end       = ELASTIC_public_end;
524
  lev->l.public_eligible  = ELASTIC_public_eligible;
525
  lev->l.public_dispatch  = ELASTIC_public_dispatch;
526
  lev->l.public_epilogue  = ELASTIC_public_epilogue;
527
  lev->l.public_activate  = ELASTIC_public_activate;
528
  lev->l.public_unblock   = ELASTIC_public_unblock;
529
  lev->l.public_block     = ELASTIC_public_block;
530
  lev->l.public_message   = ELASTIC_public_message;
531
 
741 giacomo 532
  lev->elist = kern_alloc(MAX_PROC * sizeof(ELASTIC_task_descr));
533
 
676 giacomo 534
  /* fill the ELASTIC task descriptor part */
671 giacomo 535
  for (i=0; i<MAX_PROC; i++) {
536
     NULL_TIMESPEC(&(lev->elist[i].dline));
537
     lev->elist[i].Tmin = 0;
538
     lev->elist[i].Tmax = 0;
691 anton 539
     lev->elist[i].T = 0;
697 anton 540
     lev->elist[i].U = 0;
691 anton 541
     lev->elist[i].C = 0;
542
     lev->elist[i].E = 0;
671 giacomo 543
     lev->elist[i].beta = 0;
707 anton 544
     lev->elist[i].flags = 0;
671 giacomo 545
  }
546
 
741 giacomo 547
  lev->c_scaling_factor = SCALING_UNIT;
548
 
691 anton 549
  lev->U = U;
671 giacomo 550
 
551
  lev->scheduling_level = master;
552
 
553
  lev->current_level = l;
554
 
707 anton 555
  lev->flags = 0;
671 giacomo 556
 
557
  return l;
558
}
559
 
707 anton 560
 
561
/* Force the period of task p to a given value */
562
 
563
int ELASTIC_set_period(PID p, TIME period) {
564
 
565
  SYS_FLAGS f;
745 giacomo 566
  int saveE;          
567
  unsigned int temp;
707 anton 568
  ext_bandwidth_t saveU;
569
 
570
  f = kern_fsave();
571
 
572
  ELASTIC_level_des *lev;
573
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
574
  ELASTIC_task_descr *et = &lev->elist[p];
575
 
576
  saveE = et->E;
577
  saveU = et->U;
578
 
737 anton 579
  et->E = 0;  /* set elasticity to zero to force period */
745 giacomo 580
  mul32div32to32(et->C,lev->c_scaling_factor,SCALING_UNIT,temp);
581
  et->U = ((long long)MAX_BANDWIDTH * (long long)(temp))/((long long)period);
707 anton 582
 
583
  if (ELASTIC_compress(lev) == -1) {
584
#ifdef ELASTIC_DEBUG
585
    cprintf("ELASTIC_set_period failed: could not compress\n");
586
#endif
587
    et->E = saveE;
588
    et->U = saveU;
589
    kern_frestore(f);
590
    return -1;
591
  }
592
 
593
  et->E = saveE;     /* Restore E when compression is done */
594
  kern_frestore(f);
595
  return 0;
596
}
708 giacomo 597
 
598
int ELASTIC_get_period(PID p) {
599
 
600
  SYS_FLAGS f;
601
  ELASTIC_level_des *lev;
602
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 603
  TIME retval;
708 giacomo 604
 
605
  f = kern_fsave();
606
 
607
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
737 anton 608
    retval = lev->elist[p].T;
708 giacomo 609
    kern_frestore(f);
737 anton 610
    return retval;
708 giacomo 611
 
612
  } else {
613
 
614
    kern_frestore(f);
615
    return -1;
616
 
617
  }
618
 
619
}
620
 
744 anton 621
 
622
int ELASTIC_get_Tmin(PID p) {
623
 
624
  SYS_FLAGS f;
625
  ELASTIC_level_des *lev;
626
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
627
  TIME retval;
628
 
629
  f = kern_fsave();
630
 
631
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
632
    retval = lev->elist[p].Tmin;
633
    kern_frestore(f);
634
    return retval;
635
 
636
  } else {
637
 
638
    kern_frestore(f);
639
    return -1;
640
 
641
  }
642
 
643
}
644
 
645
 
646
int ELASTIC_get_Tmax(PID p) {
647
 
648
  SYS_FLAGS f;
649
  ELASTIC_level_des *lev;
650
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
651
  TIME retval;
652
 
653
  f = kern_fsave();
654
 
655
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
656
    retval = lev->elist[p].Tmax;
657
    kern_frestore(f);
658
    return retval;
659
 
660
  } else {
661
 
662
    kern_frestore(f);
663
    return -1;
664
 
665
  }
666
 
667
}
668
 
669
 
670
int ELASTIC_get_C(PID p) {
671
 
672
  SYS_FLAGS f;
673
  ELASTIC_level_des *lev;
674
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
675
  TIME retval;
676
 
677
  f = kern_fsave();
678
 
679
  if (lev->elist[p].flags & ELASTIC_PRESENT) {  
680
    retval = lev->elist[p].C;
681
    kern_frestore(f);
682
    return retval;
683
 
684
  } else {
685
 
686
    kern_frestore(f);
687
    return -1;
688
 
689
  }
690
 
691
}
692
 
693
 
737 anton 694
int ELASTIC_set_E(PID p, int E)
695
{
708 giacomo 696
  SYS_FLAGS f;
697
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
698
  ELASTIC_task_descr *et = &lev->elist[p];
699
  int saveE;
700
 
701
  f = kern_fsave();
737 anton 702
 
708 giacomo 703
  if (et->flags & ELASTIC_PRESENT) {
704
 
705
    saveE = et->E;
737 anton 706
 
707
    et->E = E;
708 giacomo 708
    if (ELASTIC_compress(lev) == -1) {
709
#ifdef ELASTIC_DEBUG
710
      cprintf("ELASTIC_set_E failed: could not compress\n");
711
#endif
712
      et->E = saveE;
713
      kern_frestore(f);
714
      return -1;
715
    }
737 anton 716
 
708 giacomo 717
    kern_frestore(f);
718
    return 0;
737 anton 719
 
708 giacomo 720
  } else {
737 anton 721
 
708 giacomo 722
    kern_frestore(f);
723
    return -1;
724
  }
725
}
726
 
727
int ELASTIC_get_E(PID p) {
737 anton 728
 
708 giacomo 729
  SYS_FLAGS f;
730
  ELASTIC_level_des *lev;
731
  lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 732
 
708 giacomo 733
  f = kern_fsave();
737 anton 734
 
708 giacomo 735
  if (lev->elist[p].flags & ELASTIC_PRESENT) {
737 anton 736
 
708 giacomo 737
    kern_frestore(f);
738
    return lev->elist[p].E;
737 anton 739
 
708 giacomo 740
  } else {
737 anton 741
 
708 giacomo 742
    kern_frestore(f);
743
    return -1;
744
  }
745
}
746
 
747
int ELASTIC_set_beta(PID p, int beta) {
737 anton 748
 
708 giacomo 749
  SYS_FLAGS f;
750
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
751
  ELASTIC_task_descr *et = &lev->elist[p];
752
  int saveBeta;
753
 
754
  f = kern_fsave();
737 anton 755
 
708 giacomo 756
  if (et->flags & ELASTIC_PRESENT) {
737 anton 757
 
708 giacomo 758
    saveBeta = et->beta;
737 anton 759
 
760
    et->beta = beta;
761
 
708 giacomo 762
    if (ELASTIC_compress(lev) == -1) {
763
#ifdef ELASTIC_DEBUG
764
      cprintf("ELASTIC_set_beta failed: could not compress\n");
765
#endif
766
      et->beta = saveBeta;
767
      kern_frestore(f);
768
      return -1;
769
    }
737 anton 770
 
708 giacomo 771
    kern_frestore(f);
772
    return 0;
737 anton 773
 
708 giacomo 774
  } else {
737 anton 775
 
708 giacomo 776
    kern_frestore(f);
777
    return -1;
737 anton 778
 
708 giacomo 779
  }
737 anton 780
 
708 giacomo 781
}
782
 
783
int ELASTIC_get_beta(PID p) {
737 anton 784
 
708 giacomo 785
  SYS_FLAGS f;
786
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[proc_table[p].task_level];
737 anton 787
  int retval;
788
 
708 giacomo 789
  f = kern_fsave();
737 anton 790
 
708 giacomo 791
  if (lev->elist[p].flags & ELASTIC_PRESENT) {
737 anton 792
    retval = lev->elist[p].beta;
708 giacomo 793
    kern_frestore(f);
737 anton 794
    return retval;
795
 
708 giacomo 796
  } else {
737 anton 797
 
708 giacomo 798
    kern_frestore(f);
799
    return -1;
737 anton 800
 
708 giacomo 801
  }
737 anton 802
 
708 giacomo 803
}
804
 
805
int ELASTIC_set_bandwidth(LEVEL level, ext_bandwidth_t U) {
737 anton 806
 
708 giacomo 807
  SYS_FLAGS f;
808
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];
809
 
810
  f = kern_fsave();
811
 
812
  lev->U = U;
813
 
814
  if (ELASTIC_compress(lev) == -1) {
815
#ifdef ELASTIC_DEBUG
816
    cprintf("ELASTIC_set_bandwidth failed: could not compress\n");
817
#endif
818
    kern_frestore(f);
819
    return -1;
820
  }
737 anton 821
 
708 giacomo 822
  kern_frestore(f);
823
  return 0;
737 anton 824
 
708 giacomo 825
}
826
 
827
ext_bandwidth_t ELASTIC_get_bandwidth(LEVEL level) {
737 anton 828
 
708 giacomo 829
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];;
830
 
831
  return lev->U;
737 anton 832
 
708 giacomo 833
}
741 giacomo 834
 
835
int ELASTIC_set_scaling_factor(LEVEL level, int scaling_factor) {
836
 
837
  SYS_FLAGS f;
838
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];
839
 
840
  f = kern_fsave();
841
 
842
  lev->c_scaling_factor = scaling_factor;
843
 
844
  if (ELASTIC_compress(lev) == -1) {
845
#ifdef ELASTIC_DEBUG
846
    cprintf("ELASTIC_set_scaling_factor failed: could not compress\n");
847
#endif
848
    kern_frestore(f);
849
    return -1;
850
  }
851
 
852
  kern_frestore(f);
853
  return 0;
854
 
855
}
856
 
857
int ELASTIC_get_scaling_factor(LEVEL level) {
858
 
859
  ELASTIC_level_des *lev = (ELASTIC_level_des *)level_table[level];;
860
 
861
  return lev->c_scaling_factor;
862
 
863
}