Subversion Repositories shark

Rev

Rev 340 | Rev 343 | 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 <kernel/trace.h>
46
#include "mpegstar.h"
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
 
54
/*+ the level redefinition for the Round Robin level +*/
55
typedef struct {
56
  level_des l;          /*+ the standard level descriptor          +*/
334 giacomo 57
 
58
  int server_Q;
59
  int server_T;
60
 
338 giacomo 61
  int budget;
62
  int current;
334 giacomo 63
 
324 giacomo 64
  int scheduling_level;
65
 
66
} MPEGSTAR_level_des;
67
 
68
static int MPEGSTAR_public_eligible(LEVEL l, PID p)
69
{
70
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
71
  return level_table[ lev->scheduling_level ]->
72
      private_eligible(lev->scheduling_level,p);
73
 
74
  return 0;
75
}
76
 
77
static int MPEGSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
78
{
79
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
80
 
334 giacomo 81
  #ifdef MPEGSTAR_DEBUG
82
    kern_printf("(MP:Crt:%d)",p);
83
  #endif
338 giacomo 84
 
85
  if (m->pclass != HARD_PCLASS) return -1;
334 giacomo 86
  if (m->level != 0 && m->level != l) return -1;
341 giacomo 87
  if (lev->current != NIL) return -1;
338 giacomo 88
 
89
  lev->current = p;
334 giacomo 90
 
91
  proc_table[p].avail_time = lev->server_Q;
338 giacomo 92
  proc_table[p].wcet       = lev->server_Q;                                                                                    
93
  proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP);                  
94
 
324 giacomo 95
  return 0; /* OK */
338 giacomo 96
 
324 giacomo 97
}
98
 
99
static void MPEGSTAR_public_dispatch(LEVEL l, PID p, int nostop)
100
{
101
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
102
 
338 giacomo 103
  #ifdef MPEGSTAR_DEBUG
104
     kern_printf("(MS:Dsp:%d)",p);
105
  #endif
106
 
107
  if (!nostop) {
339 giacomo 108
    level_table[ lev->scheduling_level ] ->
109
      private_dispatch(lev->scheduling_level, p, nostop);
338 giacomo 110
  }
334 giacomo 111
 
324 giacomo 112
}
113
 
114
static void MPEGSTAR_public_epilogue(LEVEL l, PID p)
115
{
116
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
334 giacomo 117
 
338 giacomo 118
  #ifdef MPEGSTAR_DEBUG
119
     kern_printf("(MS:Epi:%d)",p);
120
  #endif
121
 
334 giacomo 122
  level_table[ lev->scheduling_level ] ->
123
    private_epilogue(lev->scheduling_level,p);
324 giacomo 124
 
125
}
126
 
127
static void MPEGSTAR_public_activate(LEVEL l, PID p)
128
{
129
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
334 giacomo 130
  BUDGET_TASK_MODEL b;
338 giacomo 131
 
132
  budget_task_default_model(b, lev->budget);
334 giacomo 133
 
134
  #ifdef MPEGSTAR_DEBUG
338 giacomo 135
    kern_printf("(MP:Act:%d:%d)",p,lev->budget);
334 giacomo 136
  #endif
324 giacomo 137
 
334 giacomo 138
  level_table[ lev->scheduling_level ]->
139
    private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b);
140
 
324 giacomo 141
}
142
 
143
static void MPEGSTAR_public_unblock(LEVEL l, PID p)
144
{
145
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
146
 
147
}
148
 
149
static void MPEGSTAR_public_block(LEVEL l, PID p)
150
{  
151
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
152
 
153
}
154
 
155
static int MPEGSTAR_public_message(LEVEL l, PID p, void *m)
156
{
157
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
158
 
159
  switch ((long)(m)) {
160
 
161
    /* Task EndCycle */
162
    case (long)(NULL):
163
 
339 giacomo 164
      #ifdef MPEGSTAR_DEBUG
165
        kern_printf("(MS:EndCycle:%d)",p);
166
      #endif
338 giacomo 167
 
334 giacomo 168
      level_table[ lev->scheduling_level ]->
338 giacomo 169
        private_extract(lev->scheduling_level, p);
170
 
171
      level_table[ lev->scheduling_level ]->
334 giacomo 172
        public_message(lev->scheduling_level, p, NULL);
173
 
324 giacomo 174
      break;
175
 
176
    /* Task Disable */
177
    case (long)(1):
178
 
179
      break;
180
 
181
    default:
182
 
183
      break;
184
 
185
  }
186
 
187
  return 0;
188
 
189
}
190
 
