Subversion Repositories shark

Rev

Rev 2 | Rev 29 | Go to most recent revision | 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
/**
23
 ------------
24
 CVS :        $Id: descr.h,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $
25
 
26
 File:        $File$
27
 Revision:    $Revision: 1.1.1.1 $
28
 Last update: $Date: 2002-03-29 14:12:51 $
29
 ------------
30
 
31
Kernel main data structures
32
 
33
This file declare:
34
 
35
- the descriptors
36
  - cleanup handlers
37
  - levels
38
  - mutexes
39
  - mutex attributes
40
  - resource levels
41
 
42
 
43
**/
44
 
45
/*
46
 * Copyright (C) 2000 Paolo Gai
47
 *
48
 * This program is free software; you can redistribute it and/or modify
49
 * it under the terms of the GNU General Public License as published by
50
 * the Free Software Foundation; either version 2 of the License, or
51
 * (at your option) any later version.
52
 *
53
 * This program is distributed in the hope that it will be useful,
54
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56
 * GNU General Public License for more details.
57
 *
58
 * You should have received a copy of the GNU General Public License
59
 * along with this program; if not, write to the Free Software
60
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
61
 *
62
 */
63
 
64
 
65
 
66
#ifndef __KERNEL_DESCR_H__
67
#define __KERNEL_DESCR_H__
68
 
69
 
70
#include <ll/ll.h>
71
#include <kernel/model.h>
72
#include <kernel/types.h>
73
#include <limits.h>
74
 
75
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76
  CLEANUP HANDLER STRUCTURES
77
 
78
  Derived directly from posix standard, B.18.2.3
79
  This structure implements the task cleanup functions queue...
80
  look at kern.c!
81
 
82
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
83
struct _task_handler_rec {
84
  void (*f)(void *);
85
  void *a;
86
  struct _task_handler_rec *next;
87
};
88
 
89
 
90
 
91
struct condition_struct;
92
 
93
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94
  GENERAL TASK DESCRIPTOR
95
 
96
  In this type definition there is all the basic information for
97
  handling a task in the system.
98
 
99
  All the informations scheduler-dependent (like deadline, priority,
100
  and so on) are put in the level module files.
101
  In any case, a priority field is inserted to simplify the implementation
102
  of most of the scheduling algorithms
103
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
104
 
