Subversion Repositories shark

Rev

Rev 671 | Rev 674 | 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
 *
8
 * Authors     :
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
 
42
#include <stdlib.h>
43
 
44
#include <modules/elastic.h>
45
 
46
#include <tracer.h>
47
 
673 giacomo 48
#define ELASTIC_EMPTY_SLOT    0
49
#define ELASTIC_PRESENT       1
50
#define ELASTIC_SAVE_ARRIVALS 2
671 giacomo 51
 
52
typedef struct {
53
 
54
  struct timespec dline;
55
 
56
  TIME Tmin;
57
  TIME Tmax;
58
 
59
  TIME period;
60
  TIME wcet;
673 giacomo 61
 
62
  bandwidth_t Up;
671 giacomo 63
 
64
  int  kelastic;
65
  int  beta;
66
 
67
  int  nact;
68
 
69
  int  flags;
70
 
71
} ELASTIC_task_descr;
72
 
73
typedef struct {
74
  level_des l;     /*+ the standard level descriptor          +*/
75
 
76
  bandwidth_t U;   /*+ the used bandwidth by the server       +*/
77
 
78
  ELASTIC_task_descr *elist;
79
 
80
  LEVEL scheduling_level;
81
 
82
  LEVEL current_level;
83
 
84
  int flags;
85
 
86
} ELASTIC_level_des;
87
 
673 giacomo 88
static int ELASTIC_recompute() {
89
 
90
  return 0;
91
 
92
}
93
 
94
static int ELASTIC_check_guarantie() {
95
 
96
  return 0;
97
 
98
}
99
 
671 giacomo 100
static void ELASTIC_activation(ELASTIC_level_des *lev,
101
                               PID p,
102
                               struct timespec *acttime)
103
{
104
  JOB_TASK_MODEL job;
105
 
106
  /*
107
  job_task_default_model(job, lev->cbs_dline[p]);
108
  job_task_def_noexc(job);
109
  level_table[ lev->scheduling_level ]->
110
    private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job);
111
 
112
  */
113
 
114
}
115
 
116
/* The on-line guarantee is enabled only if the appropriate flag is set... */
117
static int ELASTIC_public_guarantee(LEVEL l, bandwidth_t *freebandwidth)
118
{
119
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
120
 
673 giacomo 121
  return 0;
122
 
671 giacomo 123
}
124
 
125
static int ELASTIC_public_create(LEVEL l, PID p, TASK_MODEL *m)
126
{
127
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
128
  ELASTIC_TASK_MODEL *elastic;
129
 
130
  if (m->pclass != ELASTIC_PCLASS) return -1;
131
  if (m->level != 0 && m->level != l) return -1;
132
  elastic = (ELASTIC_TASK_MODEL *)m;
133
 
673 giacomo 134
  if (elastic->wcet == 0) return -1;
135
  if (elastic->Tmin > elastic->Tmax) return -1;
136
  if (elastic->Tmax == 0) return -1;
137
 
138
  lev->elist[p].flags |= ELASTIC_PRESENT;
139
 
140
  NULL_TIMESPEC(&(lev->elist[p].dline));
141
  lev->elist[p].Tmin = elastic->Tmin;
142
  lev->elist[p].Tmax = elastic->Tmax;
143
  lev->elist[p].wcet = elastic->wcet;
144
  lev->elist[p].kelastic = elastic->kelastic;
145
  lev->elist[p].beta = elastic->beta;
146
 
147
  if (lev->flags & ELASTIC_ENABLE_GUARANTEE)
148
        if (ELASTIC_check_guarantie() != 0) {
149
                lev->elist[p].flags = ELASTIC_EMPTY_SLOT;
150
                return -1;
151
        }
152
 
153
  ELASTIC_recompute();
154
 
155
  if (lev->elist[p].period == 0) {
156
        lev->elist[p].flags = ELASTIC_EMPTY_SLOT;
157
        return -1;
158
  }
159
 
160
  lev->elist[p].flags |= ELASTIC_PRESENT;
161
 
162
  proc_table[p].wcet       = elastic->wcet;
163
  proc_table[p].control   &= ~CONTROL_CAP;
164
 
165
  if (elastic->arrivals == SAVE_ARRIVALS)
166
    lev->elist[p].flags |= ELASTIC_SAVE_ARRIVALS;
167
 
671 giacomo 168
  return 0; /* OK, also if the task cannot be guaranteed... */
169
 
170
}
171
 
172
static void ELASTIC_public_detach(LEVEL l, PID p)
173
{
174
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
175
 
176
}
177
 
178
static int ELASTIC_public_eligible(LEVEL l, PID p)
179
{
180
 
181
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
182
  JOB_TASK_MODEL job;
183
 
184
  return 0;
185
 
186
}
187
 