191
static void MPEGSTAR_public_end(LEVEL l, PID p)
192
{
193
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
341 giacomo 194
 
195
  #ifdef MPEGSTAR_DEBUG
196
    kern_printf("(MS:End:%d)", p);
197
  #endif
324 giacomo 198
 
341 giacomo 199
  lev->current = NIL;                                                                                                          proc_table[p].status = FREE;
200
 
324 giacomo 201
}
202
 
203
/* Registration functions */
204
 
205
/*+ Registration function:
206
    TIME slice                the slice for the Round Robin queue +*/
334 giacomo 207
LEVEL MPEGSTAR_register_level(int master)
324 giacomo 208
{
209
  LEVEL l;            /* the level that we register */
210
  MPEGSTAR_level_des *lev;  /* for readableness only */
211
 
212
  l = level_alloc_descriptor(sizeof(MPEGSTAR_level_des));
213
 
214
  lev = (MPEGSTAR_level_des *)level_table[l];
215
 
216
  lev->l.public_guarantee = NULL;
217
  lev->l.public_create    = MPEGSTAR_public_create;
218
  lev->l.public_end       = MPEGSTAR_public_end;
219
  lev->l.public_dispatch  = MPEGSTAR_public_dispatch;
220
  lev->l.public_epilogue  = MPEGSTAR_public_epilogue;
221
  lev->l.public_activate  = MPEGSTAR_public_activate;
222
  lev->l.public_unblock   = MPEGSTAR_public_unblock;
223
  lev->l.public_block     = MPEGSTAR_public_block;
224
  lev->l.public_message   = MPEGSTAR_public_message;
225
  lev->l.public_eligible  = MPEGSTAR_public_eligible;
226
 
338 giacomo 227
  lev->budget = NIL;
228
  lev->current = NIL;
339 giacomo 229
  lev->server_Q = 0;
230
  lev->server_T = 0;
334 giacomo 231
 
232
  lev->scheduling_level = master;
233
 
324 giacomo 234
  return l;
235
 
236
}
334 giacomo 237
 
238
int MPEGSTAR_setbudget(LEVEL l, PID p, int budget)
239
{
240
 
241
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
242
 
338 giacomo 243
  lev->budget = budget;
334 giacomo 244
 
245
  return 0;
246
 
247
}
248
 
249
int MPEGSTAR_getbudget(LEVEL l, PID p)
250
{
251
 
252
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
253
 
338 giacomo 254
  return lev->budget;
334 giacomo 255
 
256
}
257
 
258
int MPEGSTAR_budget_has_thread(LEVEL l, int budget)
338 giacomo 259
{                                                                                                                            
260
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
261
 
262
  if (lev->budget == budget) return 1;                                                                                                            
263
  return 0;
264
 
265
}
266
 
339 giacomo 267
int MPEGSTAR_rescale(int budget, TIME Q, TIME T)
334 giacomo 268
{
339 giacomo 269
  LEVEL l = SERVER_get_local_scheduler_level_from_budget(fsf_get_server_level(),budget);
334 giacomo 270
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
338 giacomo 271
 
272
  SERVER_adjust_budget(lev->scheduling_level,Q,T,lev->budget);
273
  lev->server_Q = Q;
274
  lev->server_T = T;
275
  if (lev->current != NIL) {
276
    proc_table[lev->current].avail_time = Q;
277
    proc_table[lev->current].wcet = Q;
278
  }
279
 
334 giacomo 280
  return 0;
281
}
340 giacomo 282
 
283
int MPEGSTAR_get_remain_capacity(int budget)
284
{
341 giacomo 285
  return SERVER_get_remain_capacity(fsf_get_server_level(),budget);
340 giacomo 286
}
341 giacomo 287
 
288
int MPEGSTAR_get_last_reclaiming()
289
{
290
  return SERVER_get_last_reclaiming(fsf_get_server_level(),exec_shadow);
291
}