Subversion Repositories shark

Rev

Rev 29 | Rev 79 | 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
 ------------
38 pj 24
 CVS :        $Id: descr.h,v 1.3 2003-01-07 17:12:19 pj Exp $
2 pj 25
 
26
 File:        $File$
38 pj 27
 Revision:    $Revision: 1.3 $
28
 Last update: $Date: 2003-01-07 17:12:19 $
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
        int     avail_time;   /*+ the time the task can execute before a
134
                                  timer fire. see also the control field
135
                                  and bits related in model.h             +*/
136
 
137
        PID     shadow;       /*+ Shadow task                             +*/
138
 
139
        struct _task_handler_rec *cleanup_stack;
140
                              /*+ The cleanup stack                       +*/
141
 
142
 
29 pj 143
 
2 pj 144
        int     errnumber;
145
 
146
        /* Job Execution Time fields */
147
        TIME    jet_table[JET_TABLE_DIM];
148
                              /*+ Execution time of the last
149
                                  activations of the task.                +*/
150
        int     jet_tvalid;   /*+ number of valid entry in the jet_table  +*/
151
        int     jet_curr;     /*+ Current entry in the jet_table          +*/
152
        TIME    jet_max;      /*+ Maximum Execution time since task_create
153
                                  or last jet_delstat                     +*/
154
        TIME    jet_sum;      /*+ Mean Execution time since task_create
155
                                  or last jet_delstat                     +*/
156
        TIME    jet_n;        /*+ Number of instances on witch the mean
157
                                  time have to be computed                +*/
158
 
159
        /* task_join fields */
160
        PID waiting_for_me;   /*+ the task that waits my dead,
161
                                  NIL if there aren't                     +*/
162
        void *return_value;   /*+ task return value                       +*/
163
 
164
        /* task specific data (it uses directly POSIX constant) */
165
        void *keys[PTHREAD_KEYS_MAX];
166
 
167
        /* condition variable field */
168
        struct condition_struct *cond_waiting;
169
                              /*+ the condition on that the task is
170
                                  waiting +*/
171
 
172
        /* stuff used in most algorithms; they are not used directly in
173
         * the generic kernel, with exclusion of delay_timer that is used
174
         * also in cond_timedwait
175
         */
29 pj 176
 
2 pj 177
        int     delay_timer;  /*+ A field useful to store the delay timer +*/
178
 
179
        int     wcet;         /*+ a worst case time execution             +*/
180
 
181
 
182
} proc_des;
183
 
184
 
185
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186
  LEVEL DESCRIPTOR
187
 
188
  In this type definition there is all the basic information for
189
  handling a scheduling level in the system.
190
 
191
  All the informations that depends on the particular module are put
192
  in the level module files.
193
 
38 pj 194
  Here a small description of the various functions:
2 pj 195
 
38 pj 196
  -------------------------------------------------------------------
197
  - PUBLIC Functions:
198
    on one side, a module should export an interface to the Generic
199
    Kernel, giving a set of functions that the Generic Kernel can use
200
    to ask a service to the module. That is, the Public Functions are
201
    called ONLY by the Generic Kernel.
2 pj 202
 
38 pj 203
  - PRIVATE Functions: on the other side, a module can export an
204
    interface to the public part of the same or of another
205
    module. That is, Private Functions are called ONLY by Public and
206
    Private Functions.
207
  -------------------------------------------------------------------
2 pj 208
 
38 pj 209
  int  (*private_insert  )(LEVEL l, PID p, TASK_MODEL *m);
210
  Inserts a task into the internal module data structure.
211
 
212
  void (*private_extract )(LEVEL l, PID p);
213
  Removes a task from the internal module data structure.
2 pj 214
 
38 pj 215
  int  (*private_eligible)(LEVEL l, PID p);
216
  A task inserted into the internal module data structure needs to be
217
  scheduled. returns 0 if it can be scheduled, -1 if not.
2 pj 218
 
38 pj 219
  void (*private_dispatch)(LEVEL l, PID p, int nostop);
220
  A task inserted into the internal module data structure has been dispatched.
2 pj 221
 
38 pj 222
  void (*private_epilogue)(LEVEL l, PID p);
223
  A task inserted into the internal module data structure has been preempted.
224
 
2 pj 225
 
226
 
227
 
38 pj 228
  PID  (*public_scheduler)(LEVEL l);
229
  returns a task to schedule, or -1 if no tasks are ready
2 pj 230
 
38 pj 231
  int  (*public_guarantee)(LEVEL l, bandwidth_t *freebandwidth);
232
  returns 0 if the level is guaranteed, -1 if not
233
  no guarantee if (*f)()=null
234
  the function updates the parameter freebandwidth (see guarantee() )                  
235
  int  (*public_create   )(LEVEL l, PID p, TASK_MODEL *m);
236
  the task p is created into the module
237
  returns 0->ok, -1->error
2 pj 238
 
38 pj 239
  void (*public_detach )(LEVEL l, PID p);
240
  there is an error in the public_create. The function removes all the
241
  informations about the task in the module.
2 pj 242
 
38 pj 243
  void (*public_end      )(LEVEL l, PID p);
244
  the task has been killed, or it ended regularly
2 pj 245
 
38 pj 246
  int  (*public_eligible )(LEVEL l, PID p);
247
  A task needs to be scheduled. returns 0 if it can be scheduled, -1 if not.
248
 
249
  void (*public_dispatch )(LEVEL l, PID p, int nostop);
250
  A task has been dispatched.
2 pj 251
 
38 pj 252
  void (*public_epilogue )(LEVEL l, PID p);
253
  A task has been preempted (or its capacity is exausted).
2 pj 254
 
38 pj 255
  void (*public_activate )(LEVEL l, PID p);
256
  A task has been activated.