105
typedef struct {
106
        DWORD   task_ID;      /*+ progressive task counter ID +*/
107
        LEVEL   task_level;   /*+ the "real" level that owns the task     +*/
108
 
109
        CONTEXT context;      /*+ Context area pointer (see vm.h)         +*/
110
        BYTE    *stack;       /*+ Pointer to stack area base              +*/
111
        TASK    (*body)();    /*+ Pointer to the code of the task
112
                                  (starting address)                      +*/
113
        char    name[MAX_TASKNAME]; /*+ Text identifing the process name  +*/
114
 
115
        WORD    status;       /*+ actual task status
116
                                  (it could be EXE, SLEEP, IDLE, ...)     +*/
117
        WORD    pclass;       /*+ The code number of the task model used  +*/
118
        WORD    group;        /*+ 0 if task is single, else group id      +*/
119
        WORD    stacksize;    /*+ Task stack size                         +*/
120
        DWORD   control;      /*+ Control task operating mode
121
                                 Refer to the TASK_MODEL type for its use +*/
122
 
123
        int     frozen_activations; /*+ number of frozen activation;
124
                                        see kern.c, task_block_activations
125
                                        see model.h,flag in control field +*/
126
 
127
        /* sigset_t!!! */
128
        int sigmask;          /*+ The task signal mask                    +*/
129
        int sigpending;       /*+ The signal pending mask                 +*/
130
        int sigwaiting;       /*+ The signal waiting mask                 +*/
131
 
132
        struct timespec request_time;
133
                              /*+ Last request time for the task          +*/
134
        int     avail_time;   /*+ the time the task can execute before a
135
                                  timer fire. see also the control field
136
                                  and bits related in model.h             +*/
137
 
138
        PID     shadow;       /*+ Shadow task                             +*/
139
 
140
        struct _task_handler_rec *cleanup_stack;
141
                              /*+ The cleanup stack                       +*/
142
 
143
        QUEUE   next,prev;    /*+ Next/Prev Index in the queue            +*/
144
 
145
        int     errnumber;
146
 
147
        /* Job Execution Time fields */
148
        TIME    jet_table[JET_TABLE_DIM];
149
                              /*+ Execution time of the last
150
                                  activations of the task.                +*/
151
        int     jet_tvalid;   /*+ number of valid entry in the jet_table  +*/
152
        int     jet_curr;     /*+ Current entry in the jet_table          +*/
153
        TIME    jet_max;      /*+ Maximum Execution time since task_create
154
                                  or last jet_delstat                     +*/
155
        TIME    jet_sum;      /*+ Mean Execution time since task_create
156
                                  or last jet_delstat                     +*/
157
        TIME    jet_n;        /*+ Number of instances on witch the mean
158
                                  time have to be computed                +*/
159
 
160
        /* task_join fields */
161
        PID waiting_for_me;   /*+ the task that waits my dead,
162
                                  NIL if there aren't                     +*/
163
        void *return_value;   /*+ task return value                       +*/
164
 
165
        /* task specific data (it uses directly POSIX constant) */
166
        void *keys[PTHREAD_KEYS_MAX];
167
 
168
        /* condition variable field */
169
        struct condition_struct *cond_waiting;
170
                              /*+ the condition on that the task is
171
                                  waiting +*/
172
 
173
        /* stuff used in most algorithms; they are not used directly in
174
         * the generic kernel, with exclusion of delay_timer that is used
175
         * also in cond_timedwait
176
         */
177
        DWORD   priority;     /*+ A priority field                        +*/
178
        struct timespec timespec_priority; /*+ Another priority field     +*/
179
        int     delay_timer;  /*+ A field useful to store the delay timer +*/
180
 
181
        int     wcet;         /*+ a worst case time execution             +*/
182
 
183
 
184
} proc_des;
185
 
186
 
187
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188
  LEVEL DESCRIPTOR
189
 
190
  In this type definition there is all the basic information for
191
  handling a scheduling level in the system.
192
 
193
  All the informations that depends on the particular module are put
194
  in the level module files.
195
 
196
  The initialization of a level is splitted in two parts:
197
  - the registration -> called before the system initialization, typically
198
                        AFTER the resource registration
199
  - the level_init   -> called during the system initialization,
200
                        BEFORE the resource_init(s)
201
 
202
 
203
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
204
 
