Subversion Repositories shark

Rev

Rev 673 | Rev 691 | 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
 ------------
677 giacomo 24
 CVS :        $Id: model.h,v 1.10 2004-05-25 12:14:35 giacomo Exp $
2 pj 25
 
26
 File:        $File$
677 giacomo 27
 Revision:    $Revision: 1.10 $
28
 Last update: $Date: 2004-05-25 12:14:35 $
2 pj 29
 ------------
30
 
31
 This file contains the definitions of the task and resource models.
32
 
33
**/
34
 
35
/*
36
 * Copyright (C) 2000 Paolo Gai
37
 *
38
 * This program is free software; you can redistribute it and/or modify
39
 * it under the terms of the GNU General Public License as published by
40
 * the Free Software Foundation; either version 2 of the License, or
41
 * (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
51
 *
52
 */
53
 
54
#ifndef __KERNEL_MODEL_H__
55
#define __KERNEL_MODEL_H__
56
 
57
#include "ll/ll.h"
38 pj 58
#include "kernel/types.h"
79 pj 59
#include "ll/sys/cdefs.h"
2 pj 60
 
79 pj 61
__BEGIN_DECLS
62
 
2 pj 63
/* -----------------------------------------------------------------------
64
   -----------------------------------------------------------------------
65
   -----------------------------------------------------------------------
66
   -----------------------------------------------------------------------
67
   TASK MODELS
68
   -----------------------------------------------------------------------
69
   -----------------------------------------------------------------------
70
   -----------------------------------------------------------------------
71
   ----------------------------------------------------------------------- */
72
 
73
 
74
/* -----------------------------------------------------------------------
75
   TASK_MODELS: the base struct
76
   ----------------------------------------------------------------------- */
77
 
78
/*+
79
 TASK_MODEL
80
 
81
 IMPORTANT: this structure shall not be used by the end-user!!!
82
 
83
 This structure is only used to group together a set of optional
84
 parameters describing the task model. This structure is passed
85
 to the task_create primitive.
86
 
87
 The control field is used to set special task processing
88
 functions.
89
 
90
 Currently it supports:
91
 
92
 - USE_FPU     bit
93
   If the hw architecture is not smart enough to allow automatic
94
   FPU context switch, this information is used at the VM level
95
   to perform transparently the preemption of a FPU-task
96
 
97
 - NO_KILL     bit
98
   If this bit is set, the task can't be killed via the task_kill
99
   function. To make a task unkillable for short periods of time,
100
   use the cancellability functions instead.
101
 
102
 - NO_PREEMPT  bit
103
   If this bit is set, the task can't be preempted. To set/reset it,
104
   use the primitive task_preempt/task_no_preempt
105
 
106
 - SYSTEM_TASK bit
107
   If this bit is set, the task is a system task. The whole system exit
108
   only when all the non-system tasks are terminated.
109
 
110
 - JET_ENABLED bit
111
   If this bit is set the Generic Kernel records the Job Execution Times
112
   for the task. See the jet_XXX functions...
113
 
114
 - TASK_JOINABLE bit
115
   If this bit is set the task is joinable with task_join, otherwise the
116
   task is detached...
117
 
118
 - STACKADDR_SPECIFIED bit
119
   This bit is set when the task was created if we specify in the model
120
   the stack address. When the task ends, if this bi is set, the stack
121
   is not freed.
122
 
123
 
124
 - KILL_*      bits
125
   These bits are used to memorize the cancelability state of the task.
126
 
127
 - CONTROL_CAP bit
128
   This flag has to be set in the scheduling modules (NOT by the end-user)
129
   only if the kernel has to check the capacity for the task. The kernel
130
   uses only the avail_time field of the process descriptor.
131
 
132
 - TASK_DOING_SIGNALS bit
133
   It is an internal flag used with signal handling. It is set only when
134
   the task is executing a signal handler
135
 
136
 - FREEZE_ACTIVATION
137
   If this bit is set, the task_activate primitive doesn't activate any task;
138
   instead, it increment a counter. See task_[un]block_activations in kern.c
139
 
140
 - WAIT_FOR_JOIN
141
   The flag is set when the task terminates; the descriptor is not
142
   freed because we wait a task_join
143
 
144
 - DESCRIPTOR_DISCARDED
145
   This bit is set when the task descriptor is discarded by task_createn
146
   (the wait_for_join flag is set and the task was inserted in the free
147
   queue by a scheduling level). The task will be reinserted into the
148
   free queue by task_join...
149
 
150
 All the models redefines the TASK_MODEL structure
151
 - adding new fields if needed
152
 - using a unique number in the pclass variable
153
 
154
 When the user wants to create a task, he must specify a task model.
155
 First, he have to define a XXX_TASK_MODEL, then he must initialize it with
156
 a XXX_task_default_model.
157
 
158
 Then, he can specify some attributes that characterize the model.
159
 
160
 Not all the fields of a task model are mandatory, but a scheduling level
161
 or an ahard server may require some of them.
162
 For example, if the user wants to create an ahard tasks, he may specify
163
 a wcet. The wcet is not required by a Deferrable Server, but it is mandatory
164
 for a TBS!!!.
165
 
166
+*/
167
 
