Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
23
 CVS :        $Id: dummy.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1.1.1 $
27
 Last update: $Date: 2002-03-29 14:12:52 $
28
 ------------
29
 
30
 This file contains the Dummy scheduling module
31
 
32
 Read dummy.h for further details.
33
 
34
**/
35
 
36
/*
37
 * Copyright (C) 2000 Paolo Gai
38
 *
39
 * This program is free software; you can redistribute it and/or modify
40
 * it under the terms of the GNU General Public License as published by
41
 * the Free Software Foundation; either version 2 of the License, or
42
 * (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
52
 *
53
 */
54
 
55
#include <modules/dummy.h>
56
#include <ll/ll.h>
57
#include <ll/stdio.h>
58
#include <ll/string.h>
59
#include <kernel/config.h>
60
#include <sys/types.h>
61
#include <modules/codes.h>
62
#include <kernel/model.h>
63
#include <kernel/descr.h>
64
#include <kernel/var.h>
65
#include <kernel/func.h>
66
 
67
 
68
 
69
/*+ the level redefinition for the Dummy level +*/
70
typedef struct {
71
  level_des l;     /*+ the standard level descriptor          +*/
72
 
73
  PID dummy;       /*+ the dummy task...                      +*/
74
} dummy_level_des;
75
 
76
 
77
static int dummy_level_accept_task_model(LEVEL l, TASK_MODEL *m)
78
{
79
  dummy_level_des *lev = (dummy_level_des *)(level_table[l]);
80
 
81
  if ((m->pclass == DUMMY_PCLASS || m->pclass == (DUMMY_PCLASS | l))
82
      && lev->dummy == -1)
83
    return 0;
84
  else
85
    return -1;
86
}
87
 
88
static int dummy_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
89
{
90
  return -1;
91
}
92
 
93
static void dummy_level_status(LEVEL l)
94
{
95
  dummy_level_des *lev = (dummy_level_des *)(level_table[l]);
96
 
97
  kern_printf("dummy PID: %d\n", lev->dummy);
98
};
99
 
100
 
101
static PID dummy_level_scheduler(LEVEL l)
102
{
103
  dummy_level_des *lev = (dummy_level_des *)(level_table[l]);
104
  //kern_printf("DUMMYsched!!! %d", lev->dummy);
105
  return lev->dummy;
106
}
107
 
108
/* There is not guarantee on this level!!! -> the entry must be null
109
int (*level_guarantee)(LEVEL l, DWORD *freebandwidth); */
110
 
111
static int dummy_task_create(LEVEL l, PID p, TASK_MODEL *m)
112
{
113
  /* the dummy level doesn't introduce any new field in the TASK_MODEL
114
     so, all initialization stuffs are done by the task_create.
115
     the task state is set at SLEEP by the general task_create */
116
  return 0; /* OK */
117
}
118
 
119
static void dummy_task_detach(LEVEL l, PID p)
120
{
121
  /* the dummy level doesn't introduce any new field in the TASK_MODEL
122
     so, all detach stuffs are done by the task_create
123
     The task state is set at FREE by the general task_create */
124
}
125
 
126
static int dummy_task_eligible(LEVEL l, PID p)
127
{
128
  return 0; /* if the task p is chosen, it is always eligible */
129
}
130
 
131
extern int testactive;
132
extern struct timespec s_stime[];
133
extern TIME s_curr[];
134
extern TIME s_PID[];
135
extern int useds;
136
static void dummy_task_dispatch(LEVEL l, PID p, int nostop)
137
{
138
  /* nothing... the dummy hangs the cpu waiting for interrupts... */
139
  if (0)//testactive)
140
  {
141
    s_stime[useds]= schedule_time;
142
    s_curr[useds] = -1;
143
    s_PID[useds]  = p;
144
    useds++;
145
  }
146
 
147
  //kern_printf("ÛDUMMYÛ");
148
 
149
}
150
 
151
static void dummy_task_epilogue(LEVEL l, PID p)
152
{
153
  proc_table[p].status = SLEEP; /* Paranoia */
154
}
155
 
