Subversion Repositories shark

Rev

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

Rev Author Line No. Line
324 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
 *   Trimarchi Michael   <trimarchi@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2000 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARR2ANTY; without even the implied waRR2anty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
 
39
#include <ll/stdio.h>
40
#include <ll/string.h>
41
#include <kernel/model.h>
42
#include <kernel/descr.h>
43
#include <kernel/var.h>
44
#include <kernel/func.h>
45
#include "mpegstar.h"
808 trimarchi 46
#include "fsf_contract.h"
324 giacomo 47
#include "fsf_server.h"
48
 
338 giacomo 49
//#define MPEGSTAR_DEBUG
324 giacomo 50
 
51
/*+ Status used in the level +*/
52
#define MPEGSTAR_READY   MODULE_STATUS_BASE
53
 
343 giacomo 54
#define FRAME_IDLE 0
55
#define FRAME_DECODING 1
56
#define FRAME_SKIPPED 2
57
 
324 giacomo 58
typedef struct {
59
  level_des l;          /*+ the standard level descriptor          +*/
334 giacomo 60
 
61
  int server_Q;
62
  int server_T;
63
 
338 giacomo 64
  int budget;
65
  int current;
343 giacomo 66
  int status;
334 giacomo 67
 
324 giacomo 68
  int scheduling_level;
69
 
70
} MPEGSTAR_level_des;
71
 
72
static int MPEGSTAR_public_eligible(LEVEL l, PID p)
73
{
74
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
75
  return level_table[ lev->scheduling_level ]->
76
      private_eligible(lev->scheduling_level,p);
77
 
78
  return 0;
79
}
80
 
81
static int MPEGSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
82
{
83
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
84
 
334 giacomo 85
  #ifdef MPEGSTAR_DEBUG
86
    kern_printf("(MP:Crt:%d)",p);
87
  #endif
338 giacomo 88
 
89
  if (m->pclass != HARD_PCLASS) return -1;
334 giacomo 90
  if (m->level != 0 && m->level != l) return -1;
341 giacomo 91
  if (lev->current != NIL) return -1;
338 giacomo 92
 
93
  lev->current = p;
343 giacomo 94
  lev->status = FRAME_IDLE;
334 giacomo 95
 
96
  proc_table[p].avail_time = lev->server_Q;
338 giacomo 97
  proc_table[p].wcet       = lev->server_Q;                                                                                    
98
  proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP);                  
99
 
324 giacomo 100
  return 0; /* OK */
338 giacomo 101
 
324 giacomo 102
}
103
 
104
static void MPEGSTAR_public_dispatch(LEVEL l, PID p, int nostop)
105
{
106
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
107
 
338 giacomo 108
  #ifdef MPEGSTAR_DEBUG
109
     kern_printf("(MS:Dsp:%d)",p);
110
  #endif
111
 
112
  if (!nostop) {
339 giacomo 113
    level_table[ lev->scheduling_level ] ->
114
      private_dispatch(lev->scheduling_level, p, nostop);
338 giacomo 115
  }
334 giacomo 116
 
324 giacomo 117
}
118
 
119
static void MPEGSTAR_public_epilogue(LEVEL l, PID p)
120
{
121
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
343 giacomo 122
  int r;
334 giacomo 123
 
338 giacomo 124
  #ifdef MPEGSTAR_DEBUG
125
     kern_printf("(MS:Epi:%d)",p);
126
  #endif
127
 
334 giacomo 128
  level_table[ lev->scheduling_level ] ->
129
    private_epilogue(lev->scheduling_level,p);
343 giacomo 130
 
131
  r = SERVER_get_remain_capacity(lev->scheduling_level,lev->budget);
132
  if (r < 0) {
133
 
134
    #ifdef MPEGSTAR_DEBUG
135
      kern_printf("(MS:FRAME SKIP %d)",p);
136
    #endif
137
 
138
    lev->status = FRAME_SKIPPED;
139
 
140
    level_table[ lev->scheduling_level ]->
141
        private_extract(lev->scheduling_level, p);
142
 
143
  }  
144
 
324 giacomo 145
}
146
 
147
static void MPEGSTAR_public_activate(LEVEL l, PID p)
148
{
149
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
334 giacomo 150
  BUDGET_TASK_MODEL b;
338 giacomo 151
 
152
  budget_task_default_model(b, lev->budget);
334 giacomo 153
 
154
  #ifdef MPEGSTAR_DEBUG
338 giacomo 155
    kern_printf("(MP:Act:%d:%d)",p,lev->budget);
334 giacomo 156
  #endif
324 giacomo 157
 
343 giacomo 158
  lev->status = FRAME_DECODING;
159
 
334 giacomo 160
  level_table[ lev->scheduling_level ]->
161
    private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b);
162
 
324 giacomo 163
}
164
 
165
static void MPEGSTAR_public_unblock(LEVEL l, PID p)
166
{
167
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
168
 
169
}
170
 
171
static void MPEGSTAR_public_block(LEVEL l, PID p)
172
{  
173
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
174
 
175
}
176
 