168
 
169
typedef struct {
170
    WORD    pclass;
38 pj 171
    LEVEL   level;
2 pj 172
    size_t  stacksize;
173
    void    *stackaddr;
174
    WORD    group;
175
    void    *arg;
176
    DWORD   control;
177
} TASK_MODEL;
178
 
179
/*+ Value for the control field, It is set if +*/
180
#define USE_FPU              0x0001 /*+ the task use FPU registers +*/
181
#define NO_KILL              0x0002 /*+ the task isn't killable at all +*/
182
#define NO_PREEMPT           0x0004 /*+ the task isn't preemptable +*/
183
#define SYSTEM_TASK          0x0008 /*+ the task is a system task. +*/
184
#define JET_ENABLED          0x0010 /*+ execution time monitoring enabled +*/
185
#define TASK_JOINABLE        0x0020 /*+ the task is joinable (see task_join)+*/
186
#define STACKADDR_SPECIFIED  0x0040 /*+ the stackaddr was specified +*/
187
#define TRACE_TASK          0x20000 /*+ the task must be traced +*/
188
 
189
/*+ flags contained in the control field, usettables from the models: +*/
190
#define KILLED_ON_CONDITION  0x0080 /*+ the task is killed but it is waiting
191
                                        to die because it must reaquire
192
                                        the mutex +*/
193
#define KILL_ENABLED         0x0100 /*+ cancelability enabled +*/
194
#define KILL_DEFERRED        0x0200 /*+ cancelability type deferred/async. +*/
195
#define KILL_REQUEST         0x0400 /*+ kill issued but not executed +*/
196
#define CONTROL_CAP          0x0800 /*+ Capacity control enabled +*/
197
#define TASK_DOING_SIGNALS   0x1000 /*+ see kern_deliver_pending_signals
198
                                        in signal.c +*/
199
#define FREEZE_ACTIVATION    0x2000 /*+ see task_block_activation in kern.c +*/
200
 
201
/* flags used in the implementation of the task_join */
202
#define WAIT_FOR_JOIN        0x4000 /*+ the task is terminated, but the
203
                                        descriptor is not freed because we wait
204
                                        a task_join +*/
205
#define DESCRIPTOR_DISCARDED 0x8000 /*+ the task descriptor is discarded by
206
                                        task_createn because the wait_for_join
207
                                        flag is set and it was inserted in the
208
                                        free queue by a scheduling level +*/
209
 
210
/* flag used in the implementation of the sig_timedwait */
211
#define SIGTIMEOUT_EXPIRED   0x10000 /*+ if the sigwait timer expires this
212
                                        flag is set... +*/
213
 
328 giacomo 214
/* flag to avoid task_makefree called 2 times */
215
#define TASK_MAKEFREE       0x100000
2 pj 216
 
217
/* Some macros to set various task-model parameters */
218
#define task_default_model(m,p) (m).pclass = (p), \
38 pj 219
                                (m).level = 0; \
2 pj 220
                                (m).stacksize = 4096, \
221
                                (m).stackaddr = NULL, \
222
                                (m).group = 0, \
223
                                (m).arg = NULL,\
224
                                (m).control = 0