188
static void ELASTIC_public_dispatch(LEVEL l, PID p, int nostop)
189
{
190
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
191
  level_table[ lev->scheduling_level ]->
192
    private_dispatch(lev->scheduling_level,p,nostop);
193
}
194
 
195
static void ELASTIC_public_epilogue(LEVEL l, PID p)
196
{
197
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
198
  JOB_TASK_MODEL job;
199
 
200
}
201
 
202
static void ELASTIC_public_activate(LEVEL l, PID p, struct timespec *t)
203
{
204
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
205
 
206
}
207
 
208
static void ELASTIC_public_unblock(LEVEL l, PID p)
209
{
210
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
211
  struct timespec acttime;
212
 
213
  kern_gettime(&acttime);
214
 
215
  ELASTIC_activation(lev,p,&acttime);
216
 
217
}
218
 
219
static void ELASTIC_public_block(LEVEL l, PID p)
220
{
221
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
222
 
223
  level_table[ lev->scheduling_level ]->
224
    private_extract(lev->scheduling_level,p);
225
 
226
}
227
 
228
static int ELASTIC_public_message(LEVEL l, PID p, void *m)
229
{
230
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
231
 
232
  switch((long)(m)) {
233
 
234
    case (long)(NULL):
235
 
236
      jet_update_endcycle(); /* Update the Jet data... */
237
      TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,(unsigned short int)proc_table[p].context,(unsigned int)l);
238
 
239
      break;
240
 
241
    case 1:
242
 
243
      TRACER_LOGEVENT(FTrace_EVT_task_disable,(unsigned short int)proc_table[p].context,(unsigned int)l);
244
 
245
      break;
246
 
247
  }
248
 
249
  return 0;
250
 
251
}
252
 
253
static void ELASTIC_public_end(LEVEL l, PID p)
254
{
255
  ELASTIC_level_des *lev = (ELASTIC_level_des *)(level_table[l]);
256
 
257
  level_table[ lev->scheduling_level ]->
258
    private_extract(lev->scheduling_level,p);
259
 
260
}
261
 
262
/*+ Registration function +*/
263
LEVEL ELASTIC_register_level(int flags, LEVEL master)
264
{
265
  LEVEL l;            /* the level that we register */
266
  ELASTIC_level_des *lev;  /* for readableness only */
267
  PID i;
268
 
269
  printk("ELASTIC_register_level\n");
270
 
271
  /* request an entry in the level_table */
272
  l = level_alloc_descriptor(sizeof(ELASTIC_level_des));
273
 
274
  lev = (ELASTIC_level_des *)level_table[l];
275
 
276
  /* fill the standard descriptor */
277
  if (flags & ELASTIC_ENABLE_GUARANTEE)
278
    lev->l.public_guarantee = ELASTIC_public_guarantee;
279
  else
280
    lev->l.public_guarantee = NULL;
281
  lev->l.public_create    = ELASTIC_public_create;
282
  lev->l.public_detach    = ELASTIC_public_detach;
283
  lev->l.public_end       = ELASTIC_public_end;
284
  lev->l.public_eligible  = ELASTIC_public_eligible;
285
  lev->l.public_dispatch  = ELASTIC_public_dispatch;
286
  lev->l.public_epilogue  = ELASTIC_public_epilogue;
287
  lev->l.public_activate  = ELASTIC_public_activate;
288
  lev->l.public_unblock   = ELASTIC_public_unblock;
289
  lev->l.public_block     = ELASTIC_public_block;
290
  lev->l.public_message   = ELASTIC_public_message;
291
 
292
  lev->elist = malloc(MAX_PROC * sizeof(ELASTIC_task_descr));
293
  if (lev->elist == NULL) {
294
        printk("ELASTIC: Error allocating elastic task decriptor table\n");
295
        sys_end();
296
  }
297
 
298
  /* fill the CBS descriptor part */
299
  for (i=0; i<MAX_PROC; i++) {
300
     NULL_TIMESPEC(&(lev->elist[i].dline));
301
     lev->elist[i].Tmin = 0;
302
     lev->elist[i].Tmax = 0;
303
     lev->elist[i].period = 0;
304
     lev->elist[i].wcet = 0;
305
     lev->elist[i].kelastic = 0;
306
     lev->elist[i].beta = 0;
307
     lev->elist[i].nact = 0;
308
     lev->elist[i].flags = ELASTIC_EMPTY_SLOT;
309
  }
310
 
311
  lev->U = 0;
312
 
313
  lev->scheduling_level = master;
314
 
315
  lev->current_level = l;
316
 
317
  lev->flags = flags;
318
 
319
  return l;
320
}
321