Subversion Repositories shark

Rev

Rev 14 | Details | Compare with Previous | 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
 ------------
29 pj 23
 CVS :        $Id: dummy.c,v 1.3 2002-11-11 08:32:06 pj Exp $
2 pj 24
 
25
 File:        $File$
29 pj 26
 Revision:    $Revision: 1.3 $
27
 Last update: $Date: 2002-11-11 08:32:06 $
2 pj 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)
14 pj 157
{ kern_printf("Dummy1"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 158
 
159
static void dummy_task_insert(LEVEL l, PID p)
14 pj 160
{ kern_printf("Dummy2"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 161
 
162
static void dummy_task_extract(LEVEL l, PID p)
14 pj 163
{ kern_printf("Dummy3"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 164
 
165
static void dummy_task_endcycle(LEVEL l, PID p)
14 pj 166
{ kern_printf("Dummy4"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 167
 
168
static void dummy_task_end(LEVEL l, PID p)
14 pj 169
{ kern_printf("Dummy5"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 170
 
171
static void dummy_task_sleep(LEVEL l, PID p)
14 pj 172
{ kern_printf("Dummy6"); kern_raise(XINVALID_DUMMY_OP,exec_shadow); }
2 pj 173
 
174
static int dummy_guest_create(LEVEL l, PID p, TASK_MODEL *m)
14 pj 175
{ kern_printf("Dummy8"); kern_raise(XINVALID_GUEST,exec_shadow); return 0; }
2 pj 176
 
177
static void dummy_guest_detach(LEVEL l, PID p)
14 pj 178
{ kern_printf("Dummy9"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 179
 
180
static void dummy_guest_dispatch(LEVEL l, PID p, int nostop)
14 pj 181
{ kern_printf("Dummy0"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 182
 
183
static void dummy_guest_epilogue(LEVEL l, PID p)
14 pj 184
{ kern_printf("Dummya"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 185
 
186
static void dummy_guest_activate(LEVEL l, PID p)
14 pj 187
{ kern_printf("Dummyb"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 188
 
189
static void dummy_guest_insert(LEVEL l, PID p)
14 pj 190
{ kern_printf("Dummyc"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 191
 
192
static void dummy_guest_extract(LEVEL l, PID p)
14 pj 193
{ kern_printf("Dummyd"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 194
 
195
static void dummy_guest_endcycle(LEVEL l, PID p)
14 pj 196
{ kern_printf("Dummye"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 197
 
198
static void dummy_guest_end(LEVEL l, PID p)
14 pj 199
{ kern_printf("Dummyf"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 200
 
201
static void dummy_guest_sleep(LEVEL l, PID p)
14 pj 202
{ kern_printf("Dummyg"); kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 203
 
204
 
205
/*+ Dummy task must be present & cannot be killed; +*/
206
static TASK dummy()
207
{
208
    /*
209
    It is possible to Halt the CPU & avoid consumption if idle
210
    cycle are intercepted with hlt instructions!
211
    It seems that some CPU have buggy hlt instruction or they
212
    have not it at all! So, if available, use the hlt facility!!
213
    */
214
    #ifdef __HLT_WORKS__
215
    for(;;) {
216
//       kern_printf("?");
217
        hlt();
218
    }
219
    #else
220
    for(;;);// kern_printf("?");
221
    #endif
222
}
223
 
224
/* Registration functions */
225
 
226
/*+ This init function install the dummy task +*/
227
static void dummy_create(void *l)
228
{
229
  LEVEL lev;
230
  PID p;
231
  DUMMY_TASK_MODEL m;
232
 
233
  lev = (LEVEL)l;
234
 
235
  dummy_task_default_model(m);
236
  dummy_task_def_level(m,lev);
237
  dummy_task_def_system(m);
238
  dummy_task_def_nokill(m);
239
  dummy_task_def_ctrl_jet(m);
240
 
241
  ((dummy_level_des *)level_table[lev])->dummy = p =
242
    task_create("Dummy", dummy, &m, NULL);
243
 
244
  if (p == NIL)
245
    printk("\nPanic!!! can't create dummy task...\n");
246
 
247
  /* dummy must block all tasks... */
248
  proc_table[p].sigmask = 0xFFFFFFFF;
249
}
250
 
251
 
252
/*+ Registration function:
253
    TIME slice                the slice for the Round Robin queue
254
    int createmain            1 if the level creates the main task 0 otherwise
255
    struct multiboot_info *mb used if createmain specified   +*/
256
void dummy_register_level()
257
{
258
  LEVEL l;            /* the level that we register */
259
  dummy_level_des *lev;  /* for readableness only */
260
 
261
  printk("Entro in dummy_register_level\n");
262
  /* request an entry in the level_table */
263
  l = level_alloc_descriptor();
264
 
265
  /* alloc the space needed for the dummy_level_des */
266
  lev = (dummy_level_des *)kern_alloc(sizeof(dummy_level_des));
267
 
268
  /* update the level_table with the new entry */
269
  level_table[l] = (level_des *)lev;
270
 
271
  /* fill the standard descriptor */
272
  strncpy(lev->l.level_name,  DUMMY_LEVELNAME, MAX_LEVELNAME);
273
  lev->l.level_code               = DUMMY_LEVEL_CODE;
274
  lev->l.level_version            = DUMMY_LEVEL_VERSION;
275
 
276
  lev->l.level_accept_task_model  = dummy_level_accept_task_model;
277
  lev->l.level_accept_guest_model = dummy_level_accept_guest_model;
278
  lev->l.level_status             = dummy_level_status;
279
  lev->l.level_scheduler          = dummy_level_scheduler;
280
  lev->l.level_guarantee          = NULL; /* No guarantee! */
281
 
282
  lev->l.task_create              = dummy_task_create;
283
  lev->l.task_detach              = dummy_task_detach;
284
  lev->l.task_eligible            = dummy_task_eligible;
285
  lev->l.task_dispatch            = dummy_task_dispatch;
286
  lev->l.task_epilogue            = dummy_task_epilogue;
287
  lev->l.task_activate            = dummy_task_activate;
288
  lev->l.task_insert              = dummy_task_insert;
289
  lev->l.task_extract             = dummy_task_extract;
290
  lev->l.task_endcycle            = dummy_task_endcycle;
291
  lev->l.task_end                 = dummy_task_end;
292
  lev->l.task_sleep               = dummy_task_sleep;
293
 
294
  lev->l.guest_create             = dummy_guest_create;
295
  lev->l.guest_detach             = dummy_guest_detach;
296
  lev->l.guest_dispatch           = dummy_guest_dispatch;
297
  lev->l.guest_epilogue           = dummy_guest_epilogue;
298
  lev->l.guest_activate           = dummy_guest_activate;
299
  lev->l.guest_insert             = dummy_guest_insert;
300
  lev->l.guest_extract            = dummy_guest_extract;
301
  lev->l.guest_endcycle           = dummy_guest_endcycle;
302
  lev->l.guest_end                = dummy_guest_end;
303
  lev->l.guest_sleep              = dummy_guest_sleep;
304
 
305
  /* the dummy process will be created at init_time.
306
     see also dummy_level_accept_model,dummy_create   */
307
  lev->dummy = -1;
308
 
309
  printk("\tPosto dummy_create\n");
310
 
311
  sys_atrunlevel(dummy_create,(void *) l, RUNLEVEL_INIT);
312
}