38 pj 225
#define task_def_level(m,l)     (m).level = (l)
2 pj 226
#define task_def_arg(m,a)       (m).arg = (a)
227
#define task_def_stack(m,s)     (m).stacksize = (s)
228
#define task_def_stackaddr(m,s) (m).stackaddr = (s)
229
#define task_def_group(m,g)     (m).group = (g)
230
#define task_def_usemath(m)     (m).control |= USE_FPU
231
#define task_def_system(m)      (m).control |= SYSTEM_TASK
232
#define task_def_nokill(m)      (m).control |= NO_KILL
233
#define task_def_ctrl_jet(m)    (m).control |= JET_ENABLED
234
#define task_def_joinable(m)    (m).control |= TASK_JOINABLE
235
#define task_def_unjoinable(m)  (m).control &= ~TASK_JOINABLE
236
#define task_def_trace(m)       (m).control |= TRACE_TASK
237
#define task_def_notrace(m)     (m).control &= ~TRACE_TASK
238
 
239
 
240
 
241
 
242
/* -----------------------------------------------------------------------
243
   PCLASS values
244
   ----------------------------------------------------------------------- */
245
 
38 pj 246
/* These are the value for the pclass field */
2 pj 247
 
38 pj 248
#define DUMMY_PCLASS        0
249
#define HARD_PCLASS         1
250
#define SOFT_PCLASS         2
251
#define NRT_PCLASS          3
252
#define JOB_PCLASS          4
671 giacomo 253
#define ELASTIC_PCLASS      5
2 pj 254
 
255
/* -----------------------------------------------------------------------
256
   Useful stuffs
257
   ----------------------------------------------------------------------- */
258
 
259
#define PERIODIC       0
260
#define APERIODIC      1
512 giacomo 261
#define INTDRIVE       2
2 pj 262
 
263
#define SAVE_ARRIVALS  0
264
#define SKIP_ARRIVALS  1
265
 
671 giacomo 266
#define NO_PREDEFINED_SCALING     0
267
#define WCET_SCALING   1
268
#define PERIOD_SCALING 2
2 pj 269
 
270
/* -----------------------------------------------------------------------
271
   DUMMY_TASK_MODEL: model used only for the dummy task
272
   ----------------------------------------------------------------------- */
273
 
274
/*+ the dummy task doesn't add any new field +*/
275
typedef TASK_MODEL DUMMY_TASK_MODEL;
276
 
277
#define dummy_task_default_model(m) task_default_model(m,DUMMY_PCLASS)
278
#define dummy_task_def_level(m,l)   task_def_level(m,l)
279
#define dummy_task_def_system(m)    task_def_system(m)
280
#define dummy_task_def_nokill(m)    task_def_nokill(m)
281
#define dummy_task_def_ctrl_jet(m)  task_def_ctrl_jet(m)
282
 
283
 
284
 
285
 
286
 
287
 
288
/* -----------------------------------------------------------------------
289
   HARD_TASK_MODEL: hard Tasks
290
   ----------------------------------------------------------------------- */
291
 
292
/*  A Hard Task model can be used to model periodic and sporadic tasks.
293
    These tasks are usually guaranteed basing on their minimum interarrival
657 anton 294
    time (mit) and wcet, and may have a relative deadline and a release
295
    offset.
2 pj 296
 
297
    A hard task can raise these exceptions:
298
    XDEADLINE_MISS XWCET_VIOLATION XACTIVATION
299
 
300
    The default model sets wcet, mit and relative deadline to 0, and
301
    the periodicity to PERIODIC.
302
*/
303
 
304
typedef struct {
305
  TASK_MODEL t;
306
  TIME mit;
307
  TIME drel;
308
  TIME wcet;
309
  int periodicity;
657 anton 310
  TIME offset;
2 pj 311
} HARD_TASK_MODEL;
312
 
313
#define hard_task_default_model(m)                             \
314
                        task_default_model((m).t,HARD_PCLASS), \
315
                        (m).mit         = 0,                   \
316
                        (m).drel        = 0,                   \
317
                        (m).wcet        = 0,                   \
657 anton 318
                        (m).periodicity = PERIODIC,            \
319
                        (m).offset      = 0 