177
static int MPEGSTAR_public_message(LEVEL l, PID p, void *m)
178
{
179
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
180
 
181
  switch ((long)(m)) {
182
 
183
    /* Task EndCycle */
184
    case (long)(NULL):
185
 
339 giacomo 186
      #ifdef MPEGSTAR_DEBUG
187
        kern_printf("(MS:EndCycle:%d)",p);
188
      #endif
338 giacomo 189
 
343 giacomo 190
      lev->status = FRAME_IDLE;
191
 
334 giacomo 192
      level_table[ lev->scheduling_level ]->
338 giacomo 193
        private_extract(lev->scheduling_level, p);
194
 
195
      level_table[ lev->scheduling_level ]->
334 giacomo 196
        public_message(lev->scheduling_level, p, NULL);
197
 
324 giacomo 198
      break;
199
 
200
    /* Task Disable */
201
    case (long)(1):
202
 
203
      break;
204
 
205
    default:
206
 
207
      break;
208
 
209
  }
210
 
211
  return 0;
212
 
213
}
214
 
215
static void MPEGSTAR_public_end(LEVEL l, PID p)
216
{
217
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
341 giacomo 218
 
219
  #ifdef MPEGSTAR_DEBUG
220
    kern_printf("(MS:End:%d)", p);
221
  #endif
324 giacomo 222
 
343 giacomo 223
  lev->current = NIL;
224
  lev->status = FRAME_IDLE;
225
  proc_table[p].status = FREE;
341 giacomo 226
 
324 giacomo 227
}
228
 
229
/* Registration functions */
230
 
231
/*+ Registration function:
232
    TIME slice                the slice for the Round Robin queue +*/
334 giacomo 233
LEVEL MPEGSTAR_register_level(int master)
324 giacomo 234
{
235
  LEVEL l;            /* the level that we register */
236
  MPEGSTAR_level_des *lev;  /* for readableness only */
237
 
238
  l = level_alloc_descriptor(sizeof(MPEGSTAR_level_des));
239
 
240
  lev = (MPEGSTAR_level_des *)level_table[l];
241
 
242
  lev->l.public_guarantee = NULL;
243
  lev->l.public_create    = MPEGSTAR_public_create;
244
  lev->l.public_end       = MPEGSTAR_public_end;
245
  lev->l.public_dispatch  = MPEGSTAR_public_dispatch;
246
  lev->l.public_epilogue  = MPEGSTAR_public_epilogue;
247
  lev->l.public_activate  = MPEGSTAR_public_activate;
248
  lev->l.public_unblock   = MPEGSTAR_public_unblock;
249
  lev->l.public_block     = MPEGSTAR_public_block;
250
  lev->l.public_message   = MPEGSTAR_public_message;
251
  lev->l.public_eligible  = MPEGSTAR_public_eligible;
252
 
338 giacomo 253
  lev->budget = NIL;
254
  lev->current = NIL;
343 giacomo 255
  lev->status = FRAME_IDLE;
339 giacomo 256
  lev->server_Q = 0;
257
  lev->server_T = 0;
334 giacomo 258
 
259
  lev->scheduling_level = master;
260
 
324 giacomo 261
  return l;
262
 
263
}
334 giacomo 264
 
265
int MPEGSTAR_setbudget(LEVEL l, PID p, int budget)
266
{
267
 
268
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
269
 
338 giacomo 270
  lev->budget = budget;
334 giacomo 271
 
272
  return 0;
273
 
274
}
275
 
276
int MPEGSTAR_getbudget(LEVEL l, PID p)
277
{
278
 
279
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
280
 
338 giacomo 281
  return lev->budget;
334 giacomo 282
 
283
}
284
 
285
int MPEGSTAR_budget_has_thread(LEVEL l, int budget)
338 giacomo 286
{                                                                                                                            
287
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
288
 
289
  if (lev->budget == budget) return 1;                                                                                                            
290
  return 0;
291
 
292
}
293
 
339 giacomo 294
int MPEGSTAR_rescale(int budget, TIME Q, TIME T)
334 giacomo 295
{
339 giacomo 296
  LEVEL l = SERVER_get_local_scheduler_level_from_budget(fsf_get_server_level(),budget);
334 giacomo 297
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
338 giacomo 298
 
661 giacomo 299
  SERVER_adjust_budget(lev->scheduling_level,Q,T,T,lev->budget);
338 giacomo 300
  lev->server_Q = Q;
301
  lev->server_T = T;
302
  if (lev->current != NIL) {
303
    proc_table[lev->current].avail_time = Q;
304
    proc_table[lev->current].wcet = Q;
305
  }
306
 
334 giacomo 307
  return 0;
308
}
340 giacomo 309
 
310
int MPEGSTAR_get_remain_capacity(int budget)
311
{
341 giacomo 312
  return SERVER_get_remain_capacity(fsf_get_server_level(),budget);
340 giacomo 313
}
341 giacomo 314
 
343 giacomo 315
int MPEGSTAR_get_last_reclaiming(int budget)
341 giacomo 316
{
317
  return SERVER_get_last_reclaiming(fsf_get_server_level(),exec_shadow);
318
}
343 giacomo 319
 
320
int MPEGSTAR_is_frame_skipped(int budget)
321
{
322
  LEVEL l = SERVER_get_local_scheduler_level_from_budget(fsf_get_server_level(),budget);
323
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
324
 
325
  if (lev->status == FRAME_SKIPPED)
326
    return 1;
327
  else
328
    return 0;
329
 
330
}