2 pj 257
 
38 pj 258
  void (*public_unblock  )(LEVEL l, PID p);
259
  void (*public_block    )(LEVEL l, PID p);
260
  A task has been unblocked/blocked on a synchronization point
261
  (e.g. a semaphore, a mailbox, a nanosleep).
2 pj 262
 
38 pj 263
  int (*public_message  )(LEVEL l, PID p, void *m);
264
  A task sent a message m to the module.
2 pj 265
 
38 pj 266
  If the message has value NULL the
267
  behavior should be the task_endcycle primitive behavior.
2 pj 268
 
38 pj 269
  The function returns an integer to the user.
2 pj 270
 
38 pj 271
  If you want to avoid the call to public_epilogue, after public_message,
272
  just write exec = exec_shadow = -1; in your public_message code.
2 pj 273
 
38 pj 274
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
275
 
276
typedef struct {
277
  void (*private_insert  )(LEVEL l, PID p, TASK_MODEL *m);
278
  void (*private_extract )(LEVEL l, PID p);
279
  int  (*private_eligible)(LEVEL l, PID p);
280
  void (*private_dispatch)(LEVEL l, PID p, int nostop);
281
  void (*private_epilogue)(LEVEL l, PID p);
282
 
283
  PID  (*public_scheduler)(LEVEL l);
284
  int  (*public_guarantee)(LEVEL l, bandwidth_t *freebandwidth);
285
  int  (*public_create   )(LEVEL l, PID p, TASK_MODEL *m);
286
  void (*public_detach   )(LEVEL l, PID p);
287
  void (*public_end      )(LEVEL l, PID p);
288
  int  (*public_eligible )(LEVEL l, PID p);
289
  void (*public_dispatch )(LEVEL l, PID p, int nostop);
290
  void (*public_epilogue )(LEVEL l, PID p);
291
  void (*public_activate )(LEVEL l, PID p);
292
  void (*public_unblock  )(LEVEL l, PID p);
293
  void (*public_block    )(LEVEL l, PID p);
294
  int  (*public_message  )(LEVEL l, PID p, void *m);
2 pj 295
} level_des;
296
 
297
 
298
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
299
  RESOURCE DESCRIPTOR
300
 
301
  In this type definition there is all the basic information for
302
  handling a resource module in the system.
303
 
304
  All the informations protocol-dependent (like ceiling, task that use
305
  a particular resource, and so on) are put in the resource module files.
306
 
307
  In general, the initialization of a resource module is splitted in two
308
  parts:
309
  - the registration   -> tipically done with a finction called
310
                          XXX_register_module. It is called before the
311
                          system initialization, in
312
                          the function __kernel_register_levels__().
313
  - the initialization -> called during the system initialization,
314
                          This is done posting some init functions with
315
                          the sys_at_init()
316
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
317
 
318
typedef struct {
319
  int rtype;                    /*+ resource module extented interface
320
                                    code (see model.h)                   +*/
321
 
38 pj 322
  int (*res_register)(RLEVEL l, PID p, RES_MODEL *r);
323
                                /*+ When the system knows that a
324
                                    resource model can be registered
325
                                    by a level, it calls this
326
                                    function. It registers all the
327
                                    information about the task and the
328
                                    model. returns 0 if the model
329
                                    can be handled, -1 otherwise+*/
2 pj 330
 
331
  void (*res_detach)(RLEVEL l, PID p);
332
                                /*+ this function is called when the task
333
                                    is killed or some error is occurred
334
                                    in the task_create. It have to unlink
335
                                    the task from the module... If the task
336
                                    is already unlinked from the protocol
337
                                    no action is done                    +*/
338
} resource_des;
339
 
340
 
341
 
342
 
343
 
344
 
345
 
346
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
347
  MUTEX DESCRIPTOR
348
 
349
  In this type definition there is all the basic fields for
350
  handling a mutex in the system
351
 
352
  Many of the informations protocol-dependent (like ceiling, and so on)
353
  are put in the resource module or are pointef by the field opt.
354
 
355
  The opt field is used because in this way a mutex can be allocated in
356
  a dynamic way (in this case opt points to a dynamically allocated
357
  structure) or in a static way (in this case opt can be an index or a
358
  pointer to a static structure)
359
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
360
typedef struct {
361
  RLEVEL mutexlevel;  /*+ protocol used by the mutex. +*/
362
  int use;            /*+ the mutex is used in a condition wait... +*/
363
  void *opt;
364
} mutex_t;
365
 
366
 
367
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
368
  MUTEX RESOURCE DESCRIPTOR
369
 
370
  This object is a resource_des object with a set of functions used to
371
  implement the mutex behaviour.
372
 
373
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
374
typedef struct {
375
  resource_des r;
376
 
377
  int (*init)   (RLEVEL l, mutex_t *m, const mutexattr_t *a);
38 pj 378
    /*+ this function is called when a mutex is created. it returns
379
        >=0 if the mutexattr_t can be managed by the level (=0 Ok, an
380
        error otherwise), -1 otherwise +*/
2 pj 381
  int (*destroy)(RLEVEL l, mutex_t *m);
382
  int (*lock)   (RLEVEL l, mutex_t *m);
383
  int (*trylock)(RLEVEL l, mutex_t *m);
384
  int (*unlock) (RLEVEL l, mutex_t *m);
385
 
386
} mutex_resource_des;
387
 
388
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389
  CONDITION VARIABLE DESCRIPTOR
390
 
391
  This is the condition variable descriptor.
392
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
393
 
394
typedef struct condition_struct {
29 pj 395
  IQUEUE waiters; /*+ queue for tasks waiting on the condition +*/
2 pj 396
  mutex_t *used_for_waiting;
397
} cond_t;
398
 
399
 
400
#endif /* __TYPE_H__ */