2 pj 320
#define hard_task_def_level(m,l)    task_def_level((m).t,l)
321
#define hard_task_def_arg(m,a)      task_def_arg((m).t,a)
322
#define hard_task_def_stack(m,s)    task_def_stack((m).t,s)
323
#define hard_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
324
#define hard_task_def_group(m,g)    task_def_group((m).t,g)
325
#define hard_task_def_usemath(m)    task_def_usemath((m).t)
326
#define hard_task_def_system(m)     task_def_system((m).t)
327
#define hard_task_def_nokill(m)     task_def_nokill((m).t)
328
#define hard_task_def_ctrl_jet(m)   task_def_ctrl_jet((m).t)
329
#define hard_task_def_mit(m,p)      (m).mit = (p)
330
#define hard_task_def_drel(m,d)     (m).drel = (d)
331
#define hard_task_def_wcet(m,w)     (m).wcet = (w)
657 anton 332
#define hard_task_def_offset(m,o)   (m).offset = (o)
2 pj 333
#define hard_task_def_periodic(m)   (m).periodicity = PERIODIC
334
#define hard_task_def_aperiodic(m)  (m).periodicity = APERIODIC
512 giacomo 335
#define hard_task_def_interrupt(m)  (m).periodicity = INTDRIVE
2 pj 336
#define hard_task_def_joinable(m)   task_def_joinable((m).t)
337
#define hard_task_def_unjoinable(m) task_def_unjoinable((m).t)
338
#define hard_task_def_trace(m)      task_def_trace((m).t)
339
#define hard_task_def_notrace(m)    task_def_notrace((m).t)
340
 
341
 
342
 
343
/* -----------------------------------------------------------------------
344
   SOFT_TASK_MODEL: Soft Tasks
345
   ----------------------------------------------------------------------- */
346
 
347
/*  A Soft Task model can be used to model periodic and aperiodic tasks
348
    usually not guaranteed or guaranteed basing on their period and mean
349
    execution time (met). A Soft task can also record pending activations if
350
    the arrivals are set to SAVE.
351
 
352
    A wcet field is also present for those servers that need if (i.e., TBS)
353
 
354
    The default model sets met, period and wcet to 0, the periodicity to
355
    PERIODIC and the arrivals to SAVE.
356
 
357
    A Soft Task don't raise any exception.
358
*/
359
 
360
typedef struct {
361
  TASK_MODEL t;
362
  TIME period;
363
  TIME met;
364
  TIME wcet;
365
  int periodicity;
366
  int arrivals;
367
} SOFT_TASK_MODEL;
368
 
369
#define soft_task_default_model(m)                             \
370
                        task_default_model((m).t,SOFT_PCLASS), \
371
                        (m).period      = 0,                   \
372
                        (m).met         = 0,                   \
373
                        (m).wcet        = 0,                   \
374
                        (m).periodicity = PERIODIC,            \
375
                        (m).arrivals    = SAVE_ARRIVALS
376
#define soft_task_def_level(m,l)       task_def_level((m).t,l)
377
#define soft_task_def_arg(m,a)         task_def_arg((m).t,a)
378
#define soft_task_def_stack(m,s)       task_def_stack((m).t,s)
379
#define soft_task_def_stackaddr(m,s)   task_def_stackaddr((m).t,s)
380
#define soft_task_def_group(m,g)       task_def_group((m).t,g)
381
#define soft_task_def_usemath(m)       task_def_usemath((m).t)
382
#define soft_task_def_system(m)        task_def_system((m).t)
383
#define soft_task_def_nokill(m)        task_def_nokill((m).t)
384
#define soft_task_def_ctrl_jet(m)      task_def_ctrl_jet((m).t)
385
#define soft_task_def_period(m,p)      (m).period = (p)
386
#define soft_task_def_met(m,d)         (m).met = (d)
387
#define soft_task_def_wcet(m,w)        (m).wcet = (w)
388
#define soft_task_def_periodic(m)      (m).periodicity = PERIODIC
389
#define soft_task_def_aperiodic(m)     (m).periodicity = APERIODIC
390
#define soft_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
391
#define soft_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
392
#define soft_task_def_joinable(m)      task_def_joinable((m).t)
393
#define soft_task_def_unjoinable(m)    task_def_unjoinable((m).t)
394
#define soft_task_def_trace(m)         task_def_trace((m).t)
395
#define soft_task_def_notrace(m)       task_def_notrace((m).t)
396
 
397
/* -----------------------------------------------------------------------
398
   NRT_TASK_MODEL: Non Realtime Tasks
399
   ----------------------------------------------------------------------- */
400
 
401
/* A NRT task has a weight and a time slice, plus  a policy attribute.
402
   It can be used to model Round Robin, Proportional Share, POSIX,
403
   and Priority tasks.
404
 
405
   Policy and inherit is inserted in the model to support posix
406
   compliant scheduling...
407
 
408
   The default model set weight and slice to 0, policy to RR, and inherit
409
   to explicit.
410
*/
411
 
412
#define NRT_RR_POLICY   0
413
#define NRT_FIFO_POLICY 1
414
 