205
typedef struct {
206
  char level_name[MAX_LEVELNAME]; /*+ for statistical pourposes          +*/
207
  WORD level_code;              /*+ level identification code            +*/
208
  BYTE level_version;           /*+ level version                        +*/
209
 
210
  /* LEVEL CALLS */
211
  int (*level_accept_task_model)(LEVEL l, TASK_MODEL *m);
212
                                /*+ models that a task can manage. returns
213
 
214
                                    -1 if not                            +*/
215
 
216
  int (*level_accept_guest_model)(LEVEL l, TASK_MODEL *m);
217
                                /*+ models that a task can manage as guest
218
                                    tasks. returns
219
 
220
                                    -1 if not                            +*/
221
 
222
 // void (*level_init)();       /*+ initialization of the level module   +*/
223
 // void (*level_end)();        /*+ level termination (at system end...  +*/
224
  void (*level_status)(LEVEL l);/*+ print level statistics...            +*/
225
 
226
  PID  (*level_scheduler)(LEVEL l);
227
                                /*+ the level scheduler returns a task
228
                                    chosen among those belonging to the
229
                                    level                                +*/
230
 
231
  int (*level_guarantee)(LEVEL l, bandwidth_t *freebandwidth);
232
                                /*+ 0 if the level is guaranteed, -1 if not
233
                                    no guarantee if (*f)()=null
234
                                    the function updates the parameter
235
                                    (see guarantee() )                   +*/
236
 
237
  /* TASK CALLS */
238
  int  (*task_create)(LEVEL l, PID p, TASK_MODEL *m);
239
                                /*+ the task p is created into the level
240
                                    returns 0->ok, -1->error             +*/
241
  void (*task_detach)(LEVEL l, PID p);
242
                                /*+ there is an error in the task_create
243
                                    after the task call task_create.
244
                                    The function delete all the informations
245
                                    about the task in the level.
246
                                    For the resources levels there is the
247
                                    res_detach: res_detach is called also
248
                                    when killing a task                  +*/
249
  int (*task_eligible)(LEVEL l, PID p);
250
                                /*+ correctness control when a task is
251
                                    chosen by a level scheduler (used with
252
                                    aperiodic servers) 0->ok, -1->no     +*/
253
  void (*task_dispatch)(LEVEL l, PID p, int nostop);
254
                                /*+ a task go in the EXEC status (called
255
                                    by dispatch() )                      +*/
256
  void (*task_epilogue)(LEVEL l, PID p);
257
                                /*+ a task has finished the current slice+*/
258
 
259
  void (*task_activate)(LEVEL l, PID p);
260
                                /*+ the task is activated...             +*/
261
 
262
  void (*task_insert)(LEVEL l, PID p);
263
                                /*+ opposite to task_extract             +*/
264
  void (*task_extract)(LEVEL l, PID p);
265
                                /*+ remove the task from the "ready" (if any)
266
                                    queue                                +*/
267
 
268
  void (*task_endcycle)(LEVEL l, PID p);
269
                                /*+ the (periodic) task finish the cycle +*/
270
  void (*task_end)(LEVEL l, PID p);
271
                                /*+ the task is killed; we have to remove
272
                                    it from the level queues, test if it
273
                                    is in the exec state, etc... it can
274
                                    modify the state of the task (-> FREE,
275
                                    ZOMBIE...), but
276
                                    cannot call the scheduler directly (it
277
                                    is called by the task_makefree.
278
                                    Note: the task can be in a state
279
                                    different from those managed by the
280
                                    level because the task may be blocked.
281
                                    the res_detach is in any case called
282
                                    AFTER the task_end.                  +*/
283
 
284
  void (*task_sleep)(LEVEL l, PID p);
285
                                /*+ this function will fall asleep the
286
                                    task in the EXE state. +*/
287
 
288
 
289
  void (*task_delay)(LEVEL l, PID p,DWORD tickdelay);
290
 
291
 
292
  /* guest CALLS:
293
     these functions are called from an Aperiodic Server Level for the task
294
     that are inserted in the local queues */
295
  int  (*guest_create)(LEVEL l, PID p, TASK_MODEL *m);
296
                                /*+ the task is already created in another
297
                                    level and it is inserted in the current
298
                                    level; returns 0->ok, -1->error      +*/
299
  void (*guest_detach)(LEVEL l, PID p);
300
                                /*+ there is an error in a task creation
301
                                    of a task made by an aperiodic server
302
                                    The function delete all the informations
303
                                    about the task in the level.         +*/
304
  void (*guest_dispatch)(LEVEL l, PID p, int nostop);
305
                                /*+ a task belonging to another level but
306
                                    inserted in the current level go in the
307
                                    EXEC status (called by dispatch() )  +*/
308
  void (*guest_epilogue)(LEVEL l, PID p);
309
                                /*+ a task has finished the current slice+*/
310
 
311
  void (*guest_activate)(LEVEL l, PID p);
312
                                /*+ the task is activated...             +*/
313
 
314
  void (*guest_insert)(LEVEL l, PID p);
315
                                /*+ remove the task from the "ready" (if any)
316
                                    queue                                +*/
317
  void (*guest_extract)(LEVEL l, PID p);
318
                                /*+ opposite to guest_insert             +*/
319
 
320
 
321
  void (*guest_endcycle)(LEVEL l, PID p);
322
                                /*+ the task finish the cycle +*/
323
  void (*guest_end)(LEVEL l, PID p);
324
                                /*+ the task is killed                   +*/
325
 
326
  void (*guest_sleep)(LEVEL l, PID p);
327
  void (*guest_delay)(LEVEL l, PID p, TIME tickdelay);
328
 
329
} level_des;
330
 
331
 
332
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
333
  RESOURCE DESCRIPTOR
