Subversion Repositories shark

Rev

Rev 3 | Rev 38 | 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
 ------------
29 pj 24
 CVS :        $Id: descr.h,v 1.2 2002-11-11 08:36:01 pj Exp $
2 pj 25
 
26
 File:        $File$
29 pj 27
 Revision:    $Revision: 1.2 $
28
 Last update: $Date: 2002-11-11 08:36:01 $
2 pj 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>
29 pj 73
#include <kernel/iqueue.h>
2 pj 74
#include <limits.h>
75
 
76
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
  CLEANUP HANDLER STRUCTURES
78
 
79
  Derived directly from posix standard, B.18.2.3
80
  This structure implements the task cleanup functions queue...
81
  look at kern.c!
82
 
83
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
84
struct _task_handler_rec {
85
  void (*f)(void *);
86
  void *a;
87
  struct _task_handler_rec *next;
88
};
89
 
90
 
91
 
92
struct condition_struct;
93
 
94
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
95
  GENERAL TASK DESCRIPTOR
96
 
97
  In this type definition there is all the basic information for
98
  handling a task in the system.
99
 
100
  All the informations scheduler-dependent (like deadline, priority,
101
  and so on) are put in the level module files.
102
  In any case, a priority field is inserted to simplify the implementation
103
  of most of the scheduling algorithms
104
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
105
 
106
typedef struct {
107
        DWORD   task_ID;      /*+ progressive task counter ID +*/
108
        LEVEL   task_level;   /*+ the "real" level that owns the task     +*/
109
 
110
        CONTEXT context;      /*+ Context area pointer (see vm.h)         +*/
111
        BYTE    *stack;       /*+ Pointer to stack area base              +*/
112
        TASK    (*body)();    /*+ Pointer to the code of the task
113
                                  (starting address)                      +*/
114
        char    name[MAX_TASKNAME]; /*+ Text identifing the process name  +*/
115
 
116
        WORD    status;       /*+ actual task status
117
                                  (it could be EXE, SLEEP, IDLE, ...)     +*/
118
        WORD    pclass;       /*+ The code number of the task model used  +*/
119
        WORD    group;        /*+ 0 if task is single, else group id      +*/
120
        WORD    stacksize;    /*+ Task stack size                         +*/
121
        DWORD   control;      /*+ Control task operating mode
122
                                 Refer to the TASK_MODEL type for its use +*/
123
 
124
        int     frozen_activations; /*+ number of frozen activation;
125
                                        see kern.c, task_block_activations
126
                                        see model.h,flag in control field +*/
127
 
128
        /* sigset_t!!! */
129
        int sigmask;          /*+ The task signal mask                    +*/
130
        int sigpending;       /*+ The signal pending mask                 +*/
131
        int sigwaiting;       /*+ The signal waiting mask                 +*/
132
 
133
        struct timespec request_time;
134
                              /*+ Last request time for the task          +*/
135
        int     avail_time;   /*+ the time the task can execute before a
136
                                  timer fire. see also the control field
137
                                  and bits related in model.h             +*/
138
 
139
        PID     shadow;       /*+ Shadow task                             +*/
140
 
141
        struct _task_handler_rec *cleanup_stack;
142
                              /*+ The cleanup stack                       +*/
143
 
144
 
29 pj 145
 
2 pj 146
        int     errnumber;
147
 
148
        /* Job Execution Time fields */
149
        TIME    jet_table[JET_TABLE_DIM];
150
                              /*+ Execution time of the last
151
                                  activations of the task.                +*/
152
        int     jet_tvalid;   /*+ number of valid entry in the jet_table  +*/
153
        int     jet_curr;     /*+ Current entry in the jet_table          +*/
154
        TIME    jet_max;      /*+ Maximum Execution time since task_create
155
                                  or last jet_delstat                     +*/
156
        TIME    jet_sum;      /*+ Mean Execution time since task_create
157
                                  or last jet_delstat                     +*/
158
        TIME    jet_n;        /*+ Number of instances on witch the mean
159
                                  time have to be computed                +*/
160
 
161
        /* task_join fields */
162
        PID waiting_for_me;   /*+ the task that waits my dead,
163
                                  NIL if there aren't                     +*/
164
        void *return_value;   /*+ task return value                       +*/
165
 
166
        /* task specific data (it uses directly POSIX constant) */
167
        void *keys[PTHREAD_KEYS_MAX];
168
 
169
        /* condition variable field */
170
        struct condition_struct *cond_waiting;
171
                              /*+ the condition on that the task is
172
                                  waiting +*/
173
 
174
        /* stuff used in most algorithms; they are not used directly in
175
         * the generic kernel, with exclusion of delay_timer that is used
176
         * also in cond_timedwait
177
         */
29 pj 178
 
2 pj 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_status)(LEVEL l);/*+ print level statistics...            +*/
223
 