415
#define NRT_INHERIT_SCHED  0
416
#define NRT_EXPLICIT_SCHED 1
417
 
418
typedef struct {
419
  TASK_MODEL t;
420
  int weight;
421
  TIME slice;
422
  int arrivals;
423
  int policy;
424
  int inherit;
425
} NRT_TASK_MODEL;
426
 
427
#define nrt_task_default_model(m) task_default_model((m).t,NRT_PCLASS), \
428
                                      (m).weight   = 0,                 \
429
                                      (m).slice    = 0,                 \
430
                                      (m).arrivals = SAVE_ARRIVALS,     \
431
                                      (m).policy   = NRT_RR_POLICY,     \
432
                                      (m).inherit  = NRT_EXPLICIT_SCHED
433
#define nrt_task_def_level(m,l)       task_def_level((m).t,l)
434
#define nrt_task_def_arg(m,a)         task_def_arg((m).t,a)
435
#define nrt_task_def_stack(m,s)       task_def_stack((m).t,s)
436
#define nrt_task_def_stackaddr(m,s)   task_def_stackaddr((m).t,s)
437
#define nrt_task_def_group(m,g)       task_def_group((m).t,g)
438
#define nrt_task_def_usemath(m)       task_def_usemath((m).t)
439
#define nrt_task_def_system(m)        task_def_system((m).t)
440
#define nrt_task_def_nokill(m)        task_def_nokill((m).t)
441
#define nrt_task_def_ctrl_jet(m)      task_def_ctrl_jet((m).t)
442
#define nrt_task_def_joinable(m)      task_def_joinable((m).t)
443
#define nrt_task_def_unjoinable(m)    task_def_unjoinable((m).t)
444
#define nrt_task_def_weight(m,w)      (m).weight = (w)
445
#define nrt_task_def_slice(m,s)       (m).slice = (s)
446
#define nrt_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
447
#define nrt_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
448
#define nrt_task_def_policy(m,p)      (m).policy = (p)
449
#define nrt_task_def_inherit(m,i)     (m).inherit = (i)
450
#define nrt_task_def_trace(m)         task_def_trace((m).t)
451
#define nrt_task_def_notrace(m)       task_def_notrace((m).t)
452
 
453
 
454
/* -----------------------------------------------------------------------
455
   JOB_TASK_MODEL: Job Task
456
   ----------------------------------------------------------------------- */
457
 
458
/*  This model implements a Job with an optional period and a starting
459
    deadline (for the first activation).
460
 
461
    A Job task can raise a XDEADLINE_MISS exception;
462
    if the flag noraiseexc is != 0, the exception is not raised.
463
 
464
    It represent a SINGLE job activation. Typically, a task with this
465
    model NEVER call a task_sleep or task_endcycle. Why? because it is
466
    a single activation.
467
 
468
    In fact, this model is normally used with aperiodic
469
    servers: the aperiodic server insert a guest task in another level
470
    with that model; then, when the current activation is ended (e.g. a
471
    task_sleep() is called) the level, into the XXX_task_sleep, calls
472
    the XXX_guest_end to terminate the actual activation.
473
 
474
    Note that there is no capacity control on this model.
475
    Note that the task that accept this task DOESN'T reactivate the
476
    task after a period... There is NOT a guest_endcycle defined
477
    for this model...
478
 
479
    The default model set noraiseexc and period to 0, and accept a deadline
480
*/
481
 
482
typedef struct {
483
  TASK_MODEL t;
484
  TIME period;
485
  struct timespec deadline;
486
  int noraiseexc;
487
} JOB_TASK_MODEL;
488
 
489
#define job_task_default_model(m,dl)                     \
490
                  task_default_model((m).t,JOB_PCLASS),  \
491
                  (m).period = 0,                        \
492
                  TIMESPEC_ASSIGN(&((m).deadline),&(dl)),\
493
                  (m).noraiseexc = 0