334
 
335
  In this type definition there is all the basic information for
336
  handling a resource module in the system.
337
 
338
  All the informations protocol-dependent (like ceiling, task that use
339
  a particular resource, and so on) are put in the resource module files.
340
 
341
  In general, the initialization of a resource module is splitted in two
342
  parts:
343
  - the registration   -> tipically done with a finction called
344
                          XXX_register_module. It is called before the
345
                          system initialization, in
346
                          the function __kernel_register_levels__().
347
  - the initialization -> called during the system initialization,
348
                          This is done posting some init functions with
349
                          the sys_at_init()
350
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
351
 
352
typedef struct {
353
  char res_name[MAX_MODULENAME];/*+ for statistical pourposes            +*/
354
  WORD res_code;                /*+ resource module identification code  +*/
355
  BYTE res_version;             /*+ resource module version              +*/
356
 
357
  int rtype;                    /*+ resource module extented interface
358
                                    code (see model.h)                   +*/
359
 
360
  void (*resource_status)();    /*+ print resource protocol statistics...+*/
361
 
362
  int  (*level_accept_resource_model)(RLEVEL l, RES_MODEL *r);
363
                                /*+ this function is called when the process
364
                                    is created. it returns 0 if the RES_MODEL
365
                                    can be managed by the level,-1 if not+*/
366
 
367
  void (*res_register)(RLEVEL l, PID p, RES_MODEL *r);
368
                                /*+ When the system knows that a resource
369
                                    model can be registered by a level,
370
                                    it calls this function. It registers all
371
                                    the information about the task and the
372
                                    model. +*/
373
 
374
  void (*res_detach)(RLEVEL l, PID p);
375
                                /*+ this function is called when the task
376
                                    is killed or some error is occurred
377
                                    in the task_create. It have to unlink
378
                                    the task from the module... If the task
379
                                    is already unlinked from the protocol
380
                                    no action is done                    +*/
381
} resource_des;
382
 
383
 
384
 
385
 
386
 
387
 
388
 
389
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
390
  MUTEX DESCRIPTOR
391
 
392
  In this type definition there is all the basic fields for
393
  handling a mutex in the system
394
 
395
  Many of the informations protocol-dependent (like ceiling, and so on)
396
  are put in the resource module or are pointef by the field opt.
397
 
398
  The opt field is used because in this way a mutex can be allocated in
399
  a dynamic way (in this case opt points to a dynamically allocated
400
  structure) or in a static way (in this case opt can be an index or a
401
  pointer to a static structure)
402
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
403
typedef struct {
404
  RLEVEL mutexlevel;  /*+ protocol used by the mutex. +*/
405
  int use;            /*+ the mutex is used in a condition wait... +*/
406
  void *opt;
407
} mutex_t;
408
 
409
 
410
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411
  MUTEX RESOURCE DESCRIPTOR
412
 
413
  This object is a resource_des object with a set of functions used to
414
  implement the mutex behaviour.
415
 
416
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
417
typedef struct {
418
  resource_des r;
419
 
420
  int  (*level_accept_mutexattr)(RLEVEL l, const mutexattr_t *a);
421
                                /*+ this function is called when a mutex
422
                                    is created. it returns 0 if the
423
                                    mutexattr_t
424
                                    can be managed by the level,-1 if not+*/
425
 
426
  int (*init)   (RLEVEL l, mutex_t *m, const mutexattr_t *a);
427
  int (*destroy)(RLEVEL l, mutex_t *m);
428
  int (*lock)   (RLEVEL l, mutex_t *m);
429
  int (*trylock)(RLEVEL l, mutex_t *m);
430
  int (*unlock) (RLEVEL l, mutex_t *m);
431
 
432
} mutex_resource_des;
433
 
434
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
435
  CONDITION VARIABLE DESCRIPTOR
436
 
437
  This is the condition variable descriptor.
438
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
439
 
440
typedef struct condition_struct {
441
  QUEUE waiters; /*+ queue for tasks waiting on the condition +*/
442
  mutex_t *used_for_waiting;
443
} cond_t;
444
 
445
 
446
#endif /* __TYPE_H__ */