Subversion Repositories shark

Rev

Rev 324 | Rev 338 | 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
 
49
#define MPEGSTAR_DEBUG
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
 
61
  int budget[MAX_PROC];
62
 
324 giacomo 63
  int scheduling_level;
64
 
65
} MPEGSTAR_level_des;
66
 
67
static int MPEGSTAR_public_eligible(LEVEL l, PID p)
68
{
69
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
70
  return level_table[ lev->scheduling_level ]->
71
      private_eligible(lev->scheduling_level,p);
72
 
73
  return 0;
74
}
75
 
76
static int MPEGSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
77
{
78
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
79
 
334 giacomo 80
  #ifdef MPEGSTAR_DEBUG
81
    kern_printf("(MP:Crt:%d)",p);
82
  #endif
83
 
84
  if (m->pclass != NRT_PCLASS) return -1;
85
  if (m->level != 0 && m->level != l) return -1;
86
 
87
  proc_table[p].avail_time = lev->server_Q;
88
  proc_table[p].wcet       = lev->server_Q;
89
 
90
  proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP);
91
 
324 giacomo 92
  return 0; /* OK */
93
}
94
 
95
static void MPEGSTAR_public_dispatch(LEVEL l, PID p, int nostop)
96
{
97
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
98
 
334 giacomo 99
  level_table[ lev->scheduling_level ] ->
100
    private_dispatch(lev->scheduling_level, p, nostop);
101
 
324 giacomo 102
}
103
 
104
static void MPEGSTAR_public_epilogue(LEVEL l, PID p)
105
{
106
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
334 giacomo 107
 
108
  level_table[ lev->scheduling_level ] ->
109
    private_epilogue(lev->scheduling_level,p);
324 giacomo 110
 
111
}
112
 
113
static void MPEGSTAR_public_activate(LEVEL l, PID p)
114
{
115
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
334 giacomo 116
  BUDGET_TASK_MODEL b;
117
  budget_task_default_model(b, lev->budget[p]);
118
 
119
  #ifdef MPEGSTAR_DEBUG
120
    kern_printf("(MP:Act:%d:%d)",p,lev->budget[p]);
121
  #endif
324 giacomo 122
 
334 giacomo 123
  level_table[ lev->scheduling_level ]->
124
    private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b);
125
 
324 giacomo 126
}
127
 
128
static void MPEGSTAR_public_unblock(LEVEL l, PID p)
129
{
130
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
131
 
132
}
133
 
134
static void MPEGSTAR_public_block(LEVEL l, PID p)
135
{  
136
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
137
 
138
}
139
 
140
static int MPEGSTAR_public_message(LEVEL l, PID p, void *m)
141
{
142
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
143
 
144
  switch ((long)(m)) {
145
 
146
    /* Task EndCycle */
147
    case (long)(NULL):
148
 
334 giacomo 149
      level_table[ lev->scheduling_level ]->
150
        public_message(lev->scheduling_level, p, NULL);
151
 
324 giacomo 152
      break;
153
 
154
    /* Task Disable */
155
    case (long)(1):
156
 
157
      break;
158
 
159
    default:
160
 
161
      break;
162
 
163
  }
164
 
165
  return 0;
166
 
167
}
168
 
169
static void MPEGSTAR_public_end(LEVEL l, PID p)
170
{
171
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
172
 
173
}
174
 
175
/* Registration functions */
176
 
177
/*+ Registration function:
178
    TIME slice                the slice for the Round Robin queue +*/
334 giacomo 179
LEVEL MPEGSTAR_register_level(int master)
324 giacomo 180
{
181
  LEVEL l;            /* the level that we register */
182
  MPEGSTAR_level_des *lev;  /* for readableness only */
334 giacomo 183
  int i;
324 giacomo 184
 
185
  l = level_alloc_descriptor(sizeof(MPEGSTAR_level_des));
186
 
187
  lev = (MPEGSTAR_level_des *)level_table[l];
188
 
189
  lev->l.public_guarantee = NULL;
190
  lev->l.public_create    = MPEGSTAR_public_create;
191
  lev->l.public_end       = MPEGSTAR_public_end;
192
  lev->l.public_dispatch  = MPEGSTAR_public_dispatch;
193
  lev->l.public_epilogue  = MPEGSTAR_public_epilogue;
194
  lev->l.public_activate  = MPEGSTAR_public_activate;
195
  lev->l.public_unblock   = MPEGSTAR_public_unblock;
196
  lev->l.public_block     = MPEGSTAR_public_block;
197
  lev->l.public_message   = MPEGSTAR_public_message;
198
  lev->l.public_eligible  = MPEGSTAR_public_eligible;
199
 
334 giacomo 200
  for (i=0;i<MAX_PROC;i++)
201
    lev->budget[i] = NIL;
202
 
203
  lev->scheduling_level = master;
204
 
324 giacomo 205
  return l;
206
 
207
}
334 giacomo 208
 
209
int MPEGSTAR_setbudget(LEVEL l, PID p, int budget)
210
{
211
 
212
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
213
 
214
  lev->budget[p] = budget;
215
 
216
  return 0;
217
 
218
}
219
 
220
int MPEGSTAR_getbudget(LEVEL l, PID p)
221
{
222
 
223
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
224
 
225
  return lev->budget[p];
226
 
227
}
228
 
229
int MPEGSTAR_budget_has_thread(LEVEL l, int budget)
230
{
231
 
232
  MPEGSTAR_level_des *lev = (MPEGSTAR_level_des *)(level_table[l]);
233
  int i;
234
 
235
  for(i = 0; i< MAX_PROC; i++)
236
    if (lev->budget[i] == budget) return 1;
237
 
238
  return 0;
239
 
240
}