494
#define job_task_def_level(m,l)     task_def_level((m).t,l)
495
#define job_task_def_arg(m,a)       task_def_arg((m).t,a)
496
#define job_task_def_stack(m,s)     task_def_stack((m).t,s)
497
#define job_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
498
#define job_task_def_group(m,g)     task_def_group((m).t,g)
499
#define job_task_def_usemath(m)     task_def_usemath((m).t)
500
#define job_task_def_system(m)      task_def_system((m).t)
501
#define job_task_def_nokill(m)      task_def_nokill((m).t)
502
#define job_task_def_ctrl_jet(m)    task_def_ctrl_jet((m).t)
503
#define job_task_def_period(m,per)  (m).period = (per)
504
#define job_task_def_deadline(m,dl) TIMESPEC_ASSIGN(&((m).deadline),&(dl))
505
#define job_task_def_noexc(m)       (m).noraiseexc = 1
506
#define job_task_def_yesexc(m)      (m).noraiseexc = 0
507
#define job_task_def_joinable(m)    task_def_joinable((m).t)
508
#define job_task_def_unjoinable(m)  task_def_unjoinable((m).t)
509
#define job_task_def_trace(m)       task_def_trace((m).t)
510
#define job_task_def_notrace(m)     task_def_notrace((m).t)
511
 
671 giacomo 512
/* Elastic Task */
2 pj 513
 
671 giacomo 514
typedef struct {
515
  TASK_MODEL t;
516
  TIME Tmin;
517
  TIME Tmax;
518
  TIME wcet;
519
  int  kelastic;
520
  int  beta;
521
  int  arrivals;
522
} ELASTIC_TASK_MODEL;
523
 
672 giacomo 524
#define elastic_task_default_model(m)                        \
671 giacomo 525
                  task_default_model((m).t,ELASTIC_PCLASS),  \
526
                  (m).Tmin = 0,                        \
527
                  (m).Tmax = 0,                        \
528
                  (m).wcet = 0,                        \
529
                  (m).kelastic = 0,                    \
530
                  (m).beta = NO_PREDEFINED_SCALING,    \
531
                  (m).arrivals = SKIP_ARRIVALS
532
#define elastic_task_def_level(m,l)     task_def_level((m).t,l)
533
#define elastic_task_def_arg(m,a)       task_def_arg((m).t,a)
534
#define elastic_task_def_stack(m,s)     task_def_stack((m).t,s)
535
#define elastic_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
536
#define elastic_task_def_group(m,g)     task_def_group((m).t,g)
537
#define elastic_task_def_usemath(m)     task_def_usemath((m).t)
538
#define elastic_task_def_system(m)      task_def_system((m).t)
539
#define elastic_task_def_nokill(m)      task_def_nokill((m).t)
540
#define elastic_task_def_ctrl_jet(m)    task_def_ctrl_jet((m).t)
677 giacomo 541
#define elastic_task_def_period(m,min,max)  (m).Tmin = (min),\
542
                                              (m).Tmax = (max)
543
#define elastic_task_def_wcet(m,w)      (m).wcet = (w)
544
#define elastic_task_def_param(m,k,b)   (m).kelastic = (k), \
545
                                        (m).beta = (b)
671 giacomo 546
#define elastic_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
547
#define elastic_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
548
#define elastic_task_def_joinable(m)    task_def_joinable((m).t)
549
#define elastic_task_def_unjoinable(m)  task_def_unjoinable((m).t)
550
#define elastic_task_def_trace(m)       task_def_trace((m).t)
551
#define elastic_task_def_notrace(m)     task_def_notrace((m).t)
2 pj 552
 
553
 
554
 
555
 
556
 
557
 
558
 
559
 
560
 
671 giacomo 561
 
2 pj 562
/* -----------------------------------------------------------------------
563
   -----------------------------------------------------------------------
564
   -----------------------------------------------------------------------
565
   -----------------------------------------------------------------------
566
   RESOURCE MODELS
567
   -----------------------------------------------------------------------
568
   -----------------------------------------------------------------------
569
   -----------------------------------------------------------------------
570
   ----------------------------------------------------------------------- */
571
 
572
 
573
 
574
 
575
 
576
 
577
 
578
/* -----------------------------------------------------------------------
579
   RTYPE values
580
   ----------------------------------------------------------------------- */
581
 
582
/* These are the values for the rtype field of a resource descriptor.
583
   The value in the rtype field is used to distinguish the interface really
584
   implemented by the resource object.
585
 
586
   For example, a mutex resource descriptor "inherit" from a resource_des
587
   and implements also all the mutex functions as "virtual", so a type field
588
   is added to the resource descriptor to distinguish witch interface is
589
   really added. +*/
590
 
591
#define DEFAULT_RTYPE     0  /*+ no fields added to resource_des +*/
592
#define MUTEX_RTYPE       1  /*+ the structure implements a mutex
593
                                 protocol, so a cast to mutex_resource_des