224
  PID  (*level_scheduler)(LEVEL l);
225
                                /*+ the level scheduler returns a task
226
                                    chosen among those belonging to the
227
                                    level                                +*/
228
 
229
  int (*level_guarantee)(LEVEL l, bandwidth_t *freebandwidth);
230
                                /*+ 0 if the level is guaranteed, -1 if not
231
                                    no guarantee if (*f)()=null
232
                                    the function updates the parameter
233
                                    (see guarantee() )                   +*/
234
 
235
  /* TASK CALLS */
236
  int  (*task_create)(LEVEL l, PID p, TASK_MODEL *m);
237
                                /*+ the task p is created into the level
238
                                    returns 0->ok, -1->error             +*/
239
  void (*task_detach)(LEVEL l, PID p);
240
                                /*+ there is an error in the task_create
241
                                    after the task call task_create.
242
                                    The function delete all the informations
243
                                    about the task in the level.
244
                                    For the resources levels there is the
245
                                    res_detach: res_detach is called also
246
                                    when killing a task                  +*/
247
  int (*task_eligible)(LEVEL l, PID p);
248
                                /*+ correctness control when a task is
249
                                    chosen by a level scheduler (used with
250
                                    aperiodic servers) 0->ok, -1->no     +*/
251
  void (*task_dispatch)(LEVEL l, PID p, int nostop);
252
                                /*+ a task go in the EXEC status (called
253
                                    by dispatch() )                      +*/
254
  void (*task_epilogue)(LEVEL l, PID p);
255
                                /*+ a task has finished the current slice+*/
256
 
257
  void (*task_activate)(LEVEL l, PID p);
258
                                /*+ the task is activated...             +*/
259
 
260
  void (*task_insert)(LEVEL l, PID p);
261
                                /*+ opposite to task_extract             +*/
262
  void (*task_extract)(LEVEL l, PID p);
263
                                /*+ remove the task from the "ready" (if any)
264
                                    queue                                +*/
265
 
266
  void (*task_endcycle)(LEVEL l, PID p);
267
                                /*+ the (periodic) task finish the cycle +*/
268
  void (*task_end)(LEVEL l, PID p);
269
                                /*+ the task is killed; we have to remove
270
                                    it from the level queues, test if it
271
                                    is in the exec state, etc... it can
272
                                    modify the state of the task (-> FREE,
273
                                    ZOMBIE...), but
274
                                    cannot call the scheduler directly (it
275
                                    is called by the task_makefree.
276
                                    Note: the task can be in a state
277
                                    different from those managed by the
278
                                    level because the task may be blocked.
279
                                    the res_detach is in any case called
280
                                    AFTER the task_end.                  +*/
281
 
282
  void (*task_sleep)(LEVEL l, PID p);
283
                                /*+ this function will fall asleep the
284
                                    task in the EXE state. +*/
285
 
286
 
287
  /* guest CALLS:
288
     these functions are called from an Aperiodic Server Level for the task
289
     that are inserted in the local queues */
290
  int  (*guest_create)(LEVEL l, PID p, TASK_MODEL *m);
291
                                /*+ the task is already created in another
292
                                    level and it is inserted in the current
293
                                    level; returns 0->ok, -1->error      +*/
294
  void (*guest_detach)(LEVEL l, PID p);
295
                                /*+ there is an error in a task creation
296
                                    of a task made by an aperiodic server
297
                                    The function delete all the informations
298
                                    about the task in the level.         +*/
299
  void (*guest_dispatch)(LEVEL l, PID p, int nostop);
300
                                /*+ a task belonging to another level but
301
                                    inserted in the current level go in the
302
                                    EXEC status (called by dispatch() )  +*/
303
  void (*guest_epilogue)(LEVEL l, PID p);
304
                                /*+ a task has finished the current slice+*/
305
 
306
  void (*guest_activate)(LEVEL l, PID p);
307
                                /*+ the task is activated...             +*/
308
 
309
  void (*guest_insert)(LEVEL l, PID p);
310
                                /*+ remove the task from the "ready" (if any)
311
                                    queue                                +*/
312
  void (*guest_extract)(LEVEL l, PID p);
313
                                /*+ opposite to guest_insert             +*/