156
static void dummy_task_activate(LEVEL l, PID p)
157
{ kern_printf("Dummy1"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
158
 
159
static void dummy_task_insert(LEVEL l, PID p)
160
{ kern_printf("Dummy2"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
161
 
162
static void dummy_task_extract(LEVEL l, PID p)
163
{ kern_printf("Dummy3"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
164
 
165
static void dummy_task_endcycle(LEVEL l, PID p)
166
{ kern_printf("Dummy4"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
167
 
168
static void dummy_task_end(LEVEL l, PID p)
169
{ kern_printf("Dummy5"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
170
 
171
static void dummy_task_sleep(LEVEL l, PID p)
172
{ kern_printf("Dummy6"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
173
 
174
static void dummy_task_delay(LEVEL l, PID p, TIME tickdelay)
175
{ kern_printf("Dummy7"); kern_raise(XUNVALID_DUMMY_OP,exec_shadow); }
176
 
177
static int dummy_guest_create(LEVEL l, PID p, TASK_MODEL *m)
178
{ kern_printf("Dummy8"); kern_raise(XUNVALID_GUEST,exec_shadow); return 0; }
179
 
180
static void dummy_guest_detach(LEVEL l, PID p)
181
{ kern_printf("Dummy9"); kern_raise(XUNVALID_GUEST,exec_shadow); }
182
 
183
static void dummy_guest_dispatch(LEVEL l, PID p, int nostop)
184
{ kern_printf("Dummy0"); kern_raise(XUNVALID_GUEST,exec_shadow); }
185
 
186
static void dummy_guest_epilogue(LEVEL l, PID p)
187
{ kern_printf("Dummya"); kern_raise(XUNVALID_GUEST,exec_shadow); }
188
 
189
static void dummy_guest_activate(LEVEL l, PID p)
190
{ kern_printf("Dummyb"); kern_raise(XUNVALID_GUEST,exec_shadow); }
191
 
192
static void dummy_guest_insert(LEVEL l, PID p)
193
{ kern_printf("Dummyc"); kern_raise(XUNVALID_GUEST,exec_shadow); }
194
 
195
static void dummy_guest_extract(LEVEL l, PID p)
196
{ kern_printf("Dummyd"); kern_raise(XUNVALID_GUEST,exec_shadow); }
197
 
198
static void dummy_guest_endcycle(LEVEL l, PID p)
199
{ kern_printf("Dummye"); kern_raise(XUNVALID_GUEST,exec_shadow); }
200
 
201
static void dummy_guest_end(LEVEL l, PID p)
202
{ kern_printf("Dummyf"); kern_raise(XUNVALID_GUEST,exec_shadow); }
203
 
204
static void dummy_guest_sleep(LEVEL l, PID p)
205
{ kern_printf("Dummyg"); kern_raise(XUNVALID_GUEST,exec_shadow); }
206
 
207
static void dummy_guest_delay(LEVEL l, PID p,DWORD tickdelay)
208
{ kern_printf("Dummyh"); kern_raise(XUNVALID_GUEST,exec_shadow); }
209
 
210
 
211
 
212
 
213
/*+ Dummy task must be present & cannot be killed; +*/
214
static TASK dummy()
215
{
216
    /*
217
    It is possible to Halt the CPU & avoid consumption if idle
218
    cycle are intercepted with hlt instructions!
219
    It seems that some CPU have buggy hlt instruction or they
220
    have not it at all! So, if available, use the hlt facility!!
221
    */
222
    #ifdef __HLT_WORKS__
223
    for(;;) {
224
//       kern_printf("?");
225
        hlt();
226
    }
227
    #else
228
    for(;;);// kern_printf("?");
229
    #endif
230
}
231
 
232
/* Registration functions */
233
 
234
/*+ This init function install the dummy task +*/
235
static void dummy_create(void *l)
236
{
237
  LEVEL lev;
238
  PID p;
239
  DUMMY_TASK_MODEL m;
240
 
241
  lev = (LEVEL)l;
242
 
243
  dummy_task_default_model(m);
244
  dummy_task_def_level(m,lev);
245
  dummy_task_def_system(m);
246
  dummy_task_def_nokill(m);
247
  dummy_task_def_ctrl_jet(m);
248
 
249
  ((dummy_level_des *)level_table[lev])->dummy = p =
250
    task_create("Dummy", dummy, &m, NULL);
251
 
252
  if (p == NIL)
253
    printk("\nPanic!!! can't create dummy task...\n");
254
 
255
  /* dummy must block all tasks... */
256
  proc_table[p].sigmask = 0xFFFFFFFF;
257
}
258
 
259
 
260
/*+ Registration function:
261
    TIME slice                the slice for the Round Robin queue
262
    int createmain            1 if the level creates the main task 0 otherwise
263
    struct multiboot_info *mb used if createmain specified   +*/
264
void dummy_register_level()
265
{
266
  LEVEL l;            /* the level that we register */
267
  dummy_level_des *lev;  /* for readableness only */
268
 
269
  printk("Entro in dummy_register_level\n");
270
  /* request an entry in the level_table */
271
  l = level_alloc_descriptor();
272
 
273
  /* alloc the space needed for the dummy_level_des */
274
  lev = (dummy_level_des *)kern_alloc(sizeof(dummy_level_des));
275
 
276
  /* update the level_table with the new entry */
277
  level_table[l] = (level_des *)lev;
278
 
279
  /* fill the standard descriptor */
280
  strncpy(lev->l.level_name,  DUMMY_LEVELNAME, MAX_LEVELNAME);
281
  lev->l.level_code               = DUMMY_LEVEL_CODE;
282
  lev->l.level_version            = DUMMY_LEVEL_VERSION;
283
 
284
  lev->l.level_accept_task_model  = dummy_level_accept_task_model;
285
  lev->l.level_accept_guest_model = dummy_level_accept_guest_model;
286
  lev->l.level_status             = dummy_level_status;
287
  lev->l.level_scheduler          = dummy_level_scheduler;
288
  lev->l.level_guarantee          = NULL; /* No guarantee! */
289
 
290
  lev->l.task_create              = dummy_task_create;
291
  lev->l.task_detach              = dummy_task_detach;
292
  lev->l.task_eligible            = dummy_task_eligible;
293
  lev->l.task_dispatch            = dummy_task_dispatch;
294
  lev->l.task_epilogue            = dummy_task_epilogue;
295
  lev->l.task_activate            = dummy_task_activate;
296
  lev->l.task_insert              = dummy_task_insert;
297
  lev->l.task_extract             = dummy_task_extract;
298
  lev->l.task_endcycle            = dummy_task_endcycle;
299
  lev->l.task_end                 = dummy_task_end;
300
  lev->l.task_sleep               = dummy_task_sleep;
301
  lev->l.task_delay               = dummy_task_delay;
302
 
303
  lev->l.guest_create             = dummy_guest_create;
304
  lev->l.guest_detach             = dummy_guest_detach;
305
  lev->l.guest_dispatch           = dummy_guest_dispatch;
306
  lev->l.guest_epilogue           = dummy_guest_epilogue;
307
  lev->l.guest_activate           = dummy_guest_activate;
308
  lev->l.guest_insert             = dummy_guest_insert;
309
  lev->l.guest_extract            = dummy_guest_extract;
310
  lev->l.guest_endcycle           = dummy_guest_endcycle;
311
  lev->l.guest_end                = dummy_guest_end;
312
  lev->l.guest_sleep              = dummy_guest_sleep;
313
  lev->l.guest_delay              = dummy_guest_delay;
314
 
315
  /* the dummy process will be created at init_time.
316
     see also dummy_level_accept_model,dummy_create   */
317
  lev->dummy = -1;
318
 
319
  printk("\tPosto dummy_create\n");
320
 
321
  sys_atrunlevel(dummy_create,(void *) l, RUNLEVEL_INIT);
322
}