594
                                 is legal +*/
595
 
596
 
597
 
598
/* -----------------------------------------------------------------------
599
   RES_MODEL - the base struct
600
   ----------------------------------------------------------------------- */
601
 
602
/*+
603
 RES_MODEL
604
 
605
 This structure is used like the TASK_MODEL.
606
 It groups together a set of optional parameters describing
607
 the resource model used by a task.
608
 
609
 It contains only a field; the others are model-dependent.
610
+*/
611
 
612
typedef struct {
38 pj 613
  int rclass;        /* protocol */
614
  RLEVEL level;          /* level */
2 pj 615
} RES_MODEL;
616
 
38 pj 617
#define res_default_model(r, p)      (r).rclass = (p), (r).level = 0
618
#define res_def_level(r,l)           (r).level = (l)
2 pj 619
 
620
 
621
 
622
/* -----------------------------------------------------------------------
623
   RCLASS values
624
   ----------------------------------------------------------------------- */
625
 
626
/*+ These are the values for the type field in the resource models
627
    a resource level l that accept a resource model with rclass r
628
    accept also the alias pclass (p | l)
629
    => the LSByte MUST be 0 (256 levels maximum) (as for PCLASS!!!) +*/
630
 
631
#define PC_RCLASS    0x0100
632
#define SRP_RCLASS   0x0200
633
#define SRP2_RCLASS  0x0300
634
 
635
#define BDEDF_RCLASS   0x0400
636
#define BDPSCAN_RCLASS 0x0500
637
 
638
/* -----------------------------------------------------------------------
639
   PC_RES_MODEL: BlockDevice EDF resource model
640
   ----------------------------------------------------------------------- */
641
 
642
typedef struct {
643
  RES_MODEL r;
644
  TIME dl;
645
} BDEDF_RES_MODEL;
646
 
647
#define BDEDF_res_default_model(res) \
648
  res_default_model((res).r,BDEDF_RCLASS); \
649
  (res).dl=0     
650
#define BDEDF_res_def_level(res,l)  res_def_level((res).r,l)     
651
#define BDEDF_res_def_dl(res,reldl)  (res).dl=reldl
652
 
653
/* -----------------------------------------------------------------------
654
   PC_RES_MODEL: BlockDevice PSCAN resource model
655
   ----------------------------------------------------------------------- */
656
 
657
typedef struct {
658
  RES_MODEL r;
659
  int priority;
660
} BDPSCAN_RES_MODEL;
661
 
662
#define BDPSCAN_res_default_model(res) \
663
  res_default_model((res).r,BDPSCAN_RCLASS); \
664
  (res).priority=255     
665
#define BDPSCAN_res_def_level(res,l)  res_def_level((res).r,l)     
666
#define BDPSCAN_res_def_priority(res,pri)  (res).priority=pri
667
 
668
/* -----------------------------------------------------------------------
669
   PC_RES_MODEL: Priority ceiling resource model
670
   ----------------------------------------------------------------------- */
671
 
672
/* the tasks created without using this resource models are assumed to have
673
   priority = MAX_DWORD (the lowest). */
674
 
675
typedef struct {
676
  RES_MODEL r;
677
  DWORD priority;
678
} PC_RES_MODEL;
679
 
680
#define PC_res_default_model(res, prio) \
681
                                 res_default_model((res).r, PC_RCLASS); \
682
                                 (res).priority = (prio)
683
#define PC_res_def_level(res,l)  res_def_level(res,l)
684
 
685
/* -----------------------------------------------------------------------
686
   SRP_RES_MODEL: Stack Resource Policy resource model
687
   ----------------------------------------------------------------------- */
688
 
689
/* the tasks created without using this resource model are not allowed to
690
   lock any SRP mutex. if two of this models are passed to the task_create,
691
   one of them is chosen, in a nondeterministic way, so use only one of
692
   this resource model per task!!!
693
 
694
   The First SRP version uses another resource model that is embedded into
695
   the mutex structure. refer to kernel/modules/srp.c. this second resource
696
   model has the SRP2_RCLASS
697
*/
698
 
699
typedef struct {
700
  RES_MODEL r;
701
  DWORD preempt;  /* the preemption level of a task */
702
} SRP_RES_MODEL;
703
 
704
#define SRP_res_default_model(res, pre) \
705
                                 res_default_model((res).r, SRP_RCLASS); \
706
                                 (res).preempt = (pre)