314
 
315
 
316
  void (*guest_endcycle)(LEVEL l, PID p);
317
                                /*+ the task finish the cycle +*/
318
  void (*guest_end)(LEVEL l, PID p);
319
                                /*+ the task is killed                   +*/
320
 
321
  void (*guest_sleep)(LEVEL l, PID p);
322
 
323
} level_des;
324
 
325
 
326
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327
  RESOURCE DESCRIPTOR
328
 
329
  In this type definition there is all the basic information for
330
  handling a resource module in the system.
331
 
332
  All the informations protocol-dependent (like ceiling, task that use
333
  a particular resource, and so on) are put in the resource module files.
334
 
335
  In general, the initialization of a resource module is splitted in two
336
  parts:
337
  - the registration   -> tipically done with a finction called
338
                          XXX_register_module. It is called before the
339
                          system initialization, in
340
                          the function __kernel_register_levels__().
341
  - the initialization -> called during the system initialization,
342
                          This is done posting some init functions with
343
                          the sys_at_init()
344
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
345
 
346
typedef struct {
347
  char res_name[MAX_MODULENAME];/*+ for statistical pourposes            +*/
348
  WORD res_code;                /*+ resource module identification code  +*/
349
  BYTE res_version;             /*+ resource module version              +*/
350
 
351
  int rtype;                    /*+ resource module extented interface
352
                                    code (see model.h)                   +*/
353
 
354
  void (*resource_status)();    /*+ print resource protocol statistics...+*/
355
 
356
  int  (*level_accept_resource_model)(RLEVEL l, RES_MODEL *r);
357
                                /*+ this function is called when the process
358
                                    is created. it returns 0 if the RES_MODEL
359
                                    can be managed by the level,-1 if not+*/
360
 
361
  void (*res_register)(RLEVEL l, PID p, RES_MODEL *r);
362
                                /*+ When the system knows that a resource
363
                                    model can be registered by a level,
364
                                    it calls this function. It registers all
365
                                    the information about the task and the
366
                                    model. +*/
367
 
368
  void (*res_detach)(RLEVEL l, PID p);
369
                                /*+ this function is called when the task
370
                                    is killed or some error is occurred
371
                                    in the task_create. It have to unlink
372
                                    the task from the module... If the task
373
                                    is already unlinked from the protocol
374
                                    no action is done                    +*/
375
} resource_des;
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
384
  MUTEX DESCRIPTOR
385
 
386
  In this type definition there is all the basic fields for
387
  handling a mutex in the system
388
 
389
  Many of the informations protocol-dependent (like ceiling, and so on)
390
  are put in the resource module or are pointef by the field opt.
391
 
392
  The opt field is used because in this way a mutex can be allocated in
393
  a dynamic way (in this case opt points to a dynamically allocated
394
  structure) or in a static way (in this case opt can be an index or a
395
  pointer to a static structure)
396
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
397
typedef struct {
398
  RLEVEL mutexlevel;  /*+ protocol used by the mutex. +*/
399
  int use;            /*+ the mutex is used in a condition wait... +*/
400
  void *opt;
401
} mutex_t;
402
 
403
 
404
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
405
  MUTEX RESOURCE DESCRIPTOR
406
 
407
  This object is a resource_des object with a set of functions used to
408
  implement the mutex behaviour.
409
 
410
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
411
typedef struct {
412
  resource_des r;
413
 
414
  int  (*level_accept_mutexattr)(RLEVEL l, const mutexattr_t *a);
415
                                /*+ this function is called when a mutex
416
                                    is created. it returns 0 if the
417
                                    mutexattr_t
418
                                    can be managed by the level,-1 if not+*/
419
 
420
  int (*init)   (RLEVEL l, mutex_t *m, const mutexattr_t *a);
421
  int (*destroy)(RLEVEL l, mutex_t *m);
422
  int (*lock)   (RLEVEL l, mutex_t *m);
423
  int (*trylock)(RLEVEL l, mutex_t *m);
424
  int (*unlock) (RLEVEL l, mutex_t *m);
425
 
426
} mutex_resource_des;
427
 
428
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429
  CONDITION VARIABLE DESCRIPTOR
430
 
431
  This is the condition variable descriptor.
432
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
433
 
434
typedef struct condition_struct {
29 pj 435
  IQUEUE waiters; /*+ queue for tasks waiting on the condition +*/
2 pj 436
  mutex_t *used_for_waiting;
437
} cond_t;
438
 
439
 
440
#endif /* __TYPE_H__ */