707
#define SRP_res_def_level(res,l) res_def_level(res,l)
708
 
709
 
710
/* -----------------------------------------------------------------------
711
   MUTEX Attributes
712
   ----------------------------------------------------------------------- */
713
 
714
/*+
715
  MUTEX ATTRIBUTES
716
 
717
  A mutexattr object act as the task model for the tasks in the system:
718
  It specifies the particular options used by a protocol.
719
 
720
  From this basic attribute object many other objects can be derived
721
  as done for the TASK_MODEL. These objects are used to initialize a mutex
722
  with a specified protocol.
723
+*/
724
typedef struct {
725
  int mclass;      /* the protocol type... */
726
} mutexattr_t;
727
 
728
#define mutexattr_default(a, c)  (a).mclass = (c)
729
 
730
 
731
/* -----------------------------------------------------------------------
732
   MCLASS values
733
   ----------------------------------------------------------------------- */
734
 
735
/*+ These are the value for the mclass field;
736
    a mutex level l that accept a task model with mclass m
737
    accept also the alias mclass (m | l)
738
    => the LSByte MUST be 0 (256 levels maximum) +*/
739
 
740
#define NPP_MCLASS      0x0100
741
#define PI_MCLASS       0x0200
742
#define PC_MCLASS       0x0300
743
#define SRP_MCLASS      0x0400
744
#define NOP_MCLASS      0x0500
745
#define NOPM_MCLASS     0x0600
746
 
747
/* -----------------------------------------------------------------------
748
   PI_mutexattr_t: Priority Inheritance Mutex Attribute
749
   ----------------------------------------------------------------------- */
750
 
751
typedef mutexattr_t PI_mutexattr_t;
752
 
753
#define PI_MUTEXATTR_INITIALIZER {PI_MCLASS}
754
#define PI_mutexattr_default(a)  mutexattr_default(a, PI_MCLASS)
755
 
756
/* -----------------------------------------------------------------------
757
   NPP_mutexattr_t: Non Preemptive Protocol Mutex Attribute
758
   ----------------------------------------------------------------------- */
759
 
760
typedef mutexattr_t NPP_mutexattr_t;
761
 
762
#define NPP_MUUEXATTR_INITIALIZER {NPP_MCLASS}
763
#define NPP_mutexattr_default(a)  mutexattr_default(a, NPP_MCLASS)
764
 
765
/* -----------------------------------------------------------------------
766
   PC_mutexattr_t: Priority Ceiling Mutex Attribute
767
   ----------------------------------------------------------------------- */
768
 
769
typedef struct {
770
  mutexattr_t a;
771
  DWORD ceiling;
772
} PC_mutexattr_t;
773
 
774
#define PC_MUTEXATTR_INITIALIZER {{PC_MCLASS},MAX_DWORD}
775
#define PC_mutexattr_default(at,c)  mutexattr_default((at).a, PC_MCLASS); \
776
                                    (at).ceiling = (c)
777
 
778
/* -----------------------------------------------------------------------
779
   SRP_mutexattr_t: Stack Resource Policy Mutex Attribute
780
   ----------------------------------------------------------------------- */
781
 
782
typedef mutexattr_t SRP_mutexattr_t;
783
 
784
#define SRP_MUTEXATTR_INITIALIZER {SRP_MCLASS}
785
#define SRP_mutexattr_default(a)  mutexattr_default(a, SRP_MCLASS)
786
 
787
/* -----------------------------------------------------------------------
788
   NOP_mutexattr_t: No Protocol Mutex Attribute
789
   ----------------------------------------------------------------------- */
790
 
791
typedef mutexattr_t NOP_mutexattr_t;
792
 
793
#define NOP_MUTEXATTR_INITIALIZER {NOP_MCLASS}
794
#define NOP_mutexattr_default(a)  mutexattr_default(a, NOP_MCLASS)
795
 
796
/* -----------------------------------------------------------------------
797
   NOPM_mutexattr_t: No Protocol Multiple lock Mutex Attribute
798
   ----------------------------------------------------------------------- */
799
 
800
typedef mutexattr_t NOPM_mutexattr_t;
801
 
802
#define NOPM_MUTEXATTR_INITIALIZER {NOPM_MCLASS}
803
#define NOPM_mutexattr_default(a)  mutexattr_default(a, NOPM_MCLASS)
804
 
79 pj 805
__END_DECLS
2 pj 806
#endif /* __MODEL_H__ */
807